✨feature: Add cooldown/navigation timers, move credits display to header
This commit is contained in:
@@ -136,7 +136,7 @@ try {
|
||||
}
|
||||
|
||||
$client->sellCargo( $shipSymbol, $tradeSymbol, $units );
|
||||
$statusMessage = 'Sold ' . number_format( $units ) . ' units of ' . $tradeSymbol . '.';
|
||||
$statusMessage = 'Sold ' . number_format( $units ) . ' units of ' . formatString( $tradeSymbol ) . '.';
|
||||
break;
|
||||
case 'jettison_all_cargo':
|
||||
$shipResponse = $client->getShip( $shipSymbol );
|
||||
@@ -180,7 +180,7 @@ try {
|
||||
}
|
||||
|
||||
$client->jettisonCargo( $shipSymbol, $tradeSymbol, $units );
|
||||
$statusMessage = 'Jettisoned ' . number_format( $units ) . ' units of ' . $tradeSymbol . '.';
|
||||
$statusMessage = 'Jettisoned ' . number_format( $units ) . ' units of ' . formatString( $tradeSymbol ) . '.';
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -196,6 +196,16 @@ try {
|
||||
} catch (SpacetradersApiException $e) {
|
||||
$errorMessage = $e->getMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a string by replacing underscores with spaces and capitalizing the first letter.
|
||||
*
|
||||
* @param string $str The string to format.
|
||||
* @return string The formatted string.
|
||||
*/
|
||||
function formatString( $str ) {
|
||||
return ucfirst( strtolower( str_replace( '_', ' ', $str ) ) );
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
@@ -240,7 +250,7 @@ try {
|
||||
<?php foreach ( $shipList as $listShip ) : ?>
|
||||
<?php $listSymbol = (string) ( $listShip['symbol'] ?? '' ); ?>
|
||||
<option value="<?php echo htmlspecialchars( $listSymbol ); ?>" <?php echo ( $listSymbol === $shipSymbol ) ? 'selected' : ''; ?>>
|
||||
<?php echo htmlspecialchars( $listSymbol ); ?>
|
||||
<?php echo htmlspecialchars( formatString( $listSymbol ) ); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
@@ -289,8 +299,8 @@ try {
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
<p class="mt-2 text-sm text-gray-300">
|
||||
Role: <?php echo htmlspecialchars( $shipRole ); ?> |
|
||||
Status: <?php echo htmlspecialchars( $shipStatus ); ?> |
|
||||
Role: <?php echo htmlspecialchars( formatString( $shipRole ) ); ?> |
|
||||
Status: <?php echo htmlspecialchars( formatString( $shipStatus ) ); ?> |
|
||||
Fuel: <?php echo number_format( $fuelCurrent ); ?>/<?php echo number_format( $fuelCapacity ); ?>
|
||||
</p>
|
||||
</div>
|
||||
@@ -298,18 +308,26 @@ try {
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div class="border border-gray-600 rounded p-4">
|
||||
<h2 class="text-xl font-bold mb-2">Overview</h2>
|
||||
<p><span class="font-bold">Symbol:</span> <?php echo htmlspecialchars( (string) ( $ship['symbol'] ?? '' ) ); ?></p>
|
||||
<p><span class="font-bold">Name:</span> <?php echo htmlspecialchars( (string) ( $ship['registration']['name'] ?? '' ) ); ?></p>
|
||||
<p><span class="font-bold">Role:</span> <?php echo htmlspecialchars( (string) ( $ship['registration']['role'] ?? '' ) ); ?></p>
|
||||
<p><span class="font-bold">Faction:</span> <?php echo htmlspecialchars( (string) ( $ship['registration']['factionSymbol'] ?? '' ) ); ?></p>
|
||||
<p><span class="font-bold">Symbol:</span> <?php echo htmlspecialchars( (string) ( formatString( $ship['symbol'] ?? '' ) ) ); ?></p>
|
||||
<p><span class="font-bold">Name:</span> <?php echo htmlspecialchars( (string) ( formatString( $ship['registration']['name'] ?? '' ) ) ); ?></p>
|
||||
<p><span class="font-bold">Role:</span> <?php echo htmlspecialchars( (string) ( formatString( $ship['registration']['role'] ?? '' ) ) ); ?></p>
|
||||
<p><span class="font-bold">Faction:</span> <?php echo htmlspecialchars( (string) ( formatString( $ship['registration']['factionSymbol'] ?? '' ) ) ); ?></p>
|
||||
</div>
|
||||
|
||||
<div class="border border-gray-600 rounded p-4">
|
||||
<h2 class="text-xl font-bold mb-2">Navigation</h2>
|
||||
<p><span class="font-bold">Status:</span> <?php echo htmlspecialchars( (string) ( $ship['nav']['status'] ?? '' ) ); ?></p>
|
||||
<p><span class="font-bold">Flight Mode:</span> <?php echo htmlspecialchars( (string) ( $ship['nav']['flightMode'] ?? '' ) ); ?></p>
|
||||
<p><span class="font-bold">Status:</span> <?php echo htmlspecialchars( (string) ( formatString( $ship['nav']['status'] ?? '' ) ) ); ?></p>
|
||||
<p><span class="font-bold">Flight Mode:</span> <?php echo htmlspecialchars( (string) ( formatString( $ship['nav']['flightMode'] ?? '' ) ) ); ?></p>
|
||||
<p><span class="font-bold">System:</span> <?php echo htmlspecialchars( (string) ( $ship['nav']['systemSymbol'] ?? '' ) ); ?></p>
|
||||
<p><span class="font-bold">Waypoint:</span> <?php echo htmlspecialchars( (string) ( $ship['nav']['waypointSymbol'] ?? '' ) ); ?></p>
|
||||
<p>
|
||||
<span class="font-bold">Navigation Timer:</span>
|
||||
<span
|
||||
class="ship-nav-timer"
|
||||
data-status="<?php echo htmlspecialchars( (string) ( $ship['nav']['status'] ?? '' ) ); ?>"
|
||||
data-arrival="<?php echo htmlspecialchars( (string) ( $ship['nav']['route']['arrival'] ?? '' ) ); ?>"
|
||||
></span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="border border-gray-600 rounded p-4">
|
||||
@@ -363,7 +381,6 @@ try {
|
||||
<?php else : ?>
|
||||
<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">Name</th>
|
||||
<th class="border border-gray-300 px-3 py-2">Units</th>
|
||||
<th class="border border-gray-300 px-3 py-2">Description</th>
|
||||
@@ -373,7 +390,6 @@ try {
|
||||
<?php foreach ( $inventory as $item ) : ?>
|
||||
<?php $itemUnits = (int) ( $item['units'] ?? 0 ); ?>
|
||||
<tr>
|
||||
<td class="border border-gray-300 px-3 py-2"><?php echo htmlspecialchars( (string) ( $item['symbol'] ?? '' ) ); ?></td>
|
||||
<td class="border border-gray-300 px-3 py-2"><?php echo htmlspecialchars( (string) ( $item['name'] ?? '' ) ); ?></td>
|
||||
<td class="border border-gray-300 px-3 py-2"><?php echo number_format( $itemUnits ); ?></td>
|
||||
<td class="border border-gray-300 px-3 py-2"><?php echo htmlspecialchars( (string) ( $item['description'] ?? '' ) ); ?></td>
|
||||
@@ -417,5 +433,56 @@ try {
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
const navTimerNodes = document.querySelectorAll('.ship-nav-timer');
|
||||
|
||||
function formatNavTimer(seconds) {
|
||||
if (seconds <= 0) {
|
||||
return 'Arriving';
|
||||
}
|
||||
|
||||
const total = Math.max(0, Math.floor(seconds));
|
||||
const hours = Math.floor(total / 3600);
|
||||
const minutes = Math.floor((total % 3600) / 60);
|
||||
const secs = total % 60;
|
||||
|
||||
if (hours > 0) {
|
||||
return `${hours}:${String(minutes).padStart(2, '0')}:${String(secs).padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
return `${minutes}:${String(secs).padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
function renderNavTimers() {
|
||||
const nowMs = Date.now();
|
||||
|
||||
navTimerNodes.forEach((node) => {
|
||||
const status = node.dataset.status || '';
|
||||
const arrival = node.dataset.arrival || '';
|
||||
|
||||
if (status !== 'IN_TRANSIT') {
|
||||
node.textContent = 'Ready';
|
||||
return;
|
||||
}
|
||||
|
||||
const arrivalMs = Date.parse(arrival);
|
||||
if (!Number.isFinite(arrivalMs)) {
|
||||
node.textContent = 'In transit';
|
||||
return;
|
||||
}
|
||||
|
||||
const remainingSeconds = Math.max(0, Math.floor((arrivalMs - nowMs) / 1000));
|
||||
node.textContent = formatNavTimer(remainingSeconds);
|
||||
});
|
||||
}
|
||||
|
||||
renderNavTimers();
|
||||
if (navTimerNodes.length > 0) {
|
||||
window.setInterval(renderNavTimers, 1000);
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user