-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenbinaryproto.sh
More file actions
105 lines (95 loc) · 2.43 KB
/
genbinaryproto.sh
File metadata and controls
105 lines (95 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
# Converting of ascii to binary protos has to happen in bash/linux, because Windows
# insert 0D characters after each 0A in the binary result of protoc, and I did not manage
# to prevent that.
PROTO_PATH="./src/app/proto"
OUTPUT_PATH="./src/assets/data"
ENTITIES="src/entities"
convert() {
local INPUT=$1
local PROTO=$2
local OUTPUT=$3
echo "Converting $INPUT to $OUTPUT ($PROTO)"
protoc --proto_path="$PROTO_PATH" --encode="$PROTO" "src/app/proto/template.proto" < "$INPUT" > "$OUTPUT"
}
merge() {
local INPUT_DIR=$1
local OUTPUT=$2
local NAME=$3
echo -n "" > $OUTPUT
for FILE in $INPUT_DIR/*.ascii
do
local BASE=`basename "$FILE" ".ascii"`
echo -en "\r $BASE "
echo "$NAME {" >> $OUTPUT
while IFS="\n" read -r line;
do
echo " $line" >> $OUTPUT
done < "$FILE"
#cat "$FILE" >> $OUTPUT
echo "}" >> $OUTPUT
echo "" >> $OUTPUT
done
}
process() {
local NAME=$1
local PROTO=$2
echo "converting $NAME..."
merge "$ENTITIES/$NAME" "$ENTITIES/$NAME.ascii" "$NAME"
convert "$ENTITIES/$NAME.ascii" "$PROTO" "$OUTPUT_PATH/$NAME.pb"
}
while getopts "minsaptcu" option; do
case $option in
m)
process "monsters" "dma.MonstersProto"
;;
i)
process "items" "dma.ItemsProto"
;;
n)
process "npcs" "dma.NPCsProto"
;;
s)
process "spells" "dma.SpellsProto"
;;
p)
process "products" "dma.ProductsProto"
;;
a)
process "maps" "dma.MapsProto"
;;
t)
process "tokens" "dma.TokensProto"
;;
u)
process "miniatures" "dma.MiniaturesProto"
;;
c)
process "conditions" "dma.ConditionsProto"
;;
*)
echo "Invalid option, use"
echo " -m: Monsters"
echo " -i: Items"
echo " -n: NPCs"
echo " -s: Spells"
echo " -p: Products"
echo " -a: Maps"
echo " -u: Miniatures"
echo " -c: Conditions"
echo " -t: Tokens"
;;
esac
done
if [ $OPTIND -eq 1 ]; then
echo "No options passed, processing all entities...";
process "monsters" "dma.MonstersProto"
process "items" "dma.ItemsProto"
process "npcs" "dma.NPCsProto"
process "spells" "dma.SpellsProto"
process "products" "dma.ProductsProto"
convert "$ENTITIES/maps.ascii" "dma.MapsProto" "$OUTPUT_PATH/maps.pb"
process "miniatures" "dma.MiniaturesProto"
process "conditions" "dma.ConditionsProto"
fi
echo "protos converted :-)"