annotate tools/makegmaps.php @ 307:0c370efd753b gmap2

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