Skip to content

Commit

Permalink
Add Locations column to Ship List (#1318)
Browse files Browse the repository at this point in the history
Requested by players, and improves parity with the Weapon List.
  • Loading branch information
hemberger authored May 2, 2022
1 parent abd43ed commit 7b09ec0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@
const RACE_WARS_SHIPS = 512;
const RACE_WARS_WEAPONS = 326;
const RACE_WARS_HARDWARE = 607;
const LOCATION_TYPE_TEST_SHIPYARD = 510;
const LOCATION_TYPE_FEDERAL_BEACON = 201;
const LOCATION_TYPE_FEDERAL_HQ = 101;
const LOCATION_TYPE_FEDERAL_MINT = 704;
Expand Down
20 changes: 18 additions & 2 deletions src/htdocs/ship_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,24 @@

$template = Smr\Template::getInstance();

// Get a list of all the shops that sell each ship
$shipLocs = [];
$db = Smr\Database::getInstance();
$dbResult = $db->read('SELECT ship_type_id, location_type.* FROM location_sells_ships JOIN ship_type USING (ship_type_id) JOIN location_type USING (location_type_id) WHERE location_type_id NOT IN (' . $db->escapeArray([RACE_WARS_SHIPS, LOCATION_TYPE_TEST_SHIPYARD]) . ')');
foreach ($dbResult->records() as $dbRecord) {
$shipTypeID = $dbRecord->getInt('ship_type_id');
$locTypeID = $dbRecord->getInt('location_type_id');
$shipLocs[$shipTypeID][] = SmrLocation::getLocation($locTypeID, false, $dbRecord)->getName();
}

// Get a list of all locations that sell ships
$allLocs = array_unique(array_merge(...$shipLocs));
sort($allLocs);
$template->assign('AllLocs', $allLocs);

$shipArray = [];
foreach (SmrShipType::getAll() as $shipType) {
$shipArray[] = buildShipStats($shipType);
$shipArray[] = buildShipStats($shipType, $shipLocs[$shipType->getTypeID()] ?? []);
}
$template->assign('shipArray', $shipArray);

Expand All @@ -26,7 +41,7 @@
handleException($e);
}

function buildShipStats(SmrShipType $ship): array {
function buildShipStats(SmrShipType $ship, array $shipLocs): array {
//we want to put them all in an array so we dont have to have 15 td rows
$restriction = match ($ship->getRestriction()) {
BUYER_RESTRICTION_NONE => '',
Expand Down Expand Up @@ -55,6 +70,7 @@ function buildShipStats(SmrShipType $ship): array {
'illusion' => $ship->canHaveIllusion() ? 'Yes' : '',
'jump' => $ship->canHaveJump() ? 'Yes' : '',
'scrambler' => $ship->canHaveDCS() ? 'Yes' : '',
'locs' => implode('', array_map(fn(string $name): string => '<div>' . $name . '</div>', $shipLocs)),
];
return $stat;
}
9 changes: 9 additions & 0 deletions src/templates/Default/ship_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@
</select>
</th><?php
} ?>
<th>
Locations<br />
<select onchange="filterSelect(this)">
<option>All</option><?php
foreach ($AllLocs as $Loc) { ?>
<option><?php echo $Loc; ?></option><?php
} ?>
</select>
</th>
</tr>
</thead>
<tbody class="list"><?php
Expand Down

0 comments on commit 7b09ec0

Please sign in to comment.