From 15e0bdf6fcb1bd2ecbdb94920d637472920f78a2 Mon Sep 17 00:00:00 2001 From: Jonas Weinz Date: Mon, 1 Apr 2019 16:17:20 +0200 Subject: [PATCH] several improvements, implemented revoke stuff --- main.js | 4 ++-- online_match_manager.js | 18 ++++++++++++------ tools.js | 17 ++++++++++++++++- websocket_connection.js | 33 +++++++++++++++++++++++++++++++-- 4 files changed, 61 insertions(+), 11 deletions(-) diff --git a/main.js b/main.js index c3f384a..feb6f8a 100644 --- a/main.js +++ b/main.js @@ -28,7 +28,7 @@ register_container = main_menu.create_infocontainer("Login to play online"); i_register_username = register_container.create_input("username"); i_register_pw = register_container.create_input("password", true); b_register = register_container.create_button("register/login"); -//register_container.create_label("(creates new account for a new username)"); +register_container.create_label("If the username does not exists yet, a new account is created automatically"); // logout TODO: rename container: logout_container = main_menu.create_infocontainer("Logged in as: "); @@ -42,7 +42,7 @@ l_highscores.style.textAlign = "left" // fill subcontainer: -match_slot_container = sub_menu.create_infocontainer("Running Matches
(click to open)"); +match_slot_container = sub_menu.create_infocontainer("Running Matches"); // match control: diff --git a/online_match_manager.js b/online_match_manager.js index a4c551e..6bdd5de 100644 --- a/online_match_manager.js +++ b/online_match_manager.js @@ -1,6 +1,6 @@ class OnlineMatchManager { - constructor(grid, info_func, matches_container, control_container, end_button, game_server_connection, match_id, match_state, player_name) + constructor(grid, info_func, matches_container, control_container, end_button, game_server_connection, match_id, match_state, revoke_time, player_name) { this.grid = grid; @@ -12,7 +12,8 @@ class OnlineMatchManager this.match_state = match_state; - this.player_name = player_name + this.revoke_time = Date.create_from_mysql(revoke_time); + this.player_name = player_name; var player_a = this.match_state.player_a; var player_b = this.match_state.player_b; @@ -98,9 +99,10 @@ class OnlineMatchManager } } - update_match_state(match_state) + update_match_state(match_state, revoke_time) { this.match_state = match_state; + this.revoke_time = Date.create_from_mysql(revoke_time); if (this.online_opponent.get_name() == this.match_state.active_player) { @@ -289,6 +291,10 @@ class OnlineMatchManager var current_player = this.player_name == current_player_name ? this.local_player : this.online_opponent; this.grid.player_change_listener(current_player); + + // date difference in hours: + var dt = Math.floor(Math.abs(Date.now() - this.revoke_time) / 36e5); + if (this.player_name == current_player_name) { @@ -303,19 +309,19 @@ class OnlineMatchManager { this.grid.unblock(x,y); } - this.info_func("It's your turn!", false); + this.info_func("It's your turn! (" + dt + "h left)", false); this.control_container.blink(theme_color_highlight); } else { - this.info_func("It's your turn!", false); + this.info_func("It's your turn! (" + dt + "h left)", false); this.control_container.blink(theme_color_highlight); this.grid.unblock_all(); } } else { - this.info_func("waiting for " + encodeHTML(this.online_opponent.get_name()) + "'s move", false); + this.info_func("waiting for " + encodeHTML(this.online_opponent.get_name()) + "'s move (" + dt + "h left)", false); this.control_container.blink(theme_color_highlight); } diff --git a/tools.js b/tools.js index 36a85cf..0831c8f 100644 --- a/tools.js +++ b/tools.js @@ -16,4 +16,19 @@ function clearInner(node) { // encoding helper (found here: https://stackoverflow.com/a/2794366) function encodeHTML(s) { return s.replace(/&/g, '&').replace(/click '+' to add as friend"); } }