deal with the uiTransform in the dux
This commit is contained in:
parent
012db36e65
commit
68fdda4d67
@ -11,48 +11,84 @@ import weaponry from "./weaponry/index.js";
|
||||
import { screensReqsReaction } from "./structure/screens.js";
|
||||
|
||||
const dux = new Updux({
|
||||
subduxes: {
|
||||
identification,
|
||||
propulsion,
|
||||
structure,
|
||||
carrier,
|
||||
weaponry,
|
||||
},
|
||||
initial: {
|
||||
reqs: { cost: 0, mass: 10, usedMass: 0 },
|
||||
},
|
||||
actions: {
|
||||
setShipReqs: null,
|
||||
},
|
||||
subduxes: {
|
||||
identification,
|
||||
propulsion,
|
||||
structure,
|
||||
carrier,
|
||||
weaponry,
|
||||
},
|
||||
initial: {
|
||||
reqs: { cost: 0, mass: 10, usedMass: 0 },
|
||||
},
|
||||
actions: {
|
||||
setShipReqs: null,
|
||||
setUITransform: null,
|
||||
},
|
||||
});
|
||||
|
||||
dux.setMutation("setShipMass", (mass) => u({ reqs: { mass } }));
|
||||
dux.setMutation('setShipReqs', reqs => u({reqs}));
|
||||
dux.setMutation("setShipReqs", (reqs) => u({ reqs }));
|
||||
|
||||
dux.setMutation("setUITransform", ({ system, systemId, translate }) => {
|
||||
const transform = translate
|
||||
? `translate(${translate[0]}px,${translate[1]}px)`
|
||||
: "";
|
||||
|
||||
switch (system) {
|
||||
case "firecons":
|
||||
return u.updateIn("weaponry.firecons.uiTransform", transform);
|
||||
|
||||
case "weapon":
|
||||
return u.updateIn(
|
||||
"weaponry.weapons",
|
||||
u.map(u.if(({ id }) => id === systemId, u({ uiTransform: transform })))
|
||||
);
|
||||
|
||||
case "screens":
|
||||
return u.updateIn("structure.screens.uiTransform", transform);
|
||||
|
||||
case "hull":
|
||||
return u.updateIn("structure.hull.uiTransform", transform);
|
||||
|
||||
case "internalSystems":
|
||||
const path = "structure.uiTransform";
|
||||
return u.updateIn(path, transform);
|
||||
|
||||
case "ftl":
|
||||
return u.updateIn("propulsion.ftl.uiTransform", transform);
|
||||
|
||||
case "drive":
|
||||
return u.updateIn("propulsion.drive.uiTransform", transform);
|
||||
|
||||
default:
|
||||
return (state) => state;
|
||||
}
|
||||
});
|
||||
|
||||
dux.addReaction(calculateDriveReqs);
|
||||
dux.addReaction(ftlReqsReaction);
|
||||
dux.addReaction(screensReqsReaction);
|
||||
|
||||
dux.addReaction( (store) => (state) => {
|
||||
let cost = 0;
|
||||
let mass = 0;
|
||||
dux.addReaction((store) => (state) => {
|
||||
let cost = 0;
|
||||
let mass = 0;
|
||||
|
||||
let subsystems = Object.values(state);
|
||||
let subsystems = Object.values(state);
|
||||
|
||||
while(subsystems.length>0) {
|
||||
const subsystem = subsystems.shift();
|
||||
if( typeof subsystem !== 'object' ) continue;
|
||||
while (subsystems.length > 0) {
|
||||
const subsystem = subsystems.shift();
|
||||
if (typeof subsystem !== "object") continue;
|
||||
|
||||
if( subsystem.reqs ) {
|
||||
cost += subsystem.reqs.cost;
|
||||
mass += subsystem.reqs.mass;
|
||||
}
|
||||
|
||||
subsystems.push( ...Object.values(subsystem));
|
||||
if (subsystem.reqs) {
|
||||
cost += subsystem.reqs.cost;
|
||||
mass += subsystem.reqs.mass;
|
||||
}
|
||||
|
||||
store.dispatch.setShipReqs({cost,usedMass: mass});
|
||||
subsystems.push(...Object.values(subsystem));
|
||||
}
|
||||
|
||||
store.dispatch.setShipReqs({ cost, usedMass: mass });
|
||||
});
|
||||
|
||||
export default dux;
|
||||
|
@ -10,35 +10,32 @@ const dux = new Updux({
|
||||
subduxes: { reqs },
|
||||
initial: {
|
||||
type: "none",
|
||||
uiTransform: "",
|
||||
},
|
||||
actions: {
|
||||
setFtl: null,
|
||||
setFtlReqs: null,
|
||||
setFtl: null,
|
||||
setFtlReqs: null,
|
||||
},
|
||||
});
|
||||
export default dux;
|
||||
|
||||
dux.setMutation( 'setFtl', type => u({type}) );
|
||||
dux.setMutation( 'setFtlReqs', reqs => u({reqs}) );
|
||||
dux.setMutation("setFtl", (type) => u({ type }));
|
||||
dux.setMutation("setFtlReqs", (reqs) => u({ reqs }));
|
||||
|
||||
export function calcFtlReqs(type,shipMass) {
|
||||
if(type==="none") return { cost: 0, mass: 0 };
|
||||
export function calcFtlReqs(type, shipMass) {
|
||||
if (type === "none") return { cost: 0, mass: 0 };
|
||||
|
||||
const mass = Math.ceil(shipMass / 10);
|
||||
const mass = Math.ceil(shipMass / 10);
|
||||
|
||||
return {
|
||||
mass,
|
||||
cost: mass * ( type === 'advanced' ? 3 : 2 ),
|
||||
}
|
||||
return {
|
||||
mass,
|
||||
cost: mass * (type === "advanced" ? 3 : 2),
|
||||
};
|
||||
}
|
||||
|
||||
// needs to be at the top level
|
||||
export const ftlReqsReaction = store =>
|
||||
export const ftlReqsReaction = (store) =>
|
||||
createSelector(
|
||||
[
|
||||
(ship) => ship.propulsion.ftl.type,
|
||||
(ship) => ship.reqs.mass,
|
||||
],
|
||||
(type,shipMass) =>
|
||||
store.dispatch.setFtlReqs(calcFtlReqs(type,shipMass))
|
||||
);
|
||||
[(ship) => ship.propulsion.ftl.type, (ship) => ship.reqs.mass],
|
||||
(type, shipMass) => store.dispatch.setFtlReqs(calcFtlReqs(type, shipMass))
|
||||
);
|
||||
|
@ -1,13 +1,15 @@
|
||||
import { Updux } from 'updux';
|
||||
import { Updux } from "updux";
|
||||
|
||||
import hull from './hull.js';
|
||||
import screens from './screens.js';
|
||||
import cargo from './cargo.js';
|
||||
import armor from './armor.js';
|
||||
import streamlining from './streamlining.js';
|
||||
import hull from "./hull.js";
|
||||
import screens from "./screens.js";
|
||||
import cargo from "./cargo.js";
|
||||
import armor from "./armor.js";
|
||||
import streamlining from "./streamlining.js";
|
||||
|
||||
const dux = new Updux({
|
||||
subduxes: { hull, screens, cargo, streamlining, armor }
|
||||
subduxes: { hull, screens, cargo, streamlining, armor },
|
||||
initial: {
|
||||
uiTransform: "",
|
||||
},
|
||||
});
|
||||
export default dux;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user