screens
This commit is contained in:
parent
e3c0b402d1
commit
0e76cdd4d3
@ -43,6 +43,7 @@
|
||||
"histoire": "^0.15.9",
|
||||
"jsdom": "^21.1.1",
|
||||
"lodash": "^4.17.21",
|
||||
"memoize-one": "^6.0.0",
|
||||
"redux": "^4.1.2",
|
||||
"remeda": "^1.9.1",
|
||||
"reselect": "^4.1.5",
|
||||
|
@ -12,6 +12,7 @@ import { streamliningDux as streamlining } from "./ship/structure/streamlining";
|
||||
import { calcStreamliningReqs } from "./ship/structure/rules";
|
||||
import { cargoDux } from "./ship/structure/cargo";
|
||||
import { hullDux } from "./ship/structure/hull";
|
||||
import { screensDux, screensReqsReaction } from "./ship/structure/screens";
|
||||
|
||||
const shipDux = new Updux({
|
||||
subduxes: {
|
||||
@ -22,6 +23,7 @@ const shipDux = new Updux({
|
||||
streamlining,
|
||||
cargo: cargoDux,
|
||||
hull: hullDux,
|
||||
screens: screensDux,
|
||||
},
|
||||
}),
|
||||
propulsion: new Updux({
|
||||
@ -89,4 +91,6 @@ shipDux.addReaction((api) =>
|
||||
)
|
||||
);
|
||||
|
||||
shipDux.addReaction(screensReqsReaction);
|
||||
|
||||
export default shipDux;
|
||||
|
49
src/lib/store/ship/structure/screens.ts
Normal file
49
src/lib/store/ship/structure/screens.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import { reqs } from "$lib/shipDux/reqs";
|
||||
import Updux, { createPayloadAction } from "updux";
|
||||
import u from "@yanick/updeep-remeda";
|
||||
import { createSelector } from "reselect";
|
||||
|
||||
const initialState = {
|
||||
standard: 0,
|
||||
advanced: 0,
|
||||
reqs,
|
||||
};
|
||||
|
||||
const setScreens = createPayloadAction<{ standard: number; advanced: number }>(
|
||||
"setScreens"
|
||||
);
|
||||
const setScreensReqs = createPayloadAction("setScreensReqs");
|
||||
|
||||
export const screensDux = new Updux({
|
||||
initialState,
|
||||
actions: {
|
||||
setScreensReqs,
|
||||
setScreens,
|
||||
},
|
||||
// reducers: {
|
||||
// setScreensReqs(state, action) {
|
||||
// state.reqs = action.payload;
|
||||
// },
|
||||
// },
|
||||
});
|
||||
|
||||
screensDux.addMutation(setScreens, (payload) => u(payload));
|
||||
screensDux.addMutation(setScreensReqs, (reqs) => u({ reqs }));
|
||||
|
||||
export const screensReqsReaction = (api) =>
|
||||
createSelector(
|
||||
(ship) => ship.identification.reqs.mass,
|
||||
(ship) => ship.structure.screens.standard,
|
||||
(ship) => ship.structure.screens.advanced,
|
||||
(...args) => api.dispatch.setScreensReqs(calcScreensReqs(...args))
|
||||
);
|
||||
|
||||
function calcScreensReqs(mass: number, standard: number, advanced: number) {
|
||||
const standardMass = standard * Math.max(3, Math.ceil(0.05 * mass));
|
||||
const advancedMass = advanced * Math.max(4, Math.ceil(0.075 * mass));
|
||||
|
||||
return {
|
||||
mass: standardMass + advancedMass,
|
||||
cost: 3 * standardMass + 4 * advancedMass,
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user