Mercurial > hg > batmud > gmap2
annotate tools/makegmaps.php @ 321:44e104b0ae90 gmap2
Change http uri to https.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 07 Mar 2022 00:18:29 +0200 |
parents | f2c031427bb3 |
children | a157aa18ec75 |
rev | line source |
---|---|
17
7444639be2ef
Added script for generating marker data.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 #!/usr/bin/php |
7444639be2ef
Added script for generating marker data.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 <?php |
246
a0a788e1b82e
Prevent non-cli execution of the makegmaps script.
Matti Hamalainen <ccr@tnsp.org>
parents:
242
diff
changeset
|
3 // Prevent non-cli execution |
a0a788e1b82e
Prevent non-cli execution of the makegmaps script.
Matti Hamalainen <ccr@tnsp.org>
parents:
242
diff
changeset
|
4 if (php_sapi_name() != "cli" || !empty($_SERVER["REMOTE_ADDR"])) |
277
023f5d0f627e
Cosmetics and improved error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
259
diff
changeset
|
5 die("You can only run this script as a commandline application.\n"); |
246
a0a788e1b82e
Prevent non-cli execution of the makegmaps script.
Matti Hamalainen <ccr@tnsp.org>
parents:
242
diff
changeset
|
6 |
278
2233bdad4ab5
Die if GD extension is not available as we require it.
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
7 if (!extension_loaded("gd")) |
2233bdad4ab5
Die if GD extension is not available as we require it.
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
8 die("ERROR: The required GD extension to PHP was not found or enabled.\n"); |
2233bdad4ab5
Die if GD extension is not available as we require it.
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
9 |
17
7444639be2ef
Added script for generating marker data.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 |
238 | 11 $gmapsConfig = "config.php"; |
12 | |
13 | |
35 | 14 // Paths and files |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
15 $cfgDefaults = [ |
313 | 16 "binConvert" => [1, "convert", "Path of 'convert' binary from ImageMagick or GraphicsMagick."], |
17 "binMercurial" => [1, "hg", "Path of 'hg' binary of Mercurial DVCS."], | |
18 "binMake" => [1, "make", "Path of 'make', preferably GNU make."], | |
82
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
19 |
313 | 20 "pathMapUtils" => [2, "maputils/", "Path for maputils directory tree."], |
21 "pathImageCache" => [2, "cache/", "Image cache directory."], | |
22 "pathGMap" => [2, "../", "Path to map main directory and marker data files."], | |
23 "pathTileData" => [2, "../tiles/", "Path to map tiles directory structure."], | |
242 | 24 |
313 | 25 "pathRawMaps" => [3, FALSE, "Path to the raw ASCII maps."], |
26 "pathLocFiles" => [3, FALSE, "Path to the location data LOC files."], | |
27 "worldConfig" => [3, FALSE, "Path of the world configuration file 'world.inc.php' from MapUtils."], | |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
28 ]; |
209 | 29 |
30 | |
31 | 31 $fontFile = "./lucon.ttf"; |
238 | 32 |
33 | |
34 // Internal data and settings | |
39 | 35 $tileDim = 256; |
36 | |
212
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
37 $minZoom = 1; |
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
38 $maxZoom = 10; |
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
39 |
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
40 // Font sizes |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
41 $fontSize = []; |
212
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
42 $fontSize[ 8] = 7; |
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
43 $fontSize[16] = 13; |
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
44 $fontSize[32] = 26; |
82
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
45 |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
46 $modes = [ |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
47 "xml" => ["batclient.xml" , 0, 0], |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
48 "json" => ["markers.json" , 0, 0], |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
49 ]; |
17
7444639be2ef
Added script for generating marker data.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
51 $mapPalette = []; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
52 $mapPalette["!"] = [ 204, 255, 255]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
53 $mapPalette["%"] = [ 0, 170, 170]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
54 $mapPalette["-"] = [ 51, 51, 51]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
55 $mapPalette["|"] = [ 51, 51, 51]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
56 $mapPalette["/"] = [ 51, 51, 51]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
57 $mapPalette["+"] = [ 51, 51, 51]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
58 $mapPalette["\\"] = [ 51, 51, 51]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
59 $mapPalette["="] = [ 72, 67, 57]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
60 $mapPalette["@"] = [ 255, 107, 0]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
61 $mapPalette["F"] = [ 0, 136, 0]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
62 $mapPalette["L"] = [ 255, 80, 0]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
63 $mapPalette["S"] = [ 68, 204, 204]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
64 $mapPalette["^"] = [ 113, 130, 146]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
65 $mapPalette["c"] = [ 95, 86, 85]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
66 $mapPalette["f"] = [ 0, 182, 0]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
67 $mapPalette["i"] = [ 255, 255, 255]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
68 $mapPalette["l"] = [ 100, 100, 255]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
69 $mapPalette["s"] = [ 157, 168, 10]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
70 $mapPalette["v"] = [ 34, 221, 34]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
71 $mapPalette["x"] = [ 138, 131, 96]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
72 $mapPalette["z"] = [ 177, 164, 133]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
73 $mapPalette["#"] = [ 79, 54, 69]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
74 $mapPalette["."] = [ 85, 146, 0]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
75 $mapPalette[","] = [ 140, 87, 56]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
76 $mapPalette["?"] = [ 255, 255, 0]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
77 $mapPalette["C"] = [ 153, 153, 0]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
78 $mapPalette["H"] = [ 102, 63, 0]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
79 $mapPalette["R"] = [ 51, 102, 255]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
80 $mapPalette["V"] = [ 255, 51, 0]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
81 $mapPalette["b"] = [ 207, 196, 165]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
82 $mapPalette["d"] = [ 238, 187, 34]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
83 $mapPalette["h"] = [ 153, 102, 0]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
84 $mapPalette["j"] = [ 19, 150, 54]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
85 $mapPalette["r"] = [ 102, 153, 255]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
86 $mapPalette["t"] = [ 97, 195, 162]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
87 $mapPalette["w"] = [ 119, 170, 255]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
88 $mapPalette["y"] = [ 167, 204, 20]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
89 $mapPalette["~"] = [ 51, 51, 170]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
90 $mapPalette["1"] = [ 255, 102, 16]; |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
91 $mapPalette[3] = [ 0, 0, 0]; |
26 | 92 |
17
7444639be2ef
Added script for generating marker data.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
93 |
236 | 94 // |
95 // Helper functions | |
96 // | |
97 function stMakeDir($path) | |
39 | 98 { |
99 if (file_exists($path)) | |
100 return TRUE; | |
101 else | |
102 return mkdir($path, 0755, TRUE); | |
103 } | |
104 | |
105 | |
236 | 106 function stOutputToFile($sfilename, $sdata) |
212
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
107 { |
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
108 if (file_put_contents($sfilename, $sdata, LOCK_EX) === FALSE) |
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
109 die("Error writing to '".$sfilename."'.\n"); |
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
110 } |
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
111 |
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
112 |
238 | 113 function stOutputToJSONFile($qfilename, $qdata) |
114 { | |
115 stOutputToFile($qfilename, json_encode($qdata)); | |
116 } | |
117 | |
118 | |
119 // Calculate worldmap coordinates from continent coordinates | |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
120 function stGetWorldCoords($cname, $xp, $yp, &$xc, &$yc) |
238 | 121 { |
122 global $worldMap, $continentList; | |
123 | |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
124 if (!isset($continentList[$cname])) |
238 | 125 return FALSE; |
126 | |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
127 $xc = $worldMap["ox"] + $continentList[$cname][CTI_XOFFS] + $xp - 1; |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
128 $yc = $worldMap["oy"] + $continentList[$cname][CTI_YOFFS] + $yp - 1; |
238 | 129 return TRUE; |
130 } | |
131 | |
132 | |
133 // Get worldmap coordinates for a given tradelane waypoint | |
134 function stGetWaypointCoords($waypoint, &$xc, &$yc) | |
212
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
135 { |
238 | 136 global $tradelanePoints; |
312
b0decfe4d3e4
Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
137 |
238 | 138 if (!isset($tradelanePoints[$waypoint])) |
139 return FALSE; | |
140 | |
141 return stGetWorldCoords($tradelanePoints[$waypoint][0], | |
142 $tradelanePoints[$waypoint][1], $tradelanePoints[$waypoint][2], $xc, $yc); | |
143 } | |
144 | |
145 | |
146 function stYesNoPrompt($msg, $default = FALSE) | |
147 { | |
148 echo $msg." [".($default ? "Y/n" : "y/N")."]? "; | |
149 $sprompt = strtolower(trim(fgets(STDIN))); | |
150 | |
151 if ($default) | |
152 return ($sprompt == "n"); | |
153 else | |
154 return ($sprompt == "y"); | |
155 } | |
156 | |
157 | |
158 function stInputPrompt($msg, $default = FALSE, $validate = null) | |
159 { | |
160 $valid = FALSE; | |
161 while (!$valid) | |
212
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
162 { |
242 | 163 echo $msg."\n".($default !== FALSE ? "[".$default."]" : "")."> "; |
259
90e8d193cc90
Do not lowercase result strings from text input prompts.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
164 $sprompt = trim(fgets(STDIN)); |
238 | 165 |
166 if ($sprompt == "") | |
167 $sprompt = ($default !== FALSE ? $default : ""); | |
168 | |
169 $valid = !is_callable($validate) || call_user_func($validate, $sprompt); | |
170 } | |
171 return $sprompt; | |
172 } | |
173 | |
174 | |
242 | 175 function stValidateNotEmpty($val) |
176 { | |
177 if ($val == "") | |
178 { | |
179 echo "The value can't be empty.\n"; | |
180 return FALSE; | |
181 } | |
182 else | |
183 return TRUE; | |
184 } | |
185 | |
186 | |
238 | 187 function stValidateURLPrefix($sprefix) |
188 { | |
189 if (substr($sprefix, 0, 7) != "http://" && | |
190 substr($sprefix, 0, 8) != "https://") | |
191 { | |
255
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
192 echo "URL must start with http:// or https://\n"; |
238 | 193 return FALSE; |
194 } | |
195 else | |
196 if (substr($sprefix, -1) != "/") | |
197 { | |
255
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
198 echo "URL must end with /\n"; |
238 | 199 return FALSE; |
200 } | |
201 else | |
202 if (preg_match("/^https?:\/\/[a-zA-Z0-9]+[a-zA-Z0-9\/\.\:\-]*?\//", $sprefix) === FALSE) | |
203 { | |
314
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
204 echo "Malformed URL (or atleast this silly regexp does not accept it.\n"; |
238 | 205 return FALSE; |
206 } | |
207 else | |
208 return TRUE; | |
209 } | |
210 | |
211 | |
212 function stMakeHtAccessFile($urlprefix, $sprefix, $spath) | |
213 { | |
214 global $firstRun; | |
215 $sfile = $sprefix.$spath.".htaccess"; | |
216 if (($firstRun || !file_exists($sfile)) && file_exists($sprefix.$spath."sea.png")) | |
217 { | |
212
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
218 echo "Creating ".$sfile."\n"; |
238 | 219 stOutputToFile($sfile, "ErrorDocument 404 ".$urlprefix.$spath."sea.png\n"); |
212
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
220 } |
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
221 } |
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
222 |
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
223 |
240 | 224 function stQueryConfigItems($level) |
225 { | |
242 | 226 global $cfgDefaults, $cfg; |
240 | 227 foreach ($cfgDefaults as $citem => $cdata) |
228 { | |
229 if ($cdata[0] == $level) | |
242 | 230 { |
231 $def = ($cdata[1] !== FALSE) ? $cdata[1] : $cfg[$citem]; | |
314
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
232 |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
233 $sdone = FALSE; |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
234 while (!$sdone) |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
235 { |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
236 $tmp = $cfg[$citem] = stInputPrompt($cdata[2], $def, "stValidateNotEmpty"); |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
237 |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
238 switch ($cdata[0]) |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
239 { |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
240 case 1: |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
241 exec("which ".escapeshellarg($tmp), $tmpOut, $res); |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
242 if ($res != 0) |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
243 { |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
244 echo "ERROR: Could not find '".$tmp."'. Perhaps it is not in path, or path is wrong.\n"; |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
245 } |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
246 else |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
247 $sdone = TRUE; |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
248 break; |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
249 |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
250 default: |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
251 $sdone = TRUE; |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
252 } |
068ea2f447cc
Add simple check for existence of the utility executables.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
253 } |
242 | 254 } |
240 | 255 } |
256 } | |
257 | |
212
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
258 |
238 | 259 // |
260 // Check for first run | |
261 // | |
262 echo | |
263 "===========================================================\n". | |
264 "GMaps TNG bootstrap and update script by Ggr & Jeskko\n". | |
265 "===========================================================\n"; | |
248 | 266 |
238 | 267 if (file_exists($gmapsConfig)) |
268 { | |
269 $firstRun = FALSE; | |
270 include $gmapsConfig; | |
271 } | |
272 else | |
273 { | |
274 $firstRun = TRUE; | |
275 echo | |
276 "It seems you are running this for the first time ..\n". | |
277 "You will be asked some information this time, which will be\n". | |
257 | 278 "and saved for later use in file '".$gmapsConfig."'\n\n"; |
238 | 279 |
255
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
280 $sdone = FALSE; |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
281 while (!$sdone) |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
282 { |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
283 $cfg["pageBaseURL"] = stInputPrompt( |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
284 "Enter base URL for the map page. For example: http://foobar.com/map/\n", |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
285 FALSE, "stValidateURLPrefix"); |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
286 $sdone = stYesNoPrompt("The page base URL to be used is \"".$cfg["pageBaseURL"]."\", e.g.\n". |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
287 "index.php would be: \"".$cfg["pageBaseURL"]."index.php\"\n". |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
288 "Is this correct?"); |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
289 echo "\n"; |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
290 } |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
291 |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
292 $sdone = FALSE; |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
293 while (!$sdone) |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
294 { |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
295 $cfg["urlTilePrefix"] = stInputPrompt( |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
296 "Enter URL prefix for tiles. For example: http://foobar.com/map/tiles/\n", |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
297 $cfg["pageBaseURL"]."tiles/", "stValidateURLPrefix"); |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
298 $sdone = stYesNoPrompt("The URL prefix to be used is \"".$cfg["urlTilePrefix"]."\", e.g.\n". |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
299 "htaccess to be created would be: \"".$cfg["urlTilePrefix"]."sea.png\"\n". |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
300 "Is this correct?"); |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
301 echo "\n"; |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
302 } |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
303 |
258
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
304 $cfg["gmapsKey"] = stInputPrompt( |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
305 "Enter your Google Maps API key (or leave empty, and edit later)\n", |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
306 FALSE, FALSE); |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
307 |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
308 echo |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
309 "\nNext up are some files and paths. All of them can be safely\n". |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
310 "left to their default values (e.g. just press <enter>) unless\n". |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
311 "you know you want something set differently.\n\n"; |
312
b0decfe4d3e4
Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
312 |
242 | 313 stQueryConfigItems(1); |
314 stQueryConfigItems(2); | |
315 | |
287
695d01a321ec
Fix maps build process to match with new Maputils.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
316 $cfg["pathRawMaps"] = $cfg["pathMapUtils"]."world/"; |
695d01a321ec
Fix maps build process to match with new Maputils.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
317 $cfg["pathLocFiles"] = $cfg["pathMapUtils"]."world/"; |
242 | 318 $cfg["worldConfig"] = $cfg["pathMapUtils"]."www/world.inc.php"; |
319 | |
320 stQueryConfigItems(3); | |
321 | |
238 | 322 |
258
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
323 stOutputToFile($gmapsConfig, "<?php\n\$cfg = ".var_export($cfg, TRUE)."\n?>"); |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
324 |
312
b0decfe4d3e4
Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
325 stOutputToFile($cfg["pathGMap"]."config.inc.php", |
258
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
326 "<?php\n". |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
327 "\$pageBaseURL = \"".$cfg["pageBaseURL"]."\";\n". |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
328 "\$gmapsKey = \"".$cfg["gmapsKey"]."\";\n". |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
329 "\$gmapsVersion = \"3\";\n". |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
330 "?>\n"); |
238 | 331 } |
332 | |
333 | |
334 // | |
335 // Set rest of the paths etc | |
336 // | |
258
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
337 $pathTileData = $cfg["pathGMap"]."tiles/"; |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
338 $worldJS = $cfg["pathGMap"]."world.js"; |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
339 $tradelaneOut = $cfg["pathGMap"]."tradelane.json"; |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
340 $tradelaneOverlay = $cfg["pathGMap"]."trlines.json"; |
287
695d01a321ec
Fix maps build process to match with new Maputils.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
341 $tgtMkLoc = "bin/mkloc"; |
695d01a321ec
Fix maps build process to match with new Maputils.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
342 $binMkLoc = $cfg["pathMapUtils"].$tgtMkLoc; |
238 | 343 $rawSuffix = ".new"; |
344 $rawAltSuffix = ".map"; | |
345 | |
248 | 346 /* |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
347 foreach (["." => 0600, $cfg["pathMapUtils"] => 0600] as $spath => $sperm) |
248 | 348 { |
349 if (chmod($spath, $sperm) === FALSE) | |
350 echo "Could not set permissions for '".$spath."'.\n"); | |
351 } | |
352 */ | |
353 | |
238 | 354 |
355 // | |
356 // Create htaccess files | |
357 // | |
240 | 358 stMakeHtAccessFile($cfg["urlTilePrefix"], $cfg["pathTileData"], ""); |
238 | 359 for ($i = $minZoom; $i <= $maxZoom; $i++) |
240 | 360 stMakeHtAccessFile($cfg["urlTilePrefix"], $cfg["pathTileData"], $i."/"); |
238 | 361 |
362 | |
237 | 363 // |
364 // Build maputils and fetch latest map data | |
365 // | |
238 | 366 if (!file_exists($cfg["pathMapUtils"])) |
82
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
367 { |
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
368 // If maputils does not exist, clone the repository |
321 | 369 $tmp = $cfg["binMercurial"]." clone https://tnsp.org/hg/batmud/maputils/ ".escapeshellarg($cfg["pathMapUtils"]); |
82
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
370 echo "* $tmp\n"; |
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
371 passthru($tmp) == 0 or die("Error executing: ".$tmp."\n"); |
84
c3cd3bfb7a77
Automatically clone and/or update th-libs, a requirement for the maputils.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
372 |
c3cd3bfb7a77
Automatically clone and/or update th-libs, a requirement for the maputils.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
373 // Clone th-libs |
310
63eb4661d13c
Use https URL for tnsp.org Mercurial repos.
Matti Hamalainen <ccr@tnsp.org>
parents:
307
diff
changeset
|
374 $tmp = $cfg["binMercurial"]." clone https://tnsp.org/hg/th-libs/ ".escapeshellarg($cfg["pathMapUtils"]."th-libs/"); |
84
c3cd3bfb7a77
Automatically clone and/or update th-libs, a requirement for the maputils.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
375 echo "* $tmp\n"; |
c3cd3bfb7a77
Automatically clone and/or update th-libs, a requirement for the maputils.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
376 passthru($tmp) == 0 or die("Error executing: ".$tmp."\n"); |
82
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
377 } |
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
378 else |
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
379 { |
238 | 380 $tmp = "cd ".escapeshellarg($cfg["pathMapUtils"])." && ".$cfg["binMercurial"]." pull && ".$cfg["binMercurial"]." update"; |
84
c3cd3bfb7a77
Automatically clone and/or update th-libs, a requirement for the maputils.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
381 echo "* $tmp\n"; |
c3cd3bfb7a77
Automatically clone and/or update th-libs, a requirement for the maputils.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
382 passthru($tmp) == 0 or die("Error executing: ".$tmp."\n"); |
c3cd3bfb7a77
Automatically clone and/or update th-libs, a requirement for the maputils.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
383 |
238 | 384 $tmp = "cd ".escapeshellarg($cfg["pathMapUtils"]."th-libs/")." && ".$cfg["binMercurial"]." pull && ".$cfg["binMercurial"]." update"; |
82
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
385 echo "* $tmp\n"; |
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
386 passthru($tmp) == 0 or die("Error executing: ".$tmp."\n"); |
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
387 } |
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
388 |
287
695d01a321ec
Fix maps build process to match with new Maputils.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
389 $tmp = "cd ".escapeshellarg($cfg["pathMapUtils"])." && ".$cfg["binMake"]." ".escapeshellarg($tgtMkLoc); |
87
4e7d0bc500c4
Actually build the maputils tools.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
390 echo "* $tmp\n"; |
4e7d0bc500c4
Actually build the maputils tools.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
391 passthru($tmp) == 0 or die("Error executing: ".$tmp."\n"); |
4e7d0bc500c4
Actually build the maputils tools.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
392 |
4e7d0bc500c4
Actually build the maputils tools.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
393 |
214
00e673963d35
More cleanups and improvements in building script.
Matti Hamalainen <ccr@tnsp.org>
parents:
212
diff
changeset
|
394 if (!file_exists($binMkLoc)) |
00e673963d35
More cleanups and improvements in building script.
Matti Hamalainen <ccr@tnsp.org>
parents:
212
diff
changeset
|
395 die($binMkLoc." not found. Maputils package not built, or some other error occured.\n"); |
82
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
396 |
238 | 397 $tmp = "cd ".escapeshellarg($cfg["pathMapUtils"])." && ".$cfg["binMake"]; |
82
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
398 passthru($tmp) == 0 or die("Error executing: ".$tmp."\n"); |
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
399 |
240 | 400 $tmp = "cd ".escapeshellarg($cfg["pathRawMaps"])." && ".$cfg["binMake"]." fetch 2> /dev/null"; |
238 | 401 passthru($tmp) == 0 or die("Error executing: ".$tmp."\n"); |
86
2ea7fe9f9c1d
Include configuration after we have updated/cloned the maputils repo.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
402 |
2ea7fe9f9c1d
Include configuration after we have updated/cloned the maputils repo.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
403 |
237 | 404 // |
312
b0decfe4d3e4
Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
405 // Include continent and tradelane configuration |
251
cd489f20cf9d
Move check for worldconfig later, we need to fetch maputils & co before that.
Matti Hamalainen <ccr@tnsp.org>
parents:
249
diff
changeset
|
406 // |
cd489f20cf9d
Move check for worldconfig later, we need to fetch maputils & co before that.
Matti Hamalainen <ccr@tnsp.org>
parents:
249
diff
changeset
|
407 if (!file_exists($cfg["worldConfig"])) |
cd489f20cf9d
Move check for worldconfig later, we need to fetch maputils & co before that.
Matti Hamalainen <ccr@tnsp.org>
parents:
249
diff
changeset
|
408 die("Required continent/tradelane configuration file '".$cfg["worldConfig"]."' not found.\n"); |
cd489f20cf9d
Move check for worldconfig later, we need to fetch maputils & co before that.
Matti Hamalainen <ccr@tnsp.org>
parents:
249
diff
changeset
|
409 |
cd489f20cf9d
Move check for worldconfig later, we need to fetch maputils & co before that.
Matti Hamalainen <ccr@tnsp.org>
parents:
249
diff
changeset
|
410 require $cfg["worldConfig"]; |
cd489f20cf9d
Move check for worldconfig later, we need to fetch maputils & co before that.
Matti Hamalainen <ccr@tnsp.org>
parents:
249
diff
changeset
|
411 |
cd489f20cf9d
Move check for worldconfig later, we need to fetch maputils & co before that.
Matti Hamalainen <ccr@tnsp.org>
parents:
249
diff
changeset
|
412 |
cd489f20cf9d
Move check for worldconfig later, we need to fetch maputils & co before that.
Matti Hamalainen <ccr@tnsp.org>
parents:
249
diff
changeset
|
413 // |
237 | 414 // Generate continents JavasScript data file |
415 /// | |
227
7c1cd542b2d2
Rename continents.js to world.js, and add global offset data in.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
416 echo "* Generating $worldJS ...\n"; |
7c1cd542b2d2
Rename continents.js to world.js, and add global offset data in.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
417 $str = "var pmapWorld = {"; |
7c1cd542b2d2
Rename continents.js to world.js, and add global offset data in.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
418 foreach ($worldMap as $wkey => $wval) |
7c1cd542b2d2
Rename continents.js to world.js, and add global offset data in.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
419 $str .= "\"".$wkey."\": ".$wval.", "; |
7c1cd542b2d2
Rename continents.js to world.js, and add global offset data in.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
420 $str .= "};\n"; |
7c1cd542b2d2
Rename continents.js to world.js, and add global offset data in.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
421 |
7c1cd542b2d2
Rename continents.js to world.js, and add global offset data in.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
422 $str .= "var pmapContinents =\n[\n"; |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
423 foreach ($continentList as $cname => $cdata) |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
424 if ($cdata[CTI_HAS_MAP] && $cdata[CTI_REG_CONT]) |
77
f278e5e08f55
Add continents.js generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
425 { |
227
7c1cd542b2d2
Rename continents.js to world.js, and add global offset data in.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
426 $str .= sprintf(" [%-15s, %5d, %5d, %5d, %5d, %5d, %5d],\n", |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
427 "\"".$cdata[CTI_NAME]."\"", |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
428 $cdata[CTI_XOFFS], |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
429 $cdata[CTI_YOFFS], |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
430 $cdata[CTI_XOFFS] + $cdata[CTI_WIDTH] - 1, |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
431 $cdata[CTI_YOFFS] + $cdata[CTI_HEIGHT] - 1, |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
432 $cdata[CTI_WIDTH], $cdata[CTI_HEIGHT]); |
77
f278e5e08f55
Add continents.js generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
433 } |
f278e5e08f55
Add continents.js generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
434 $str .= "];\n"; |
f278e5e08f55
Add continents.js generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
435 |
236 | 436 stOutputToFile($worldJS, $str); |
77
f278e5e08f55
Add continents.js generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
437 |
f278e5e08f55
Add continents.js generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
438 |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
439 |
237 | 440 // |
441 // Generate marker files from LOC data | |
442 /// | |
30 | 443 echo "Converting location data from LOC files to GMaps markers...\n"; |
119
2f2937e8921f
More work on sanitizing the overlays generation etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
444 |
2f2937e8921f
More work on sanitizing the overlays generation etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
445 foreach ($modes as $mode => $mdata) |
64 | 446 { |
258
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
447 $tmp = escapeshellcmd($binMkLoc)." -v -o ".escapeshellarg($cfg["pathGMap"].$mdata[0])." -G ".$mode." "; |
119
2f2937e8921f
More work on sanitizing the overlays generation etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
448 |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
449 foreach ($continentList as $cname => $cdata) |
119
2f2937e8921f
More work on sanitizing the overlays generation etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
450 { |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
451 if ($cdata[CTI_HAS_MAP] && $cdata[CTI_REG_CONT]) |
119
2f2937e8921f
More work on sanitizing the overlays generation etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
452 { |
2f2937e8921f
More work on sanitizing the overlays generation etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
453 // has a map |
2f2937e8921f
More work on sanitizing the overlays generation etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
454 $tmp .= |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
455 "-l ".escapeshellarg($cfg["pathLocFiles"].$cname.".loc")." ". |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
456 "-c ".escapeshellarg($cdata[CTI_NAME])." ". |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
457 "-x ".escapeshellarg($worldMap["ox"] + $cdata[CTI_XOFFS] + $mdata[1])." ". |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
458 "-y ".escapeshellarg($worldMap["oy"] + $cdata[CTI_YOFFS] + $mdata[2])." "; |
119
2f2937e8921f
More work on sanitizing the overlays generation etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
459 } |
17
7444639be2ef
Added script for generating marker data.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
460 } |
7444639be2ef
Added script for generating marker data.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
461 |
24 | 462 passthru($tmp) == 0 or die("Error executing: ".$tmp."\n"); |
17
7444639be2ef
Added script for generating marker data.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
463 } |
7444639be2ef
Added script for generating marker data.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
464 |
24 | 465 |
237 | 466 // |
467 // Export tradelane waypoint data | |
468 // | |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
469 if (!isset($tradelanePoints)) |
242 | 470 die("PHP array \$tradelanePoints not set, '".$cfg["worldConfig"]."' is old or incompatible.\n"); |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
471 |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
472 echo "\nCreating tradelane waypoint data '".$tradelaneOut."' ...\n"; |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
473 |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
474 $qdata = []; |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
475 |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
476 foreach ($tradelanePoints as $tname => $tlane) |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
477 { |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
478 $html = "<b>TRADELANE WPT</b><br>".htmlentities($tname); |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
479 |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
480 if (!stGetWorldCoords($tlane[0], $tlane[1], $tlane[2], $xc, $yc)) |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
481 die("Invalid tradelane waypoint '".$tname."', continent '".$tlane[0]."' not defined.\n"); |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
482 |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
483 $qdata[] = [ |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
484 "x" => $xc, |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
485 "y" => $yc, |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
486 "name" => $tname, |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
487 "html" => $html, |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
488 "continent" => "", |
192
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
489 "type" => "tradelane", |
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
490 "flags" => 0, |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
491 ]; |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
492 } |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
493 |
236 | 494 stOutputToJSONFile($tradelaneOut, $qdata); |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
495 |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
496 |
237 | 497 // |
498 // Export tradelane polyline data | |
499 // | |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
500 echo "\nCreating tradelane polyline data '".$tradelaneOverlay."' ...\n"; |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
501 if (!isset($tradelaneDefs)) |
240 | 502 die("PHP array \$tradelaneDefs not set, '".$cfg["worldConfig"]."' is old or incompatible.\n"); |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
503 |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
504 $qdata = []; |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
505 foreach ($tradelaneDefs as $index => $points) |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
506 { |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
507 $qline = []; |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
508 |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
509 foreach ($points as $point) |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
510 { |
238 | 511 if (!stGetWaypointCoords($point, $xc, $yc)) |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
512 die("Invalid tradelane definition #$index: waypoint '".$point."' not defined.\n"); |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
513 |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
514 $qline[] = [ |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
515 "x" => $xc, |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
516 "y" => $yc |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
517 ]; |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
518 } |
312
b0decfe4d3e4
Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
519 |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
520 $qdata[] = $qline; |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
521 } |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
522 |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
523 |
236 | 524 stOutputToJSONFile($tradelaneOverlay, $qdata); |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
525 |
237 | 526 |
527 // | |
528 // Generate PNG maps | |
529 // | |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
530 function makeMap($inFilename, $outFilename, $zlevel, $cdata) |
26 | 531 { |
212
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
532 global $mapPalette, $fontFile, $fontSize; |
30 | 533 |
534 // Try to open input file | |
277
023f5d0f627e
Cosmetics and improved error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
259
diff
changeset
|
535 if (($file = @fopen($inFilename, "r")) === FALSE) |
64 | 536 { |
30 | 537 echo "Could not open input '".$inFilename."'\n"; |
538 return FALSE; | |
539 } | |
540 | |
35 | 541 // Derp |
30 | 542 $zoom = pow(2, $zlevel - 1); |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
543 $width = $cdata[CTI_WIDTH]; |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
544 $height = $cdata[CTI_HEIGHT]; |
30 | 545 |
546 // Create image and assign colors | |
277
023f5d0f627e
Cosmetics and improved error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
259
diff
changeset
|
547 if (($im = imagecreate($width*$zoom, $height*$zoom)) === FALSE) |
64 | 548 { |
35 | 549 echo "Could not allocate image data for '".$inFilename."'\n"; |
550 return FALSE; | |
551 } | |
552 | |
26 | 553 $black = imagecolorallocate($im, 0, 0, 0); |
30 | 554 foreach ($mapPalette as $id => $val) |
26 | 555 $colors[$id] = imagecolorallocate($im, $val[0], $val[1], $val[2]); |
556 | |
557 imagefilledrectangle($im, 0, 0, $width*$zoom, $height*$zoom, $black); | |
30 | 558 |
559 // Read input raw | |
26 | 560 $y = 0; |
312
b0decfe4d3e4
Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
561 while ($y < $height && ($data = fgets($file, 4096)) !== FALSE) |
26 | 562 { |
563 for ($x = 0; $x < $width; $x++) | |
564 { | |
64 | 565 if ($zoom == 1) |
566 { | |
26 | 567 imagesetpixel($im, $x, $y, $colors[$data[$x]]); |
109 | 568 } |
312
b0decfe4d3e4
Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
569 else |
64 | 570 if ($zoom < 6) |
571 { | |
26 | 572 imagefilledrectangle($im, $x*$zoom, $y*$zoom, ($x+1)*$zoom-1, ($y+1)*$zoom-1, $colors[$data[$x]]); |
109 | 573 } |
574 else | |
575 { | |
52 | 576 imagettftext($im, |
225 | 577 $fontSize[$zoom], 0, |
578 $x*$zoom + $fontSize[$zoom]/4, | |
579 $y*$zoom + $fontSize[$zoom], | |
26 | 580 $colors[$data[$x]], |
30 | 581 $fontFile, |
26 | 582 $data[$x]); |
583 } | |
584 } | |
585 $y++; | |
31 | 586 echo "."; |
30 | 587 } |
588 | |
64 | 589 if (imagepng($im, $outFilename) === FALSE) |
590 { | |
30 | 591 echo "Error creating '".$outFilename."'\n"; |
592 imagedestroy($im); | |
593 return FALSE; | |
26 | 594 } |
595 | |
30 | 596 imagedestroy($im); |
597 return TRUE; | |
598 } | |
599 | |
277
023f5d0f627e
Cosmetics and improved error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
259
diff
changeset
|
600 if (!stMakeDir($cfg["pathImageCache"])) |
023f5d0f627e
Cosmetics and improved error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
259
diff
changeset
|
601 { |
240 | 602 die("Failed to create cache directory '".$cfg["pathImageCache"]."'!\n"); |
41 | 603 } |
26 | 604 |
30 | 605 echo "Generating basic map data...\n"; |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
606 foreach ($continentList as $cname => $cdata) |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
607 if ($cdata[CTI_HAS_MAP] && $cdata[CTI_REG_CONT]) |
30 | 608 { |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
609 $inFilename = $cfg["pathRawMaps"].$cname.$rawSuffix; |
64 | 610 if (!file_exists($inFilename)) |
611 { | |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
612 $inFilename = $cfg["pathRawMaps"].$cname.$rawAltSuffix; |
82
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
613 if (!file_exists($inFilename)) |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
614 die("Required file '".$cfg["pathRawMaps"].$cname."(".$rawSuffix."|".$rawAltSuffix.")' does not exist.\n"); |
41 | 615 } |
35 | 616 $inMtime = filemtime($inFilename); |
312
b0decfe4d3e4
Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
617 |
64 | 618 for ($zoom = 1; $zoom <= 5; $zoom++) |
619 { | |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
620 $outFilename = $cfg["pathImageCache"].$cname."_".($zoom + 4).".png"; |
41 | 621 $outMtime = file_exists($outFilename) ? filemtime($outFilename) : -1; |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
622 echo "- ".$cname." (".$cdata[CTI_NAME]."): "; |
65 | 623 if ($inMtime > $outMtime) |
624 { | |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
625 $res = makeMap($inFilename, $outFilename, $zoom, $cdata); |
35 | 626 echo ($res ? "OK" : "FAIL")."\n"; |
109 | 627 } |
628 else | |
35 | 629 echo "SKIPPED\n"; |
630 } | |
26 | 631 } |
632 | |
633 | |
30 | 634 /* |
33 | 635 * Generate small versions |
636 */ | |
637 echo "\nGenerating scaled small map data...\n"; | |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
638 $mapScales = ["50", "25", "12.5", "6.25", "3.125"]; |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
639 foreach ($continentList as $cname => &$cdata) |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
640 if ($cdata[CTI_HAS_MAP] && $cdata[CTI_REG_CONT]) |
33 | 641 { |
642 $n = count($mapScales); | |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
643 $inFilename = $cfg["pathImageCache"].$cname."_".$n.".png"; |
64 | 644 if (!file_exists($inFilename)) |
645 { | |
35 | 646 die("Required file '".$inFilename."' does not exist.\n"); |
647 } | |
648 $inMtime = filemtime($inFilename); | |
33 | 649 |
64 | 650 foreach ($mapScales as $scale) |
651 { | |
33 | 652 $n--; |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
653 $outFilename = $cfg["pathImageCache"].$cname."_".$n.".png"; |
35 | 654 $outMtime = file_exists($outFilename) ? filemtime($outFilename) : -1; |
655 | |
656 echo "* ".$inFilename." -> ".$outFilename.": "; | |
65 | 657 if ($inMtime > $outMtime) |
658 { | |
280
632e61498905
Do not use paletted conversion for intermediate files. It seems to make
Matti Hamalainen <ccr@tnsp.org>
parents:
279
diff
changeset
|
659 $tmp = escapeshellcmd($cfg["binConvert"])." ". |
632e61498905
Do not use paletted conversion for intermediate files. It seems to make
Matti Hamalainen <ccr@tnsp.org>
parents:
279
diff
changeset
|
660 escapeshellarg($inFilename)." ". |
632e61498905
Do not use paletted conversion for intermediate files. It seems to make
Matti Hamalainen <ccr@tnsp.org>
parents:
279
diff
changeset
|
661 "-scale ".escapeshellarg($scale."%")." ". |
632e61498905
Do not use paletted conversion for intermediate files. It seems to make
Matti Hamalainen <ccr@tnsp.org>
parents:
279
diff
changeset
|
662 //"-type Palette ". |
632e61498905
Do not use paletted conversion for intermediate files. It seems to make
Matti Hamalainen <ccr@tnsp.org>
parents:
279
diff
changeset
|
663 escapeshellarg($outFilename); |
632e61498905
Do not use paletted conversion for intermediate files. It seems to make
Matti Hamalainen <ccr@tnsp.org>
parents:
279
diff
changeset
|
664 |
35 | 665 passthru($tmp) == 0 or die("Error executing: ".$tmp."\n"); |
666 echo "OK\n"; | |
109 | 667 } |
668 else | |
35 | 669 echo "SKIPPED\n"; |
33 | 670 } |
671 } | |
672 | |
673 | |
39 | 674 /* |
675 * Build tiles | |
676 */ | |
64 | 677 function createTile($scale, $zoom, $x, $y, $mapData, $mapMtime) |
678 { | |
241 | 679 global $continentList, $worldMap, $cfg, $tileDim; |
39 | 680 |
240 | 681 $outFilename = $cfg["pathTileData"].$zoom."/".$y."/".$x.".png"; |
64 | 682 if (file_exists($outFilename) && filemtime($outFilename) >= $mapMtime) |
683 { | |
39 | 684 echo "!"; |
685 return; | |
686 } | |
687 | |
241 | 688 $drawn = false; |
52 | 689 $im = false; |
39 | 690 |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
691 foreach ($continentList as $cname => &$cdata) |
64 | 692 { |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
693 if (!$cdata[CTI_HAS_MAP] || !$cdata[CTI_REG_CONT]) |
229
ccd79b97dc52
Don't attempt to generate tile data from non-existent virtual continents.
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
694 continue; |
312
b0decfe4d3e4
Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
695 |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
696 $cx = $cdata[CTI_XOFFS] + $worldMap["ox"]; |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
697 $cy = $cdata[CTI_YOFFS] + $worldMap["oy"]; |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
698 $cw = $cdata[CTI_WIDTH]; |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
699 $ch = $cdata[CTI_HEIGHT]; |
312
b0decfe4d3e4
Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
700 |
39 | 701 $tx = -($cx*$scale - $x*$tileDim); |
702 $ty = -($cy*$scale - $y*$tileDim); | |
703 | |
312
b0decfe4d3e4
Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
704 if (($cx + $cw)*$scale > $x*$tileDim && |
52 | 705 ($cy + $ch)*$scale > $y*$tileDim && |
312
b0decfe4d3e4
Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
706 ($cx * $scale) < ($x+1)*$tileDim && |
65 | 707 ($cy * $scale) < ($y+1)*$tileDim) |
708 { | |
241 | 709 if (!$drawn) |
65 | 710 { |
711 if ($zoom < 9) | |
712 { | |
279
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
713 $im = imagecreate($tileDim, $tileDim); |
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
714 if ($im === false || get_resource_type($im) != "gd") |
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
715 die("\nCould not create GD image resource open dim=".$tileDim. |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
716 " for zoom=".$zoom.", continent=".$cname."\n"); |
279
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
717 |
39 | 718 $sea = imagecolorallocate($im, 51, 51, 170); |
719 imagefilledrectangle($im, 0, 0, $tileDim, $tileDim, $sea); | |
109 | 720 } |
721 else | |
722 { | |
240 | 723 $inFilename = $cfg["pathTileData"].$zoom."/sea.png"; |
279
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
724 $im = imagecreatefrompng($inFilename); |
52 | 725 if ($im === false) |
726 die("\nCould not open '".$inFilename."'.\n"); | |
279
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
727 |
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
728 if (get_resource_type($im) != "gd") |
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
729 die("Not an GD image resource ".$im." in '".$inFilename."'\n"); |
52 | 730 } |
39 | 731 } |
732 | |
52 | 733 $dx = $tileDim; |
734 $dy = $tileDim; | |
735 $xx = 0; | |
736 $yy = 0; | |
39 | 737 |
64 | 738 if ($tx < 0) |
739 { | |
59 | 740 $xx -= $tx; |
741 $dx += $tx+1; | |
742 $tx = 0; | |
39 | 743 } |
744 | |
64 | 745 if ($ty < 0) |
746 { | |
59 | 747 $yy -= $ty; |
748 $dy += $ty+1; | |
749 $ty = 0; | |
39 | 750 } |
751 | |
64 | 752 if ($dx > $cw*$scale-$tx) |
52 | 753 $dx = $cw*$scale - $tx; |
39 | 754 |
64 | 755 if ($dy > $ch*$scale-$ty) |
52 | 756 $dy = $ch*$scale - $ty; |
39 | 757 |
64 | 758 if ($im !== false) |
759 { | |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
760 imagecopy($im, $mapData[$cname], $xx, $yy, $tx, $ty, $dx, $dy); |
241 | 761 $drawn = TRUE; |
52 | 762 } |
39 | 763 } |
764 } | |
765 | |
241 | 766 if ($drawn) |
64 | 767 { |
240 | 768 stMakeDir($cfg["pathTileData"].$zoom."/".$y, 0755); |
52 | 769 imagepng($im, $outFilename); |
770 imagedestroy($im); | |
39 | 771 } |
312
b0decfe4d3e4
Delete trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
772 /* |
52 | 773 else { |
774 if (file_exists($outFilename)) | |
775 unlink($outFilename); | |
776 | |
240 | 777 symlink($cfg["pathTileData"]."sea.png", $outFilename); |
52 | 778 echo "+"; |
779 } | |
780 */ | |
39 | 781 } |
782 | |
783 | |
128 | 784 echo "\nBuilding tiles data for all zoom levels ...\n"; |
785 | |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
786 $mapData = []; |
39 | 787 |
212
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
788 for ($zoom = $minZoom; $zoom <= $maxZoom; $zoom++) |
65 | 789 { |
39 | 790 $zoom2 = $zoom - 1; |
791 $scale = pow(2, $zoom2 - 5); | |
792 | |
240 | 793 stMakeDir($cfg["pathTileData"].$zoom); |
39 | 794 |
240 | 795 echo "\nZoom level $zoom: "; |
39 | 796 |
797 $mx = ceil(($worldMap["w"] * $scale) / $tileDim); | |
798 $my = ceil(($worldMap["h"] * $scale) / $tileDim); | |
799 $mw = ceil( $worldMap["w"] * $scale); | |
800 $mh = ceil( $worldMap["h"] * $scale); | |
801 | |
802 $mapMtime = -1; | |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
803 foreach ($continentList as $cname => &$cdata) |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
804 if ($cdata[CTI_HAS_MAP] && $cdata[CTI_REG_CONT]) |
64 | 805 { |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
806 $mapFile = $cfg["pathImageCache"].$cname."_".$zoom2.".png"; |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
807 $mapData[$cname] = imagecreatefrompng($mapFile); |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
808 if ($mapData[$cname] === FALSE || |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
809 get_resource_type($mapData[$cname]) != "gd") |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
810 die("Not an GD image resource ".$mapData[$cname]." in '".$mapFile."'\n"); |
279
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
811 |
39 | 812 $tmp = filemtime($mapFile); |
813 if ($tmp > $mapMtime) | |
814 $mapMtime = $tmp; | |
815 } | |
816 | |
64 | 817 for ($y = 0; $y < $mx; $y++) |
818 { | |
39 | 819 for ($x = 0; $x < $my; $x++) |
820 createTile($scale, $zoom, $x, $y, $mapData, $mapMtime); | |
821 echo "."; | |
822 } | |
823 echo "\n"; | |
824 | |
64 | 825 // Free image data for each continent |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
826 foreach ($continentList as $cname => &$cdata) |
109 | 827 { |
311
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
828 if ($cdata[CTI_HAS_MAP] && $cdata[CTI_REG_CONT]) |
3a67c8425d1b
Clean up the code a bit, use the CTI_* constants defined in
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
829 imagedestroy($mapData[$cname]); |
109 | 830 } |
39 | 831 } |
832 | |
17
7444639be2ef
Added script for generating marker data.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
833 ?> |