Merge branch 'gt38-add-version-schema'

This commit is contained in:
Yanick Champoux 2023-04-16 14:06:20 -04:00
commit c466631f27
7 changed files with 153 additions and 43 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

View File

@ -0,0 +1,99 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`state has the expected shape 1`] = `
{
"carrier": {
"nbrBays": 0,
"reqs": {
"cost": 0,
"mass": 0,
},
"squadrons": [],
},
"identification": {
"isCarrier": false,
"reqs": {
"cost": 0,
"mass": 10,
"usedMass": 0,
},
"shipClass": "",
"shipType": "",
},
"propulsion": {
"drive": {
"advanced": false,
"rating": 0,
"reqs": {
"cost": 0,
"mass": 0,
},
},
"ftl": {
"reqs": {
"cost": 0,
"mass": 0,
},
"type": "none",
},
},
"schemaVersion": "1",
"structure": {
"armor": {
"layers": [],
"reqs": {
"cost": 0,
"mass": 0,
},
},
"cargo": {
"reqs": {
"cost": 0,
"mass": 0,
},
"space": 0,
},
"hull": {
"max": 0,
"min": 0,
"rating": 0,
"reqs": {
"cost": 0,
"mass": 0,
},
},
"screens": {
"advanced": 0,
"reqs": {
"cost": 0,
"mass": 0,
},
"standard": 0,
},
"streamlining": {
"reqs": {
"cost": 0,
"mass": 0,
},
"type": "none",
},
},
"weaponry": {
"adfc": {
"rating": 0,
"reqs": {
"cost": 0,
"mass": 0,
},
},
"firecons": {
"reqs": {
"cost": 0,
"mass": 0,
},
"stations": 0,
},
"weapons": [],
},
}
`;

View File

@ -2,60 +2,68 @@ import { test, expect } from "vitest";
import ship from "./ship";
test("kicking the tires", () => {
const store = ship.createStore();
store.dispatch.setFtlType("standard");
const store = ship.createStore();
store.dispatch.setFtlType("standard");
expect(store.getState().propulsion.ftl.reqs.mass).toEqual(1);
expect(store.getState().identification.reqs.usedMass).toEqual(1);
expect(store.getState().propulsion.ftl.reqs.mass).toEqual(1);
expect(store.getState().identification.reqs.usedMass).toEqual(1);
store.dispatch.setDrive({ rating: 3, advanced: true });
store.dispatch.setDrive({ rating: 3, advanced: true });
expect(store.getState().propulsion.drive.reqs).toEqual({ mass: 2, cost: 6 });
expect(store.getState().propulsion.drive.reqs).toEqual({ mass: 2, cost: 6 });
store.dispatch.setNbrCarrierBays(1);
expect(store.getState().carrier.nbrBays).toEqual(1);
store.dispatch.setNbrCarrierBays(2);
expect(store.getState().carrier.nbrBays).toEqual(2);
store.dispatch.setNbrCarrierBays(1);
expect(store.getState().carrier.nbrBays).toEqual(1);
store.dispatch.setNbrCarrierBays(2);
expect(store.getState().carrier.nbrBays).toEqual(2);
store.dispatch.setSquadronType(2, "fast");
store.dispatch.setSquadronType(2, "fast");
expect(store.getState().carrier.squadrons[1]).toHaveProperty("type", "fast");
expect(store.getState().carrier.squadrons[1]).toHaveProperty("type", "fast");
expect(store.getState.isCarrier()).toBe(true);
expect(store.getState.isCarrier()).toBe(true);
store.dispatch.setStreamlining("partial");
store.dispatch.setStreamlining("partial");
expect(store.getState.getStreamlining()).toBe("partial");
expect(store.selectors.getStreamlining(store.getState())).toBe("partial");
expect(store.getState.getStreamlining()).toBe("partial");
expect(store.selectors.getStreamlining(store.getState())).toBe("partial");
store.dispatch.setCargo(3);
expect(store.getState().structure.cargo).toEqual({
space: 3,
reqs: {
mass: 3,
cost: 0,
},
});
store.dispatch.setCargo(3);
expect(store.getState().structure.cargo).toEqual({
space: 3,
reqs: {
mass: 3,
cost: 0,
},
});
store.dispatch.setNbrArmorLayers(1);
store.dispatch.setArmorRating(1, 3);
store.dispatch.setNbrArmorLayers(1);
store.dispatch.setArmorRating(1, 3);
expect(store.getState().structure.armor).toEqual({
layers: [3],
reqs: {
cost: 6,
mass: 6,
},
});
expect(store.getState().structure.armor).toEqual({
layers: [3],
reqs: {
cost: 6,
mass: 6,
},
});
store.dispatch.addWeapon("beam");
expect(store.getState().weaponry.weapons[0]).toEqual({
id: 1,
reqs: { cost: 3, mass: 1 },
specs: {
arcs: ["FS", "F", "FP", "AP", "A", "AS"],
type: "beam",
weaponClass: 1,
},
});
store.dispatch.addWeapon("beam");
expect(store.getState().weaponry.weapons[0]).toEqual({
id: 1,
reqs: { cost: 3, mass: 1 },
specs: {
arcs: ["FS", "F", "FP", "AP", "A", "AS"],
type: "beam",
weaponClass: 1,
},
});
});
test("state has a schema version", () => {
expect(ship.initialState).toHaveProperty("schemaVersion");
});
test("state has the expected shape", () => {
expect(ship.initialState).toMatchSnapshot();
});

View File

@ -51,6 +51,9 @@ const weaponry = new Updux({
});
const shipDux = new Updux({
initialState: {
schemaVersion: "1",
},
subduxes: {
identification,
structure,