Mercurial > hg > batmud > gmap2
comparison tools/makegmaps.php @ 324:b0c2f11e60fa gmap2 tip
Canonize boolean values to true/false instead of mixing TRUE/FALSE in.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 12 Mar 2023 14:58:57 +0200 |
parents | a157aa18ec75 |
children |
comparison
equal
deleted
inserted
replaced
323:a157aa18ec75 | 324:b0c2f11e60fa |
---|---|
20 "pathMapUtils" => [2, "maputils/", "Path for maputils directory tree."], | 20 "pathMapUtils" => [2, "maputils/", "Path for maputils directory tree."], |
21 "pathImageCache" => [2, "cache/", "Image cache directory."], | 21 "pathImageCache" => [2, "cache/", "Image cache directory."], |
22 "pathGMap" => [2, "../", "Path to map main directory and marker data files."], | 22 "pathGMap" => [2, "../", "Path to map main directory and marker data files."], |
23 "pathTileData" => [2, "../tiles/", "Path to map tiles directory structure."], | 23 "pathTileData" => [2, "../tiles/", "Path to map tiles directory structure."], |
24 | 24 |
25 "pathRawMaps" => [3, FALSE, "Path to the raw ASCII maps."], | 25 "pathRawMaps" => [3, false, "Path to the raw ASCII maps."], |
26 "pathLocFiles" => [3, FALSE, "Path to the location data LOC files."], | 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."], | 27 "worldConfig" => [3, false, "Path of the world configuration file 'world.inc.php' from MapUtils."], |
28 ]; | 28 ]; |
29 | 29 |
30 | 30 |
31 $fontFile = "./lucon.ttf"; | 31 $fontFile = "./lucon.ttf"; |
32 | 32 |
95 // Helper functions | 95 // Helper functions |
96 // | 96 // |
97 function stMakeDir($path) | 97 function stMakeDir($path) |
98 { | 98 { |
99 if (file_exists($path)) | 99 if (file_exists($path)) |
100 return TRUE; | 100 return true; |
101 else | 101 else |
102 return mkdir($path, 0755, TRUE); | 102 return mkdir($path, 0755, true); |
103 } | 103 } |
104 | 104 |
105 | 105 |
106 function stOutputToFile($sfilename, $sdata) | 106 function stOutputToFile($sfilename, $sdata) |
107 { | 107 { |
108 if (file_put_contents($sfilename, $sdata, LOCK_EX) === FALSE) | 108 if (file_put_contents($sfilename, $sdata, LOCK_EX) === false) |
109 die("Error writing to '".$sfilename."'.\n"); | 109 die("Error writing to '".$sfilename."'.\n"); |
110 } | 110 } |
111 | 111 |
112 | 112 |
113 function stOutputToJSONFile($qfilename, $qdata) | 113 function stOutputToJSONFile($qfilename, $qdata) |
120 function stGetWorldCoords($cname, $xp, $yp, &$xc, &$yc) | 120 function stGetWorldCoords($cname, $xp, $yp, &$xc, &$yc) |
121 { | 121 { |
122 global $worldMap, $continentList; | 122 global $worldMap, $continentList; |
123 | 123 |
124 if (!isset($continentList[$cname])) | 124 if (!isset($continentList[$cname])) |
125 return FALSE; | 125 return false; |
126 | 126 |
127 $xc = $worldMap["ox"] + $continentList[$cname][CTI_XOFFS] + $xp - 1; | 127 $xc = $worldMap["ox"] + $continentList[$cname][CTI_XOFFS] + $xp - 1; |
128 $yc = $worldMap["oy"] + $continentList[$cname][CTI_YOFFS] + $yp - 1; | 128 $yc = $worldMap["oy"] + $continentList[$cname][CTI_YOFFS] + $yp - 1; |
129 return TRUE; | 129 return true; |
130 } | 130 } |
131 | 131 |
132 | 132 |
133 // Get worldmap coordinates for a given tradelane waypoint | 133 // Get worldmap coordinates for a given tradelane waypoint |
134 function stGetWaypointCoords($waypoint, &$xc, &$yc) | 134 function stGetWaypointCoords($waypoint, &$xc, &$yc) |
135 { | 135 { |
136 global $tradelanePoints; | 136 global $tradelanePoints; |
137 | 137 |
138 if (!isset($tradelanePoints[$waypoint])) | 138 if (!isset($tradelanePoints[$waypoint])) |
139 return FALSE; | 139 return false; |
140 | 140 |
141 return stGetWorldCoords($tradelanePoints[$waypoint][0], | 141 return stGetWorldCoords($tradelanePoints[$waypoint][0], |
142 $tradelanePoints[$waypoint][1], $tradelanePoints[$waypoint][2], $xc, $yc); | 142 $tradelanePoints[$waypoint][1], $tradelanePoints[$waypoint][2], $xc, $yc); |
143 } | 143 } |
144 | 144 |
145 | 145 |
146 function stYesNoPrompt($msg, $default = FALSE) | 146 function stYesNoPrompt($msg, $default = false) |
147 { | 147 { |
148 echo $msg." [".($default ? "Y/n" : "y/N")."]? "; | 148 echo $msg." [".($default ? "Y/n" : "y/N")."]? "; |
149 $sprompt = strtolower(trim(fgets(STDIN))); | 149 $sprompt = strtolower(trim(fgets(STDIN))); |
150 | 150 |
151 if ($default) | 151 if ($default) |
153 else | 153 else |
154 return ($sprompt == "y"); | 154 return ($sprompt == "y"); |
155 } | 155 } |
156 | 156 |
157 | 157 |
158 function stInputPrompt($msg, $default = FALSE, $validate = null) | 158 function stInputPrompt($msg, $default = false, $validate = null) |
159 { | 159 { |
160 $valid = FALSE; | 160 $valid = false; |
161 while (!$valid) | 161 while (!$valid) |
162 { | 162 { |
163 echo $msg."\n".($default !== FALSE ? "[".$default."]" : "")."> "; | 163 echo $msg."\n".($default !== false ? "[".$default."]" : "")."> "; |
164 $sprompt = trim(fgets(STDIN)); | 164 $sprompt = trim(fgets(STDIN)); |
165 | 165 |
166 if ($sprompt == "") | 166 if ($sprompt == "") |
167 $sprompt = ($default !== FALSE ? $default : ""); | 167 $sprompt = ($default !== false ? $default : ""); |
168 | 168 |
169 $valid = !is_callable($validate) || call_user_func($validate, $sprompt); | 169 $valid = !is_callable($validate) || call_user_func($validate, $sprompt); |
170 } | 170 } |
171 return $sprompt; | 171 return $sprompt; |
172 } | 172 } |
175 function stValidateNotEmpty($val) | 175 function stValidateNotEmpty($val) |
176 { | 176 { |
177 if ($val == "") | 177 if ($val == "") |
178 { | 178 { |
179 echo "The value can't be empty.\n"; | 179 echo "The value can't be empty.\n"; |
180 return FALSE; | 180 return false; |
181 } | 181 } |
182 else | 182 else |
183 return TRUE; | 183 return true; |
184 } | 184 } |
185 | 185 |
186 | 186 |
187 function stValidateURLPrefix($sprefix) | 187 function stValidateURLPrefix($sprefix) |
188 { | 188 { |
189 if (substr($sprefix, 0, 7) != "http://" && | 189 if (substr($sprefix, 0, 7) != "http://" && |
190 substr($sprefix, 0, 8) != "https://") | 190 substr($sprefix, 0, 8) != "https://") |
191 { | 191 { |
192 echo "URL must start with http:// or https://\n"; | 192 echo "URL must start with http:// or https://\n"; |
193 return FALSE; | 193 return false; |
194 } | 194 } |
195 else | 195 else |
196 if (substr($sprefix, -1) != "/") | 196 if (substr($sprefix, -1) != "/") |
197 { | 197 { |
198 echo "URL must end with /\n"; | 198 echo "URL must end with /\n"; |
199 return FALSE; | 199 return false; |
200 } | 200 } |
201 else | 201 else |
202 if (preg_match("/^https?:\/\/[a-zA-Z0-9]+[a-zA-Z0-9\/\.\:\-]*?\//", $sprefix) === FALSE) | 202 if (preg_match("/^https?:\/\/[a-zA-Z0-9]+[a-zA-Z0-9\/\.\:\-]*?\//", $sprefix) === false) |
203 { | 203 { |
204 echo "Malformed URL (or atleast this silly regexp does not accept it.\n"; | 204 echo "Malformed URL (or atleast this silly regexp does not accept it.\n"; |
205 return FALSE; | 205 return false; |
206 } | 206 } |
207 else | 207 else |
208 return TRUE; | 208 return true; |
209 } | 209 } |
210 | 210 |
211 | 211 |
212 function stMakeHtAccessFile($urlprefix, $sprefix, $spath) | 212 function stMakeHtAccessFile($urlprefix, $sprefix, $spath) |
213 { | 213 { |
226 global $cfgDefaults, $cfg; | 226 global $cfgDefaults, $cfg; |
227 foreach ($cfgDefaults as $citem => $cdata) | 227 foreach ($cfgDefaults as $citem => $cdata) |
228 { | 228 { |
229 if ($cdata[0] == $level) | 229 if ($cdata[0] == $level) |
230 { | 230 { |
231 $def = ($cdata[1] !== FALSE) ? $cdata[1] : $cfg[$citem]; | 231 $def = ($cdata[1] !== false) ? $cdata[1] : $cfg[$citem]; |
232 | 232 |
233 $sdone = FALSE; | 233 $sdone = false; |
234 while (!$sdone) | 234 while (!$sdone) |
235 { | 235 { |
236 $tmp = $cfg[$citem] = stInputPrompt($cdata[2], $def, "stValidateNotEmpty"); | 236 $tmp = $cfg[$citem] = stInputPrompt($cdata[2], $def, "stValidateNotEmpty"); |
237 | 237 |
238 switch ($cdata[0]) | 238 switch ($cdata[0]) |
242 if ($res != 0) | 242 if ($res != 0) |
243 { | 243 { |
244 echo "ERROR: Could not find '".$tmp."'. Perhaps it is not in path, or path is wrong.\n"; | 244 echo "ERROR: Could not find '".$tmp."'. Perhaps it is not in path, or path is wrong.\n"; |
245 } | 245 } |
246 else | 246 else |
247 $sdone = TRUE; | 247 $sdone = true; |
248 break; | 248 break; |
249 | 249 |
250 default: | 250 default: |
251 $sdone = TRUE; | 251 $sdone = true; |
252 } | 252 } |
253 } | 253 } |
254 } | 254 } |
255 } | 255 } |
256 } | 256 } |
264 "GMaps TNG bootstrap and update script by Ggr & Jeskko\n". | 264 "GMaps TNG bootstrap and update script by Ggr & Jeskko\n". |
265 "===========================================================\n"; | 265 "===========================================================\n"; |
266 | 266 |
267 if (file_exists($gmapsConfig)) | 267 if (file_exists($gmapsConfig)) |
268 { | 268 { |
269 $firstRun = FALSE; | 269 $firstRun = false; |
270 include $gmapsConfig; | 270 include $gmapsConfig; |
271 } | 271 } |
272 else | 272 else |
273 { | 273 { |
274 $firstRun = TRUE; | 274 $firstRun = true; |
275 echo | 275 echo |
276 "It seems you are running this for the first time ..\n". | 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". | 277 "You will be asked some information this time, which will be\n". |
278 "and saved for later use in file '".$gmapsConfig."'\n\n"; | 278 "and saved for later use in file '".$gmapsConfig."'\n\n"; |
279 | 279 |
280 $sdone = FALSE; | 280 $sdone = false; |
281 while (!$sdone) | 281 while (!$sdone) |
282 { | 282 { |
283 $cfg["pageBaseURL"] = stInputPrompt( | 283 $cfg["pageBaseURL"] = stInputPrompt( |
284 "Enter base URL for the map page. For example: http://foobar.com/map/\n", | 284 "Enter base URL for the map page. For example: http://foobar.com/map/\n", |
285 FALSE, "stValidateURLPrefix"); | 285 false, "stValidateURLPrefix"); |
286 $sdone = stYesNoPrompt("The page base URL to be used is \"".$cfg["pageBaseURL"]."\", e.g.\n". | 286 $sdone = stYesNoPrompt("The page base URL to be used is \"".$cfg["pageBaseURL"]."\", e.g.\n". |
287 "index.php would be: \"".$cfg["pageBaseURL"]."index.php\"\n". | 287 "index.php would be: \"".$cfg["pageBaseURL"]."index.php\"\n". |
288 "Is this correct?"); | 288 "Is this correct?"); |
289 echo "\n"; | 289 echo "\n"; |
290 } | 290 } |
291 | 291 |
292 $sdone = FALSE; | 292 $sdone = false; |
293 while (!$sdone) | 293 while (!$sdone) |
294 { | 294 { |
295 $cfg["urlTilePrefix"] = stInputPrompt( | 295 $cfg["urlTilePrefix"] = stInputPrompt( |
296 "Enter URL prefix for tiles. For example: http://foobar.com/map/tiles/\n", | 296 "Enter URL prefix for tiles. For example: http://foobar.com/map/tiles/\n", |
297 $cfg["pageBaseURL"]."tiles/", "stValidateURLPrefix"); | 297 $cfg["pageBaseURL"]."tiles/", "stValidateURLPrefix"); |
301 echo "\n"; | 301 echo "\n"; |
302 } | 302 } |
303 | 303 |
304 $cfg["gmapsKey"] = stInputPrompt( | 304 $cfg["gmapsKey"] = stInputPrompt( |
305 "Enter your Google Maps API key (or leave empty, and edit later)\n", | 305 "Enter your Google Maps API key (or leave empty, and edit later)\n", |
306 FALSE, FALSE); | 306 false, false); |
307 | 307 |
308 echo | 308 echo |
309 "\nNext up are some files and paths. All of them can be safely\n". | 309 "\nNext up are some files and paths. All of them can be safely\n". |
310 "left to their default values (e.g. just press <enter>) unless\n". | 310 "left to their default values (e.g. just press <enter>) unless\n". |
311 "you know you want something set differently.\n\n"; | 311 "you know you want something set differently.\n\n"; |
318 $cfg["worldConfig"] = $cfg["pathMapUtils"]."www/world.inc.php"; | 318 $cfg["worldConfig"] = $cfg["pathMapUtils"]."www/world.inc.php"; |
319 | 319 |
320 stQueryConfigItems(3); | 320 stQueryConfigItems(3); |
321 | 321 |
322 | 322 |
323 stOutputToFile($gmapsConfig, "<?php\n\$cfg = ".var_export($cfg, TRUE)."\n?>"); | 323 stOutputToFile($gmapsConfig, "<?php\n\$cfg = ".var_export($cfg, true)."\n?>"); |
324 | 324 |
325 stOutputToFile($cfg["pathGMap"]."config.inc.php", | 325 stOutputToFile($cfg["pathGMap"]."config.inc.php", |
326 "<?php\n". | 326 "<?php\n". |
327 "\$pageBaseURL = \"".$cfg["pageBaseURL"]."\";\n". | 327 "\$pageBaseURL = \"".$cfg["pageBaseURL"]."\";\n". |
328 "\$gmapsKey = \"".$cfg["gmapsKey"]."\";\n". | 328 "\$gmapsKey = \"".$cfg["gmapsKey"]."\";\n". |
344 $rawAltSuffix = ".map"; | 344 $rawAltSuffix = ".map"; |
345 | 345 |
346 /* | 346 /* |
347 foreach (["." => 0600, $cfg["pathMapUtils"] => 0600] as $spath => $sperm) | 347 foreach (["." => 0600, $cfg["pathMapUtils"] => 0600] as $spath => $sperm) |
348 { | 348 { |
349 if (chmod($spath, $sperm) === FALSE) | 349 if (chmod($spath, $sperm) === false) |
350 echo "Could not set permissions for '".$spath."'.\n"); | 350 echo "Could not set permissions for '".$spath."'.\n"); |
351 } | 351 } |
352 */ | 352 */ |
353 | 353 |
354 | 354 |
530 function makeMap($inFilename, $outFilename, $zlevel, $cdata) | 530 function makeMap($inFilename, $outFilename, $zlevel, $cdata) |
531 { | 531 { |
532 global $mapPalette, $fontFile, $fontSize; | 532 global $mapPalette, $fontFile, $fontSize; |
533 | 533 |
534 // Try to open input file | 534 // Try to open input file |
535 if (($file = @fopen($inFilename, "r")) === FALSE) | 535 if (($file = @fopen($inFilename, "r")) === false) |
536 { | 536 { |
537 echo "Could not open input '".$inFilename."'\n"; | 537 echo "Could not open input '".$inFilename."'\n"; |
538 return FALSE; | 538 return false; |
539 } | 539 } |
540 | 540 |
541 // Derp | 541 // Derp |
542 $zoom = pow(2, $zlevel - 1); | 542 $zoom = pow(2, $zlevel - 1); |
543 $width = $cdata[CTI_WIDTH]; | 543 $width = $cdata[CTI_WIDTH]; |
544 $height = $cdata[CTI_HEIGHT]; | 544 $height = $cdata[CTI_HEIGHT]; |
545 | 545 |
546 // Create image and assign colors | 546 // Create image and assign colors |
547 if (($im = imagecreate($width*$zoom, $height*$zoom)) === FALSE) | 547 if (($im = imagecreate($width*$zoom, $height*$zoom)) === false) |
548 { | 548 { |
549 echo "Could not allocate image data for '".$inFilename."'\n"; | 549 echo "Could not allocate image data for '".$inFilename."'\n"; |
550 return FALSE; | 550 return false; |
551 } | 551 } |
552 | 552 |
553 $black = imagecolorallocate($im, 0, 0, 0); | 553 $black = imagecolorallocate($im, 0, 0, 0); |
554 foreach ($mapPalette as $id => $val) | 554 foreach ($mapPalette as $id => $val) |
555 $colors[$id] = imagecolorallocate($im, $val[0], $val[1], $val[2]); | 555 $colors[$id] = imagecolorallocate($im, $val[0], $val[1], $val[2]); |
556 | 556 |
557 imagefilledrectangle($im, 0, 0, $width*$zoom, $height*$zoom, $black); | 557 imagefilledrectangle($im, 0, 0, $width*$zoom, $height*$zoom, $black); |
558 | 558 |
559 // Read input raw | 559 // Read input raw |
560 $y = 0; | 560 $y = 0; |
561 while ($y < $height && ($data = fgets($file, 4096)) !== FALSE) | 561 while ($y < $height && ($data = fgets($file, 4096)) !== false) |
562 { | 562 { |
563 for ($x = 0; $x < $width; $x++) | 563 for ($x = 0; $x < $width; $x++) |
564 { | 564 { |
565 if ($zoom == 1) | 565 if ($zoom == 1) |
566 { | 566 { |
584 } | 584 } |
585 $y++; | 585 $y++; |
586 echo "."; | 586 echo "."; |
587 } | 587 } |
588 | 588 |
589 if (imagepng($im, $outFilename) === FALSE) | 589 if (imagepng($im, $outFilename) === false) |
590 { | 590 { |
591 echo "Error creating '".$outFilename."'\n"; | 591 echo "Error creating '".$outFilename."'\n"; |
592 imagedestroy($im); | 592 imagedestroy($im); |
593 return FALSE; | 593 return false; |
594 } | 594 } |
595 | 595 |
596 imagedestroy($im); | 596 imagedestroy($im); |
597 return TRUE; | 597 return true; |
598 } | 598 } |
599 | 599 |
600 if (!stMakeDir($cfg["pathImageCache"])) | 600 if (!stMakeDir($cfg["pathImageCache"])) |
601 { | 601 { |
602 die("Failed to create cache directory '".$cfg["pathImageCache"]."'!\n"); | 602 die("Failed to create cache directory '".$cfg["pathImageCache"]."'!\n"); |
753 $dy = $ch*$scale - $ty; | 753 $dy = $ch*$scale - $ty; |
754 | 754 |
755 if ($im !== false) | 755 if ($im !== false) |
756 { | 756 { |
757 imagecopy($im, $mapData[$cname], $xx, $yy, $tx, $ty, $dx, $dy); | 757 imagecopy($im, $mapData[$cname], $xx, $yy, $tx, $ty, $dx, $dy); |
758 $drawn = TRUE; | 758 $drawn = true; |
759 } | 759 } |
760 } | 760 } |
761 } | 761 } |
762 | 762 |
763 if ($drawn) | 763 if ($drawn) |