✨feature: Added ship details and mining fleet pages
This commit is contained in:
345
agent-info.php
345
agent-info.php
@@ -35,6 +35,16 @@ if (! is_string( $token ) || trim( $token ) === '') {
|
||||
$agent = array();
|
||||
$ships = array();
|
||||
$contracts = array();
|
||||
$system = array();
|
||||
$systemWaypoints = array();
|
||||
$paginatedWaypoints = array();
|
||||
$marketDetails = array();
|
||||
$shipyardDetails = array();
|
||||
$selectedShipSymbol = '';
|
||||
$selectedWaypointSymbol = '';
|
||||
$waypointPageSize = 25;
|
||||
$waypointPage = isset( $_GET['waypoint_page'] ) ? max( 1, (int) $_GET['waypoint_page'] ) : 1;
|
||||
$waypointTotalPages = 1;
|
||||
|
||||
if (! isset( $tokenError ) ) {
|
||||
$client = new SpacetradersApi(
|
||||
@@ -45,6 +55,35 @@ if (! isset( $tokenError ) ) {
|
||||
(int) $config['cache_ttl']
|
||||
);
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset( $_POST['navigate_ship'] ) && isset( $_POST['ship_symbol'] ) && isset( $_POST['waypoint_symbol'] )) {
|
||||
$selectedShipSymbol = trim( (string) $_POST['ship_symbol'] );
|
||||
$selectedWaypointSymbol = trim( (string) $_POST['waypoint_symbol'] );
|
||||
|
||||
if ($selectedShipSymbol !== '' && $selectedWaypointSymbol !== '' ) {
|
||||
try {
|
||||
$selectedShipResponse = $client->getShip( $selectedShipSymbol );
|
||||
$selectedShipData = $selectedShipResponse['data'] ?? array();
|
||||
$shipNavStatus = (string) ( $selectedShipData['nav']['status'] ?? '' );
|
||||
|
||||
if ($shipNavStatus === 'IN_TRANSIT' ) {
|
||||
throw new SpacetradersApiException(
|
||||
'Selected ship is currently in transit and cannot navigate yet.'
|
||||
);
|
||||
}
|
||||
|
||||
if ($shipNavStatus === 'DOCKED' ) {
|
||||
$client->orbitShip( $selectedShipSymbol );
|
||||
}
|
||||
|
||||
$client->navigateShip( $selectedShipSymbol, $selectedWaypointSymbol );
|
||||
$storage->clearAllCache();
|
||||
$statusMessage = 'Navigation started for ' . $selectedShipSymbol . '.';
|
||||
} catch (SpacetradersApiException $e) {
|
||||
$errorMessage = 'Unable to navigate ship: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset( $_GET['accept_contract'] ) && is_string( $_GET['accept_contract'] ) && trim( $_GET['accept_contract'] ) !== '') {
|
||||
try {
|
||||
$client->acceptContract( trim( $_GET['accept_contract'] ) );
|
||||
@@ -65,6 +104,101 @@ try {
|
||||
$agent = $agentResponse['data'] ?? $agentResponse;
|
||||
$ships = $shipsResponse['data'] ?? $shipsResponse;
|
||||
$contracts = $contractsResponse['data'] ?? $contractsResponse;
|
||||
|
||||
$currentSystemSymbol = '';
|
||||
if (isset( $ships[0]['nav']['systemSymbol'] ) && is_string( $ships[0]['nav']['systemSymbol'] ) ) {
|
||||
$currentSystemSymbol = $ships[0]['nav']['systemSymbol'];
|
||||
}
|
||||
|
||||
if ($currentSystemSymbol === '' && isset( $agent['headquarters'] ) && is_string( $agent['headquarters'] ) ) {
|
||||
$hqParts = explode( '-', $agent['headquarters'] );
|
||||
if (count( $hqParts ) >= 2 ) {
|
||||
$currentSystemSymbol = $hqParts[0] . '-' . $hqParts[1];
|
||||
}
|
||||
}
|
||||
|
||||
if ($currentSystemSymbol !== '' ) {
|
||||
$systemResponse = $client->getSystem( $currentSystemSymbol );
|
||||
$system = $systemResponse['data'] ?? $systemResponse;
|
||||
|
||||
$page = 1;
|
||||
$total = 0;
|
||||
do {
|
||||
$waypointsResponse = $client->listWaypoints(
|
||||
$currentSystemSymbol,
|
||||
array(
|
||||
'page' => $page,
|
||||
'limit' => 20,
|
||||
)
|
||||
);
|
||||
$pageData = $waypointsResponse['data'] ?? array();
|
||||
if (! is_array( $pageData ) || empty( $pageData ) ) {
|
||||
break;
|
||||
}
|
||||
|
||||
$systemWaypoints = array_merge( $systemWaypoints, $pageData );
|
||||
$total = (int) ( $waypointsResponse['meta']['total'] ?? count( $systemWaypoints ) );
|
||||
$page++;
|
||||
} while (count( $systemWaypoints ) < $total);
|
||||
|
||||
foreach ( $systemWaypoints as $waypoint ) {
|
||||
$waypointSymbol = (string) ( $waypoint['symbol'] ?? '' );
|
||||
$traits = $waypoint['traits'] ?? array();
|
||||
$hasMarket = false;
|
||||
$hasShipyard = false;
|
||||
|
||||
foreach ( $traits as $trait ) {
|
||||
$traitSymbol = (string) ( $trait['symbol'] ?? '' );
|
||||
if ($traitSymbol === 'MARKETPLACE' ) {
|
||||
$hasMarket = true;
|
||||
}
|
||||
|
||||
if ($traitSymbol === 'SHIPYARD' ) {
|
||||
$hasShipyard = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($hasMarket ) {
|
||||
$marketRecord = array(
|
||||
'waypoint' => $waypoint,
|
||||
'data' => array(),
|
||||
'error' => '',
|
||||
);
|
||||
try {
|
||||
$marketResponse = $client->getWaypointMarket( $currentSystemSymbol, $waypointSymbol );
|
||||
$marketRecord['data'] = $marketResponse['data'] ?? array();
|
||||
} catch (SpacetradersApiException $e) {
|
||||
$marketRecord['error'] = $e->getMessage();
|
||||
}
|
||||
|
||||
$marketDetails[] = $marketRecord;
|
||||
}
|
||||
|
||||
if ($hasShipyard ) {
|
||||
$shipyardRecord = array(
|
||||
'waypoint' => $waypoint,
|
||||
'data' => array(),
|
||||
'error' => '',
|
||||
);
|
||||
try {
|
||||
$shipyardResponse = $client->getWaypointShipyard( $currentSystemSymbol, $waypointSymbol );
|
||||
$shipyardRecord['data'] = $shipyardResponse['data'] ?? array();
|
||||
} catch (SpacetradersApiException $e) {
|
||||
$shipyardRecord['error'] = $e->getMessage();
|
||||
}
|
||||
|
||||
$shipyardDetails[] = $shipyardRecord;
|
||||
}
|
||||
}
|
||||
|
||||
$waypointCount = count( $systemWaypoints );
|
||||
if ($waypointCount > 0 ) {
|
||||
$waypointTotalPages = (int) ceil( $waypointCount / $waypointPageSize );
|
||||
$waypointPage = min( $waypointPage, $waypointTotalPages );
|
||||
$offset = ( $waypointPage - 1 ) * $waypointPageSize;
|
||||
$paginatedWaypoints = array_slice( $systemWaypoints, $offset, $waypointPageSize );
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SpacetradersApiException $e) {
|
||||
$error = array(
|
||||
@@ -107,6 +241,10 @@ try {
|
||||
|
||||
<div class="mb-6">
|
||||
<a href="config.php" class="text-blue-400 hover:underline">Configuration</a>
|
||||
<span class="mx-2">|</span>
|
||||
<a href="buy-ships.php" class="text-blue-400 hover:underline">Buy Ships</a>
|
||||
<span class="mx-2">|</span>
|
||||
<a href="mining-fleet.php" class="text-blue-400 hover:underline">Mining Fleet</a>
|
||||
</div>
|
||||
|
||||
<?php if ($statusMessage !== '' ) : ?>
|
||||
@@ -135,6 +273,172 @@ try {
|
||||
System: <span class="font-normal"><?php echo htmlspecialchars( $ships[0]['nav']['systemSymbol'] ); ?></span>
|
||||
</h3>
|
||||
|
||||
<div class="mb-8 border border-gray-600 p-4 rounded">
|
||||
<h2 class="text-2xl font-bold mb-2">System Details</h2>
|
||||
<p class="mb-3 text-gray-300">
|
||||
Current System:
|
||||
<span class="font-semibold"><?php echo htmlspecialchars( (string) ( $system['symbol'] ?? 'Unknown' ) ); ?></span>
|
||||
<?php if (isset( $system['type'] ) ) : ?>
|
||||
(<?php echo htmlspecialchars( (string) $system['type'] ); ?>)
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
|
||||
<form method="post" class="mb-4 flex flex-wrap items-end gap-3">
|
||||
<input type="hidden" name="navigate_ship" value="1">
|
||||
<div>
|
||||
<label for="ship_symbol" class="block text-sm mb-1">Ship</label>
|
||||
<select id="ship_symbol" name="ship_symbol" class="px-3 py-2 rounded text-black min-w-52">
|
||||
<?php foreach ( $ships as $ship ) : ?>
|
||||
<?php $shipSymbol = (string) ( $ship['symbol'] ?? '' ); ?>
|
||||
<option value="<?php echo htmlspecialchars( $shipSymbol ); ?>" <?php echo ( $shipSymbol === $selectedShipSymbol ) ? 'selected' : ''; ?>>
|
||||
<?php echo htmlspecialchars( $shipSymbol ); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label for="waypoint_symbol" class="block text-sm mb-1">Destination Waypoint</label>
|
||||
<select id="waypoint_symbol" name="waypoint_symbol" class="px-3 py-2 rounded text-black min-w-64">
|
||||
<?php foreach ( $systemWaypoints as $waypoint ) : ?>
|
||||
<?php $waypointSymbol = (string) ( $waypoint['symbol'] ?? '' ); ?>
|
||||
<?php $waypointType = (string) ( $waypoint['type'] ?? '' ); ?>
|
||||
<option value="<?php echo htmlspecialchars( $waypointSymbol ); ?>" <?php echo ( $waypointSymbol === $selectedWaypointSymbol ) ? 'selected' : ''; ?>>
|
||||
<?php echo htmlspecialchars( $waypointSymbol . ' (' . $waypointType . ')' ); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="px-4 py-2 bg-blue-600 rounded hover:bg-blue-500">Navigate</button>
|
||||
</form>
|
||||
|
||||
<div class="mb-3 flex gap-2">
|
||||
<button type="button" class="system-tab px-3 py-2 bg-gray-700 rounded hover:bg-gray-600" data-tab-target="tab-waypoints">Waypoints</button>
|
||||
<button type="button" class="system-tab px-3 py-2 bg-gray-700 rounded hover:bg-gray-600" data-tab-target="tab-markets">Markets</button>
|
||||
<button type="button" class="system-tab px-3 py-2 bg-gray-700 rounded hover:bg-gray-600" data-tab-target="tab-shipyards">Shipyards</button>
|
||||
</div>
|
||||
|
||||
<div id="tab-waypoints" class="system-tab-panel">
|
||||
<?php
|
||||
$waypointCount = count( $systemWaypoints );
|
||||
$waypointStart = $waypointCount > 0 ? ( ( $waypointPage - 1 ) * $waypointPageSize ) + 1 : 0;
|
||||
$waypointEnd = min( $waypointPage * $waypointPageSize, $waypointCount );
|
||||
?>
|
||||
<div class="mb-3 flex items-center justify-between">
|
||||
<p class="text-sm text-gray-300">
|
||||
Showing <?php echo number_format( $waypointStart ); ?>-<?php echo number_format( $waypointEnd ); ?>
|
||||
of <?php echo number_format( $waypointCount ); ?> waypoints
|
||||
</p>
|
||||
<div class="flex gap-2">
|
||||
<?php if ($waypointPage > 1 ) : ?>
|
||||
<a
|
||||
href="agent-info.php?waypoint_page=<?php echo (int) ( $waypointPage - 1 ); ?>"
|
||||
class="px-3 py-1 bg-gray-700 rounded hover:bg-gray-600"
|
||||
>
|
||||
Previous
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if ($waypointPage < $waypointTotalPages ) : ?>
|
||||
<a
|
||||
href="agent-info.php?waypoint_page=<?php echo (int) ( $waypointPage + 1 ); ?>"
|
||||
class="px-3 py-1 bg-gray-700 rounded hover:bg-gray-600"
|
||||
>
|
||||
Next
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table-auto border-collapse border border-gray-300 w-full">
|
||||
<tr>
|
||||
<th class="border border-gray-300 px-3 py-2">Symbol</th>
|
||||
<th class="border border-gray-300 px-3 py-2">Type</th>
|
||||
<th class="border border-gray-300 px-3 py-2">Coordinates</th>
|
||||
<th class="border border-gray-300 px-3 py-2">Traits</th>
|
||||
</tr>
|
||||
<?php foreach ( $paginatedWaypoints as $waypoint ) : ?>
|
||||
<tr>
|
||||
<td class="border border-gray-300 px-3 py-2"><?php echo htmlspecialchars( (string) ( $waypoint['symbol'] ?? '' ) ); ?></td>
|
||||
<td class="border border-gray-300 px-3 py-2"><?php echo htmlspecialchars( (string) ( $waypoint['type'] ?? '' ) ); ?></td>
|
||||
<td class="border border-gray-300 px-3 py-2">
|
||||
<?php echo htmlspecialchars( (string) ( $waypoint['x'] ?? 0 ) ); ?>,
|
||||
<?php echo htmlspecialchars( (string) ( $waypoint['y'] ?? 0 ) ); ?>
|
||||
</td>
|
||||
<td class="border border-gray-300 px-3 py-2">
|
||||
<?php
|
||||
$traitNames = array();
|
||||
foreach ( (array) ( $waypoint['traits'] ?? array() ) as $trait ) {
|
||||
$traitNames[] = (string) ( $trait['symbol'] ?? '' );
|
||||
}
|
||||
echo htmlspecialchars( implode( ', ', array_filter( $traitNames ) ) );
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="tab-markets" class="system-tab-panel hidden">
|
||||
<?php if (empty( $marketDetails ) ) : ?>
|
||||
<p class="text-gray-300">No markets found in this system.</p>
|
||||
<?php endif; ?>
|
||||
<?php foreach ( $marketDetails as $market ) : ?>
|
||||
<div class="mb-3 border border-gray-500 p-3 rounded">
|
||||
<h3 class="font-bold">
|
||||
<?php echo htmlspecialchars( (string) ( $market['waypoint']['symbol'] ?? '' ) ); ?>
|
||||
</h3>
|
||||
<?php if ($market['error'] !== '' ) : ?>
|
||||
<p class="text-red-300"><?php echo htmlspecialchars( (string) $market['error'] ); ?></p>
|
||||
<?php else : ?>
|
||||
<?php $tradeGoods = (array) ( $market['data']['tradeGoods'] ?? array() ); ?>
|
||||
<p class="text-sm text-gray-300">Trade Goods: <?php echo htmlspecialchars( (string) count( $tradeGoods ) ); ?></p>
|
||||
<?php if (! empty( $tradeGoods ) ) : ?>
|
||||
<p class="text-sm text-gray-300">
|
||||
<?php
|
||||
$symbols = array();
|
||||
foreach ( $tradeGoods as $tradeGood ) {
|
||||
$symbols[] = (string) ( $tradeGood['symbol'] ?? '' );
|
||||
}
|
||||
echo htmlspecialchars( implode( ', ', array_filter( $symbols ) ) );
|
||||
?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<div id="tab-shipyards" class="system-tab-panel hidden">
|
||||
<?php if (empty( $shipyardDetails ) ) : ?>
|
||||
<p class="text-gray-300">No shipyards found in this system.</p>
|
||||
<?php endif; ?>
|
||||
<?php foreach ( $shipyardDetails as $shipyard ) : ?>
|
||||
<div class="mb-3 border border-gray-500 p-3 rounded">
|
||||
<h3 class="font-bold">
|
||||
<?php echo htmlspecialchars( (string) ( $shipyard['waypoint']['symbol'] ?? '' ) ); ?>
|
||||
</h3>
|
||||
<?php if ($shipyard['error'] !== '' ) : ?>
|
||||
<p class="text-red-300"><?php echo htmlspecialchars( (string) $shipyard['error'] ); ?></p>
|
||||
<?php else : ?>
|
||||
<?php $shipTypes = (array) ( $shipyard['data']['shipTypes'] ?? array() ); ?>
|
||||
<p class="text-sm text-gray-300">Ships Available: <?php echo htmlspecialchars( (string) count( $shipTypes ) ); ?></p>
|
||||
<?php if (! empty( $shipTypes ) ) : ?>
|
||||
<p class="text-sm text-gray-300">
|
||||
<?php
|
||||
$types = array();
|
||||
foreach ( $shipTypes as $shipType ) {
|
||||
$types[] = (string) ( $shipType['type'] ?? '' );
|
||||
}
|
||||
echo htmlspecialchars( implode( ', ', array_filter( $types ) ) );
|
||||
?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2 class="text-2xl font-bold my-4">Ships</h2>
|
||||
<table class="table-auto border-collapse border border-gray-300">
|
||||
<tr>
|
||||
@@ -148,7 +452,14 @@ try {
|
||||
|
||||
<?php foreach ( $ships as $ship ) : ?>
|
||||
<tr>
|
||||
<td class="border border-gray-300 px-4 py-2"><?php echo htmlspecialchars( ucfirst( strtolower( $ship['registration']['name'] ) ) ); ?></td>
|
||||
<td class="border border-gray-300 px-4 py-2">
|
||||
<a
|
||||
href="ship-details.php?ship=<?php echo urlencode( (string) ( $ship['symbol'] ?? '' ) ); ?>"
|
||||
class="text-blue-400 hover:underline"
|
||||
>
|
||||
<?php echo htmlspecialchars( ucfirst( strtolower( $ship['registration']['name'] ) ) ); ?>
|
||||
</a>
|
||||
</td>
|
||||
<td class="border border-gray-300 px-4 py-2"><?php echo htmlspecialchars( ucfirst( strtolower( $ship['registration']['role'] ) ) ); ?></td>
|
||||
<td class="border border-gray-300 px-4 py-2"><?php echo htmlspecialchars( $ship['frame']['name'] ); ?></td>
|
||||
<td class="border border-gray-300 px-4 py-2"><?php echo htmlspecialchars( ucfirst( strtolower( $ship['nav']['status'] ) ) ); ?></td>
|
||||
@@ -218,5 +529,37 @@ try {
|
||||
endforeach;
|
||||
?>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
const tabs = document.querySelectorAll('.system-tab');
|
||||
const panels = document.querySelectorAll('.system-tab-panel');
|
||||
|
||||
function activateTab(targetId) {
|
||||
panels.forEach((panel) => {
|
||||
panel.classList.toggle('hidden', panel.id !== targetId);
|
||||
});
|
||||
|
||||
tabs.forEach((tab) => {
|
||||
const isActive = tab.getAttribute('data-tab-target') === targetId;
|
||||
tab.classList.toggle('bg-blue-700', isActive);
|
||||
tab.classList.toggle('bg-gray-700', !isActive);
|
||||
});
|
||||
}
|
||||
|
||||
tabs.forEach((tab) => {
|
||||
tab.addEventListener('click', () => {
|
||||
const targetId = tab.getAttribute('data-tab-target');
|
||||
if (targetId) {
|
||||
activateTab(targetId);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (tabs.length > 0) {
|
||||
activateTab('tab-waypoints');
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user