-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathstate.ts
More file actions
206 lines (190 loc) · 7.14 KB
/
state.ts
File metadata and controls
206 lines (190 loc) · 7.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import { Type } from 'class-transformer';
import * as z from 'zod';
import {
Equals,
IsArray,
IsInt,
IsObject,
IsUUID,
Min,
ValidateNested,
} from 'class-validator';
import { defaultMaterialTemplatesById } from './data/default-state/material-templates.js';
import { defaultPersonnelTemplatesById } from './data/default-state/personnel-templates.js';
import {
AlarmGroup,
Client,
EocLogEntry,
Hospital,
HospitalPatient,
RestrictedZone,
MapImage,
MapImageTemplate,
Material,
Patient,
PatientCategory,
Personnel,
SimulatedRegion,
TransferPoint,
Vehicle,
VehicleTemplate,
Viewport,
ExerciseConfiguration,
exerciseStatusAllowedValues,
getCreate,
SpatialTree,
MaterialTemplate,
PersonnelTemplate,
} from './models/index.js';
import type { ExerciseStatus, LogEntry } from './models/index.js';
import type { ExerciseRadiogram } from './models/radiogram/index.js';
import { getRadiogramConstructor } from './models/radiogram/index.js';
import {
RandomState,
seededRandomState,
} from './simulation/utils/randomness.js';
import type { SpatialElementPlural } from './store/action-reducers/utils/spatial-elements.js';
import type { UUID } from './utils/index.js';
import { uuid, uuidValidationOptions } from './utils/index.js';
import {
IsIdMap,
IsLiteralUnion,
IsMultiTypedIdMap,
} from './utils/validators/index.js';
import {
createCatchAllHospital,
catchAllHospitalId,
defaultPatientCategories,
defaultMapImagesTemplatesById,
} from './data/index.js';
import { IsZodSchema } from './utils/validators/is-zod-object.js';
import { vehicleSchema } from './models/vehicle.js';
import { defaultVehicleTemplatesById } from './data/default-state/vehicle-templates.js';
import type { TreatmentAssignment } from './store/index.js';
import { restrictedZoneSchema } from './models/restricted-zone.js';
import { materialSchema } from './models/material.js';
import { materialTemplateSchema } from './models/material-template.js';
import { personnelTemplateSchema } from './models/personnel-template.js';
import { personnelSchema } from './models/personnel.js';
import { vehicleTemplateSchema } from './models/vehicle-template.js';
import { type ParticipantKey, participantKeySchema } from './exercise-keys.js';
export class ExerciseState {
@IsUUID(4, uuidValidationOptions)
public readonly id = uuid();
/**
* The number of ms since the start of the exercise.
* This time is updated each `tick` by a constant value, is guaranteed to be (a bit) slower than the real time
* (depending on the server load and overhead of the tick).
*
* It is guaranteed that the `ExerciseTickAction` is the only action that modifies this value.
*/
@IsInt()
@Min(0)
public readonly currentTime: number = 0;
@IsLiteralUnion(exerciseStatusAllowedValues)
public readonly currentStatus: ExerciseStatus = 'notStarted';
@Type(() => RandomState)
@ValidateNested()
public readonly randomState: RandomState = seededRandomState();
@IsIdMap(Viewport)
public readonly viewports: { readonly [key: UUID]: Viewport } = {};
@IsIdMap(SimulatedRegion)
public readonly simulatedRegions: {
readonly [key: UUID]: SimulatedRegion;
} = {};
@IsZodSchema(z.record(z.uuidv4(), vehicleSchema))
public readonly vehicles: { readonly [key: UUID]: Vehicle } = {};
@IsZodSchema(z.record(z.uuidv4(), personnelSchema))
public readonly personnel: { readonly [key: UUID]: Personnel } = {};
@IsIdMap(Patient)
public readonly patients: { readonly [key: UUID]: Patient } = {};
@IsZodSchema(z.record(z.uuidv4(), materialSchema))
public readonly materials: { readonly [key: UUID]: Material } = {};
@IsZodSchema(z.record(z.uuidv4(), restrictedZoneSchema))
public readonly restrictedZones: { readonly [key: UUID]: RestrictedZone } =
{};
@IsIdMap(MapImage)
public readonly mapImages: { readonly [key: UUID]: MapImage } = {};
@IsIdMap(TransferPoint)
public readonly transferPoints: { readonly [key: UUID]: TransferPoint } =
{};
@IsIdMap(Hospital)
public readonly hospitals: { readonly [key: UUID]: Hospital } = {
[catchAllHospitalId]: createCatchAllHospital(),
};
@IsIdMap(HospitalPatient, (hospitalPatient) => hospitalPatient.patientId)
public readonly hospitalPatients: {
readonly [key: UUID]: HospitalPatient;
} = {};
@IsIdMap(AlarmGroup)
public readonly alarmGroups: { readonly [key: UUID]: AlarmGroup } = {};
@IsIdMap(Client)
public readonly clients: { readonly [key: UUID]: Client } = {};
@IsMultiTypedIdMap(getRadiogramConstructor)
@ValidateNested()
public readonly radiograms: { readonly [key: UUID]: ExerciseRadiogram } =
{};
@IsArray()
@ValidateNested()
@Type(() => PatientCategory)
public readonly patientCategories = defaultPatientCategories;
@IsZodSchema(z.record(z.uuidv4(), vehicleTemplateSchema))
public readonly vehicleTemplates: {
readonly [key: UUID]: VehicleTemplate;
} = defaultVehicleTemplatesById;
@IsZodSchema(z.record(z.uuidv4(), materialTemplateSchema))
public readonly materialTemplates: {
readonly [key: UUID]: MaterialTemplate;
} = defaultMaterialTemplatesById;
@IsZodSchema(z.record(z.uuidv4(), personnelTemplateSchema))
public readonly personnelTemplates: {
readonly [key: UUID]: PersonnelTemplate;
} = defaultPersonnelTemplatesById;
@IsIdMap(MapImageTemplate)
public readonly mapImageTemplates: {
readonly [key: UUID]: MapImageTemplate;
} = defaultMapImagesTemplatesById;
@IsArray()
@ValidateNested()
@Type(() => EocLogEntry)
public readonly eocLog: readonly EocLogEntry[] = [];
@IsZodSchema(participantKeySchema)
public readonly participantKey: ParticipantKey;
// WritableDraft<ExerciseState>` could still have immutable objects in spatialTree
@IsObject()
public readonly spatialTrees: {
[type in SpatialElementPlural]: SpatialTree;
} = {
materials: SpatialTree.create(),
patients: SpatialTree.create(),
personnel: SpatialTree.create(),
};
@ValidateNested()
@Type(() => ExerciseConfiguration)
public readonly configuration = ExerciseConfiguration.create();
@IsInt()
@Min(0)
public readonly patientCounter: number = 0;
/**
* The log entries generated for the statistics.
* This must not be defined on a normal state,
* unless the statistics are currently being generated.
*/
@Equals(undefined)
public logEntries?: LogEntry[];
@Equals(undefined)
public previousTreatmentAssignment?: TreatmentAssignment;
/**
* @deprecated Use {@link create} instead.
*/
constructor(participantKey: ParticipantKey) {
this.participantKey = participantKey;
}
static readonly create = getCreate(this);
/**
* **Important**
*
* This number MUST be increased every time a change to any object (that is part of the state or the state itself) is made in a way that there may be states valid before that are no longer valid.
*/
static readonly currentStateVersion = 47;
}