From d15f4cd48bcf7f1e02fb220f58263b3006fef5c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dzieko=C5=84ski?= Date: Mon, 1 Aug 2022 23:18:54 +0200 Subject: [PATCH] GH-91 Cleanup slot renderer --- simulator.php | 62 ++++++++++--------- templates/default_template/simulator_slot.tpl | 2 +- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/simulator.php b/simulator.php index 437ef7892..803b7690b 100644 --- a/simulator.php +++ b/simulator.php @@ -510,36 +510,42 @@ function ($value, $key) { $TPL_Row = gettemplate('simulator_row'); $TPL_NoLeft = gettemplate('simulator_row_noleft'); -for($i = 1; $i <= $MaxACSSlots; $i += 1) -{ - $ThisSlot = []; - $ThisSlot['SlotID'] = $i; - $ThisSlot['txt'] = ''; - - $parse = $_Lang; - $parse['i'] = $i; - if($i > 1) - { - $ThisSlot['SlotHidden'] = 'hide'; - } - - if (MORALE_ENABLED) { - $ThisSlot['txt'] .= AttackSimulator\Components\MoraleInputsSection\render([ - 'slotIdx' => $i, +for ( + $slotIdx = 1; + $slotIdx <= $MaxACSSlots; + $slotIdx += 1 +) { + $thisSlotElements = [ + ( + MORALE_ENABLED ? + AttackSimulator\Components\MoraleInputsSection\render([ + 'slotIdx' => $slotIdx, + 'input' => &$_POST, + ])['componentHTML'] : + '' + ), + AttackSimulator\Components\TechInputsSection\render([ + 'slotIdx' => $slotIdx, 'input' => &$_POST, - ])['componentHTML']; - } - - $ThisSlot['txt'] .= AttackSimulator\Components\TechInputsSection\render([ - 'slotIdx' => $i, - 'input' => &$_POST, - ])['componentHTML']; - $ThisSlot['txt'] .= AttackSimulator\Components\UnitInputsSection\render([ - 'slotIdx' => $i, - 'input' => &$_POST, - ])['componentHTML']; + ])['componentHTML'], + AttackSimulator\Components\UnitInputsSection\render([ + 'slotIdx' => $slotIdx, + 'input' => &$_POST, + ])['componentHTML'], + ]; + $isMainFleetsSlot = ($slotIdx === 1); + + $thisSlotProps = [ + 'SlotID' => $slotIdx, + 'SlotInitiallyHidden' => ( + !$isMainFleetsSlot ? + 'hide' : + '' + ), + 'txt' => implode('', $thisSlotElements), + ]; - $_Lang['rows'] .= parsetemplate($TPL_Slot, $ThisSlot); + $_Lang['rows'] .= parsetemplate($TPL_Slot, $thisSlotProps); } $isUsingPrettyInputs = ($_User['settings_useprettyinputbox'] == 1); diff --git a/templates/default_template/simulator_slot.tpl b/templates/default_template/simulator_slot.tpl index 7562d8342..e753c3cbf 100644 --- a/templates/default_template/simulator_slot.tpl +++ b/templates/default_template/simulator_slot.tpl @@ -1 +1 @@ -{txt} +{txt}