From 961a06166243a9d5e979ec3f5093925b79312d64 Mon Sep 17 00:00:00 2001 From: Hash Borgir Date: Tue, 30 May 2023 12:38:50 -0600 Subject: [PATCH] Gendocs cube generator fixes. More needed. Removed Exocet font. Need to fix image paths. --- genDocs.php | 377 ++++++++++++++++++------------------------ templates/htmlTop.php | 2 +- 2 files changed, 162 insertions(+), 217 deletions(-) diff --git a/genDocs.php b/genDocs.php index b0c24b8..afa4cfc 100755 --- a/genDocs.php +++ b/genDocs.php @@ -85,23 +85,22 @@ $htmlbottom = ""; // genDocUniqueItems if ($cmd == "genDocUniqueItems") { - - $tableTop = ' - + $tableTop = '
- - - - - - - - + + + + + + + + - '; - $tableBottom = '
NameLvlLvl ReqTypeCodeItem
NameLvlLvl ReqTypeCodeItem
'; + '; - // grab unique item index only (to save on memory) + $tableBottom = ''; + + // Grab unique item index only (to save on memory) $sql = "SELECT `index` FROM `uniqueitems` WHERE `enabled`='1'"; $uIndex = PDO_FetchAll($sql); @@ -112,85 +111,83 @@ if ($cmd == "genDocUniqueItems") { echo $tableTop; ob_flush(); - // main loop: grab the data for each uIndex (index from uniqueitems.txt) + // Main loop: grab the data for each uIndex (index from uniqueitems.txt) foreach ($uIndex as $u) { $item = $idata->uniqueItems($u['index'], true); - $itemBoxTop = ""; - $itemBoxTop .= "{$item['index']}"; - $itemBoxTop .= "{$item['lvl']}"; - $itemBoxTop .= "{$item["lvl req"]}"; - $itemBoxTop .= "{$item["*type"]}"; - $itemBoxTop .= "{$item['code']}"; + $itemBoxTop = ''; + $itemBoxTop .= '' . $item['index'] . ''; + $itemBoxTop .= '' . $item['lvl'] . ''; + $itemBoxTop .= '' . $item["lvl req"] . ''; + $itemBoxTop .= '' . $item["*type"] . ''; + $itemBoxTop .= '' . $item['code'] . ''; + $itemBoxTop .= << +
+
+ +
+
+
+

+ HTML; - $itemBoxTop .= << -

- -
- -
-
-
-

- EOT; - $itemBoxBottom = << -

