fix vbox not recalculating on spec remove

This commit is contained in:
ntr 2019-04-03 23:44:02 +11:00
parent b664396ddf
commit 13cd21c925
4 changed files with 18 additions and 2 deletions

View File

@ -72,7 +72,7 @@ function InstanceComponent(args) {
if (!instance) return <div>...</div>; if (!instance) return <div>...</div>;
const cryps = instance.cryps.map(c => Cryp(c, sendVboxApply, setInfo)); const cryps = instance.cryps.map((c, i) => Cryp(c, sendVboxApply, setInfo));
return ( return (
<main className="instance" > <main className="instance" >

View File

@ -54,6 +54,8 @@ function registerEvents(store) {
} }
function setPlayer(v) { function setPlayer(v) {
const { instance } = store.getState();
console.log(instance === v);
return store.dispatch(actions.setInstance(v)); return store.dispatch(actions.setInstance(v));
} }

View File

@ -44,7 +44,7 @@ const defaultInstance = null;
function instanceReducer(state = defaultInstance, action) { function instanceReducer(state = defaultInstance, action) {
switch (action.type) { switch (action.type) {
case actions.SET_INSTANCE: case actions.SET_INSTANCE:
return action.value; return Object.assign({}, action.value);
default: default:
return state; return state;
} }

View File

@ -638,6 +638,20 @@ pub fn vbox_unequip(params: VboxUnequipParams, tx: &mut Transaction, account: &A
None => return Err(err_msg("var has no effect on cryps")), None => return Err(err_msg("var has no effect on cryps")),
} }
// now the var has been applied
// recalculate the stats of the whole team
let team_colours = player.cryps.iter().fold(Colours::new(), |tc, c| {
Colours {
red: tc.red + c.colours.red,
green: tc.green + c.colours.green,
blue: tc.blue + c.colours.blue
}
});
for cryp in player.cryps.iter_mut() {
cryp.apply_modifiers(&team_colours);
}
player.vbox.bound.push(params.target); player.vbox.bound.push(params.target);
return player_update(tx, player, false); return player_update(tx, player, false);
} }