Mercurial > hg > batmud > gmap2
annotate tools/makegmaps.php @ 307:0c370efd753b gmap2
Use modern PHP array syntax.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 11 Sep 2017 13:37:05 +0300 |
parents | 695d01a321ec |
children | 63eb4661d13c |
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 = [ |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
16 "binConvert" => [1, "convert", "Path of 'convert' binary from ImageMagick or GraphicsMagick."], |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
17 "binMercurial" => [1, "hg", "Path of 'hg' binary of Mercurial DVCS."], |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
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 |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
20 "pathMapUtils" => [2, "maputils/", "Path for maputils directory tree."], |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
21 "pathImageCache" => [2, "cache/", "Image cache directory."], |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
22 "pathGMap" => [2, "../", "Path to map main directory and marker data files."], |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
23 "pathTileData" => [2, "../tiles/", "Path to map tiles directory structure."], |
242 | 24 |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
25 "pathRawMaps" => [3, FALSE, "Path to the raw ASCII maps."], |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
26 "pathLocFiles" => [3, FALSE, "Path to the location data LOC files."], |
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
27 "worldConfig" => [3, FALSE, "Path of the world configuration file 'world.inc.php' from MapUtils."], |
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 | |
120 function stGetWorldCoords($cont, $xp, $yp, &$xc, &$yc) | |
121 { | |
122 global $worldMap, $continentList; | |
123 | |
124 if (!isset($continentList[$cont])) | |
125 return FALSE; | |
126 | |
127 $xc = $worldMap["ox"] + $continentList[$cont][1] + $xp - 1; | |
128 $yc = $worldMap["oy"] + $continentList[$cont][2] + $yp - 1; | |
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; |
137 | |
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 { | |
204 echo "Malformed URL (or atleast this silly regexp does not want it.\n"; | |
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]; | |
232 $cfg[$citem] = stInputPrompt($cdata[2], $def, "stValidateNotEmpty"); | |
233 } | |
240 | 234 } |
235 } | |
236 | |
212
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
237 |
238 | 238 // |
239 // Check for first run | |
240 // | |
241 echo | |
242 "===========================================================\n". | |
243 "GMaps TNG bootstrap and update script by Ggr & Jeskko\n". | |
244 "===========================================================\n"; | |
248 | 245 |
238 | 246 if (file_exists($gmapsConfig)) |
247 { | |
248 $firstRun = FALSE; | |
249 include $gmapsConfig; | |
250 } | |
251 else | |
252 { | |
253 $firstRun = TRUE; | |
254 echo | |
255 "It seems you are running this for the first time ..\n". | |
256 "You will be asked some information this time, which will be\n". | |
257 | 257 "and saved for later use in file '".$gmapsConfig."'\n\n"; |
238 | 258 |
255
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
259 $sdone = FALSE; |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
260 while (!$sdone) |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
261 { |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
262 $cfg["pageBaseURL"] = stInputPrompt( |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
263 "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
|
264 FALSE, "stValidateURLPrefix"); |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
265 $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
|
266 "index.php would be: \"".$cfg["pageBaseURL"]."index.php\"\n". |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
267 "Is this correct?"); |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
268 echo "\n"; |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
269 } |
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 $sdone = FALSE; |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
272 while (!$sdone) |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
273 { |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
274 $cfg["urlTilePrefix"] = stInputPrompt( |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
275 "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
|
276 $cfg["pageBaseURL"]."tiles/", "stValidateURLPrefix"); |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
277 $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
|
278 "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
|
279 "Is this correct?"); |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
280 echo "\n"; |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
281 } |
d9e51ab58503
Improve the bootstrap configuration process.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
282 |
258
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
283 $cfg["gmapsKey"] = stInputPrompt( |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
284 "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
|
285 FALSE, FALSE); |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
286 |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
287 echo |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
288 "\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
|
289 "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
|
290 "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
|
291 |
242 | 292 stQueryConfigItems(1); |
293 stQueryConfigItems(2); | |
294 | |
287
695d01a321ec
Fix maps build process to match with new Maputils.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
295 $cfg["pathRawMaps"] = $cfg["pathMapUtils"]."world/"; |
695d01a321ec
Fix maps build process to match with new Maputils.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
296 $cfg["pathLocFiles"] = $cfg["pathMapUtils"]."world/"; |
242 | 297 $cfg["worldConfig"] = $cfg["pathMapUtils"]."www/world.inc.php"; |
298 | |
299 stQueryConfigItems(3); | |
300 | |
238 | 301 |
258
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
302 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
|
303 |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
304 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
|
305 "<?php\n". |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
306 "\$pageBaseURL = \"".$cfg["pageBaseURL"]."\";\n". |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
307 "\$gmapsKey = \"".$cfg["gmapsKey"]."\";\n". |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
308 "\$gmapsVersion = \"3\";\n". |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
309 "?>\n"); |
238 | 310 } |
311 | |
312 | |
313 // | |
314 // Set rest of the paths etc | |
315 // | |
258
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
316 $pathTileData = $cfg["pathGMap"]."tiles/"; |
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
317 $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
|
318 $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
|
319 $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
|
320 $tgtMkLoc = "bin/mkloc"; |
695d01a321ec
Fix maps build process to match with new Maputils.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
321 $binMkLoc = $cfg["pathMapUtils"].$tgtMkLoc; |
238 | 322 $rawSuffix = ".new"; |
323 $rawAltSuffix = ".map"; | |
324 | |
248 | 325 /* |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
326 foreach (["." => 0600, $cfg["pathMapUtils"] => 0600] as $spath => $sperm) |
248 | 327 { |
328 if (chmod($spath, $sperm) === FALSE) | |
329 echo "Could not set permissions for '".$spath."'.\n"); | |
330 } | |
331 */ | |
332 | |
238 | 333 |
334 // | |
335 // Create htaccess files | |
336 // | |
240 | 337 stMakeHtAccessFile($cfg["urlTilePrefix"], $cfg["pathTileData"], ""); |
238 | 338 for ($i = $minZoom; $i <= $maxZoom; $i++) |
240 | 339 stMakeHtAccessFile($cfg["urlTilePrefix"], $cfg["pathTileData"], $i."/"); |
238 | 340 |
341 | |
237 | 342 // |
343 // Build maputils and fetch latest map data | |
344 // | |
238 | 345 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
|
346 { |
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
347 // If maputils does not exist, clone the repository |
238 | 348 $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
|
349 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
|
350 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
|
351 |
c3cd3bfb7a77
Automatically clone and/or update th-libs, a requirement for the maputils.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
352 // Clone th-libs |
238 | 353 $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
|
354 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
|
355 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
|
356 } |
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
357 else |
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
358 { |
238 | 359 $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
|
360 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
|
361 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
|
362 |
238 | 363 $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
|
364 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
|
365 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
|
366 } |
80aae13d1b42
Cleanups; Clone and/or update maputils repo automatically; Use raw map data from
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
367 |
287
695d01a321ec
Fix maps build process to match with new Maputils.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
368 $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
|
369 echo "* $tmp\n"; |
4e7d0bc500c4
Actually build the maputils tools.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
370 passthru($tmp) == 0 or die("Error executing: ".$tmp."\n"); |
4e7d0bc500c4
Actually build the maputils tools.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
371 |
4e7d0bc500c4
Actually build the maputils tools.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
372 |
214
00e673963d35
More cleanups and improvements in building script.
Matti Hamalainen <ccr@tnsp.org>
parents:
212
diff
changeset
|
373 if (!file_exists($binMkLoc)) |
00e673963d35
More cleanups and improvements in building script.
Matti Hamalainen <ccr@tnsp.org>
parents:
212
diff
changeset
|
374 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
|
375 |
238 | 376 $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
|
377 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
|
378 |
240 | 379 $tmp = "cd ".escapeshellarg($cfg["pathRawMaps"])." && ".$cfg["binMake"]." fetch 2> /dev/null"; |
238 | 380 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
|
381 |
2ea7fe9f9c1d
Include configuration after we have updated/cloned the maputils repo.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
382 |
237 | 383 // |
251
cd489f20cf9d
Move check for worldconfig later, we need to fetch maputils & co before that.
Matti Hamalainen <ccr@tnsp.org>
parents:
249
diff
changeset
|
384 // 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
|
385 // |
cd489f20cf9d
Move check for worldconfig later, we need to fetch maputils & co before that.
Matti Hamalainen <ccr@tnsp.org>
parents:
249
diff
changeset
|
386 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
|
387 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
|
388 |
cd489f20cf9d
Move check for worldconfig later, we need to fetch maputils & co before that.
Matti Hamalainen <ccr@tnsp.org>
parents:
249
diff
changeset
|
389 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
|
390 |
cd489f20cf9d
Move check for worldconfig later, we need to fetch maputils & co before that.
Matti Hamalainen <ccr@tnsp.org>
parents:
249
diff
changeset
|
391 |
cd489f20cf9d
Move check for worldconfig later, we need to fetch maputils & co before that.
Matti Hamalainen <ccr@tnsp.org>
parents:
249
diff
changeset
|
392 // |
237 | 393 // Generate continents JavasScript data file |
394 /// | |
227
7c1cd542b2d2
Rename continents.js to world.js, and add global offset data in.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
395 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
|
396 $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
|
397 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
|
398 $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
|
399 $str .= "};\n"; |
7c1cd542b2d2
Rename continents.js to world.js, and add global offset data in.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
400 |
7c1cd542b2d2
Rename continents.js to world.js, and add global offset data in.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
401 $str .= "var pmapContinents =\n[\n"; |
77
f278e5e08f55
Add continents.js generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
402 foreach ($continentList as $name => $data) |
f278e5e08f55
Add continents.js generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
403 if ($data[4] && $data[7]) |
f278e5e08f55
Add continents.js generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
404 { |
227
7c1cd542b2d2
Rename continents.js to world.js, and add global offset data in.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
405 $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
|
406 "\"".$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
|
407 $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
|
408 $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
|
409 $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
|
410 $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
|
411 $data[5], $data[6]); |
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 $str .= "];\n"; |
f278e5e08f55
Add continents.js generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
414 |
236 | 415 stOutputToFile($worldJS, $str); |
77
f278e5e08f55
Add continents.js generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
416 |
f278e5e08f55
Add continents.js generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
417 |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
418 |
237 | 419 // |
420 // Generate marker files from LOC data | |
421 /// | |
30 | 422 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
|
423 |
2f2937e8921f
More work on sanitizing the overlays generation etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
424 foreach ($modes as $mode => $mdata) |
64 | 425 { |
258
8a8bd1d4a51c
Some more work on setup process. Still missing some pieces.
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
426 $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
|
427 |
2f2937e8921f
More work on sanitizing the overlays generation etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
428 foreach ($continentList as $name => $data) |
2f2937e8921f
More work on sanitizing the overlays generation etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
429 { |
2f2937e8921f
More work on sanitizing the overlays generation etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
430 if ($data[4] && $data[7]) |
2f2937e8921f
More work on sanitizing the overlays generation etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
431 { |
2f2937e8921f
More work on sanitizing the overlays generation etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
432 // has a map |
2f2937e8921f
More work on sanitizing the overlays generation etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
433 $tmp .= |
240 | 434 "-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
|
435 "-c ".escapeshellarg($data[0])." ". |
2f2937e8921f
More work on sanitizing the overlays generation etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
436 "-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
|
437 "-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
|
438 } |
17
7444639be2ef
Added script for generating marker data.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
439 } |
7444639be2ef
Added script for generating marker data.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
440 |
24 | 441 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
|
442 } |
7444639be2ef
Added script for generating marker data.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
443 |
24 | 444 |
237 | 445 // |
446 // Export tradelane waypoint data | |
447 // | |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
448 if (!isset($tradelanePoints)) |
242 | 449 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
|
450 |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
451 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
|
452 |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
453 $qdata = []; |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
454 |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
455 foreach ($tradelanePoints as $name => $data) |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
456 { |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
457 $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
|
458 |
238 | 459 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
|
460 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
|
461 |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
462 $qdata[] = [ |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
463 "x" => $xc, |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
464 "y" => $yc, |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
465 "name" => $name, |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
466 "html" => $html, |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
467 "continent" => "", |
192
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
468 "type" => "tradelane", |
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
469 "flags" => 0, |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
470 ]; |
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 |
236 | 473 stOutputToJSONFile($tradelaneOut, $qdata); |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
474 |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
475 |
237 | 476 // |
477 // Export tradelane polyline data | |
478 // | |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
479 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
|
480 if (!isset($tradelaneDefs)) |
240 | 481 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
|
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 foreach ($tradelaneDefs as $index => $points) |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
485 { |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
486 $qline = []; |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
487 |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
488 foreach ($points as $point) |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
489 { |
238 | 490 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
|
491 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
|
492 |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
493 $qline[] = [ |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
494 "x" => $xc, |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
495 "y" => $yc |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
496 ]; |
177
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 |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
499 $qdata[] = $qline; |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
500 } |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
501 |
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
502 |
236 | 503 stOutputToJSONFile($tradelaneOverlay, $qdata); |
177
876e9bb593d5
Move less time-consuming stuff earlier in the script.
Matti Hamalainen <ccr@tnsp.org>
parents:
160
diff
changeset
|
504 |
237 | 505 |
506 // | |
507 // Generate PNG maps | |
508 // | |
30 | 509 function makeMap($inFilename, $outFilename, $zlevel, $data) |
26 | 510 { |
212
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
511 global $mapPalette, $fontFile, $fontSize; |
30 | 512 |
513 // Try to open input file | |
277
023f5d0f627e
Cosmetics and improved error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
259
diff
changeset
|
514 if (($file = @fopen($inFilename, "r")) === FALSE) |
64 | 515 { |
30 | 516 echo "Could not open input '".$inFilename."'\n"; |
517 return FALSE; | |
518 } | |
519 | |
35 | 520 // Derp |
30 | 521 $zoom = pow(2, $zlevel - 1); |
522 $width = $data[5]; | |
523 $height = $data[6]; | |
524 | |
525 // Create image and assign colors | |
277
023f5d0f627e
Cosmetics and improved error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
259
diff
changeset
|
526 if (($im = imagecreate($width*$zoom, $height*$zoom)) === FALSE) |
64 | 527 { |
35 | 528 echo "Could not allocate image data for '".$inFilename."'\n"; |
529 return FALSE; | |
530 } | |
531 | |
26 | 532 $black = imagecolorallocate($im, 0, 0, 0); |
30 | 533 foreach ($mapPalette as $id => $val) |
26 | 534 $colors[$id] = imagecolorallocate($im, $val[0], $val[1], $val[2]); |
535 | |
536 imagefilledrectangle($im, 0, 0, $width*$zoom, $height*$zoom, $black); | |
30 | 537 |
538 // Read input raw | |
26 | 539 $y = 0; |
540 while ($y < $height && ($data = fgets($file, 4096)) !== FALSE) | |
541 { | |
542 for ($x = 0; $x < $width; $x++) | |
543 { | |
64 | 544 if ($zoom == 1) |
545 { | |
26 | 546 imagesetpixel($im, $x, $y, $colors[$data[$x]]); |
109 | 547 } |
548 else | |
64 | 549 if ($zoom < 6) |
550 { | |
26 | 551 imagefilledrectangle($im, $x*$zoom, $y*$zoom, ($x+1)*$zoom-1, ($y+1)*$zoom-1, $colors[$data[$x]]); |
109 | 552 } |
553 else | |
554 { | |
52 | 555 imagettftext($im, |
225 | 556 $fontSize[$zoom], 0, |
557 $x*$zoom + $fontSize[$zoom]/4, | |
558 $y*$zoom + $fontSize[$zoom], | |
26 | 559 $colors[$data[$x]], |
30 | 560 $fontFile, |
26 | 561 $data[$x]); |
562 } | |
563 } | |
564 $y++; | |
31 | 565 echo "."; |
30 | 566 } |
567 | |
64 | 568 if (imagepng($im, $outFilename) === FALSE) |
569 { | |
30 | 570 echo "Error creating '".$outFilename."'\n"; |
571 imagedestroy($im); | |
572 return FALSE; | |
26 | 573 } |
574 | |
30 | 575 imagedestroy($im); |
576 return TRUE; | |
577 } | |
578 | |
277
023f5d0f627e
Cosmetics and improved error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
259
diff
changeset
|
579 if (!stMakeDir($cfg["pathImageCache"])) |
023f5d0f627e
Cosmetics and improved error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
259
diff
changeset
|
580 { |
240 | 581 die("Failed to create cache directory '".$cfg["pathImageCache"]."'!\n"); |
41 | 582 } |
26 | 583 |
30 | 584 echo "Generating basic map data...\n"; |
33 | 585 foreach ($continentList as $name => $data) |
81
4cdb23e2121d
Check continent [4] and [7].
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
586 if ($data[4] && $data[7]) |
30 | 587 { |
240 | 588 $inFilename = $cfg["pathRawMaps"].$name.$rawSuffix; |
64 | 589 if (!file_exists($inFilename)) |
590 { | |
240 | 591 $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
|
592 if (!file_exists($inFilename)) |
240 | 593 die("Required file '".$cfg["pathRawMaps"].$name."(".$rawSuffix."|".$rawAltSuffix.")' does not exist.\n"); |
41 | 594 } |
35 | 595 $inMtime = filemtime($inFilename); |
596 | |
64 | 597 for ($zoom = 1; $zoom <= 5; $zoom++) |
598 { | |
240 | 599 $outFilename = $cfg["pathImageCache"].$name."_".($zoom + 4).".png"; |
41 | 600 $outMtime = file_exists($outFilename) ? filemtime($outFilename) : -1; |
35 | 601 echo "- ".$name." (".$data[0]."): "; |
65 | 602 if ($inMtime > $outMtime) |
603 { | |
35 | 604 $res = makeMap($inFilename, $outFilename, $zoom, $data); |
605 echo ($res ? "OK" : "FAIL")."\n"; | |
109 | 606 } |
607 else | |
35 | 608 echo "SKIPPED\n"; |
609 } | |
26 | 610 } |
611 | |
612 | |
30 | 613 /* |
33 | 614 * Generate small versions |
615 */ | |
616 echo "\nGenerating scaled small map data...\n"; | |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
617 $mapScales = ["50", "25", "12.5", "6.25", "3.125"]; |
33 | 618 foreach ($continentList as $name => $data) |
81
4cdb23e2121d
Check continent [4] and [7].
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
619 if ($data[4] && $data[7]) |
33 | 620 { |
621 $n = count($mapScales); | |
240 | 622 $inFilename = $cfg["pathImageCache"].$name."_".$n.".png"; |
64 | 623 if (!file_exists($inFilename)) |
624 { | |
35 | 625 die("Required file '".$inFilename."' does not exist.\n"); |
626 } | |
627 $inMtime = filemtime($inFilename); | |
33 | 628 |
64 | 629 foreach ($mapScales as $scale) |
630 { | |
33 | 631 $n--; |
240 | 632 $outFilename = $cfg["pathImageCache"].$name."_".$n.".png"; |
35 | 633 $outMtime = file_exists($outFilename) ? filemtime($outFilename) : -1; |
634 | |
635 echo "* ".$inFilename." -> ".$outFilename.": "; | |
65 | 636 if ($inMtime > $outMtime) |
637 { | |
280
632e61498905
Do not use paletted conversion for intermediate files. It seems to make
Matti Hamalainen <ccr@tnsp.org>
parents:
279
diff
changeset
|
638 $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
|
639 escapeshellarg($inFilename)." ". |
632e61498905
Do not use paletted conversion for intermediate files. It seems to make
Matti Hamalainen <ccr@tnsp.org>
parents:
279
diff
changeset
|
640 "-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
|
641 //"-type Palette ". |
632e61498905
Do not use paletted conversion for intermediate files. It seems to make
Matti Hamalainen <ccr@tnsp.org>
parents:
279
diff
changeset
|
642 escapeshellarg($outFilename); |
632e61498905
Do not use paletted conversion for intermediate files. It seems to make
Matti Hamalainen <ccr@tnsp.org>
parents:
279
diff
changeset
|
643 |
35 | 644 passthru($tmp) == 0 or die("Error executing: ".$tmp."\n"); |
645 echo "OK\n"; | |
109 | 646 } |
647 else | |
35 | 648 echo "SKIPPED\n"; |
33 | 649 } |
650 } | |
651 | |
652 | |
39 | 653 /* |
654 * Build tiles | |
655 */ | |
64 | 656 function createTile($scale, $zoom, $x, $y, $mapData, $mapMtime) |
657 { | |
241 | 658 global $continentList, $worldMap, $cfg, $tileDim; |
39 | 659 |
240 | 660 $outFilename = $cfg["pathTileData"].$zoom."/".$y."/".$x.".png"; |
64 | 661 if (file_exists($outFilename) && filemtime($outFilename) >= $mapMtime) |
662 { | |
39 | 663 echo "!"; |
664 return; | |
665 } | |
666 | |
241 | 667 $drawn = false; |
52 | 668 $im = false; |
39 | 669 |
64 | 670 foreach ($continentList as $continent => $data) |
671 { | |
229
ccd79b97dc52
Don't attempt to generate tile data from non-existent virtual continents.
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
672 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
|
673 continue; |
ccd79b97dc52
Don't attempt to generate tile data from non-existent virtual continents.
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
674 |
39 | 675 $cx = $data[1] + $worldMap["ox"]; |
676 $cy = $data[2] + $worldMap["oy"]; | |
677 $cw = $data[5]; | |
678 $ch = $data[6]; | |
679 | |
680 $tx = -($cx*$scale - $x*$tileDim); | |
681 $ty = -($cy*$scale - $y*$tileDim); | |
682 | |
52 | 683 if (($cx + $cw)*$scale > $x*$tileDim && |
684 ($cy + $ch)*$scale > $y*$tileDim && | |
685 ($cx * $scale) < ($x+1)*$tileDim && | |
65 | 686 ($cy * $scale) < ($y+1)*$tileDim) |
687 { | |
241 | 688 if (!$drawn) |
65 | 689 { |
690 if ($zoom < 9) | |
691 { | |
279
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
692 $im = imagecreate($tileDim, $tileDim); |
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
693 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
|
694 die("\nCould not create GD image resource open dim=".$tileDim. |
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
695 " for zoom=".$zoom.", continent=".$continent."\n"); |
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
696 |
39 | 697 $sea = imagecolorallocate($im, 51, 51, 170); |
698 imagefilledrectangle($im, 0, 0, $tileDim, $tileDim, $sea); | |
109 | 699 } |
700 else | |
701 { | |
240 | 702 $inFilename = $cfg["pathTileData"].$zoom."/sea.png"; |
279
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
703 $im = imagecreatefrompng($inFilename); |
52 | 704 if ($im === false) |
705 die("\nCould not open '".$inFilename."'.\n"); | |
279
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
706 |
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
707 if (get_resource_type($im) != "gd") |
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
708 die("Not an GD image resource ".$im." in '".$inFilename."'\n"); |
52 | 709 } |
39 | 710 } |
711 | |
52 | 712 $dx = $tileDim; |
713 $dy = $tileDim; | |
714 $xx = 0; | |
715 $yy = 0; | |
39 | 716 |
64 | 717 if ($tx < 0) |
718 { | |
59 | 719 $xx -= $tx; |
720 $dx += $tx+1; | |
721 $tx = 0; | |
39 | 722 } |
723 | |
64 | 724 if ($ty < 0) |
725 { | |
59 | 726 $yy -= $ty; |
727 $dy += $ty+1; | |
728 $ty = 0; | |
39 | 729 } |
730 | |
64 | 731 if ($dx > $cw*$scale-$tx) |
52 | 732 $dx = $cw*$scale - $tx; |
39 | 733 |
64 | 734 if ($dy > $ch*$scale-$ty) |
52 | 735 $dy = $ch*$scale - $ty; |
39 | 736 |
64 | 737 if ($im !== false) |
738 { | |
52 | 739 imagecopy($im, $mapData[$continent], $xx, $yy, $tx, $ty, $dx, $dy); |
241 | 740 $drawn = TRUE; |
52 | 741 } |
39 | 742 } |
743 } | |
744 | |
241 | 745 if ($drawn) |
64 | 746 { |
240 | 747 stMakeDir($cfg["pathTileData"].$zoom."/".$y, 0755); |
52 | 748 imagepng($im, $outFilename); |
749 imagedestroy($im); | |
39 | 750 } |
52 | 751 /* |
752 else { | |
753 if (file_exists($outFilename)) | |
754 unlink($outFilename); | |
755 | |
240 | 756 symlink($cfg["pathTileData"]."sea.png", $outFilename); |
52 | 757 echo "+"; |
758 } | |
759 */ | |
39 | 760 } |
761 | |
762 | |
128 | 763 echo "\nBuilding tiles data for all zoom levels ...\n"; |
764 | |
307
0c370efd753b
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
287
diff
changeset
|
765 $mapData = []; |
39 | 766 |
212
3adc7a98ef0a
Improve bootstrapping by generating htaccess files automagically.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
767 for ($zoom = $minZoom; $zoom <= $maxZoom; $zoom++) |
65 | 768 { |
39 | 769 $zoom2 = $zoom - 1; |
770 $scale = pow(2, $zoom2 - 5); | |
771 | |
240 | 772 stMakeDir($cfg["pathTileData"].$zoom); |
39 | 773 |
240 | 774 echo "\nZoom level $zoom: "; |
39 | 775 |
776 $mx = ceil(($worldMap["w"] * $scale) / $tileDim); | |
777 $my = ceil(($worldMap["h"] * $scale) / $tileDim); | |
778 $mw = ceil( $worldMap["w"] * $scale); | |
779 $mh = ceil( $worldMap["h"] * $scale); | |
780 | |
781 $mapMtime = -1; | |
279
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
782 foreach ($continentList as $continent => &$data) |
81
4cdb23e2121d
Check continent [4] and [7].
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
783 if ($data[4] && $data[7]) |
64 | 784 { |
240 | 785 $mapFile = $cfg["pathImageCache"].$continent."_".$zoom2.".png"; |
279
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
786 $mapData[$continent] = imagecreatefrompng($mapFile); |
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
787 if ($mapData[$continent] === FALSE || |
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
788 get_resource_type($mapData[$continent]) != "gd") |
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
789 die("Not an GD image resource ".$mapData[$continent]." in '".$mapFile."'\n"); |
0374836ed73a
Various fixes in the image data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
278
diff
changeset
|
790 |
39 | 791 $tmp = filemtime($mapFile); |
792 if ($tmp > $mapMtime) | |
793 $mapMtime = $tmp; | |
794 } | |
795 | |
64 | 796 for ($y = 0; $y < $mx; $y++) |
797 { | |
39 | 798 for ($x = 0; $x < $my; $x++) |
799 createTile($scale, $zoom, $x, $y, $mapData, $mapMtime); | |
800 echo "."; | |
801 } | |
802 echo "\n"; | |
803 | |
64 | 804 // Free image data for each continent |
39 | 805 foreach($continentList as $continent => $data) |
109 | 806 { |
807 if ($data[4] && $data[7]) | |
808 imagedestroy($mapData[$continent]); | |
809 } | |
39 | 810 } |
811 | |
17
7444639be2ef
Added script for generating marker data.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
812 ?> |