changeset 66:58e1d6507e26

Cosmetics.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 11 Feb 2014 10:42:22 +0200
parents ac95c8028769
children 74777d6109a0
files index.php
diffstat 1 files changed, 76 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/index.php	Tue Feb 11 10:34:30 2014 +0200
+++ b/index.php	Tue Feb 11 10:42:22 2014 +0200
@@ -85,7 +85,8 @@
   if ($y < 0) { $col = 1; $y = &$i; } else 
               { $col = 2; $z = &$i; }
 
-  for ($i = 0; $i < $dbDims[$col]; $i++) {
+  for ($i = 0; $i < $dbDims[$col]; $i++)
+  {
     if (($db[$x][$y][$z][$idx] == $ifval) == $equals)
          $db[$x][$y][$z][$idx] = $setval;
   }
@@ -94,7 +95,8 @@
 
 function alch_find_pairs($item, $key)
 {
-  foreach ($item as $key => $val) {
+  foreach ($item as $key => $val)
+  {
     $minTab[$val[0]]++;
     $orgTab[$val[1]]++;
     $herbTab[$val[2]]++;
@@ -121,8 +123,10 @@
 function array_search_multi($val, $arr)
 {
   foreach ($arr as $key => $pair)
+  {
     if ($pair[0] == $val || $pair[1] == $val)
       return $key;
+  }
 
   return false;
 }
@@ -131,7 +135,8 @@
 function alch_matrix_cell($r)
 {
   $res = $r[0];
-  switch ($r[0]) {
+  switch ($r[0])
+  {
     case "!": $class = "accepted"; break;
 
     case "?": $class = ($r[1] == "*") ? "pairclose" : "close"; break;
@@ -167,20 +172,20 @@
 
   // Determine number of columns by number of cells
   $max = count($pdata);
-  if ($max / 3 > 10)
-    $div = $max / 3;
-  else
-    $div = $max / 2;
+  $div = ($max / 3 > 10) ? ($max / 3) : ($max / 2);
     
   // Print selection for primary key
   echo "<table class=\"seltable\" border=\"1\" cellspacing=\"0\">\n";
+
   $n = 0;
-  foreach ($pdata as $key => $val) {
+  foreach ($pdata as $key => $val)
+  {
     if ($n == 0) echo " <tr>\n";
 
-    echo "  <td class=\"".
-    ($key == $active ? "atab" : "tab").
-    "\"><a href=\"?".$mode."=".$key."\">";
+    echo
+      "  <td class=\"".
+      ($key == $active ? "atab" : "tab").
+      "\"><a href=\"?".$mode."=".$key."\">";
     
     if (is_array($val))
       echo htmlentities($val[0])."<br />".htmlentities($val[1]);
@@ -189,11 +194,13 @@
 
     echo "</a></td>\n";
 
-    if (++$n >= $div) {
+    if (++$n >= $div)
+    {
       echo " </tr>\n";
       $n = 0;
     }
   }
+
   if ($n != 0)
     echo " </tr>\n";
 
@@ -201,22 +208,29 @@
   // Print mix table header
   $str = is_array($pdata[0]) ? $pdata[$active][0]." or ".$pdata[$active][1] : $pdata[$active];
 
-  echo "</table>\n".
-  "<h1>".htmlentities($str)."</h1>\n".
-  "<table class=\"mixtable\" border=\"1\" cellspacing=\"0\">\n".
-  " <tr>\n".
-  "  <th></th>\n";
+  echo
+    "</table>\n".
+    "<h1>".htmlentities($str)."</h1>\n".
+    "<table class=\"mixtable\" border=\"1\" cellspacing=\"0\">\n".
+    " <tr>\n".
+    "  <th></th>\n";
 
   $imgWidth = 12;
   $imgHeight = 80;
-  foreach ($data2 as $key => $val) {
+  foreach ($data2 as $key => $val)
+  {
     $str = is_array($val) ? $val[0]." / ".$val[1] : $val;
 
     // Create image files for the text entries, if they don't already exist
     $filename = "txt_".preg_replace("/[^a-z0-9]/", "_", strtolower($str)).".png";
-    echo "  <th><img src=\"".$imagePath.urlencode($filename)."\" alt=\"".htmlentities($str)."\" width=\"".$imgWidth."\" height=\"".$imgHeight."\"></th>\n";
 
-    if (!file_exists($imagePath.$filename)) {
+    echo
+      "  <th><img src=\"".$imagePath.urlencode($filename).
+      "\" alt=\"".htmlentities($str)."\" width=\"".$imgWidth.
+      "\" height=\"".$imgHeight."\"></th>\n";
+
+    if (!file_exists($imagePath.$filename))
+    {
       $image = imagecreate($imgWidth, $imgHeight);
       $c_black = imagecolorallocate($image,   0,   0,   0);
       $c_white = imagecolorallocate($image, 255, 255, 255);
@@ -233,26 +247,54 @@
   echo " </tr>\n";
 
   // Print the table itself
-  foreach ($data1 as $rowKey => $rowVal) {
+  foreach ($data1 as $rowKey => $rowVal)
+  {
     $str = is_array($rowVal) ? $rowVal[0]." / ".$rowVal[1] : $rowVal;
     echo " <tr><th>".htmlentities($str)."</th>";
-    foreach ($data2 as $colKey => $colVal) {
+
+    foreach ($data2 as $colKey => $colVal)
       alch_matrix_cell($db[$px][$py][$pz]);
-    }
+
     echo "</tr>\n";
   }
   echo "</table>\n";
 }
 
 
+function alch_print_item($x, $y, $z, $s, &$index)
+{
+  global $dbNames, $db;
+  $index++;
+  echo "<tr>".
+    "<th>".$index."</th>".
+    "<td>".$dbNames[0][$x]."</td>".
+    "<td>".$dbNames[1][$y]."</td>".
+    "<td>".$dbNames[2][$z][0]." / ".$dbNames[2][$z][1]."</td>".
+    "<td>".$s."</td></tr>";
+}
+
+
+function alch_check_item($x, $y, $z, &$index)
+{
+  global $dbNames, $db;
+  $s = $db[$x][$y][$z];
+  if ($s[0] == "!")
+    alch_print_item($x, $y, $z, substr($s, 1), $index);
+}
+
+
+
 // Select view mode based on script GET arguments
 $mode = "min";
 $active = 0;
-foreach ($dbModes as $name => $data) {
-  if (isset($_GET[$name])) {
+foreach ($dbModes as $name => $data)
+{
+  if (isset($_GET[$name]))
+  {
     $active = intval($_GET[$name]);
     if ($active < 0 || $active >= $dbDims[$data[1]])
       $active = 0;
+
     $mode = $name;
     break;
   }
@@ -376,6 +418,7 @@
 for ($z = 0; $z < $dbDims[2]; $z++)
   $results[$db[$x][$y][$z][0]]++;
 
+
 echo "<b>".$results["!"]."</b> found potions, ".
   "<b>".$results["?"]."</b> active partial matches, ".
   "<b>".$results["-"]."</b> combinations eliminated, ".
@@ -383,26 +426,6 @@
   "</div>\n";
 
 
-function printItem($x, $y, $z, $s, &$index)
-{
-  global $dbNames, $db;
-  $index++;
-  echo "<tr>".
-    "<th>".$index."</th>".
-    "<td>".$dbNames[0][$x]."</td>".
-    "<td>".$dbNames[1][$y]."</td>".
-    "<td>".$dbNames[2][$z][0]." / ".$dbNames[2][$z][1]."</td>".
-    "<td>".$s."</td></tr>";
-}
-
-function checkItem($x, $y, $z, &$index)
-{
-  global $dbNames, $db;
-  $s = $db[$x][$y][$z];
-  if ($s[0] == "!")
-    printItem($x, $y, $z, substr($s, 1), $index);
-}
-
 echo "<div id=\"controls\">Change index key to ";
 foreach ($dbModes as $id => $data)
   echo "[<a href=\"?".$id."=0\">".$data[2]."</a>] ";
@@ -426,21 +449,23 @@
     for ($x = 0; $x < $dbDims[0]; $x++)
     for ($y = 0; $y < $dbDims[1]; $y++)
     for ($z = 0; $z < $dbDims[2]; $z++)
-      checkItem($x, $y, $z, $index);
+      alch_check_item($x, $y, $z, $index);
   }
-  else if ($active == 1)
+  else
+  if ($active == 1)
   {
     for ($y = 0; $y < $dbDims[1]; $y++)
     for ($x = 0; $x < $dbDims[0]; $x++)
     for ($z = 0; $z < $dbDims[2]; $z++)
-      checkItem($x, $y, $z, $index);
+      alch_check_item($x, $y, $z, $index);
   }
-  else if ($active == 2)
+  else
+  if ($active == 2)
   {
     for ($z = 0; $z < $dbDims[2]; $z++)
     for ($x = 0; $x < $dbDims[0]; $x++)
     for ($y = 0; $y < $dbDims[1]; $y++)
-      checkItem($x, $y, $z, $index);
+      alch_check_item($x, $y, $z, $index);
   }
   else
   {
@@ -455,7 +480,7 @@
     }
     ksort($potions);
     foreach ($potions as $name => $data)
-      printItem($data[0], $data[1], $data[2], $name, $index);
+      alch_print_item($data[0], $data[1], $data[2], $name, $index);
   }
   echo "</table>\n";
 }