Merge branch 'default-beam' into main
This commit is contained in:
commit
4d11f6feeb
@ -2,42 +2,48 @@ import Updux from "updux";
|
|||||||
import { action, payload } from "ts-action";
|
import { action, payload } from "ts-action";
|
||||||
import u from "updeep";
|
import u from "updeep";
|
||||||
import { createSelector } from "reselect";
|
import { createSelector } from "reselect";
|
||||||
import { weapon_cost_mass } from '../../weapons/rules';
|
import { weapon_cost_mass } from "../../weapons/rules";
|
||||||
|
|
||||||
const add_weapon = action('add_weapon', payload());
|
const add_weapon = action("add_weapon", payload());
|
||||||
const remove_weapon = action('remove_weapon', payload());
|
const remove_weapon = action("remove_weapon", payload());
|
||||||
|
|
||||||
const uu = transform => state => transform(state)(state)
|
const uu = (transform) => (state) => transform(state)(state);
|
||||||
|
|
||||||
const with_reqs = uu( weapon => u(weapon_cost_mass(weapon)));
|
const with_reqs = uu((weapon) => u(weapon_cost_mass(weapon)));
|
||||||
|
|
||||||
const dux = new Updux({
|
const dux = new Updux({
|
||||||
initial: [],
|
initial: [],
|
||||||
})
|
});
|
||||||
|
|
||||||
const weapon_initial = {
|
const weapon_initial = {
|
||||||
beam: { weapon_type: "beam", weapon_class: 1, arcs: ['F'] },
|
beam: {
|
||||||
|
weapon_type: "beam",
|
||||||
|
weapon_class: 1,
|
||||||
|
arcs: ["F", "A", "FS", "FP", "AS", "AP"],
|
||||||
|
},
|
||||||
submunition: {
|
submunition: {
|
||||||
weapon_type: "submunition", arcs: ['F'] },
|
weapon_type: "submunition",
|
||||||
pds: { weapon_type: 'pds' },
|
arcs: ["F"],
|
||||||
scattergun: { weapon_type: 'scattergun' },
|
},
|
||||||
needle: { weapon_type: 'needle', arcs: ['F'] },
|
pds: { weapon_type: "pds" },
|
||||||
|
scattergun: { weapon_type: "scattergun" },
|
||||||
|
needle: { weapon_type: "needle", arcs: ["F"] },
|
||||||
};
|
};
|
||||||
|
|
||||||
dux.addMutation( add_weapon, (type) => state => {
|
dux.addMutation(add_weapon, (type) => (state) => {
|
||||||
const id = 1 + Math.max(0, ...state.map(({ id }) => id));
|
const id = 1 + Math.max(0, ...state.map(({ id }) => id));
|
||||||
return [...state, { ...with_reqs(weapon_initial[type]), id }];
|
return [...state, { ...with_reqs(weapon_initial[type]), id }];
|
||||||
});
|
});
|
||||||
|
|
||||||
dux.addMutation( remove_weapon, id => state =>
|
dux.addMutation(remove_weapon, (id) => (state) =>
|
||||||
state.filter( w => w.id !== id )
|
state.filter((w) => w.id !== id)
|
||||||
);
|
);
|
||||||
|
|
||||||
const set_weapon = action('set_weapon',payload());
|
const set_weapon = action("set_weapon", payload());
|
||||||
|
|
||||||
dux.addMutation(
|
dux.addMutation(set_weapon, (payload) =>
|
||||||
set_weapon, payload => u.map( u.if( _.matches({id: payload.id}),
|
u.map(
|
||||||
state => with_reqs(u(payload,state)) )
|
u.if(_.matches({ id: payload.id }), (state) => with_reqs(u(payload, state)))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
5
src/dux/weaponry/weapons/test.js
Normal file
5
src/dux/weaponry/weapons/test.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import dux from ".";
|
||||||
|
import tap from "tap";
|
||||||
|
|
||||||
|
const state = dux.upreducer(dux.actions.add_weapon("beam"))([]);
|
||||||
|
tap.equal(state[0].arcs.length, 6, "default beam is all arcs");
|
Loading…
Reference in New Issue
Block a user