annotate tools/makegmaps.php @ 277:023f5d0f627e gmap2

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