From 86e26cbb7603c3df2832d1a483667d31a30bfc52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dzieko=C5=84ski?= Date: Mon, 18 Jul 2022 22:19:07 +0200 Subject: [PATCH 01/38] GH-91 Simplify own fleets & defenses object generation --- simulator.php | 45 ++++++++++++++---------- templates/default_template/simulator.tpl | 2 +- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/simulator.php b/simulator.php index 1de3cad65..fc4a053bd 100644 --- a/simulator.php +++ b/simulator.php @@ -7,6 +7,8 @@ use UniEngine\Engine\Modules\Flights; +use UniEngine\Engine\Includes\Helpers\World; + loggedCheck(); includeLang('simulator'); @@ -669,30 +671,37 @@ function ($matches) use ($Offsets) { ); $_Lang['fill_with_mytechs'] = "var MyTechs = new Array();\nMyTechs[1] = ".(string)($_User['tech_weapons'] + 0).";\nMyTechs[3] = ".(string)($_User['tech_shielding'] + 0).";\nMyTechs[2] = ".(string)($_User['tech_armour'] + 0).";\nMyTechs[4] = ".(string)($_User['tech_laser'] + 0).";\nMyTechs[5] = ".(string)($_User['tech_ion'] + 0).";\nMyTechs[6] = ".(string)($_User['tech_plasma'] + 0).";\nMyTechs[7] = ".(string)($_User['tech_antimatter'] + 0).";\nMyTechs[8] = ".(string)($_User['tech_disintegration'] + 0).";\nMyTechs[9] = ".(string)($_User['tech_graviton'] + 0).";\n"; -$_Lang['fill_with_myfleets'] = "var MyFleets = new Array();\n"; $UsingPrettyInputBox = ($_User['settings_useprettyinputbox'] == 1 ? true : false); -foreach($_Vars_ElementCategories['fleet'] as $ID) -{ - if($_Planet[$_Vars_GameElements[$ID]] > 0) - { - $_Lang['fill_with_myfleets'] .= "MyFleets[{$ID}] = '".($UsingPrettyInputBox === true ? prettyNumber($_Planet[$_Vars_GameElements[$ID]]) : $_Planet[$_Vars_GameElements[$ID]])."';\n"; +$fleetsAndDefenses = array_filter( + array_merge($_Vars_ElementCategories['fleet'], $_Vars_ElementCategories['defense']), + function ($elementId) { + return ( + World\Elements\isShip($elementId) || + World\Elements\isDefenseSystem($elementId) + ); } -} -foreach($_Vars_ElementCategories['defense'] as $ID) -{ - if(in_array($ID, $_Vars_ElementCategories['rockets'])) - { - continue; +); +$ownFleetsAndDefenses = object_map( + $fleetsAndDefenses, + function ($elementId) use (&$_Planet, &$_User, $UsingPrettyInputBox) { + $currentCount = World\Elements\getElementCurrentCount($elementId, $_Planet, $_User); + $currentCountDisplay = ( + $UsingPrettyInputBox ? + prettyNumber($currentCount) : + $currentCount + ); + + return [ + $currentCountDisplay, + $elementId + ]; } +); + +$_Lang['fill_with_myfleets'] = json_encode($ownFleetsAndDefenses); - if($_Planet[$_Vars_GameElements[$ID]] > 0) - { - $_Lang['fill_with_myfleets'] .= "MyFleets[{$ID}] = '".($UsingPrettyInputBox === true ? prettyNumber($_Planet[$_Vars_GameElements[$ID]]) : $_Planet[$_Vars_GameElements[$ID]])."';\n"; - } -} -$_Lang['fill_with_myfleets'] .= "\n"; $_Lang['AllowPrettyInputBox'] = ($_User['settings_useprettyinputbox'] == 1 ? 'true' : 'false'); //Display page diff --git a/templates/default_template/simulator.tpl b/templates/default_template/simulator.tpl index 874918b4d..f20789387 100644 --- a/templates/default_template/simulator.tpl +++ b/templates/default_template/simulator.tpl @@ -1,7 +1,7 @@ From ba69b406ea89c34bfb3d51fd31b7d770da94b74c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dzieko=C5=84ski?= Date: Mon, 18 Jul 2022 22:23:11 +0200 Subject: [PATCH 02/38] GH-91 Simplify setting AllowPrettyInputBox for template --- simulator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simulator.php b/simulator.php index fc4a053bd..de01dc59b 100644 --- a/simulator.php +++ b/simulator.php @@ -702,7 +702,7 @@ function ($elementId) use (&$_Planet, &$_User, $UsingPrettyInputBox) { $_Lang['fill_with_myfleets'] = json_encode($ownFleetsAndDefenses); -$_Lang['AllowPrettyInputBox'] = ($_User['settings_useprettyinputbox'] == 1 ? 'true' : 'false'); +$_Lang['AllowPrettyInputBox'] = ($UsingPrettyInputBox ? 'true' : 'false'); //Display page $page = parsetemplate(gettemplate('simulator'), $_Lang); From 2e408bf6efa0d068870d02972d3476423487e8ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dzieko=C5=84ski?= Date: Mon, 18 Jul 2022 22:47:05 +0200 Subject: [PATCH 03/38] GH-91 Simplify own techs object generation --- simulator.php | 16 +++++++++++++--- templates/default_template/simulator.tpl | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/simulator.php b/simulator.php index de01dc59b..3f43a9d80 100644 --- a/simulator.php +++ b/simulator.php @@ -670,10 +670,20 @@ function ($matches) use ($Offsets) { $_Lang['rows'] ); -$_Lang['fill_with_mytechs'] = "var MyTechs = new Array();\nMyTechs[1] = ".(string)($_User['tech_weapons'] + 0).";\nMyTechs[3] = ".(string)($_User['tech_shielding'] + 0).";\nMyTechs[2] = ".(string)($_User['tech_armour'] + 0).";\nMyTechs[4] = ".(string)($_User['tech_laser'] + 0).";\nMyTechs[5] = ".(string)($_User['tech_ion'] + 0).";\nMyTechs[6] = ".(string)($_User['tech_plasma'] + 0).";\nMyTechs[7] = ".(string)($_User['tech_antimatter'] + 0).";\nMyTechs[8] = ".(string)($_User['tech_disintegration'] + 0).";\nMyTechs[9] = ".(string)($_User['tech_graviton'] + 0).";\n"; - $UsingPrettyInputBox = ($_User['settings_useprettyinputbox'] == 1 ? true : false); +$ownTechLevels = object_map( + $TechEquivalents, + function ($elementId, $idx) use (&$_Planet, &$_User) { + $currentLevel = World\Elements\getElementCurrentLevel($elementId, $_Planet, $_User); + + return [ + $currentLevel, + $idx + ]; + } +); + $fleetsAndDefenses = array_filter( array_merge($_Vars_ElementCategories['fleet'], $_Vars_ElementCategories['defense']), function ($elementId) { @@ -700,8 +710,8 @@ function ($elementId) use (&$_Planet, &$_User, $UsingPrettyInputBox) { } ); +$_Lang['fill_with_mytechs'] = json_encode($ownTechLevels); $_Lang['fill_with_myfleets'] = json_encode($ownFleetsAndDefenses); - $_Lang['AllowPrettyInputBox'] = ($UsingPrettyInputBox ? 'true' : 'false'); //Display page diff --git a/templates/default_template/simulator.tpl b/templates/default_template/simulator.tpl index f20789387..6829fd541 100644 --- a/templates/default_template/simulator.tpl +++ b/templates/default_template/simulator.tpl @@ -1,6 +1,6 @@