Mercurial > hg > batmud > misc
changeset 296:8724b9de70bf misc
Variable renames, cleanups, etc.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 09 Mar 2015 14:03:41 +0200 |
parents | 89262bdba061 |
children | 0620fe91a259 |
files | materials/index.php materials/info.php |
diffstat | 2 files changed, 107 insertions(+), 108 deletions(-) [+] |
line wrap: on
line diff
--- a/materials/index.php Mon Mar 09 13:36:55 2015 +0200 +++ b/materials/index.php Mon Mar 09 14:03:41 2015 +0200 @@ -142,12 +142,12 @@ { $setSortColumn = 0; if ($setSortDirection) - krsort($matTable, SORT_STRING); + krsort($matDataTable, SORT_STRING); else - ksort($matTable, SORT_STRING); + ksort($matDataTable, SORT_STRING); } else - uasort($matTable, "stSortMatFunc"); + uasort($matDataTable, "stSortMatFunc"); // Print page header @@ -218,9 +218,9 @@ <td> <select multiple="multiple" size="5" name="h[]"> <? -reset($transNameTable); -next($transNameTable); -while (list($key, $value) = each($transNameTable)) +reset($matTransNames); +next($matTransNames); +while (list($key, $value) = each($matTransNames)) { echo " <option". (isset($setHideColumns[$key]) ? " selected=\"selected\"" : ""). @@ -234,7 +234,7 @@ <? $typeFilter = isset($setAttrFilters[14]) ? $setAttrFilters[14] : -1; if ($typeFilter == -1) unset($setAttrFilters[14]); -$typeTable = $transTable[14]; +$typeTable = $matTransTable[14]; $typeTable[-1] = "EVERYTHING"; ksort($typeTable); foreach ($typeTable as $key => $value) @@ -261,7 +261,7 @@ $filters = array(); foreach ($setAttrFilters as $fkey => $fval) if ($fkey >= 0) - $filters[] = "<b>".strtolower($transNameTable[$fkey + 1])."</b>=".strtolower($transTable[$fkey][$fval]); + $filters[] = "<b>".strtolower($matTransNames[$fkey + 1])."</b>=".strtolower($matTransTable[$fkey][$fval]); echo "<p>Filtering: ".implode(", ", $filters)."</p>\n"; } @@ -283,7 +283,7 @@ "<table class=\"matTable\">\n". " <tr>\n"; -foreach ($transNameTable as $key => $value) +foreach ($matTransNames as $key => $value) { if ($key == 0 || !isset($setHideColumns[$key])) { @@ -309,42 +309,42 @@ // // Material data rows // -foreach ($matTable as $key => $value) +foreach ($matDataTable as $mname => $mdata) { // // Check what filters apply here // $doShow = TRUE; foreach ($setAttrFilters as $fkey => $fval) - if ($fval >= 0 && $value[$fkey] != $fval) + if ($fval >= 0 && $mdata[$fkey] != $fval) { $doShow = FALSE; break; } - if ($setEnableMatFilters && !isset($setMatFilters[$key])) + if ($setEnableMatFilters && !isset($setMatFilters[$mname])) $doShow = FALSE; if ($doShow) { // Create temporary filter list for material filter link $tmpFilters = $setMatFilters; - if (isset($tmpFilters[$key])) - unset($tmpFilters[$key]); + if (isset($tmpFilters[$mname])) + unset($tmpFilters[$mname]); else - $tmpFilters[$key] = 1; + $tmpFilters[$mname] = 1; // First column is material name $col = 0; echo " <tr>".stGetTC("td", $col++). - "<a class=\"matToggle ".(isset($setMatFilters[$key]) ? "active" : "inactive"). + "<a class=\"matToggle ".(isset($setMatFilters[$mname]) ? "active" : "inactive"). "\" href=\"?".stGetURLStr($setAttrFilters, $setSortColumn, $setSortDirection, $setEnableMatFilters, $tmpFilters). - "\">".(isset($setMatFilters[$key]) ? "-" : "+")."</a>". - "<a href=\"/mat/".urlencode($key)."\">".chentities($key)."</a>". + "\">".(isset($setMatFilters[$mname]) ? "-" : "+")."</a>". + "<a href=\"/mat/".urlencode($mname)."\">".chentities($mname)."</a>". "</td>"; - foreach ($value as $kkey => $kvalue) + foreach ($mdata as $kkey => $kvalue) { if (!isset($setHideColumns[$kkey + 1])) { @@ -355,10 +355,10 @@ reset($kvalue); if (list($nam, $lode) = each($kvalue)) - echo chentities($transTable[$kkey][$lode]); + echo chentities($matTransTable[$kkey][$lode]); while (list($nam, $lode) = each($kvalue)) - echo ", ".chentities($transTable[$kkey][$lode]); + echo ", ".chentities($matTransTable[$kkey][$lode]); } else { @@ -371,7 +371,7 @@ echo "<a href=\"?". stGetURLStr($tmpFilters, $setSortColumn, $setSortDirection, $setEnableMatFilters, $setMatFilters). - "\">".chentities($transTable[$kkey][$kvalue])."</a>"; + "\">".chentities($matTransTable[$kkey][$kvalue])."</a>"; } echo "</td>"; }
--- a/materials/info.php Mon Mar 09 13:36:55 2015 +0200 +++ b/materials/info.php Mon Mar 09 14:03:41 2015 +0200 @@ -1,31 +1,40 @@ <? $pageTitle = "Pupunen BatMUD Alloy Browser"; $pageIndex = "info.php"; +$people = array("Hair", "Malacoda", "Kiomet", "Aegenor", "Gileon", "Corto"); + +$matTypeTable = array( + 0 => array("Organic + cloth (sewing)", 0, 1), + 1 => array("Wood + bone (carpentry)", 5, 3), + 2 => array("Metal + alloy (blacksmithing)", 4, 7), + 3 => array("Stone (masonry)", 6, -1), + 4 => array("Gem (gemcutting)", 10, -1), + 5 => array("Inorganic (sculpture)", 8, -1), + 6 => array("Glass (glassblowing)", 9, -1), + + 7 => array("Organic", 0, -1), + 8 => array("Wood", 5, -1), + 9 => array("Metal", 4, -1), + + 10 => array("Cloth", -1, 1), + 11 => array("Bone", -1, 3), + 12 => array("Alloy", -1, 7), +); + require "msitegen.inc.php"; require "materials.inc.php"; require "alloys.inc.php"; -$showOnly = intval(stGetRequestItem("o", 0, TRUE)); - -if (isset($_GET["m"])) -{ - $showMat = strtolower($_GET["m"]); - $showMatName = strtoupper(substr($showMat,0,1)).substr($showMat, 1); -} - -$swapRows = (isset($_GET["swap"]) && is_array($_GET["swap"])) ? $_GET["swap"] : array(); - - -function matLink($mat, $title = "", $extra = "") +function stGetMatLink($mat, $title = "", $extra = "") { $tmp = ($title != "") ? " title=\"".chentities($title)."\"" : ""; return "<a href=\"/mat/".urlencode($mat)."\"".$tmp.">".chentities($mat)."</a>".$extra; } -function addValueStyle($n) +function stGetValueStyle($n) { if ($n >= 40) $str = 40; else @@ -43,6 +52,20 @@ } +// +// Actual main code begins +// +$setShowOnly = intval(stGetRequestItem("o", 0, TRUE)); + +if (isset($_GET["m"])) +{ + $setShowMat = strtolower($_GET["m"]); + $setShowMatName = strtoupper(substr($setShowMat,0,1)).substr($setShowMat, 1); +} + +$setSwapRows = (isset($_GET["swap"]) && is_array($_GET["swap"])) ? $_GET["swap"] : array(); + + cmPrintPageHeader($pageTitle, " <meta name=\"robots\" content=\"nofollow\" /> <style type=\"text/css\"> @@ -81,12 +104,13 @@ <span class="hits40">40 or more</span></b>. </li> <? -$people = array("Hair", "Malacoda", "Kiomet", "Aegenor", "Gileon", "Corto"); -$tmp = array(); -foreach ($people as $key) - $tmp[] = "<b>".$key."</b>"; - -echo "<li>Thanks to the following people for providing alloying data: ".join(", ", $tmp).".</li>"; +if (isset($people) && count($people) > 0) +{ + $tmp = array(); + foreach ($people as $key) + $tmp[] = "<b>".$key."</b>"; + echo "<li>Thanks to the following people for providing alloying data: ".join(", ", $tmp).".</li>"; +} ?> </ul> </td> @@ -95,39 +119,21 @@ <td class="icenter"> <select name="o"> <? -$typeTable = array( - 0 => array("Organic + cloth (sewing)", 0, 1), - 1 => array("Wood + bone (carpentry)", 5, 3), - 2 => array("Metal + alloy (blacksmithing)", 4, 7), - 3 => array("Stone (masonry)", 6, -1), - 4 => array("Gem (gemcutting)", 10, -1), - 5 => array("Inorganic (sculpture)", 8, -1), - 6 => array("Glass (glassblowing)", 9, -1), - - 7 => array("Organic", 0, -1), - 8 => array("Wood", 5, -1), - 9 => array("Metal", 4, -1), - - 10 => array("Cloth", -1, 1), - 11 => array("Bone", -1, 3), - 12 => array("Alloy", -1, 7), -); - -foreach ($typeTable as $key => $value) +foreach ($matTypeTable as $key => $value) { $n = 0; - foreach ($matTable as $name => $data) + foreach ($matDataTable as $name => $data) { if ($data[14] == $value[1] || $data[14] == $value[2]) $n++; } - $typeTable[$key][] = $n; + $matTypeTable[$key][] = $n; printf( " <option value=\"%s\"%s>%-30s [%d]</option>\n", $key, - ($showOnly == $key ? " selected=\"selected\"" : ""), + ($setShowOnly == $key ? " selected=\"selected\"" : ""), chentities($value[0]), $n); } @@ -141,60 +147,53 @@ </table> </form> <? -if (isset($showMat)) +if (isset($setShowMat)) { - if (!isset($matTable[$showMat])) + if (!isset($matDataTable[$setShowMat])) { echo - "<h2>Error! No such material '".$showMatName."'</h2>\n". + "<h2>Error! No such material '".$setShowMatName."'</h2>\n". "<p>Material is not known. Check spelling.</p>\n"; } else { - echo "<h2>".$showMatName."</h2>\n". + echo "<h2>".$setShowMatName."</h2>\n". "<table width=\"95%\">\n". "<tr>"; $n = 0; - foreach ($matTable[$showMat] as $key => $val) + foreach ($matDataTable[$setShowMat] as $key => $val) { - echo "<th>".chentities($transNameTable[$key+1])."</th><td>"; + echo "<th>".chentities($matTransNames[$key + 1])."</th><td>"; if (is_array($val)) { - reset($val); - if (list($nam, $lode) = each($val)) - echo chentities($transTable[$key][$lode]); - - while (list($nam, $lode) = each($val)) - echo ", ".chentities($transTable[$key][$lode]); + $tmp = array(); + foreach ($val as $lode) + $tmp[] = chentities($matTransTable[$key][$lode]); + echo join(", ", $tmp); } else { - echo chentities($transTable[$key][$val]); + echo chentities($matTransTable[$key][$val]); } echo "</td>"; if ($n++ >= 2) { echo "</tr>\n<tr>"; $n = 0; } } - echo "</tr>\n</table>\n"; echo "<h3>Alloy combinations</h3>\n"; - if (isset($alloyRevTable[$showMat])) + if (isset($alloyRevTable[$setShowMat])) { echo "<ul>\n"; - - foreach ($alloyRevTable[$showMat] as $mat => $value) + foreach ($alloyRevTable[$setShowMat] as $mat => $value) { - echo " <li>".matLink($mat)." <b>+</b> "; + $tmp = array(); + foreach ($value as $qkey => $qval) + $tmp[] = stGetMatLink($qkey); - reset($value); - if (list($a, $b) = each($value)) - echo matLink($a); - - while (list($a, $b) = each($value)) - echo " <b>|</b> ".matLink($a); - - echo "<b> = ".chentities($showMat)."</b></li>\n"; + echo + " <li>".stGetMatLink($mat)." <b>+</b> ".join(" <b>|</b> ", $tmp). + "<b> = ".chentities($setShowMat)."</b></li>\n"; } echo "</ul>\n". @@ -211,37 +210,37 @@ /* $typeMats = array(); - foreach ($matTable as $name => $data) { - if ($data[14] == $matTable[$showMat][14] && $name != $showMat) + foreach ($matDataTable as $name => $data) { + if ($data[14] == $matDataTable[$setShowMat][14] && $name != $setShowMat) $typeMats[] = $name; } echo "Full mix: "; if (list($a, $b) = each($typeMats)) - echo matLink($b); + echo stGetMatLink($b); while (list($a, $b) = each($typeMats)) - echo " <b>+</b> ".matLink($b); + echo " <b>+</b> ".stGetMatLink($b); echo "<br />\n"; */ echo "<h3>Mixtable</h3>\n"; - if (count($alloyTable[$showMat]) > 0) + if (count($alloyTable[$setShowMat]) > 0) { echo "<table class=\"matTable\">". " <tr>\n". " <th>+</th>\n"; - foreach ($alloyTable[$showMat] as $key => $value) + foreach ($alloyTable[$setShowMat] as $key => $value) { - echo "<th>".matLink($key)."</th>\n"; + echo "<th>".stGetMatLink($key)."</th>\n"; } echo " </tr>\n". - " <tr><th>".chentities($showMat)."</th>"; - foreach ($alloyTable[$showMat] as $key => $value) + " <tr><th>".chentities($setShowMat)."</th>"; + foreach ($alloyTable[$setShowMat] as $key => $value) if (list($a, $b) = each($value)) { - echo "<td ".addValueStyle($b).">".matLink($a)."</td>"; + echo "<td ".stGetValueStyle($b).">".stGetMatLink($a)."</td>"; } echo "</tr></table>\n"; } @@ -258,19 +257,19 @@ */ // Filter table from maintable matching desired material type(s) $currTable = array(); - foreach ($matTable as $name => $data) + foreach ($matDataTable as $name => $data) { - if ($data[14] == $typeTable[$showOnly][1] || - $data[14] == $typeTable[$showOnly][2]) + if ($data[14] == $matTypeTable[$setShowOnly][1] || + $data[14] == $matTypeTable[$setShowOnly][2]) $currTable[] = $name; } // Swap desired rows - if (count($swapRows) > 0) + if (count($setSwapRows) > 0) { $str = array(); $nkeys = count($currTable); - foreach ($swapRows as $from => $to) + foreach ($setSwapRows as $from => $to) if ($from >= 0 && $from < $nkeys && $to >= 0 && $to < $nkeys && $to != $from) { $str[] = $from." <=> ".$to; @@ -292,7 +291,7 @@ foreach ($currTable as $name) { - echo " <th>".matLink($name)."</th>\n"; + echo " <th>".stGetMatLink($name)."</th>\n"; } echo " </tr>\n"; @@ -301,7 +300,7 @@ foreach ($currTable as $mat1) { - echo " <tr><th>".matLink($mat1)."</th>"; + echo " <tr><th>".stGetMatLink($mat1)."</th>"; foreach ($currTable as $mat2) { // Is the combo possible? @@ -329,14 +328,14 @@ $slist = array(); foreach ($tmp as $a => $b) { - $slist[] = matLink($a, + $slist[] = stGetMatLink($a, $b." successful alloys (".$mat1." + ".$mat2." = ".$a.")". (count($tmp) > 1 ? " [UNSTABLE]" : "") ); // , " <sup>".$b."</sup>"); } echo - "<td".addValueStyle($value, count($tmp) > 1 ? " mitalic" : "").">". + "<td".stGetValueStyle($value, count($tmp) > 1 ? " mitalic" : "").">". join(" <span class=\"alternate\">/</span> ", $slist)."</td>"; } else