changeset 240:0a719f1dbf01 gmap2

Moar work.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 17 Mar 2014 02:05:37 +0200
parents 7fe37bb4faf9
children f0a36bb9a334
files tools/makegmaps.php
diffstat 1 files changed, 43 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/tools/makegmaps.php	Mon Mar 17 01:58:41 2014 +0200
+++ b/tools/makegmaps.php	Mon Mar 17 02:05:37 2014 +0200
@@ -5,15 +5,16 @@
 
 
 // Paths and files
-$cfg = array();
-$cfg["binConvert"] = "convert";
-$cfg["binMercurial"] = "hg";
-$cfg["binMake"] = "make";
+$cfgDefaults = array(
+  "binConvert" => array(1, "convert", ""),
+  "binMercurial" => array(1, "hg", ""),
+  "binMake" => array(1, "make", ""),
 
 $cfg["pathMapUtils"] = "maputils/";
 $pathImageCache = "cache/";
 $pathMarkerData = "../";
 $pathTileData = "../tiles/";
+);
 
 
 $fontFile = "./lucon.ttf";
@@ -197,6 +198,16 @@
 }
 
 
+function stQueryConfigItems($level)
+{
+  global $cfgDefaults;
+  foreach ($cfgDefaults as $citem => $cdata)
+  {
+    if ($cdata[0] == $level)
+      $cfg[$citem] = stInputPrompt($cdata[2], $cdata[1], "stValidateNotEmpty");
+  }
+}
+
 
 //
 // Check for first run
@@ -236,15 +247,10 @@
 //
 // Set rest of the paths etc
 //
-$pathRawMaps = $cfg["pathMapUtils"]."maps/";
-$pathLocFiles = $cfg["pathMapUtils"]."maps/";
-$worldConfig = $cfg["pathMapUtils"]."www/world.inc.php";
-
-$worldJS = $pathMarkerData."world.js";
-$tradelaneOut = $pathMarkerData."tradelane.json";
-$tradelaneOverlay = $pathMarkerData."trlines.json";
+$worldJS = $cfg["pathMarkerData"]."world.js";
+$tradelaneOut = $cfg["pathMarkerData"]."tradelane.json";
+$tradelaneOverlay = $cfg["pathMarkerData"]."trlines.json";
 $binMkLoc = $cfg["pathMapUtils"]."mkloc";
-
 $rawSuffix = ".new";
 $rawAltSuffix = ".map";
 
@@ -252,18 +258,18 @@
 //
 // Include continent and tradelane configuration 
 //
-if (!file_exists($worldConfig))
-  die("Required continent/tradelane configuration file '".$worldConfig."' not found.\n");
+if (!file_exists($cfg["worldConfig"]))
+  die("Required continent/tradelane configuration file '".$cfg["worldConfig"]."' not found.\n");
 
-require $worldConfig;
+require $cfg["worldConfig"];
 
 
 //
 // Create htaccess files
 //
-stMakeHtAccessFile($cfg["urlTilePrefix"], $pathTileData, "");
+stMakeHtAccessFile($cfg["urlTilePrefix"], $cfg["pathTileData"], "");
 for ($i = $minZoom; $i <= $maxZoom; $i++)
-  stMakeHtAccessFile($cfg["urlTilePrefix"], $pathTileData, $i."/");
+  stMakeHtAccessFile($cfg["urlTilePrefix"], $cfg["pathTileData"], $i."/");
 
 
 //
@@ -303,7 +309,7 @@
 $tmp = "cd ".escapeshellarg($cfg["pathMapUtils"])." && ".$cfg["binMake"];
 passthru($tmp) == 0 or die("Error executing: ".$tmp."\n");
 
-$tmp = "cd ".escapeshellarg($pathRawMaps)." && ".$cfg["binMake"]." fetch 2> /dev/null";
+$tmp = "cd ".escapeshellarg($cfg["pathRawMaps"])." && ".$cfg["binMake"]." fetch 2> /dev/null";
 passthru($tmp) == 0 or die("Error executing: ".$tmp."\n");
 
 
