this.socket.onmessage = (msg) => this.onmessage(msg);
this.socket.onclose = () => this.onclose();
this.state = "Connecting";
+
+ this.scheduled_actions = [];
+ this.schedule_timeout = null;
}
onopen() {
break;
case "TakeActionSuccess":
case "NewAction":
- this.game.take_action(message.action);
+ this.schedule_action(this.game, message.action);
break;
case "LogoutSuccess":
delete this.auth;
}
}
+ pause_time_for_action(action) {
+ switch(action) {
+ case "Join":
+ case "Leave":
+ case "KnockedOut":
+ case "NextToDeal":
+ case "ChooseTrumps":
+ case "EndDeal":
+ case "WinGame":
+ return 0;
+ case "ReceiveCard":
+ case "CommunityCard":
+ return 200;
+ case "CutCard":
+ return 1000;
+ case "PlayCard":
+ return 500;
+ case "WinTrick":
+ case "WinCall":
+ case "WinHand":
+ return 1000;
+ case "PostBlind":
+ case "Fold":
+ case "TimeoutFold":
+ return 0;
+ case "Bet":
+ return 500;
+ default:
+ return 0;
+ }
+ }
+
+ set_schedule_timeout(timeout) {
+ this.schedule_timeout = setTimeout(() => {
+ if (this.scheduled_actions.length == 0) {
+ this.schedule_timeout = null;
+ } else {
+ const {game, user_action} = this.scheduled_actions.shift();
+ game.take_action(user_action);
+ this.set_schedule_timeout(this.pause_time_for_action(user_action.action.action));
+ }
+ }, timeout);
+ }
+
+ schedule_action(game, user_action) {
+ this.scheduled_actions.push({game, user_action});
+ if (this.schedule_timeout === null) {
+ this.set_schedule_timeout(0);
+ }
+ }
+
hide_login() {
document.getElementById("login-background").classList.add("hidden");
}
constructor(container, summary, actions, username, send) {
this.container = container;
this.summary = summary;
- this.actions = actions;
this.username = username;
this.send = send;
this.seats = new Map();
}
this.container.append(this.svg);
- for (const user_action of this.actions) {
+ for (const user_action of actions) {
this.take_action(user_action);
}