Mercurial > hg > batmud > misc
changeset 313:c31c428afaf5 misc
Many code cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 29 Dec 2015 13:04:18 +0200 |
parents | a802307e733b |
children | 7615bf7f980f |
files | materials/info.php |
diffstat | 1 files changed, 69 insertions(+), 67 deletions(-) [+] |
line wrap: on
line diff
--- a/materials/info.php Tue Dec 29 10:32:04 2015 +0200 +++ b/materials/info.php Tue Dec 29 13:04:18 2015 +0200 @@ -1,25 +1,25 @@ <? $pageTitle = "Pupunen BatMUD Alloy Browser"; $pageIndex = "info.php"; -$people = array("Hair", "Malacoda", "Kiomet", "Aegenor", "Gileon", "Corto"); +$people = ["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), +$matTypeTable = [ + 0 => ["Organic + cloth (sewing)", 0, 1], + 1 => ["Wood + bone (carpentry)", 5, 3], + 2 => ["Metal + alloy (blacksmithing)", 4, 7], + 3 => ["Stone (masonry)", 6, -1], + 4 => ["Gem (gemcutting)", 10, -1], + 5 => ["Inorganic (sculpture)", 8, -1], + 6 => ["Glass (glassblowing)", 9, -1], - 7 => array("Organic", 0, -1), - 8 => array("Wood", 5, -1), - 9 => array("Metal", 4, -1), + 7 => ["Organic", 0, -1], + 8 => ["Wood", 5, -1], + 9 => ["Metal", 4, -1], - 10 => array("Cloth", -1, 1), - 11 => array("Bone", -1, 3), - 12 => array("Alloy", -1, 7), -); + 10 => ["Cloth", -1, 1], + 11 => ["Bone", -1, 3], + 12 => ["Alloy", -1, 7], +]; require "mgeneric.inc.php"; @@ -34,21 +34,24 @@ } +$reliability = [ + [ 1, 1, "1 test", "background: #a00; color: white;" ], + [ 2, 4, "2-4 tests", "background: #750; color: white;" ], + [ 5, 9, "5-9 tests", "background: #c90; color: black;", "color: black;" ], + [ 10, 19, "10-19 tests", "background: #080; color: white;" ], + [ 20, 1000, "20 or more", "background: #0c0; color: black;", "color: black;" ], +]; + + function stGetValueStyle($n) { - if ($n >= 40) $str = 40; - else - if ($n >= 20) $str = 20; - else - if ($n >= 10) $str = 10; - else - if ($n >= 5) $str = 5; - else - if ($n > 0) $str = 0; - else - return ""; - - return " class=\"hits".$str."\""; + global $reliability; + foreach ($reliability as $chk) + { + if ($n >= $chk[0] && $n <= $chk[1]) + return " class=\"hits".$chk[0]."to".$chk[1]."\""; + } + return ""; } @@ -65,52 +68,51 @@ $setSwapRows = (isset($_GET["swap"]) && is_array($_GET["swap"])) ? $_GET["swap"] : array(); +$extraCSS = []; +$extraInfo = []; +foreach ($reliability as $chk) +{ + $tmps = "hits".$chk[0]."to".$chk[1]; + $extraCSS[] = " td.".$tmps.", .".$tmps." { ".$chk[3]." }"; + if (isset($chk[4])) + $extraCSS[] = " td.".$tmps." a { ".$chk[4]." }"; + + $extraInfo[] = "<span class=\"hits".$chk[0]."to".$chk[1]."\"><b>".$chk[2]."</b></span>"; +} cmPrintPageHeader($pageTitle, " <meta name=\"robots\" content=\"nofollow\" /> <style type=\"text/css\"> span.alternate { color: red; font-weight: bold; } - td.hits20 a, .hits20 { color: black; } - - td.hits40, .hits40 { background: #0f0; color: white; } - td.hits20, .hits20 { background: #0c0; color: black; } - td.hits10, .hits10 { background: #080; } - td.hits5, .hits5 { background: #750; } - td.hits0, .hits0 { background: #a00; } +".implode("\n", $extraCSS)." td.nohits, .nohits { background: black; } td.impossible { background: black; color: #f00; text-align: center; } </style> "); -?> -<h1><? echo $pageTitle; ?></h1> -<form action="<? echo $pageIndex; ?>" method="get"> -<table class="optionsTable" width="100%"> - <tr> - <th width="25%">Show type</th> - <td rowspan="3" class="infobox"> - [<a href="<? echo $pageIndex; ?>">Reset/Clear</a>] [<a href="index.php">Material browser</a>] - <br /> - <ul> - <li><b>Also available in <a href="alloys.txt">ASCII plaintext format</a>.</b></li> - <li><b><a href="instructions.php">Read this</a> for instructions on how you can collect and submit your own alloy research data.</b></li> - <li>Only 2-material alloys are supported by this browser.</li> - <li>There may be errors, and lots of combinations are not researched yet.</li> - <li>The cell colour reflects how "reliable" the information is: - <b> - <span class="hits0">1-4 tries</span>, - <span class="hits5">5-9 tries</span>, - <span class="hits10">10-19 tries</span>, - <span class="hits20">20..39 tries</span>, - <span class="hits40">40 or more</span></b>. - </li> -<? +echo + "<h1>".$pageTitle."</h1>\n". + "<form action=\"".$pageIndex."\" method=\"get\">\n". + "<table class=\"optionsTable\" width=\"100%\">\n". + " <tr>\n". + " <th width=\"25%\">Show type</th>\n". + " <td rowspan=\"3\" class=\"infobox\">\n". + " [<a href=\"".$pageIndex."\">Reset/Clear</a>] [<a href=\"index.php\">Material browser</a>]\n". + " <br />\n". + " <ul>\n". + " <li><b>Also available in <a href=\"alloys.txt\">ASCII plaintext format</a>.</b></li>\n". + " <li><b><a href=\"instructions.php\">Read this</a> for instructions on how you can collect and submit your own alloy research data.</b></li>\n". + " <li>Only 2-material alloys are supported by this browser.</li>\n". + " <li>There may be errors, and lots of combinations are not researched yet.</li>\n". + " <li>The cell colour reflects how \"reliable\" the information is: ". + implode(", ", $extraInfo).".</li>\n"; + if (isset($people) && count($people) > 0) { - $tmp = array(); + $tmp = []; foreach ($people as $key) $tmp[] = "<b>".$key."</b>"; - echo "<li>Thanks to the following people for providing alloying data: ".join(", ", $tmp).".</li>"; + echo " <li>Thanks to the following people for providing alloying data: ".join(", ", $tmp).".</li>\n"; } echo @@ -169,7 +171,7 @@ echo "<th>".chentities($matTransNames[$key + 1])."</th><td>"; if (is_array($val)) { - $tmp = array(); + $tmp = []; foreach ($val as $lode) $tmp[] = chentities($matTransTable[$key][$lode]); echo join(", ", $tmp); @@ -189,7 +191,7 @@ echo "<ul>\n"; foreach ($alloyRevTable[$setShowMat] as $mat => $value) { - $tmp = array(); + $tmp = []; foreach ($value as $qkey => $qval) $tmp[] = stGetMatLink($qkey); @@ -211,7 +213,7 @@ } /* - $typeMats = array(); + $typeMats = []; foreach ($matDataTable as $name => $data) { if ($data[14] == $matDataTable[$setShowMat][14] && $name != $setShowMat) @@ -265,7 +267,7 @@ * Print alloy table for given material type */ // Filter table from maintable matching desired material type(s) - $currTable = array(); + $currTable = []; foreach ($matDataTable as $name => $data) { if ($data[14] == $matTypeTable[$setShowOnly][1] || @@ -276,7 +278,7 @@ // Swap desired rows if (count($setSwapRows) > 0) { - $str = array(); + $str = []; $nkeys = count($currTable); foreach ($setSwapRows as $from => $to) if ($from >= 0 && $from < $nkeys && $to >= 0 && $to < $nkeys && $to != $from) @@ -338,7 +340,7 @@ $researched++; $researchValue += $value; - $slist = array(); + $slist = []; foreach ($tmp as $a => $b) { $slist[] = stGetMatLink($a,