Skip to content

Commit

Permalink
GH-139 Simplify target position validation in step two
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jun 1, 2022
1 parent 481653d commit 2b44c0e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 41 deletions.
65 changes: 27 additions & 38 deletions fleet1.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
include($_EnginePath . 'modules/flightControl/_includes.php');

use UniEngine\Engine\Includes\Helpers\Common\Collections;
use UniEngine\Engine\Modules\Flights;
use UniEngine\Engine\Modules\FlightControl;

loggedCheck();
Expand Down Expand Up @@ -140,53 +141,41 @@

$unionData = $joinUnionResult['payload']['unionData'];

$SetPos['g'] = $unionData['end_galaxy'];
$SetPos['s'] = $unionData['end_system'];
$SetPos['p'] = $unionData['end_planet'];
$SetPos['t'] = $unionData['end_type'];
$SetPos['galaxy'] = $unionData['end_galaxy'];
$SetPos['system'] = $unionData['end_system'];
$SetPos['planet'] = $unionData['end_planet'];
$SetPos['type'] = $unionData['end_type'];

$_Lang['fl1_ACSJoiningFleet'] = sprintf(
$_Lang['fl1_ACSJoiningFleet'],
$unionData['name'], $unionData['end_galaxy'], $unionData['end_system'], $unionData['end_planet']
);
$_Lang['P_DisableCoordSel'] = 'disabled';
$_Lang['SelectedACSID'] = $unionData['id'];
$_Lang['SetTargetMission'] = 2;
}

if(empty($SetPos))
{
$SetPos['g'] = intval($_POST['galaxy']);
$SetPos['s'] = intval($_POST['system']);
$SetPos['p'] = intval($_POST['planet']);
$SetPos['t'] = (isset($_POST['planet_type']) ? intval($_POST['planet_type']) : 0);
if(!in_array($SetPos['t'], array(1, 2, 3)) && isset($_POST['planettype']))
{
$SetPos['t'] = intval($_POST['planettype']);
}

if($SetPos['g'] < 1 OR $SetPos['g'] > MAX_GALAXY_IN_WORLD)
{
$SetPos['g'] = $_Planet['galaxy'];
}
if($SetPos['s'] < 1 OR $SetPos['s'] > MAX_SYSTEM_IN_GALAXY)
{
$SetPos['s'] = $_Planet['system'];
}
if($SetPos['p'] < 1 OR $SetPos['p'] > (MAX_PLANET_IN_SYSTEM + 1))
{
$SetPos['p'] = $_Planet['planet'];
}
if(!in_array($SetPos['t'], array(1, 2, 3)))
{
$SetPos['t'] = $_Planet['planet_type'];
if (empty($SetPos)) {
$SetPos['galaxy'] = intval($_POST['galaxy']);
$SetPos['system'] = intval($_POST['system']);
$SetPos['planet'] = intval($_POST['planet']);
$SetPos['type'] = (isset($_POST['planet_type']) ? intval($_POST['planet_type']) : null);
$SetPos['type'] = (!isset($SetPos['type']) ? intval($_POST['planettype']) : $SetPos['type']);
$SetPos['type'] = (!isset($SetPos['type']) ? $_Planet['planet_type'] : $SetPos['type']);

$isValidCoordinate = Flights\Utils\Checks\isValidCoordinate([ 'coordinate' => $SetPos ]);

if (!$isValidCoordinate['isValid']) {
$SetPos = [
'galaxy' => $_Planet['galaxy'],
'system' => $_Planet['system'],
'planet' => $_Planet['planet'],
'type' => $_Planet['planet_type'],
];
}

$_Lang['SetTargetMission'] = $_POST['target_mission'];
}
else
{
$_Lang['SetTargetMission'] = 2;
}

$slowestShipSpeed = FlightControl\Utils\Helpers\getSlowestShipSpeed([
'shipsDetails' => $shipsDetails,
Expand Down Expand Up @@ -220,13 +209,13 @@
$_Lang['P_MaxSystem'] = MAX_SYSTEM_IN_GALAXY;
$_Lang['P_MaxPlanet'] = MAX_PLANET_IN_SYSTEM + 1;

foreach($SetPos as $Key => $Value)
{
if($Key == 't')
{
foreach ($SetPos as $Key => $Value) {
if ($Key == 'type') {
$_Lang['SetPos_Type'.$Value.'Selected'] = 'selected';

continue;
}

$_Lang['SetPos_'.$Key] = $Value;
}

Expand Down
6 changes: 3 additions & 3 deletions templates/default_template/fleet1_body.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ var shipsDetails = {P_ShipsDetailsJSON};
<tr>
<th style="width: 30%;">{fl_dest}</th>
<th>
<input class="updateInfo" id="galaxy_selector" name="galaxy" size="3" maxlength="2" value="{SetPos_g}" autocomplete="off" {P_DisableCoordSel} />
<input class="updateInfo" id="system_selector" name="system" size="3" maxlength="3" value="{SetPos_s}" autocomplete="off" {P_DisableCoordSel} />
<input class="updateInfo"id="select_planet" name="planet" size="3" maxlength="2" value="{SetPos_p}" autocomplete="off" {P_DisableCoordSel} />
<input class="updateInfo" id="galaxy_selector" name="galaxy" size="3" maxlength="2" value="{SetPos_galaxy}" autocomplete="off" {P_DisableCoordSel} />
<input class="updateInfo" id="system_selector" name="system" size="3" maxlength="3" value="{SetPos_system}" autocomplete="off" {P_DisableCoordSel} />
<input class="updateInfo" id="select_planet" name="planet" size="3" maxlength="2" value="{SetPos_planet}" autocomplete="off" {P_DisableCoordSel} />
<select class="updateInfo" id="type_selector" name="planettype" {P_DisableCoordSel}>
<option value="1" {SetPos_Type1Selected}>{fl_planet}</option>
<option value="2" {SetPos_Type2Selected}>{fl_ruins}</option>
Expand Down

0 comments on commit 2b44c0e

Please sign in to comment.