@@ -341,7 +347,7 @@
 
 foreach ($modes as $mode => $mdata)
 {
-  $tmp = escapeshellcmd($binMkLoc)." -v -o ".escapeshellarg($pathMarkerData.$mdata[0])." -G ".$mode." ";
+  $tmp = escapeshellcmd($binMkLoc)." -v -o ".escapeshellarg($cfg["pathMarkerData"].$mdata[0])." -G ".$mode." ";
 
   foreach ($continentList as $name => $data)
   {
@@ -349,7 +355,7 @@
     {
       // has a map
       $tmp .=
-      "-l ".escapeshellarg($pathLocFiles.$name.".loc")." ".
+      "-l ".escapeshellarg($cfg["pathLocFiles"].$name.".loc")." ".
       "-c ".escapeshellarg($data[0])." ".
       "-x ".escapeshellarg($worldMap["ox"] + $data[1] + $mdata[1])." ".
       "-y ".escapeshellarg($worldMap["oy"] + $data[2] + $mdata[2])." ";
@@ -364,7 +370,7 @@
 // Export tradelane waypoint data
 //
 if (!isset($tradelanePoints))
-  die("PHP array \$tradelanePoints not set, '$worldConfig' is old or incompatible.\n");
+  die("PHP array \$tradelanePoints not set, '$cfg["worldConfig"]' is old or incompatible.\n");
 
 echo "\nCreating tradelane waypoint data '".$tradelaneOut."' ...\n";
 
@@ -396,7 +402,7 @@
 //
 echo "\nCreating tradelane polyline data '".$tradelaneOverlay."' ...\n";
 if (!isset($tradelaneDefs))
-  die("PHP array \$tradelaneDefs not set, '".$worldConfig."' is old or incompatible.\n");
+  die("PHP array \$tradelaneDefs not set, '".$cfg["worldConfig"]."' is old or incompatible.\n");
 
 $qdata = array();
 foreach ($tradelaneDefs as $index => $points)
@@ -496,26 +502,26 @@
   return TRUE;
 }
 
-if (!stMakeDir($pathImageCache)) {
-  die("Failed to create cache directory '".$pathImageCache."'!\n");
+if (!stMakeDir($cfg["pathImageCache"])) {
+  die("Failed to create cache directory '".$cfg["pathImageCache"]."'!\n");
 }
 
 echo "Generating basic map data...\n";
 foreach ($continentList as $name => $data)
 if ($data[4] && $data[7])
 {
-  $inFilename = $pathRawMaps.$name.$rawSuffix;
+  $inFilename = $cfg["pathRawMaps"].$name.$rawSuffix;
   if (!file_exists($inFilename))
   {
-    $inFilename = $pathRawMaps.$name.$rawAltSuffix;
+    $inFilename = $cfg["pathRawMaps"].$name.$rawAltSuffix;
     if (!file_exists($inFilename))
-      die("Required file '".$pathRawMaps.$name."(".$rawSuffix."|".$rawAltSuffix.")' does not exist.\n");
+      die("Required file '".$cfg["pathRawMaps"].$name."(".$rawSuffix."|".$rawAltSuffix.")' does not exist.\n");
   }
   $inMtime = filemtime($inFilename);
   
   for ($zoom = 1; $zoom <= 5; $zoom++)
   {
-    $outFilename = $pathImageCache.$name."_".($zoom + 4).".png";
+    $outFilename = $cfg["pathImageCache"].$name."_".($zoom + 4).".png";
     $outMtime = file_exists($outFilename) ? filemtime($outFilename) : -1;
     echo "- ".$name." (".$data[0]."): ";
     if ($inMtime > $outMtime)
@@ -538,7 +544,7 @@
 if ($data[4] && $data[7])
 {
   $n = count($mapScales);
-  $inFilename = $pathImageCache.$name."_".$n.".png";
+  $inFilename = $cfg["pathImageCache"].$name."_".$n.".png";
   if (!file_exists($inFilename))
   {
     die("Required file '".$inFilename."' does not exist.\n");
@@ -548,7 +554,7 @@
   foreach ($mapScales as $scale)
   {
     $n--;
-    $outFilename = $pathImageCache.$name."_".$n.".png";
+    $outFilename = $cfg["pathImageCache"].$name."_".$n.".png";
     $outMtime = file_exists($outFilename) ? filemtime($outFilename) : -1;
 
     echo "* ".$inFilename." -> ".$outFilename.": ";
@@ -571,7 +577,7 @@
 {
   global $continentList, $worldMap, $pathImageCache, $pathTileData, $tileDim;
 
-  $outFilename = $pathTileData.$zoom."/".$y."/".$x.".png";
+  $outFilename = $cfg["pathTileData"].$zoom."/".$y."/".$x.".png";
   if (file_exists($outFilename) && filemtime($outFilename) >= $mapMtime)
   {
     echo "!";
@@ -609,7 +615,7 @@
         }
         else
         {
-          $inFilename = $pathTileData.$zoom."/sea.png";
+          $inFilename = $cfg["pathTileData"].$zoom."/sea.png";
           $im = @imagecreatefrompng($inFilename);
           if ($im === false)
             die("\nCould not open '".$inFilename."'.\n");
@@ -651,7 +657,7 @@
 
   if ($drawn > 0)
   {
-    stMakeDir($pathTileData.$zoom."/".$y, 0755);
+    stMakeDir($cfg["pathTileData"].$zoom."/".$y, 0755);
     imagepng($im, $outFilename);
     imagedestroy($im);
   }
@@ -660,7 +666,7 @@
     if (file_exists($outFilename))
       unlink($outFilename);
 
-    symlink($pathTileData."sea.png", $outFilename);
+    symlink($cfg["pathTileData"]."sea.png", $outFilename);
     echo "+";
   }
 */
@@ -676,9 +682,9 @@
   $zoom2 = $zoom - 1;
   $scale = pow(2, $zoom2 - 5);
 
-  stMakeDir($pathTileData.$zoom);
+  stMakeDir($cfg["pathTileData"].$zoom);
 
-  echo "\nzoom level $zoom: ";
+  echo "\nZoom level $zoom: ";
 
   $mx = ceil(($worldMap["w"] * $scale) / $tileDim);
   $my = ceil(($worldMap["h"] * $scale) / $tileDim);
@@ -689,7 +695,7 @@
   foreach ($continentList as $continent => $data)
   if ($data[4] && $data[7])
   {
-    $mapFile = $pathImageCache.$continent."_".$zoom2.".png";
+    $mapFile = $cfg["pathImageCache"].$continent."_".$zoom2.".png";
     $mapData[$continent] = @imagecreatefrompng($mapFile);
     $tmp = filemtime($mapFile);
     if ($tmp > $mapMtime)