Skip to content

Commit

Permalink
GH-91 Move tech inputs section to a component
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jul 29, 2022
1 parent 2ca3b4c commit 9599d92
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 28 deletions.
1 change: 1 addition & 0 deletions modules/attackSimulator/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
include($includePath . './components/MoraleInputsSection/MoraleInputsSection.component.php');
include($includePath . './components/ShipInput/ShipInput.component.php');
include($includePath . './components/TechInput/TechInput.component.php');
include($includePath . './components/TechInputsSection/TechInputsSection.component.php');

include($includePath . './utils/combatTechs.utils.php');

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace UniEngine\Engine\Modules\AttackSimulator\Components\TechInputsSection;

use UniEngine\Engine\Modules\AttackSimulator;

/**
* @param array $props
* @param number $props['slotIdx']
* @param arrayRef $props['input']
*/
function render($props) {
global $_Lang;

$slotIdx = $props['slotIdx'];
$input = &$props['input'];

$combatTechs = AttackSimulator\Utils\CombatTechs\getTechsList();

$localTemplateLoader = createLocalTemplateLoader(__DIR__);
$tplBodyCache = [
'body' => $localTemplateLoader('body'),
'techRow' => $localTemplateLoader('techRow'),
];

$techRows = array_map_withkeys(
$combatTechs,
function ($elementId) use ($slotIdx, &$input, &$_Lang, &$tplBodyCache) {
$formInputValueAttacker = (
isset($input['atk_techs'][$slotIdx][$elementId]) ?
$input['atk_techs'][$slotIdx][$elementId] :
null
);
$formInputValueDefender = (
isset($input['def_techs'][$slotIdx][$elementId]) ?
$input['def_techs'][$slotIdx][$elementId] :
null
);

$rowTemplateBodyProps = [
'prop_techName' => $_Lang['tech'][$elementId],
'prop_AttackerInput' => AttackSimulator\Components\TechInput\render([
'slotIdx' => $slotIdx,
'elementId' => $elementId,
'columnType' => 'attacker',
'initialValue' => $formInputValueAttacker,
])['componentHTML'],
'prop_DefenderInput' => AttackSimulator\Components\TechInput\render([
'slotIdx' => $slotIdx,
'elementId' => $elementId,
'columnType' => 'defender',
'initialValue' => $formInputValueDefender,
])['componentHTML'],
];

return parsetemplate(
$tplBodyCache['techRow'],
$rowTemplateBodyProps
);
}
);

$templateBodyProps = [
'lang_Technology' => $_Lang['Technology'],
'lang_FillMyTechs' => $_Lang['FillMyTechs'],
'lang_Fill_Clean' => $_Lang['Fill_Clean'],

'prop_techRowsHTML' => implode('', $techRows),
];

$componentHTML = parsetemplate(
$tplBodyCache['body'],
$templateBodyProps
);

return [
'componentHTML' => $componentHTML,
];
}

?>
26 changes: 26 additions & 0 deletions modules/attackSimulator/components/TechInputsSection/body.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<tr>
<th colspan="4" class="c">
{lang_Technology}
</th>
</tr>
<tr>
<th class="c pad5 r_b" colspan="2">
<a class="orange point fillTech_atk">
{lang_FillMyTechs}
</a>
/
<a class="orange point clnTech_atk">
{lang_Fill_Clean}
</a>
</th>
<th class="c pad5 r_b" colspan="2">
<a class="orange point fillTech_def">
{lang_FillMyTechs}
</a>
/
<a class="orange point clnTech_def">
{lang_Fill_Clean}
</a>
</th>
</tr>
{prop_techRowsHTML}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
14 changes: 14 additions & 0 deletions modules/attackSimulator/components/TechInputsSection/techRow.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<tr>
<th class="c pad5 ta_r r_l">
{prop_techName}:
</th>
<th class="c pad5 ta_l r_i">
{prop_AttackerInput}
</th>
<th class="c pad5 ta_r r_l">
{prop_techName}:
</th>
<th class="c pad5 ta_l r_i">
{prop_DefenderInput}
</th>
</tr>
32 changes: 4 additions & 28 deletions simulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,34 +530,10 @@ function ($value, $key) {
])['componentHTML'];
}

$parse['RowText'] = $_Lang['Technology'];
$ThisSlot['txt'] .= parsetemplate($TPL_SingleRow, $parse);
$parse['RowText'] = '<a class="orange point fillTech_atk">'.$_Lang['FillMyTechs'].'</a> / <a class="orange point clnTech_atk">'.$_Lang['Fill_Clean'].'</a>';
$parse['RowText2'] = '<a class="orange point fillTech_def">'.$_Lang['FillMyTechs'].'</a> / <a class="orange point clnTech_def">'.$_Lang['Fill_Clean'].'</a>';
$ThisSlot['txt'] .= parsetemplate($TPL_NoBoth, $parse);

foreach ($combatTechs as $elementId) {
$ThisRow_InsertValue_Atk = isset($_POST['atk_techs'][$i][$elementId]) ? $_POST['atk_techs'][$i][$elementId] : null;
$ThisRow_InsertValue_Def = isset($_POST['def_techs'][$i][$elementId]) ? $_POST['def_techs'][$i][$elementId] : null;

$parse['RowText'] = $_Lang['tech'][$elementId];
$parse['RowInput'] = AttackSimulator\Components\TechInput\render([
'slotIdx' => $i,
'elementId' => $elementId,
'columnType' => 'attacker',
'initialValue' => $ThisRow_InsertValue_Atk,
])['componentHTML'];

$parse['RowText2'] = $_Lang['tech'][$elementId];
$parse['RowInput2'] = AttackSimulator\Components\TechInput\render([
'slotIdx' => $i,
'elementId' => $elementId,
'columnType' => 'defender',
'initialValue' => $ThisRow_InsertValue_Def,
])['componentHTML'];

$ThisSlot['txt'] .= parsetemplate($TPL_Row, $parse);
}
$ThisSlot['txt'] .= AttackSimulator\Components\TechInputsSection\render([
'slotIdx' => $i,
'input' => &$_POST,
])['componentHTML'];

$parse['RowText'] = $_Lang['Fleets'];
$ThisSlot['txt'] .= parsetemplate($TPL_SingleRow, $parse);
Expand Down

0 comments on commit 9599d92

Please sign in to comment.