-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmake_mapdef.sh
executable file
·175 lines (148 loc) · 3.57 KB
/
make_mapdef.sh
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/sh
# takes one argument: path to .def file
ed_for_def()
{
printf -- "" > "/tmp/def_name"
printf -- "1 0 1" > "/tmp/def_color"
printf -- "" > "/tmp/def_mins"
printf -- "" > "/tmp/def_mins"
printf -- "" > "/tmp/def_maxs"
printf -- "" > "/tmp/def_usage"
printf -- "" > "/tmp/def_model"
{ cat "$1"; echo; } | while read LINE
do
SEG1=$(echo "$LINE" | awk '{ print $1 }')
SEG2=$(echo "$LINE" | awk '{ print $2 }')
KEY="$(echo "$LINE" | awk -F"\"" '{ print $2 }')"
VAL="$(echo "$LINE" | awk -F"\"" '{ print $4 }')"
if [ "$KEY" = "entityDef" ]
then
printf -- "$VAL" > "/tmp/def_name"
fi
if [ "$SEG1" = "entityDef" ]
then
printf -- "$SEG2" > "/tmp/def_name"
fi
if [ "$KEY" = "editor_color" ]
then
printf -- "$VAL" > "/tmp/def_color"
fi
if [ "$KEY" = "editor_mins" ]
then
printf -- "$VAL" > "/tmp/def_mins"
fi
if [ "$KEY" = "editor_maxs" ]
then
printf -- "$VAL" > "/tmp/def_maxs"
fi
if [ "$KEY" = "mins" ]
then
if [ -z "$(cat /tmp/def_mins)" ]
then
printf -- "$VAL" > "/tmp/def_mins"
fi
fi
if [ "$KEY" = "maxs" ]
then
if [ -z "$(cat /tmp/def_maxs)" ]
then
printf -- "$VAL" > "/tmp/def_maxs"
fi
fi
if [ "$KEY" = "editor_usage" ]
then
printf -- "$VAL" > "/tmp/def_usage"
fi
if [ "$KEY" = "netname" ]
then
if [ -z "$(cat /tmp/def_usage)" ]
then
printf -- "$VAL" > "/tmp/def_usage"
fi
fi
if [ "$KEY" = "editor_model" ]
then
printf -- "$VAL" > "/tmp/def_model"
fi
if [ "$KEY" = "model" ]
then
if [ -z "$(cat /tmp/def_model)" ]
then
printf -- "$VAL" > "/tmp/def_model"
fi
fi
if [ "$SEG1" = "}" ]
then
KEY_NAME="$(cat /tmp/def_name)"
KEY_COLOR="$(cat /tmp/def_color)"
KEY_MINS="$(cat /tmp/def_mins)"
KEY_MAXS="$(cat /tmp/def_maxs)"
KEY_USAGE="$(cat /tmp/def_usage)"
KEY_MODEL="$(cat /tmp/def_model)"
printf -- "" > "/tmp/def_name"
printf -- "" > "/tmp/def_color"
printf -- "" > "/tmp/def_mins"
printf -- "" > "/tmp/def_mins"
printf -- "" > "/tmp/def_maxs"
printf -- "" > "/tmp/def_usage"
printf -- "" > "/tmp/def_model"
if [ -z "$KEY_NAME" ]
then
exit 0
fi
if [ -z "$KEY_COLOR" ]
then
exit 0
fi
# no mins/maxs
if [ -z "$KEY_MINS" ]
then
printf "/*QUAKED $KEY_NAME ($KEY_COLOR) ?\n"
else
printf "/*QUAKED $KEY_NAME ($KEY_COLOR) ($KEY_MINS) ($KEY_MAXS)\n"
fi
printf "$KEY_USAGE\n"
# no model
if [ ! -z "$KEY_MODEL" ]
then
printf -- "-------- MODEL FOR RADIANT ONLY - DO NOT SET THIS AS A KEY --------\n"
printf "model=\"$KEY_MODEL\"\n"
fi
printf "*/\n"
fi
done
}
ent_for_mod()
{
# don't bother if we don't have sources
if ! [ -f "./$1/src/Makefile" ]; then
exit
fi
ENT_OUTFILE="./$1/entities.def"
echo '' > "$ENT_OUTFILE"
echo "Scanning for definitions inside the game directory."
find ./$1/src/ -type f \( -iname \*.qc \) | while read EDEF_N; do
echo "... $EDEF_N"
sed -n '/\/*!QUAKED/,/*\//p' $EDEF_N >> "$ENT_OUTFILE"
# fix doxygen markup
sed -i 's/*!QUAKED/*QUAKED/g' "$ENT_OUTFILE"
done;
find ./$1/ -type f \( -iname \*.def \) | while read EDEF_N; do
ed_for_def "$EDEF_N" >> "$ENT_OUTFILE"
done;
cat ./platform/entities.def >> $ENT_OUTFILE
}
# first dump all the general purpose entities
BASE_ENT="./platform/entities.def"
echo '' > "$BASE_ENT"
echo "Scanning for definitions inside the general entity codebase."
find ./src/gs-entbase/ -type f \( -iname \*.qc \) | while read EDEF_N; do
echo "... $EDEF_N"
sed -n '/\/*!QUAKED/,/*\//p' $EDEF_N >> "$BASE_ENT"
# fix doxygen markup
sed -i 's/*!QUAKED/*QUAKED/g' "$BASE_ENT"
done;
# each game gets its own ents + general purpose ents appended at the end
if [ $# -gt 0 ]; then
ent_for_mod $1
fi