-
-
- - EOT; - $itemBoxBottom .= ""; + $itemBoxBottom = << +
+
+
+ + + HTML; echo $itemBoxTop; ob_flush(); $htmlFinal .= $itemBoxTop; - //index - $props = "'; echo $props; echo $itemBoxBottom; ob_flush(); $htmlFinal .= $props . $itemBoxBottom; - }// end loop + } $htmlFinal .= $tableBottom; @@ -206,13 +203,11 @@ if ($cmd == "genDocUniqueItems") { if ($cmd == "genDocCube") { $htmlFinal = ''; $htmlFinal .= $htmltop; - - echo $htmltop; - ob_flush(); - + echo $htmltop; + ob_flush(); $table = << - + + @@ -226,7 +221,7 @@ if ($cmd == "genDocCube") { - + EOT; echo $table; @@ -266,42 +261,33 @@ EOT; // get all cube rows // changed enabled=1 to enabled > 0 for CubeOps.dll users - - $sql = " - SELECT * - FROM cubemain - WHERE enabled > 0 - AND `input 1` <> 'ib3' - AND `description` NOT LIKE '%Stone x%' - AND `description` NOT LIKE '%Unstacker%' - "; - + + $sql = "SELECT * + FROM cubemain + WHERE enabled > 0 + AND `input 1` <> 'ib3' + AND `description` NOT LIKE '%Stone x%' + AND `description` NOT LIKE '%Unstacker%' "; $res = PDO_FetchAll($sql); - // ddump($res); - - // process each cube row here foreach ($res as $r) { $desc = str_replace('+', '
+
', $r['description']); - $desc = str_replace('->', '
=
', $desc); + $desc = str_replace('->', '
=
', $desc); $desc .= "
"; // grab all inputs - $input_codes = array_filter( - [ - "input 1" => $r["input 1"], - "input 2" => $r["input 2"], - "input 3" => $r["input 3"], - "input 4" => $r["input 4"], - "input 5" => $r["input 5"], - "input 6" => $r["input 6"], - "input 7" => $r["input 7"], - ] - ); + $input_codes = array_filter([ + "input 1" => $r["input 1"], + "input 2" => $r["input 2"], + "input 3" => $r["input 3"], + "input 4" => $r["input 4"], + "input 5" => $r["input 5"], + "input 6" => $r["input 6"], + "input 7" => $r["input 7"], + ]); foreach ($input_codes as $inputNum => $value) { - if (str_contains($value, ',')) { $input_codes[$inputNum] = explode(",", $value); // hpot,qty=3 @@ -310,14 +296,12 @@ EOT; // if spelldescstr is set, use it. Else use item string tbl // first find the item code in either armor, misc, or weapons // then get spelldesc/spelldescstr -// $sql = "SELECT `String` FROM `strings` WHERE Key=\"{$oarray[0]}\""; -// $str = PDO_FetchOne($sql); - - $str = $strings[$oarray[0]]; - + // $sql = "SELECT `String` FROM `strings` WHERE Key=\"{$oarray[0]}\""; + // $str = PDO_FetchOne($sql); + $str = $strings[$oarray[0]]; // Assuming $strings array is defined // if empty str == 4-letter code, call $idoc->getItemName() if (empty($str)) { - $input_codes[$inputNum][0] = ($oarray[0]); + $input_codes[$inputNum][0] = $oarray[0]; } else { $input_codes[$inputNum][0] = $str; } @@ -333,14 +317,12 @@ EOT; // if spelldescstr is set, use it. Else use item string tbl // first find the item code in either armor, misc, or weapons // then get spelldesc/spelldescstr -// $sql = "SELECT `String` FROM `strings` WHERE Key=\"{$oarray[0]}\""; -// $str = PDO_FetchOne($sql); - - $str = $strings[$oarray[0]]; - + // $sql = "SELECT `String` FROM `strings` WHERE Key=\"{$oarray[0]}\""; + // $str = PDO_FetchOne($sql); + $str = $strings[$oarray[0]]; // Assuming $strings array is defined // if empty str == 4-letter code, so just display if (empty($str)) { - $input_codes[$inputNum][0] = ($oarray[0]); + $input_codes[$inputNum][0] = $oarray[0]; } else { $input_codes[$inputNum][0] = $str; } @@ -353,24 +335,32 @@ EOT; // processs output, output b, output c // grab all inputs $output_codes = array_filter( - [ - "output" => str_replace('"', "", $r["output"]), - "output b" => str_replace('"', "", $r["output b"]), - "output c" => str_replace('"', "", $r["output c"]) - ] + [ + "output" => str_replace('"', "", $r["output"]), + "output b" => str_replace('"', "", $r["output b"]), + "output c" => str_replace('"', "", $r["output c"]) + ] ); - - // ddump($output_codes); + // var_dump($output_codes); + // output_codes is an array + // output codes of outputs, like output, output b, output c. + // each output can have 3 or 4 level item code or a amu,mag,pre=331 code + // outputNum is output a, or output b, or output c, should have been called outputLetter whatever foreach ($output_codes as $outputNum => $value) { + //outputNum will be output, or output b, or c + // value will be 3/4 letter code or sometimes 'Cow Portal' or words + // or rin,mag,pre=353 + // if value contains a comma, e.g., rin,mag,pre=353 + // then explode it at the comma if (str_contains($value, ',')) { $output_codes[$outputNum] = explode(",", $value); // hpot,qty=3 $oarray = explode(",", $value); // hpot,qty=3 - $sql = $strings[$oarray[0]]; // "SELECT `String` FROM `strings` WHERE Key=\"{$oarray[0]}\""; + + $str = $strings[$oarray[0]]; // "SELECT `String` FROM `strings` WHERE Key=\"{$oarray[0]}\""; // clean str // $str = PDO_FetchOne($sql); - if (str_contains($str, "ÿc")) { $p = "/ÿc[\d:;\/.]/i"; $str = preg_replace($p, "", $str); @@ -389,7 +379,7 @@ EOT; $output_codes[$outputNum] = explode(",", $value); // hpot,qty=3 $oarray = explode(",", $value); // hpot,qty=3 - $sql = $strings[$oarray[0]]; //"SELECT `String` FROM `strings` WHERE Key=\"{$oarray[0]}\""; + $str = $strings[$oarray[0]]; //"SELECT `String` FROM `strings` WHERE Key=\"{$oarray[0]}\""; // clean color codes // $str = PDO_FetchOne($sql); @@ -409,7 +399,7 @@ EOT; $output_codes[$outputNum]["img"] = $idoc->getImage($oarray[0]); } - + //var_dump($output_codes); // if output[1] or output[2], output[3], output[4] contains `=' sign // parse_str or explode at = to get modifer and value // if modifier = pre or suf, find ID in magic prefix/suffix line. @@ -487,17 +477,16 @@ EOT; "par" => $par, "min" => $min, "max" => $max, - // "val1" => $funcval['val1'], - // "func1" => $funcval['func1'] - // 'item' => $return + // "val1" => $funcval['val1'], + // "func1" => $funcval['func1'] + // 'item' => $return ]; $output['mods'][$k]["str"] = $idesc->getDesc($params); } - - // dump($output); - - // var_dump($output); + + + //var_dump($output); // At this point, $output contains raw accurte data // TODO: build output correctly // input1-input7,output a,b,c item codes can be found in $strings @@ -551,11 +540,7 @@ EOT; $output["output"][0] = preg_replace($p, "", $output["output"][0]); } - $key1 = array_search($output["input $i"][0], $itemtypesTbl); - - //var_dump($output); - // if the item is in itemtypes grab it, it's 4 letter code fron itemtypes - + $htmlRow .= '' . $output["output"][0] . "
"; $key1 = array_search($output["input $i"][0], $itemtypesTbl); if (str_contains($output["output"][1], "ÿc")) { @@ -563,9 +548,9 @@ EOT; $output["output"][1] = preg_replace($p, "", $output["output"][1]); } if ($i_params[$output["output"][0]]) { - $htmlRow .= '' . $output["output"][0] . "
"; + $htmlRow .= '' . $i_params[$output["output"][0]] . "
"; } else { - $htmlRow .= $output["output"][0] . "
"; + $htmlRow .= $i_params[$output["output"][0]] . "
"; } if ($i_params[$output["output"][1]]) { $htmlRow .= $i_params[$output["output"][1]] . "
"; @@ -626,7 +611,7 @@ EOT; } $htmlRow .= ""; - $htmlRow .= "
- + - EOT; } - - $htmlFinal = $htmltop . $tableTop . $tr . $tableBottom . $htmlbottom; ob_flush(); echo $htmlFinal; - //file_put_contents("$dir/armor.html", $htmlFinal); - //header("Location: docs/{$_SESSION['modname']}/armor.html"); + file_put_contents("$dir/armor.html", $htmlFinal); + header("Location: docs/{$_SESSION['modname']}/armor.html"); } -if ($cmd == 'genDocWeapons') { +// Generate weapons.txt docs +if ($cmd == 'genDocWeapons') { $tableTop = << body { font-family: Tahoma,Arial,Sans-Serif} @@ -1413,7 +1364,6 @@ EOT; $res = PDO_FetchAll($sql); foreach ($res as $r) { - $name = (!empty($strings[$r['namestr']])) ? $strings[$r['namestr']] : $r['name']; if ($r['indestructible'] == '1') { @@ -1422,9 +1372,8 @@ EOT; $indestructable = "No"; } - - $imgUnique = (!empty($r['uniqueinvfile'])) ? "
" : ""; - $imgSet = (!empty($r['setinvfile'])) ? "
" : ""; + $imgUnique = (!empty($r['uniqueinvfile'])) ? "
" : ""; + $imgSet = (!empty($r['setinvfile'])) ? "
" : ""; if (!empty($r['auto prefix'])) { $sql = "SELECT * FROM automagic WHERE `group` = ?"; @@ -1461,15 +1410,15 @@ EOT; } $strbonus = (!empty($r['StrBonus'])) ? "Strength Bonus: {$r['StrBonus']}" : ""; - - if (empty($r['mindmg']) OR empty($r['maxdmg'])){ + + if (empty($r['mindmg']) OR empty($r['maxdmg'])) { $mindmg = $r['2handmindam']; $maxdmg = $r['2handmaxdam']; } else { - $mindmg = $r['mindmg']; - $maxdmg = $r['maxdmg']; + $mindmg = $r['mindmg']; + $maxdmg = $r['maxdmg']; } - + $tr .= <<
- + - EOT; } diff --git a/templates/htmlTop.php b/templates/htmlTop.php index f7cd468..2d262d9 100644 --- a/templates/htmlTop.php +++ b/templates/htmlTop.php @@ -28,7 +28,7 @@ $htmltop = <<
Recipe Input 1 2 3
"; // change _output3 to normal + $htmlRow .= ""; // change _output3 to normal if (!empty($output["output c"]["img"])) { $htmlRow .= "
"; if (str_contains($output["output c"][0], "ÿc")) { @@ -673,21 +658,19 @@ EOT; echo $htmlbottom; ob_flush(); $htmlFinal .= $tableBottom . $htmlbottom; - - // echo $htmlFinal; + // echo $htmlFinal; // save file and redirect to it file_put_contents("$dir/cubemain.html", $htmlFinal); header("Location: docs/{$_SESSION['modname']}/cubemain.html"); } if ($cmd == "getImages") { - $sql = " -SELECT code,invfile,type,type2 FROM armor -UNION ALL -SELECT code,invfile,type,type2 FROM misc -UNION ALL -SELECT code,invfile,type,type2 FROM weapons"; + $sql = "SELECT code,invfile,type,type2 FROM armor + UNION ALL + SELECT code,invfile,type,type2 FROM misc + UNION ALL + SELECT code,invfile,type,type2 FROM weapons"; $res = PDO_FetchAll($sql); $isc = null; foreach ($res as $r) { @@ -807,7 +790,6 @@ if ($cmd == "genDocGems") { //echo $table; $htmlFinal .= $table; //ob_flush(); - // $gems are all the gems, processed, now display them foreach ($gems as $g) { @@ -859,16 +841,15 @@ if ($cmd == "genDocGems") { $htmlFinal .= $htmlRow; //echo $htmlRow; - // ob_flush(); + // ob_flush(); } $htmlFinal .= $tableBottom . $htmlbottom; //echo $tableBottom . $htmlbottom; //ob_flush(); - //ob_start(); file_put_contents("$dir/gems.html", $htmlFinal); - header("Location: /docs/{$_SESSION['modname']}/gems.html",TRUE,301); + header("Location: /docs/{$_SESSION['modname']}/gems.html", TRUE, 301); } @@ -925,31 +906,14 @@ if ($cmd == 'genDocRunewords') { $rr[5] = str_replace('', '', $strings[$rune['Rune5']]); $rr[6] = str_replace('', '', $strings[$rune['Rune6']]); - if (str_contains($rr[1], "ÿc")) { - $p = "/ÿc[\d:;\/.]/i"; - $rr[1] = preg_replace($p, "", $rr[1]); - } - if (str_contains($rr[2], "ÿc")) { - $p = "/ÿc[\d:;\/.]/i"; - $rr[2] = preg_replace($p, "", $rr[2]); - } - if (str_contains($rr[3], "ÿc")) { - $p = "/ÿc[\d:;\/.]/i"; - $rr[3] = preg_replace($p, "", $rr[3]); - } - if (str_contains($rr[4], "ÿc")) { - $p = "/ÿc[\d:;\/.]/i"; - $rr[4] = preg_replace($p, "", $rr[4]); - } - if (str_contains($rr[5], "ÿc")) { - $p = "/ÿc[\d:;\/.]/i"; - $rr[5] = preg_replace($p, "", $rr[5]); - } - if (str_contains($rr[6], "ÿc")) { - $p = "/ÿc[\d:;\/.]/i"; - $rr[6] = preg_replace($p, "", $rr[6]); + for ($i = 1; $i <= 6; $i++) { + if (str_contains($rr[$i], "ÿc")) { + $p = "/ÿc[\d:;\/.]/i"; + $rr[$i] = preg_replace($p, "", $rr[$i]); + } } + $rr = array_filter($rr); $rune_count = count($rr); $rune_count_duplicates = array_count_values($rr); @@ -1176,27 +1140,23 @@ EOT; $data['nameable'] = "Can be personalized by Anya"; } - if ($r['stat1']) { - $stats['stat1'] = "{$r['stat1']}"; - } - if ($r['stat2']) { - $stats['stat2'] = "{$r['stat2']}"; - } - if ($r['stat3']) { - $stats['stat3'] = "{$r['stat3']}"; + $statFields = ['stat1', 'stat2', 'stat3']; + $calcFields = ['calc1', 'calc2', 'calc3']; + + foreach ($statFields as $field) { + if (isset($r[$field])) { + $stats[$field] = "{$r[$field]}"; + } } - if ($r['calc1']) { - $stats['calc1'] = "{$r['calc1']}"; - } - if ($r['calc2']) { - $stats['calc2'] = "{$r['calc2']}"; - } - if ($r['calc3']) { - $stats['calc3'] = "{$r['calc3']}"; + foreach ($calcFields as $field) { + if (isset($r[$field])) { + $stats[$field] = "{$r[$field]}"; + } } + $data = array_filter($data); if ($stats) $stat = array_filter($stats); @@ -1246,6 +1206,7 @@ EOT; +// Armor.txt docs generator if ($cmd == 'genDocArmor') { $tableTop = <<" : ""; + $imgSet = (!empty($r['setinvfile'])) ? "
" : ""; - - $imgUnique = (!empty($r['uniqueinvfile'])) ? "
" : ""; - $imgSet = (!empty($r['setinvfile'])) ? "
" : ""; - - if (!empty($r['auto prefix'])) { $sql = "SELECT * FROM automagic WHERE `group` = ?"; $ret = PDO_FetchRow($sql, [$r['auto prefix']]); @@ -1327,7 +1283,7 @@ EOT; $strbonus = (!empty($r['StrBonus'])) ? "Strength Bonus: {$r['StrBonus']}" : ""; $block = (!empty($r['block'])) ? "Block: {$r['block']}" : ""; - + $tr .= <<
@@ -1360,35 +1316,30 @@ EOT;
  • {$props[2]}
  • $strbonus
  • $block
  • - - -
    Level:
    {$r['level']}
    Level Required:
    {$r['levelreq']}
    Level Required:
    {$r['levelreq']}
    Requird Strength:
    {$r['reqstr']}
    Min AC:
    {$r['minac']}
    Max AC:
    {$r['maxac']}
    Block:
    {$r['block']}
    @@ -1502,18 +1451,14 @@ EOT;
  • {$props[2]}
  • $strbonus
  • $block
  • - - -
    Level:
    {$r['level']}
    Level Required:
    {$r['levelreq']}
    Level Required:
    {$r['levelreq']}
    Requird Strength:
    {$r['reqstr']}
    Min Dmg:
    {$mindmg}
    Max Dmg:
    {$maxdmg}