annotate tools/makegmaps.php @ 321:44e104b0ae90 gmap2

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