Mercurial > hg > batmud > alchtool
changeset 34:0989d8dab1df
Add sorting functionality, etc.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 21 Mar 2011 21:52:03 +0200 |
parents | 41a1e2acdb73 |
children | 888b5b6f07c1 |
files | index.php |
diffstat | 1 files changed, 71 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/index.php Mon Mar 21 19:48:01 2011 +0200 +++ b/index.php Mon Mar 21 21:52:03 2011 +0200 @@ -18,6 +18,7 @@ "min" => array("Mineral", 0), "org" => array("Organ", 1), "herb" => array("Herb", 2), + "list" => array("Potion list", 3), ); $dbNames = array( @@ -56,6 +57,8 @@ array("strawberry", "mugwort"), array("turnip", "mysticcarrot"), array("vine_seed", "lungwort") ), + + array("sorted by mineral", "sorted by organ", "sorted by herb pair", "sorted by potion name"), ); @@ -247,20 +250,13 @@ // Select view mode based on script GET arguments $mode = "min"; $active = 0; -if (isset($_GET["view"])) -{ - $mode = "view"; -} -else -{ - foreach ($dbModes as $name => $idx) { - if (isset($_GET[$name])) { - $active = intval($_GET[$name]); - if ($active < 0 || $active >= $dbDims[$idx[1]]) - $active = 0; - $mode = $name; - break; - } +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; } } @@ -357,33 +353,75 @@ $results["."]." combinations untested.<br />\n"; -if ($mode == "view") +function printItem($x, $y, $z, $s, &$index) { - echo "<table style=\"background: #444; width: 60%;\"> + 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); +} + + +if ($mode == "list") +{ + $index = 0; + echo "<h1>".$dbModes[$mode][0]." view (".$dbNames[$dbModes[$mode][1]][$active].")</h1> + <table class=\"potlist\"> <tr> <th>#</th> - <th>Mineral</th> - <th>Organ</th> - <th>Herb</th> - <th>Result</th> + <th><a href=\"?list=0\">Mineral</a></th> + <th><a href=\"?list=1\">Organ</a></th> + <th><a href=\"?list=2\">Herb</a></th> + <th><a href=\"?list=3\">Potion</a></th> </tr> "; - $n = 0; - for ($x = 0; $x < $dbDims[0]; $x++) - for ($y = 0; $y < $dbDims[1]; $y++) - for ($z = 0; $z < $dbDims[2]; $z++) + if ($active == 0) + { + 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); + } + else if ($active == 1) { - $s = $db[$x][$y][$z]; - if ($s[0] == "!") + 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); + } + 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); + } + else + { + $potions = array(); + for ($z = 0; $z < $dbDims[2]; $z++) + for ($x = 0; $x < $dbDims[0]; $x++) + for ($y = 0; $y < $dbDims[1]; $y++) { - $n++; - echo "<tr>". - "<td>".$n."</td>". - "<td>".$dbNames[0][$x]."</td>". - "<td>".$dbNames[1][$y]."</td>". - "<td>".$dbNames[2][$z][0]." / ".$dbNames[2][$z][1]."</td>". - "<td>".substr($s, 1)."</td></tr>"; + $s = $db[$x][$y][$z]; + if ($s[0] == "!") + $potions[substr($s, 1)] = array($x, $y, $z); } + ksort($potions); + foreach ($potions as $name => $data) + printItem($data[0], $data[1], $data[2], $name, $index); } echo "</table>\n"; } else