# HG changeset patch # User Matti Hamalainen # Date 1392108142 -7200 # Node ID 58e1d6507e26a4f9869dd2b861743869502b7079 # Parent ac95c80287691562cf4b55e1ca93922e4e3000f9 Cosmetics. diff -r ac95c8028769 -r 58e1d6507e26 index.php --- 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 "\n"; + $n = 0; - foreach ($pdata as $key => $val) { + foreach ($pdata as $key => $val) + { if ($n == 0) echo " \n"; - echo " \n"; - if (++$n >= $div) { + if (++$n >= $div) + { echo " \n"; $n = 0; } } + if ($n != 0) echo " \n"; @@ -201,22 +208,29 @@ // Print mix table header $str = is_array($pdata[0]) ? $pdata[$active][0]." or ".$pdata[$active][1] : $pdata[$active]; - echo "
"; + echo + " "; if (is_array($val)) echo htmlentities($val[0])."
".htmlentities($val[1]); @@ -189,11 +194,13 @@ echo "
\n". - "

".htmlentities($str)."

\n". - "\n". - " \n". - " \n"; + echo + "
\n". + "

".htmlentities($str)."

\n". + "\n". + " \n". + " \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 " \n"; - if (!file_exists($imagePath.$filename)) { + echo + " \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 " \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 " "; - foreach ($data2 as $colKey => $colVal) { + + foreach ($data2 as $colKey => $colVal) alch_matrix_cell($db[$px][$py][$pz]); - } + echo "\n"; } echo "
\"".htmlentities($str)."\"\"".htmlentities($str)."\"
".htmlentities($str)."
\n"; } +function alch_print_item($x, $y, $z, $s, &$index) +{ + global $dbNames, $db; + $index++; + echo "". + "".$index."". + "".$dbNames[0][$x]."". + "".$dbNames[1][$y]."". + "".$dbNames[2][$z][0]." / ".$dbNames[2][$z][1]."". + "".$s.""; +} + + +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 "".$results["!"]." found potions, ". "".$results["?"]." active partial matches, ". "".$results["-"]." combinations eliminated, ". @@ -383,26 +426,6 @@ "\n"; -function printItem($x, $y, $z, $s, &$index) -{ - global $dbNames, $db; - $index++; - echo "". - "".$index."". - "".$dbNames[0][$x]."". - "".$dbNames[1][$y]."". - "".$dbNames[2][$z][0]." / ".$dbNames[2][$z][1]."". - "".$s.""; -} - -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 "
Change index key to "; foreach ($dbModes as $id => $data) echo "[".$data[2]."] "; @@ -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 "\n"; }