✨feature: Buy ships page updates
This commit is contained in:
@@ -23,6 +23,7 @@ $ships = array();
|
||||
$shipyards = array();
|
||||
$agent = array();
|
||||
$currentSystemSymbol = '';
|
||||
$waypointShipMap = array();
|
||||
|
||||
if (! is_string( $token ) || trim( $token ) === '' ) {
|
||||
$envToken = getenv( 'SPACETRADERS_TOKEN' );
|
||||
@@ -67,6 +68,22 @@ try {
|
||||
$agent = $agentResponse['data'] ?? $agentResponse;
|
||||
$ships = $shipsResponse['data'] ?? $shipsResponse;
|
||||
|
||||
foreach ( $ships as $ship ) {
|
||||
$shipSymbol = (string) ( $ship['symbol'] ?? '' );
|
||||
$shipStatus = (string) ( $ship['nav']['status'] ?? '' );
|
||||
$waypointSymbol = (string) ( $ship['nav']['waypointSymbol'] ?? '' );
|
||||
|
||||
if ($shipSymbol === '' || $waypointSymbol === '' || $shipStatus === 'IN_TRANSIT' ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! isset( $waypointShipMap[ $waypointSymbol ] ) ) {
|
||||
$waypointShipMap[ $waypointSymbol ] = array();
|
||||
}
|
||||
|
||||
$waypointShipMap[ $waypointSymbol ][] = $shipSymbol;
|
||||
}
|
||||
|
||||
if (isset( $ships[0]['nav']['systemSymbol'] ) && is_string( $ships[0]['nav']['systemSymbol'] ) ) {
|
||||
$currentSystemSymbol = $ships[0]['nav']['systemSymbol'];
|
||||
}
|
||||
@@ -119,6 +136,7 @@ try {
|
||||
'waypoint' => $waypoint,
|
||||
'shipTypes' => array(),
|
||||
'prices' => array(),
|
||||
'shipSymbols' => (array) ( $waypointShipMap[ $waypointSymbol ] ?? array() ),
|
||||
'error' => '',
|
||||
);
|
||||
|
||||
@@ -127,6 +145,15 @@ try {
|
||||
$shipyardData = $shipyardResponse['data'] ?? array();
|
||||
$record['shipTypes'] = (array) ( $shipyardData['shipTypes'] ?? array() );
|
||||
|
||||
$shipsForSale = (array) ( $shipyardData['ships'] ?? array() );
|
||||
foreach ( $shipsForSale as $shipForSale ) {
|
||||
$shipType = (string) ( $shipForSale['type'] ?? '' );
|
||||
$price = (int) ( $shipForSale['purchasePrice'] ?? 0 );
|
||||
if ($shipType !== '' && $price > 0 ) {
|
||||
$record['prices'][ $shipType ] = $price;
|
||||
}
|
||||
}
|
||||
|
||||
$transactions = (array) ( $shipyardData['transactions'] ?? array() );
|
||||
foreach ( $transactions as $transaction ) {
|
||||
$shipType = (string) ( $transaction['shipType'] ?? '' );
|
||||
@@ -184,13 +211,6 @@ try {
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<p class="mb-6">
|
||||
Credits: <span class="font-semibold"><?php echo number_format( (int) ( $agent['credits'] ?? 0 ) ); ?></span>
|
||||
<?php if ($currentSystemSymbol !== '' ) : ?>
|
||||
| Current System: <span class="font-semibold"><?php echo htmlspecialchars( $currentSystemSymbol ); ?></span>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
|
||||
<?php if (empty( $shipyards ) ) : ?>
|
||||
<div class="border border-gray-600 p-4 rounded">
|
||||
No shipyards were found in your current system.
|
||||
@@ -203,6 +223,14 @@ try {
|
||||
Shipyard: <?php echo htmlspecialchars( (string) ( $shipyard['waypoint']['symbol'] ?? '' ) ); ?>
|
||||
</h2>
|
||||
|
||||
<p class="text-sm text-gray-300 mb-3">
|
||||
Ships Here:
|
||||
<?php
|
||||
$shipSymbols = (array) ( $shipyard['shipSymbols'] ?? array() );
|
||||
echo htmlspecialchars( ! empty( $shipSymbols ) ? formatString( implode( ', ', $shipSymbols ) ) : 'None' );
|
||||
?>
|
||||
</p>
|
||||
|
||||
<?php if ((string) $shipyard['error'] !== '' ) : ?>
|
||||
<p class="text-red-300"><?php echo htmlspecialchars( (string) $shipyard['error'] ); ?></p>
|
||||
<?php else : ?>
|
||||
@@ -216,7 +244,7 @@ try {
|
||||
<?php $shipType = (string) ( $shipTypeRecord['type'] ?? '' ); ?>
|
||||
<?php $knownPrice = (int) ( $shipyard['prices'][ $shipType ] ?? 0 ); ?>
|
||||
<tr>
|
||||
<td class="border border-gray-300 px-4 py-2"><?php echo htmlspecialchars( $shipType ); ?></td>
|
||||
<td class="border border-gray-300 px-4 py-2"><?php echo htmlspecialchars( formatString( str_replace( 'SHIP_', '', $shipType ) ) ); ?></td>
|
||||
<td class="border border-gray-300 px-4 py-2">
|
||||
<?php echo $knownPrice > 0 ? number_format( $knownPrice ) : 'Unknown'; ?>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user