From 1b5050a7bf746716177675e85f782ee4979c8d44 Mon Sep 17 00:00:00 2001 From: ntr Date: Tue, 12 Nov 2019 15:51:33 +1100 Subject: [PATCH] fix auto ready and remove activeConstruct reducer --- client/src/actions.jsx | 1 - client/src/components/account.status.jsx | 1 - client/src/components/game.jsx | 10 +--------- client/src/components/header.jsx | 1 - client/src/components/instance.constructs.jsx | 15 ++------------- client/src/components/instance.ctrl.btns.jsx | 9 --------- client/src/components/nav.jsx | 1 - client/src/events.jsx | 17 ++++++++++++----- client/src/reducers.jsx | 1 - 9 files changed, 15 insertions(+), 41 deletions(-) diff --git a/client/src/actions.jsx b/client/src/actions.jsx index e42d349c..ef463a40 100644 --- a/client/src/actions.jsx +++ b/client/src/actions.jsx @@ -1,5 +1,4 @@ export const setAccount = value => ({ type: 'SET_ACCOUNT', value }); -export const setActiveConstruct = value => ({ type: 'SET_ACTIVE_CONSTRUCT', value }); export const setAnimating = value => ({ type: 'SET_ANIMATING', value }); export const setAnimCb = value => ({ type: 'SET_ANIM_CB', value }); diff --git a/client/src/components/account.status.jsx b/client/src/components/account.status.jsx index 422d2233..c25b0855 100644 --- a/client/src/components/account.status.jsx +++ b/client/src/components/account.status.jsx @@ -36,7 +36,6 @@ const addState = connect( dispatch(actions.setCombiner([])); dispatch(actions.setReclaiming(false)); dispatch(actions.setActiveSkill(null)); - dispatch(actions.setActiveConstruct(null)); dispatch(actions.setInfo(null)); dispatch(actions.setItemEquip(null)); dispatch(actions.setItemUnequip([])); diff --git a/client/src/components/game.jsx b/client/src/components/game.jsx index 88cc3a1d..2767d290 100644 --- a/client/src/components/game.jsx +++ b/client/src/components/game.jsx @@ -14,7 +14,6 @@ const addState = connect( account, animating, activeSkill, - activeConstruct, } = state; function selectSkillTarget(targetConstructId) { @@ -34,7 +33,6 @@ const addState = connect( account, animating, activeSkill, - activeConstruct, selectSkillTarget, }; }, @@ -44,11 +42,7 @@ const addState = connect( dispatch(actions.setActiveSkill(constructId, skill)); } - function setActiveConstruct(construct) { - dispatch(actions.setActiveConstruct(construct)); - } - - return { setActiveSkill, setActiveConstruct }; + return { setActiveSkill }; } ); @@ -59,7 +53,6 @@ function Game(props) { account, animating, setActiveSkill, - setActiveConstruct, } = props; if (!game) return
...
; @@ -91,7 +84,6 @@ function Game(props) { function gameClick(e) { e.stopPropagation(); - setActiveConstruct(null); } return ( diff --git a/client/src/components/header.jsx b/client/src/components/header.jsx index 2ce0368f..76e96fe7 100644 --- a/client/src/components/header.jsx +++ b/client/src/components/header.jsx @@ -35,7 +35,6 @@ const addState = connect( dispatch(actions.setCombiner([])); dispatch(actions.setReclaiming(false)); dispatch(actions.setActiveSkill(null)); - dispatch(actions.setActiveConstruct(null)); dispatch(actions.setInfo(null)); dispatch(actions.setItemEquip(null)); dispatch(actions.setItemUnequip([])); diff --git a/client/src/components/instance.constructs.jsx b/client/src/components/instance.constructs.jsx index da843f8f..312ce513 100644 --- a/client/src/components/instance.constructs.jsx +++ b/client/src/components/instance.constructs.jsx @@ -66,10 +66,6 @@ const addState = connect( dispatch(actions.setInfo(item)); } - function setActiveConstruct(value) { - dispatch(actions.setActiveConstruct(value)); - } - function setItemEquip(v) { return dispatch(actions.setItemEquip(v)); } @@ -78,7 +74,7 @@ const addState = connect( return dispatch(actions.setItemUnequip(v)); } - return { quit, setInfo, setActiveConstruct, setItemUnequip, setItemEquip }; + return { quit, setInfo, setItemUnequip, setItemEquip }; } ); @@ -101,7 +97,6 @@ function Construct(props) { sendVboxAcceptEquip, sendVboxUnequipApply, sendUnequip, - setActiveConstruct, setItemUnequip, setItemEquip, setInfo, @@ -144,7 +139,6 @@ function Construct(props) { function skillClick(e) { if (!skill) return false; setItemUnequip([construct.id, skill.skill]); - setActiveConstruct(construct); e.stopPropagation(); return true; } @@ -152,7 +146,6 @@ function Construct(props) { function skillDblClick(e) { if (!skill) return false; sendUnequip(construct.id, skill.skill); - setActiveConstruct(null); setItemUnequip([]); e.stopPropagation(); e.preventDefault(); @@ -203,12 +196,10 @@ function Construct(props) { function specClick(e) { e.stopPropagation(); setItemUnequip([construct.id, s]); - setActiveConstruct(construct); } function specDblClick(e) { sendUnequip(construct.id, s); - setActiveConstruct(null); setItemUnequip([]); e.stopPropagation(); e.preventDefault(); @@ -291,7 +282,6 @@ class InstanceConstructs extends preact.Component { itemInfo, // Function calls setInfo, - setActiveConstruct, sendVboxApply, sendVboxAcceptEquip, sendVboxUnequipApply, @@ -321,7 +311,6 @@ class InstanceConstructs extends preact.Component { sendVboxAcceptEquip, sendVboxUnequipApply, setInfo, - setActiveConstruct, itemInfo, setVboxHighlight, sendUnequip, @@ -331,7 +320,7 @@ class InstanceConstructs extends preact.Component { }); return ( -
setActiveConstruct(null)}> +
{constructs}
); diff --git a/client/src/components/instance.ctrl.btns.jsx b/client/src/components/instance.ctrl.btns.jsx index ecfded9c..59752c1e 100644 --- a/client/src/components/instance.ctrl.btns.jsx +++ b/client/src/components/instance.ctrl.btns.jsx @@ -55,15 +55,6 @@ function InstanceCtrlBtns(args) { const finished = instance && instance.phase === 'Finished'; - // cheeky to make sure nubs don't just abandon their first game - const beingNub = instance.phase_end - && instance.phase === 'Lobby' - && Date.parse(instance.phase_end) - Date.now() < 2000; - - if (beingNub) { - sendReady(); - } - return (
diff --git a/client/src/components/nav.jsx b/client/src/components/nav.jsx index daf513f1..e254690a 100644 --- a/client/src/components/nav.jsx +++ b/client/src/components/nav.jsx @@ -36,7 +36,6 @@ const addState = connect( dispatch(actions.setCombiner([])); dispatch(actions.setReclaiming(false)); dispatch(actions.setActiveSkill(null)); - dispatch(actions.setActiveConstruct(null)); dispatch(actions.setInfo(null)); dispatch(actions.setItemEquip(null)); dispatch(actions.setItemUnequip([])); diff --git a/client/src/events.jsx b/client/src/events.jsx index 0c745017..29fea424 100644 --- a/client/src/events.jsx +++ b/client/src/events.jsx @@ -177,7 +177,6 @@ function registerEvents(store) { function clearInfo() { store.dispatch(actions.setInfo(null)); - store.dispatch(actions.setActiveConstruct(null)); console.log('event clear item'); } @@ -185,7 +184,6 @@ function registerEvents(store) { store.dispatch(actions.setCombiner([])); store.dispatch(actions.setReclaiming(false)); store.dispatch(actions.setActiveSkill(null)); - store.dispatch(actions.setActiveConstruct(null)); store.dispatch(actions.setInfo(null)); store.dispatch(actions.setItemEquip(null)); store.dispatch(actions.setItemUnequip([])); @@ -208,6 +206,7 @@ function registerEvents(store) { return store.dispatch(actions.setInvite(code)); } + let autoReady = null; function setInstance(v) { const { account, instance, ws, tutorial } = store.getState(); if (v) { @@ -216,15 +215,23 @@ function registerEvents(store) { store.dispatch(actions.setPlayer(player)); if (!instance || v.id !== instance.id) { - store.dispatch(actions.setNav('vbox')); - const first = player.constructs[0]; - store.dispatch(actions.setActiveConstruct(first)); + clearTimeout(autoReady); } if (v.phase === 'Finished') { ws.sendAccountInstances(); } + if (v.phase_end && v.phase === 'Lobby' && !autoReady) { + const autoReadyDelay = Date.parse(v.phase_end) - Date.now() - 1000; + autoReady = setTimeout(() => { + ws.sendInstanceReady(v.id); + autoReady = null; + }, autoReadyDelay); + } + + if (v.phase !== 'Lobby') clearTimeout(autoReady); + // instance.mobile.less hides info at @media 1000 if (localStorage.getItem('tutorial-complete') || window.innerWidth <= 1100) { store.dispatch(actions.setTutorial(null)); diff --git a/client/src/reducers.jsx b/client/src/reducers.jsx index 96d8001c..e8bae9ef 100644 --- a/client/src/reducers.jsx +++ b/client/src/reducers.jsx @@ -10,7 +10,6 @@ function createReducer(defaultState, actionType) { /* eslint-disable key-spacing */ module.exports = { account: createReducer(null, 'SET_ACCOUNT'), - activeConstruct: createReducer(null, 'SET_ACTIVE_CONSTRUCT'), activeItem: createReducer(null, 'SET_ACTIVE_VAR'), activeSkill: createReducer(null, 'SET_ACTIVE_SKILL'),