Skip to content

Commit

Permalink
GH-139 Simplify empty fleet array check code in fleet3 as well
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed May 25, 2022
1 parent a2683f6 commit a361a7b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
3 changes: 1 addition & 2 deletions fleet2.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@
}
}

if($Fleet['count'] <= 0)
{
if ($Fleet['count'] <= 0) {
message($_Lang['fl1_NoShipsGiven'], $ErrorTitle, 'fleet.php', 3);
}
$Fleet['array'] = $FleetArray;
Expand Down
53 changes: 26 additions & 27 deletions fleet3.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,42 +182,41 @@ function messageRed($Text, $Title)
$FleetArray = [];

if (
!empty($Fleet['array']) &&
is_array($Fleet['array'])
empty($Fleet['array']) ||
!is_array($Fleet['array'])
) {
$fleetArrayValidationResult = FlightControl\Utils\Validators\validateFleetArray([
'fleet' => $Fleet['array'],
'planet' => &$_Planet,
'isFromDirectUserInput' => false,
]);
messageRed($_Lang['fl1_NoShipsGiven'], $ErrorTitle);
}

if (!$fleetArrayValidationResult['isValid']) {
$firstValidationError = $fleetArrayValidationResult['errors'][0];
$errorMessage = FlightControl\Utils\Errors\mapFleetArrayValidationErrorToReadableMessage($firstValidationError);
$fleetArrayValidationResult = FlightControl\Utils\Validators\validateFleetArray([
'fleet' => $Fleet['array'],
'planet' => &$_Planet,
'isFromDirectUserInput' => false,
]);

messageRed($errorMessage, $ErrorTitle);
}
if (!$fleetArrayValidationResult['isValid']) {
$firstValidationError = $fleetArrayValidationResult['errors'][0];
$errorMessage = FlightControl\Utils\Errors\mapFleetArrayValidationErrorToReadableMessage($firstValidationError);

messageRed($errorMessage, $ErrorTitle);
}

foreach ($Fleet['array'] as $ShipID => $ShipCount) {
$ShipID = intval($ShipID);
$ShipCount = floor($ShipCount);
$FleetArray[$ShipID] = $ShipCount;
$Fleet['count'] += $ShipCount;
foreach ($Fleet['array'] as $ShipID => $ShipCount) {
$ShipID = intval($ShipID);
$ShipCount = floor($ShipCount);
$FleetArray[$ShipID] = $ShipCount;
$Fleet['count'] += $ShipCount;

$allShipsOfTypeStorage = getShipsStorageCapacity($ShipID) * $ShipCount;
$allShipsOfTypeStorage = getShipsStorageCapacity($ShipID) * $ShipCount;

if (canShipPillage($ShipID)) {
$Fleet['storage'] += $allShipsOfTypeStorage;
} else {
$Fleet['FuelStorage'] += $allShipsOfTypeStorage;
}
if (canShipPillage($ShipID)) {
$Fleet['storage'] += $allShipsOfTypeStorage;
} else {
$Fleet['FuelStorage'] += $allShipsOfTypeStorage;
}
} else {
messageRed($_Lang['fl1_NoShipsGiven'], $ErrorTitle);
}

if($Fleet['count'] <= 0)
{
if ($Fleet['count'] <= 0) {
messageRed($_Lang['fl1_NoShipsGiven'], $ErrorTitle);
}
$Fleet['array'] = $FleetArray;
Expand Down

0 comments on commit a361a7b

Please sign in to comment.