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