changeset 177:876e9bb593d5 gmap2

Move less time-consuming stuff earlier in the script.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 11 Mar 2014 22:40:49 +0200
parents d68111417b8e
children ddc3ebdeb31e
files tools/makegmaps.php
diffstat 1 files changed, 94 insertions(+), 93 deletions(-) [+]
line wrap: on
line diff
--- a/tools/makegmaps.php	Tue Mar 11 22:34:26 2014 +0200
+++ b/tools/makegmaps.php	Tue Mar 11 22:40:49 2014 +0200
@@ -156,6 +156,7 @@
   die("Error writing continent data to ".$continentJS."\n");
 
 
+
 /*
  * Generate marker files from LOC data
  */
@@ -182,6 +183,99 @@
 }
 
 
+/* Calculate worldmap coordinates from continent coordinates
+ */
+function getWorldCoords($cont, $xp, $yp, &$xc, &$yc)
+{
+  global $worldMap, $continentList;
+
+  if (!isset($continentList[$cont]))
+    return FALSE;
+
+  $xc = $worldMap["ox"] + $continentList[$cont][1] + $xp - 1;
+  $yc = $worldMap["oy"] + $continentList[$cont][2] + $yp - 1;
+  return TRUE;
+}
+
+
+/* Get worldmap coordinates for a given tradelane waypoint
+ */
+function getWaypointCoords($waypoint, &$xc, &$yc)
+{
+  global $tradelanePoints;
+  
+  if (!isset($tradelanePoints[$waypoint]))
+    return FALSE;
+
+  return getWorldCoords($tradelanePoints[$waypoint][0],
+    $tradelanePoints[$waypoint][1], $tradelanePoints[$waypoint][2], $xc, $yc);
+}
+
+
+function outputJSON($qfilename, $qdata)
+{
+  if (file_put_contents($qfilename, json_encode($qdata), LOCK_EX) === FALSE)
+    die("Could not write to file '".$qfilename."'.\n");
+}
+
+
+/* Export tradelane waypoint data
+ */
+if (!isset($tradelanePoints))
+  die("PHP array \$tradelanePoints not set, '$config' is old or incompatible.\n");
+
+echo "\nCreating tradelane waypoint data '".$tradelaneOut."' ...\n";
+
+$qdata = array();
+
+foreach ($tradelanePoints as $name => $data)
+{
+  $html = "<b>TRADELANE WPT</b><br>".htmlentities($name);
+
+  if (!getWorldCoords($data[0], $data[1], $data[2], $xc, $yc))
+    die("Invalid tradelane waypoint '".$name."', continent '".$data[0]."' not defined.\n");
+
+  $qdata[] = array(
+    "x" => $xc,
+    "y" => $yc,
+    "name" => $name,
+    "html" => $html,
+    "continent" => "",
+    "type" => "tradelane"
+  );
+}
+
+outputJSON($tradelaneOut, $qdata);
+
+
+/* Export tradelane polyline data
+ */
+echo "\nCreating tradelane polyline data '".$tradelaneOverlay."' ...\n";
+if (!isset($tradelaneDefs))
+  die("PHP array \$tradelaneDefs not set, '$config' is old or incompatible.\n");
+
+$qdata = array();
+foreach ($tradelaneDefs as $index => $points)
+{
+  $qline = array();
+
+  foreach ($points as $point)
+  {
+    if (!getWaypointCoords($point, $xc, $yc))
+      die("Invalid tradelane definition #$index: waypoint '".$point."' not defined.\n");
+
+    $qline[] = array(
+      "x" => $xc,
+      "y" => $yc
+    );
+  }
+  
+  $qdata[] = $qline;
+}
+
+
+outputJSON($tradelaneOverlay, $qdata);
+
 /*
  * Generate PNG maps
  */
@@ -330,99 +424,6 @@
 }
 
 
-/* Calculate worldmap coordinates from continent coordinates
- */
-function getWorldCoords($cont, $xp, $yp, &$xc, &$yc)
-{
-  global $worldMap, $continentList;
-
-  if (!isset($continentList[$cont]))
-    return FALSE;
-
-  $xc = $worldMap["ox"] + $continentList[$cont][1] + $xp - 1;
-  $yc = $worldMap["oy"] + $continentList[$cont][2] + $yp - 1;
-  return TRUE;
-}
-
-
-/* Get worldmap coordinates for a given tradelane waypoint
- */
-function getWaypointCoords($waypoint, &$xc, &$yc)
-{
-  global $tradelanePoints;
-  
-  if (!isset($tradelanePoints[$waypoint]))
-    return FALSE;
-
-  return getWorldCoords($tradelanePoints[$waypoint][0],
-    $tradelanePoints[$waypoint][1], $tradelanePoints[$waypoint][2], $xc, $yc);
-}
-
-
-function outputJSON($qfilename, $qdata)
-{
-  if (file_put_contents($qfilename, json_encode($qdata), LOCK_EX) === FALSE)
-    die("Could not write to file '".$qfilename."'.\n");
-}
-
-
-/* Export tradelane waypoint data
- */
-if (!isset($tradelanePoints))
-  die("PHP array \$tradelanePoints not set, '$config' is old or incompatible.\n");
-
-echo "\nCreating tradelane waypoint data '".$tradelaneOut."' ...\n";
-
-$qdata = array();
-
-foreach ($tradelanePoints as $name => $data)
-{
-  $html = "<b>TRADELANE WPT</b><br>".htmlentities($name);
-
-  if (!getWorldCoords($data[0], $data[1], $data[2], $xc, $yc))
-    die("Invalid tradelane waypoint '".$name."', continent '".$data[0]."' not defined.\n");
-
-  $qdata[] = array(
-    "x" => $xc,
-    "y" => $yc,
-    "name" => $name,
-    "html" => $html,
-    "continent" => "",
-    "type" => "tradelane"
-  );
-}
-
-outputJSON($tradelaneOut, $qdata);
-
-
-/* Export tradelane polyline data
- */
-echo "\nCreating tradelane polyline data '".$tradelaneOverlay."' ...\n";
-if (!isset($tradelaneDefs))
-  die("PHP array \$tradelaneDefs not set, '$config' is old or incompatible.\n");
-
-$qdata = array();
-foreach ($tradelaneDefs as $index => $points)
-{
-  $qline = array();
-
-  foreach ($points as $point)
-  {
-    if (!getWaypointCoords($point, $xc, $yc))
-      die("Invalid tradelane definition #$index: waypoint '".$point."' not defined.\n");
-
-    $qline[] = array(
-      "x" => $xc,
-      "y" => $yc
-    );
-  }
-  
-  $qdata[] = $qline;
-}
-
-
-outputJSON($tradelaneOverlay, $qdata);
-
 /*
  * Build tiles
  */