Disable interaction while resolution is playing
This commit is contained in:
parent
0b71a531cc
commit
6f1dbf6f4f
|
@ -104,5 +104,37 @@ module TK.SpaceTac.UI.Specs {
|
|||
]);
|
||||
check.equals(battleview.turn_plannings[1].collectAllActions(), []);
|
||||
});
|
||||
|
||||
test.case("disables player interaction while resolution is playing", check => {
|
||||
const battleview = testgame.view;
|
||||
const ship = battleview.actual_battle.fleets[0].ships[0];
|
||||
battleview.setShipSelected(ship);
|
||||
check.in("initial", check => {
|
||||
check.equals(battleview.interacting, true);
|
||||
check.equals(battleview.ship_selected, ship);
|
||||
});
|
||||
battleview.actual_battle.applyDiffs([new TurnStartDiff([])]);
|
||||
battleview.log_processor.processPending();
|
||||
check.in("start 1", check => {
|
||||
check.equals(battleview.interacting, false);
|
||||
check.equals(battleview.ship_selected, null);
|
||||
});
|
||||
battleview.actual_battle.applyDiffs([new TurnEndDiff()]);
|
||||
battleview.log_processor.processPending();
|
||||
check.in("end 1", check => {
|
||||
check.equals(battleview.interacting, true);
|
||||
});
|
||||
battleview.actual_battle.endBattle(null);
|
||||
battleview.battle.applyDiffs([new TurnStartDiff([])]);
|
||||
battleview.log_processor.processPending();
|
||||
check.in("start 2", check => {
|
||||
check.equals(battleview.interacting, false);
|
||||
});
|
||||
battleview.actual_battle.applyDiffs([new TurnEndDiff()]);
|
||||
battleview.log_processor.processPending();
|
||||
check.in("end 2", check => {
|
||||
check.equals(battleview.interacting, false);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -152,9 +152,28 @@ module TK.SpaceTac.UI {
|
|||
});
|
||||
this.inputs.bindCheat("a", "Use AI to play", () => this.playAI());
|
||||
|
||||
// Bind to log events
|
||||
this.log_processor.register(diff => {
|
||||
if (diff instanceof TurnStartDiff) {
|
||||
return {
|
||||
foreground: async () => {
|
||||
this.setInteractionEnabled(false);
|
||||
}
|
||||
};
|
||||
} else if (diff instanceof TurnEndDiff) {
|
||||
return {
|
||||
foreground: async () => this.setInteractionEnabled(true)
|
||||
};
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
});
|
||||
|
||||
// "Battle" animation, then start processing the log
|
||||
if (this.battle.ended) {
|
||||
this.endBattle();
|
||||
} else if (this.gameui.isTesting) {
|
||||
this.setInteractionEnabled(true);
|
||||
} else if (this.splash) {
|
||||
this.showSplash().then(() => {
|
||||
this.log_processor.start();
|
||||
|
@ -272,13 +291,13 @@ module TK.SpaceTac.UI {
|
|||
}
|
||||
|
||||
/**
|
||||
* Handle the pression of a validation key (enter or space)
|
||||
* Handle the pressing of a validation key (enter or space)
|
||||
*/
|
||||
validationPressed(): void {
|
||||
if (this.targetting.active) {
|
||||
this.targetting.validate((action, target) => this.applyPlayerAction(action, target));
|
||||
} else {
|
||||
this.action_bar.keyActionPressed(-1);
|
||||
this.startResolution();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -357,10 +376,14 @@ module TK.SpaceTac.UI {
|
|||
this.action_bar.setShip(ship);
|
||||
}
|
||||
|
||||
// Enable or disable the global player interaction
|
||||
// Disable interaction when it is the AI turn, or when the current ship can't play
|
||||
/**
|
||||
* Enable or disable the global player interaction
|
||||
*
|
||||
* Interaction should be disabled when showing the battle resolution, or when the AI is still thinking, or
|
||||
* when the battle is ended
|
||||
*/
|
||||
setInteractionEnabled(enabled: boolean): void {
|
||||
if (this.session.spectator) {
|
||||
if (this.session.spectator || this.battle.ended) {
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
|
@ -371,6 +394,7 @@ module TK.SpaceTac.UI {
|
|||
|
||||
if (!enabled) {
|
||||
this.setShipHovered(null);
|
||||
this.setShipSelected(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,21 +54,19 @@ module TK.SpaceTac.UI {
|
|||
* Start log processing
|
||||
*/
|
||||
start() {
|
||||
if (!this.view.gameui.isTesting) {
|
||||
this.log.play(async diff => {
|
||||
while (this.view.isPaused()) {
|
||||
await this.view.timer.sleep(500);
|
||||
}
|
||||
this.log.play(async diff => {
|
||||
while (this.view.isPaused()) {
|
||||
await this.view.timer.sleep(500);
|
||||
}
|
||||
|
||||
await this.processBattleDiff(diff);
|
||||
await this.processBattleDiff(diff);
|
||||
|
||||
if (this.log.atEnd()) {
|
||||
this.temp_speed = undefined;
|
||||
}
|
||||
});
|
||||
if (this.log.atEnd()) {
|
||||
this.temp_speed = undefined;
|
||||
}
|
||||
});
|
||||
|
||||
this.transferControl();
|
||||
}
|
||||
this.transferControl();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue