Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ScanResourcesFinishHandler extends BaseActionHandler {
if (this.asteroid.Celestial?.scanStatus !== Asteroid.SCAN_STATUSES.RESOURCE_SCANNING) {
throw new ValidationError('Asteroid is not currently resource scanning');
}
StateMachineValidator.assertFinished(this.asteroid.Celestial, 'Resource scan');
StateMachineValidator.assertFinished(this.asteroid.Celestial, 'Resource scan', 'scanFinishTime');
}

async applyStateChanges() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ScanSurfaceFinishHandler extends BaseActionHandler {
if (this.asteroid.Celestial?.scanStatus !== Asteroid.SCAN_STATUSES.SURFACE_SCANNING) {
throw new ValidationError('Asteroid is not currently surface scanning');
}
StateMachineValidator.assertFinished(this.asteroid.Celestial, 'Surface scan');
StateMachineValidator.assertFinished(this.asteroid.Celestial, 'Surface scan', 'scanFinishTime');
}

async applyStateChanges() {
Expand Down
2 changes: 1 addition & 1 deletion src/common/gameLogic/handlers/ship/assembleStart.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class AssembleShipStartHandler extends BaseActionHandler {
data: {
shipType: this.shipType,
status: Ship.STATUSES.UNDER_CONSTRUCTION,
variant: Ship.getVariant(this.shipId),
variant: Ship.VARIANTS.STANDARD,
readyAt: 0,
emergencyAt: 0,
transitDeparture: 0,
Expand Down
11 changes: 6 additions & 5 deletions src/common/gameLogic/validators/stateMachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ class StateMachineValidator {
* Asserts a time-gated operation has finished (finishTime has passed).
* Used for construction, extraction, processing, transit completions.
*
* @param {object} component - Component with a finishTime field
* @param {object} component - Component with a finishTime (or custom) field
* @param {string} [label] - Human-readable label for error messages
* @param {string} [field] - Field name containing the finish timestamp (default: 'finishTime')
*/
static assertFinished(component, label = 'Component') {
static assertFinished(component, label = 'Component', field = 'finishTime') {
if (!component) throw new ValidationError(`${label} not found`);
if (!component.finishTime) throw new ValidationError(`${label} has no finish time`);
if (!component[field]) throw new ValidationError(`${label} has no finish time`);

const now = Math.floor(Date.now() / 1000);
if (component.finishTime > now) {
if (component[field] > now) {
throw new ValidationError(
`${label} not finished yet (finishes at ${component.finishTime}, now ${now})`
`${label} not finished yet (finishes at ${component[field]}, now ${now})`
);
}
}
Expand Down
Loading