Show fresh player capacity on Fleet cards
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import type { PlayerCapacityObservation } from '../../server-capacity.js';
|
||||
import { monitoringStatus } from './health-observations.js';
|
||||
import { MonitoringSnapshot } from './monitoring-snapshot.js';
|
||||
|
||||
/** Read only the accepted, current-instance sample; never dispatch a probe. */
|
||||
export function observedPlayerCapacity(server: string, snapshot: MonitoringSnapshot): PlayerCapacityObservation {
|
||||
const game = monitoringStatus(server, snapshot)?.game;
|
||||
const capacity = game?.result.ok ? game.result.status.capacity : null;
|
||||
return typeof capacity === 'number' && Number.isSafeInteger(capacity) && capacity > 0
|
||||
? { capacity, capacity_observed_at: game!.observedAt }
|
||||
: { capacity: null, capacity_observed_at: null };
|
||||
}
|
||||
|
||||
/** One joined identity read for a fleet, or a single server on a detail route. */
|
||||
export function playerCapacityReader(serverName?: string) {
|
||||
const snapshot = new MonitoringSnapshot(serverName);
|
||||
return (server: string) => observedPlayerCapacity(server, snapshot);
|
||||
}
|
||||
Reference in New Issue
Block a user