add carrier to dux
This commit is contained in:
parent
7cc85f2572
commit
5602441364
@ -53,6 +53,14 @@ exports[`state has the expected shape 1`] = `
|
|||||||
},
|
},
|
||||||
"space": 0,
|
"space": 0,
|
||||||
},
|
},
|
||||||
|
"carrier": {
|
||||||
|
"nbrBays": 0,
|
||||||
|
"reqs": {
|
||||||
|
"cost": 0,
|
||||||
|
"mass": 0,
|
||||||
|
},
|
||||||
|
"squadrons": [],
|
||||||
|
},
|
||||||
"hull": {
|
"hull": {
|
||||||
"max": 0,
|
"max": 0,
|
||||||
"min": 0,
|
"min": 0,
|
||||||
|
@ -17,11 +17,13 @@ test("kicking the tires", () => {
|
|||||||
store.dispatch.setNbrCarrierBays(2);
|
store.dispatch.setNbrCarrierBays(2);
|
||||||
expect(store.getState().carrier.nbrBays).toEqual(2);
|
expect(store.getState().carrier.nbrBays).toEqual(2);
|
||||||
|
|
||||||
|
expect(store.getState.isCarrier()).toBe(false);
|
||||||
|
|
||||||
|
store.dispatch.setCarrier(true);
|
||||||
store.dispatch.setSquadronType(2, "fast");
|
store.dispatch.setSquadronType(2, "fast");
|
||||||
|
|
||||||
expect(store.getState().carrier.squadrons[1]).toHaveProperty("type", "fast");
|
|
||||||
|
|
||||||
expect(store.getState.isCarrier()).toBe(true);
|
expect(store.getState.isCarrier()).toBe(true);
|
||||||
|
expect(store.getState().carrier.squadrons[1]).toHaveProperty("type", "fast");
|
||||||
|
|
||||||
store.dispatch.setStreamlining("partial");
|
store.dispatch.setStreamlining("partial");
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ const structure = new Updux({
|
|||||||
hull: hullDux,
|
hull: hullDux,
|
||||||
screens: screensDux,
|
screens: screensDux,
|
||||||
armor: armorDux,
|
armor: armorDux,
|
||||||
|
carrier: carrierDux,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -89,30 +89,3 @@ function squadronReqs(type: string) {
|
|||||||
cost: 6 * squadronTypes.find((s) => s.type === type)?.cost,
|
cost: 6 * squadronTypes.find((s) => s.type === type)?.cost,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
export const { actions, reducer } = createSlice({
|
|
||||||
name: "carrier",
|
|
||||||
initialStateState,
|
|
||||||
reducers: {
|
|
||||||
setCarrierBays: (state, action: PayloadAction<number>) => {
|
|
||||||
state.bays = action.payload;
|
|
||||||
state.reqs = calcBaysReqs(action.payload);
|
|
||||||
state.squadrons = adjustSquadrons(action.payload)(state.squadrons);
|
|
||||||
},
|
|
||||||
setSquadronType: (
|
|
||||||
state,
|
|
||||||
action: PayloadAction<{ type: string; id: number }>
|
|
||||||
) => {
|
|
||||||
state.squadrons[action.payload.id - 1] = {
|
|
||||||
type: action.payload.type,
|
|
||||||
reqs: squadronReqs(action.payload.type),
|
|
||||||
};
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import Updux, { createAction, withPayload } from "updux";
|
import Updux, { createAction, withPayload } from "updux";
|
||||||
import u from "@yanick/updeep-remeda";
|
import u from "@yanick/updeep-remeda";
|
||||||
import * as R from "remeda";
|
|
||||||
import { carrierDux } from "./carrier";
|
import { carrierDux } from "./carrier";
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
@ -17,6 +16,7 @@ const initialState = {
|
|||||||
const setShipClass = createAction("setShipClass", withPayload<string>());
|
const setShipClass = createAction("setShipClass", withPayload<string>());
|
||||||
const updateIdentification = createAction("updateIdentification");
|
const updateIdentification = createAction("updateIdentification");
|
||||||
const setShipReqs = createAction("setShipReqs", withPayload());
|
const setShipReqs = createAction("setShipReqs", withPayload());
|
||||||
|
const setCarrier = createAction("setCarrier", withPayload<boolean>());
|
||||||
|
|
||||||
export const identificationDux = new Updux({
|
export const identificationDux = new Updux({
|
||||||
initialState,
|
initialState,
|
||||||
@ -24,6 +24,7 @@ export const identificationDux = new Updux({
|
|||||||
setShipClass,
|
setShipClass,
|
||||||
updateIdentification,
|
updateIdentification,
|
||||||
setShipReqs,
|
setShipReqs,
|
||||||
|
setCarrier,
|
||||||
},
|
},
|
||||||
selectors: {
|
selectors: {
|
||||||
getShipMass: (state) => state.reqs.mass,
|
getShipMass: (state) => state.reqs.mass,
|
||||||
@ -33,12 +34,15 @@ export const identificationDux = new Updux({
|
|||||||
|
|
||||||
identificationDux.addMutation(setShipClass, (shipClass) => u({ shipClass }));
|
identificationDux.addMutation(setShipClass, (shipClass) => u({ shipClass }));
|
||||||
identificationDux.addMutation(updateIdentification, (update) => u(update));
|
identificationDux.addMutation(updateIdentification, (update) => u(update));
|
||||||
|
|
||||||
|
identificationDux.addMutation(setCarrier, (isCarrier) => u({ isCarrier }));
|
||||||
|
identificationDux.addEffect(setCarrier, (api) => (next) => (action) => {
|
||||||
|
next(action);
|
||||||
|
if (!action.payload) {
|
||||||
|
api.dispatch(carrierDux.actions.setNbrCarrierBays(0));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
identificationDux.addMutation(setShipReqs, (reqs) => u({ reqs }));
|
identificationDux.addMutation(setShipReqs, (reqs) => u({ reqs }));
|
||||||
|
|
||||||
identificationDux.addMutation(carrierDux.actions.setNbrCarrierBays, (nbrBays) =>
|
|
||||||
u({
|
|
||||||
isCarrier: nbrBays > 0,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
export default identificationDux;
|
export default identificationDux;
|
||||||
|
Loading…
Reference in New Issue
Block a user