Skip to content

Commit

Permalink
GH-91 Create shared user data object creator
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jul 27, 2022
1 parent 270de9d commit 4d81c52
Showing 1 changed file with 34 additions and 32 deletions.
66 changes: 34 additions & 32 deletions simulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,30 @@ function ($value, $key) use ($TechEquivalents) {
],
];

/**
* @param array $params
* @param number $params['userSlotIdx']
* @param string $params['usernamePrefix']
* @param array $params['userKeyedTechs']
*/
$createSimulationUserData = function ($params) {
return [
'fleetRow' => [
'fleet_owner' => '0',
'fleet_start_galaxy' => '0',
'fleet_start_system' => '0',
'fleet_start_planet' => '0',
],
'user' => array_merge(
[
'username' => "{$params['usernamePrefix']}{$params['userSlotIdx']}",
],
$params['userKeyedTechs']
),
'moraleData' => null,
];
};

foreach ($inputMappingGroups as $inputMappingGroup) {
if (empty($_POST[$inputMappingGroup['techInputKey']])) {
continue;
Expand All @@ -106,21 +130,11 @@ function ($value, $key) use ($TechEquivalents) {
$userTechs[$elementKey] = $safeElementValue;
}

$inputMappingGroup['usersAccumulatorObject'][$userIdx] = [
'fleetRow' => [
'fleet_owner' => '0',
'fleet_start_galaxy' => '0',
'fleet_start_system' => '0',
'fleet_start_planet' => '0',
],
'user' => array_merge(
[
'username' => "{$inputMappingGroup['usernamePrefix']}{$userSlotIdx}",
],
$userTechs
),
'moraleData' => null,
];
$inputMappingGroup['usersAccumulatorObject'][$userIdx] = $createSimulationUserData([
'userSlotIdx' => $userSlotIdx,
'usernamePrefix' => $inputMappingGroup['usernamePrefix'],
'userKeyedTechs' => $userTechs,
]);
}
}

Expand Down Expand Up @@ -166,24 +180,12 @@ function ($value, $key) use ($TechEquivalents) {
unset($inputMappingGroup['usersAccumulatorObject'][$userIdx]);
} else if (empty($inputMappingGroup['techsAccumulatorObject'][$userIdx])) {
// Fill user techs (with zeros) & details
$userTechs = [];

$inputMappingGroup['techsAccumulatorObject'][$userIdx] = [];
$inputMappingGroup['usersAccumulatorObject'][$userIdx] = [
'fleetRow' => [
'fleet_owner' => '0',
'fleet_start_galaxy' => '0',
'fleet_start_system' => '0',
'fleet_start_planet' => '0',
],
'user' => array_merge(
[
'username' => "{$inputMappingGroup['usernamePrefix']}{$userSlotIdx}",
],
$userTechs
),
'moraleData' => null,
];
$inputMappingGroup['usersAccumulatorObject'][$userIdx] = $createSimulationUserData([
'userSlotIdx' => $userSlotIdx,
'usernamePrefix' => $inputMappingGroup['usernamePrefix'],
'userKeyedTechs' => [],
]);
}
}
}
Expand Down

0 comments on commit 4d81c52

Please sign in to comment.