clean up abandon and reset tutorial if in progress

This commit is contained in:
Mashy 2019-10-27 20:10:47 +10:00
parent bb94e43ca1
commit 29c4bfe891
5 changed files with 13 additions and 10 deletions

View File

@ -8,6 +8,7 @@ const addState = connect(
const {
ws,
game,
animating,
} = state;
function sendAbandon() {
@ -16,30 +17,31 @@ const addState = connect(
return {
game,
sendAbandon,
animating,
};
},
function receiveDispatch(dispatch) {
function leave() {
dispatch(actions.setNav('play'));
dispatch(actions.setGame(null));
dispatch(actions.setInstance(null));
}
return { leave };
}
);
function GameCtrlTopBtns(args) {
const {
game,
leave,
sendAbandon,
animating,
} = args;
const finished = game && game.phase === 'Finished';
const finished = game && game.phase === 'Finish';
const { abandonState } = this.state;
const abandonStateTrue = e => {
@ -52,7 +54,7 @@ function GameCtrlTopBtns(args) {
const abandonText = abandonState ? 'Confirm' : 'Abandon';
const abandonAction = abandonState ? sendAbandon : abandonStateTrue;
const abandonBtn = <button class={abandonClasses} disabled={finished} onClick={abandonAction}>{abandonText}</button>;
const abandonBtn = <button class={abandonClasses} disabled={finished || animating} onClick={abandonAction}>{abandonText}</button>;
const leaveBtn = <button class='abandon confirming' onClick={leave}>Leave</button>;
return (

View File

@ -8,6 +8,7 @@ const addState = connect(
const {
ws,
instance,
tutorial,
} = state;
function sendAbandon() {
@ -21,10 +22,11 @@ const addState = connect(
};
},
function receiveDispatch(dispatch) {
function leave() {
function leave(tutorial) {
dispatch(actions.setNav('play'));
dispatch(actions.setGame(null));
dispatch(actions.setInstance(null));
if (tutorial && tutorial < 7) dispatch(actions.setTutorial(1));
}
return { leave };
@ -37,6 +39,7 @@ function InstanceTopBtns(args) {
leave,
sendAbandon,
tutorial,
} = args;
const finished = instance && instance.phase === 'Finished';
@ -53,7 +56,7 @@ function InstanceTopBtns(args) {
const abandonAction = abandonState ? sendAbandon : abandonStateTrue;
const abandonBtn = <button class={abandonClasses} disabled={finished} onClick={abandonAction}>{abandonText}</button>;
const leaveBtn = <button class='abandon confirming' onClick={leave}>Leave</button>;
const leaveBtn = <button class='abandon confirming' onClick={() => leave(tutorial)}>Leave</button>;
return (
<div class="instance-ctrl-btns">

View File

@ -210,7 +210,6 @@ function registerEvents(store) {
}
if (v.phase === 'Finished') {
setGame(null);
ws.sendAccountInstances();
}
if (v.time_control === 'Practice' && v.rounds.length === 1 && tutorial) {

View File

@ -78,7 +78,6 @@ function tutorialVbox(player, store, tutorial) {
vbox.free[2] = [];
}
}
console.log(stage);
store.dispatch(actions.setTutorial(stage));
}