1use serde_json::{json, Map, Value};
7
8pub const VIEW_LAYOUT_VERSION: u32 = 27;
11
12#[allow(missing_docs)]
28pub mod header {
29 pub const MINUTES: usize = 0;
30 pub const TOWER_REVISION: usize = 1;
31 pub const META_REVISION: usize = 2;
32 pub const MEAL_OVERLAY_REVISION: usize = 3;
33 pub const LOG_SEQ: usize = 4;
34 pub const MONEY: usize = 5;
35 pub const STAR: usize = 6;
36 pub const UNLOCKED: usize = 7;
37 pub const POPULATION: usize = 8;
38 pub const WEATHER: usize = 9;
39 pub const SANTA_FX_SEQ: usize = 10;
40 pub const EXPLOSION_FX_SEQ: usize = 11;
41 pub const EXPLOSION_FX_FLOOR: usize = 12;
42 pub const EXPLOSION_FX_X: usize = 13;
43 pub const THIEF_FX_SEQ: usize = 14;
44 pub const THIEF_FX_CAUGHT: usize = 15;
45 pub const THIEF_FX_FLOOR: usize = 16;
46 pub const TREASURE_FX_SEQ: usize = 17;
47 pub const TREASURE_FX_FLOOR: usize = 18;
48 pub const TREASURE_FX_X: usize = 19;
49 pub const VIP_FX_SEQ: usize = 20;
50 pub const FIRES_STARTED: usize = 21;
51 pub const FIRES_GUT_ROOMS: usize = 22;
52 pub const BOMBS_DETONATED: usize = 23;
53 pub const PENDING_CHOICE: usize = 24;
54 pub const ON_HOUR_RUNS: usize = 25;
55 pub const ROOMS: usize = 26;
56 pub const FULL: usize = 27;
57 pub const FRAME_SEQ: usize = 28;
58 pub const PEOPLE: usize = 29;
59 pub const UNITS: usize = 30;
60 pub const TRANSPORTS: usize = 31;
61 pub const DAY: usize = 32;
62 pub const DAY_OF_WEEK: usize = 33;
63 pub const IS_WEEKEND: usize = 34;
64 pub const QUARTER: usize = 35;
65 pub const YEAR: usize = 36;
66 pub const WEEK_DAYS: usize = 37;
67 pub const WEEKEND_DAYS: usize = 38;
68 pub const BOMB_SEARCH_SEQ: usize = 39;
69 pub const THIEF_FX_X: usize = 40;
70}
71
72pub const HEADER: usize = header::THIEF_FX_X + 1;
74
75#[allow(missing_docs)]
78pub mod person {
79 pub const ID: usize = 0;
80 pub const SEED: usize = 1;
81 pub const STAFF: usize = 2;
82 pub const STATE: usize = 3;
83 pub const FLOOR: usize = 4;
84 pub const X: usize = 5;
85 pub const FY: usize = 6;
86 pub const WAIT: usize = 7;
87}
88
89pub const PERSON_RECORD: usize = person::WAIT + 1;
91
92#[allow(missing_docs)]
96pub mod unit {
97 pub const SLOT: usize = 0;
98 pub const STATE: usize = 1;
99 pub const OCCUPANTS: usize = 2;
100 pub const CUSTOMERS_IN: usize = 3;
101 pub const HOTEL_CUSTOMERS_IN: usize = 4;
102 pub const OUT_FOR_MEAL: usize = 5;
103}
104
105pub const UNIT_RECORD: usize = unit::OUT_FOR_MEAL + 1;
107
108#[allow(missing_docs)]
112pub mod transport {
113 pub const ID: usize = 0;
114 pub const CARS: usize = 1;
115}
116
117pub const TRANSPORT_FIXED: usize = transport::CARS + 1;
119
120#[allow(missing_docs)]
123pub mod car {
124 pub const POSITION: usize = 0;
125 pub const LOAD: usize = 1;
126 pub const DIRECTION: usize = 2;
127}
128
129pub const CAR_RECORD: usize = car::DIRECTION + 1;
131
132#[allow(missing_docs)]
140pub mod structure {
141 pub const REVISION: usize = 0;
142 pub const ROOMS: usize = 1;
143 pub const RUNS: usize = 2;
144 pub const SHAFTS: usize = 3;
145 pub const HIGHEST_FLOOR: usize = 4;
146 pub const LOWEST_FLOOR: usize = 5;
147 pub const MODE: usize = 6;
148 pub const CALENDAR: usize = 7;
149 pub const SCENE_SEED: usize = 8;
150}
151
152pub const STRUCTURE_HEADER: usize = structure::SCENE_SEED + 1;
154
155#[allow(missing_docs)]
158pub mod room {
159 pub const ID: usize = 0;
160 pub const KIND: usize = 1;
161 pub const FLOOR: usize = 2;
162 pub const X: usize = 3;
163 pub const WIDTH: usize = 4;
164}
165
166pub const ROOM_RECORD: usize = room::WIDTH + 1;
168
169#[allow(missing_docs)]
174pub mod run {
175 pub const KIND: usize = 0;
176 pub const FLOOR: usize = 1;
177 pub const X: usize = 2;
178 pub const WIDTH: usize = 3;
179 pub const COUNT: usize = 4;
180 pub const STATE: usize = 5;
181 pub const OCCUPANTS: usize = 6;
182 pub const CUSTOMERS_IN: usize = 7;
183 pub const HOTEL_CUSTOMERS_IN: usize = 8;
184 pub const OUT_FOR_MEAL: usize = 9;
185}
186
187pub const RUN_RECORD: usize = run::OUT_FOR_MEAL + 1;
189
190#[allow(missing_docs)]
194pub mod shaft {
195 pub const ID: usize = 0;
196 pub const KIND: usize = 1;
197 pub const X: usize = 2;
198 pub const WIDTH: usize = 3;
199 pub const BOTTOM: usize = 4;
200 pub const TOP: usize = 5;
201 pub const CARS: usize = 6;
202 pub const SKIPS: usize = 7;
203}
204
205pub const SHAFT_FIXED: usize = shaft::SKIPS + 1;
207
208pub(crate) struct Table {
211 pub(crate) name: &'static str,
212 pub(crate) slots: &'static [(&'static str, usize)],
213 pub(crate) width_name: &'static str,
214 pub(crate) width: usize,
215}
216
217pub(crate) const TABLES: &[Table] = &[
219 Table {
220 name: "header",
221 slots: &[
222 ("minutes", header::MINUTES),
223 ("towerRevision", header::TOWER_REVISION),
224 ("metaRevision", header::META_REVISION),
225 ("mealOverlayRevision", header::MEAL_OVERLAY_REVISION),
226 ("logSeq", header::LOG_SEQ),
227 ("money", header::MONEY),
228 ("star", header::STAR),
229 ("unlocked", header::UNLOCKED),
230 ("population", header::POPULATION),
231 ("weather", header::WEATHER),
232 ("santaFxSeq", header::SANTA_FX_SEQ),
233 ("explosionFxSeq", header::EXPLOSION_FX_SEQ),
234 ("explosionFxFloor", header::EXPLOSION_FX_FLOOR),
235 ("explosionFxX", header::EXPLOSION_FX_X),
236 ("thiefFxSeq", header::THIEF_FX_SEQ),
237 ("thiefFxCaught", header::THIEF_FX_CAUGHT),
238 ("thiefFxFloor", header::THIEF_FX_FLOOR),
239 ("treasureFxSeq", header::TREASURE_FX_SEQ),
240 ("treasureFxFloor", header::TREASURE_FX_FLOOR),
241 ("treasureFxX", header::TREASURE_FX_X),
242 ("vipFxSeq", header::VIP_FX_SEQ),
243 ("firesStarted", header::FIRES_STARTED),
244 ("firesGutRooms", header::FIRES_GUT_ROOMS),
245 ("bombsDetonated", header::BOMBS_DETONATED),
246 ("pendingChoice", header::PENDING_CHOICE),
247 ("onHourRuns", header::ON_HOUR_RUNS),
248 ("rooms", header::ROOMS),
249 ("full", header::FULL),
250 ("frameSeq", header::FRAME_SEQ),
251 ("people", header::PEOPLE),
252 ("units", header::UNITS),
253 ("transports", header::TRANSPORTS),
254 ("day", header::DAY),
255 ("dayOfWeek", header::DAY_OF_WEEK),
256 ("isWeekend", header::IS_WEEKEND),
257 ("quarter", header::QUARTER),
258 ("year", header::YEAR),
259 ("weekDays", header::WEEK_DAYS),
260 ("weekendDays", header::WEEKEND_DAYS),
261 ("bombSearchSeq", header::BOMB_SEARCH_SEQ),
262 ("thiefFxX", header::THIEF_FX_X),
263 ],
264 width_name: "headerWidth",
265 width: HEADER,
266 },
267 Table {
268 name: "person",
269 slots: &[
270 ("id", person::ID),
271 ("seed", person::SEED),
272 ("staff", person::STAFF),
273 ("state", person::STATE),
274 ("floor", person::FLOOR),
275 ("x", person::X),
276 ("fy", person::FY),
277 ("wait", person::WAIT),
278 ],
279 width_name: "personWidth",
280 width: PERSON_RECORD,
281 },
282 Table {
283 name: "unit",
284 slots: &[
285 ("slot", unit::SLOT),
286 ("state", unit::STATE),
287 ("occupants", unit::OCCUPANTS),
288 ("customersIn", unit::CUSTOMERS_IN),
289 ("hotelCustomersIn", unit::HOTEL_CUSTOMERS_IN),
290 ("outForMeal", unit::OUT_FOR_MEAL),
291 ],
292 width_name: "unitWidth",
293 width: UNIT_RECORD,
294 },
295 Table {
296 name: "transport",
297 slots: &[("id", transport::ID), ("cars", transport::CARS)],
298 width_name: "transportFixed",
299 width: TRANSPORT_FIXED,
300 },
301 Table {
302 name: "car",
303 slots: &[
304 ("position", car::POSITION),
305 ("load", car::LOAD),
306 ("direction", car::DIRECTION),
307 ],
308 width_name: "carWidth",
309 width: CAR_RECORD,
310 },
311 Table {
312 name: "structure",
313 slots: &[
314 ("revision", structure::REVISION),
315 ("rooms", structure::ROOMS),
316 ("runs", structure::RUNS),
317 ("shafts", structure::SHAFTS),
318 ("highestFloor", structure::HIGHEST_FLOOR),
319 ("lowestFloor", structure::LOWEST_FLOOR),
320 ("mode", structure::MODE),
321 ("calendar", structure::CALENDAR),
322 ("sceneSeed", structure::SCENE_SEED),
323 ],
324 width_name: "structureWidth",
325 width: STRUCTURE_HEADER,
326 },
327 Table {
328 name: "room",
329 slots: &[
330 ("id", room::ID),
331 ("kind", room::KIND),
332 ("floor", room::FLOOR),
333 ("x", room::X),
334 ("width", room::WIDTH),
335 ],
336 width_name: "roomWidth",
337 width: ROOM_RECORD,
338 },
339 Table {
340 name: "run",
341 slots: &[
342 ("kind", run::KIND),
343 ("floor", run::FLOOR),
344 ("x", run::X),
345 ("width", run::WIDTH),
346 ("count", run::COUNT),
347 ("state", run::STATE),
348 ("occupants", run::OCCUPANTS),
349 ("customersIn", run::CUSTOMERS_IN),
350 ("hotelCustomersIn", run::HOTEL_CUSTOMERS_IN),
351 ("outForMeal", run::OUT_FOR_MEAL),
352 ],
353 width_name: "runWidth",
354 width: RUN_RECORD,
355 },
356 Table {
357 name: "shaft",
358 slots: &[
359 ("id", shaft::ID),
360 ("kind", shaft::KIND),
361 ("x", shaft::X),
362 ("width", shaft::WIDTH),
363 ("bottom", shaft::BOTTOM),
364 ("top", shaft::TOP),
365 ("cars", shaft::CARS),
366 ("skips", shaft::SKIPS),
367 ],
368 width_name: "shaftFixed",
369 width: SHAFT_FIXED,
370 },
371];
372
373pub(crate) const UNIT_STATES: [&str; 10] = [
375 "construction",
376 "empty",
377 "occupied",
378 "moving_in",
379 "vacating",
380 "asleep",
381 "dirty",
382 "infested",
383 "fire",
384 "gutted",
385];
386
387pub(crate) const PERSON_STATES: [&str; 7] = [
389 "toShaft", "waiting", "riding", "climbing", "toDest", "dwelling", "done",
390];
391
392pub(crate) const WEATHER: [&str; 3] = ["clear", "cloudy", "rain"];
394
395pub(crate) const MODES: [&str; 2] = ["classic", "modern"];
397
398pub(crate) const CALENDARS: [&str; 2] = ["canon", "realWorld"];
401
402pub(crate) const META_RECORD: [&str; 3] = ["id", "label", "subtype"];
405
406pub fn layout_json() -> Value {
413 let mut m = Map::new();
414 m.insert("version".into(), json!(VIEW_LAYOUT_VERSION));
415 for t in TABLES {
416 let slots: Map<String, Value> = t
417 .slots
418 .iter()
419 .map(|(name, slot)| ((*name).to_owned(), json!(slot)))
420 .collect();
421 m.insert(t.name.into(), Value::Object(slots));
422 m.insert(t.width_name.into(), json!(t.width));
423 }
424 let facilities = &crate::facilities::FACILITIES;
425 m.insert(
426 "kinds".into(),
427 json!(facilities.iter().map(|f| f.key).collect::<Vec<_>>()),
428 );
429 m.insert(
430 "names".into(),
431 json!(facilities.iter().map(|f| f.name).collect::<Vec<_>>()),
432 );
433 m.insert("unitStates".into(), json!(UNIT_STATES));
434 m.insert("personStates".into(), json!(PERSON_STATES));
435 m.insert("weather".into(), json!(WEATHER));
436 m.insert("modes".into(), json!(MODES));
437 m.insert("calendars".into(), json!(CALENDARS));
438 m.insert("metaRecord".into(), json!(META_RECORD));
439 Value::Object(m)
440}