From 66d29266351c4cc8eef3d966fad2dfa7979d9b43 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Mon, 12 Aug 2019 14:04:57 +0200 Subject: [PATCH] Implement status handling to provide visual clue about the game state --- www/game.js | 1 + www/index.html | 1 + www/login.js | 1 + www/main.js | 5 +++-- www/statusHandler.js | 20 ++++++++++++++++++++ 5 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 www/statusHandler.js diff --git a/www/game.js b/www/game.js index f9898f3..02e4821 100644 --- a/www/game.js +++ b/www/game.js @@ -16,6 +16,7 @@ function Game(modules) { if(document.hasFocus()) { modules.async.run(handleGameMessage(o)); } else { + modules.statusHandler.set("♪"); queue.push(handleGameMessage(o)); } }); diff --git a/www/index.html b/www/index.html index 439b986..9a1f8a6 100644 --- a/www/index.html +++ b/www/index.html @@ -12,6 +12,7 @@ + diff --git a/www/login.js b/www/login.js index ef51a32..1ac5141 100644 --- a/www/login.js +++ b/www/login.js @@ -56,6 +56,7 @@ function Login(modules) { var name = modules.room.name(o.from); // invitations should come only from known players, in doubt say «no» if(name) { + modules.statusHandler.set("🎴"); modules.screen.dialog({ text: modules.i18n.get('invited')(name), answers: invitationAnswers diff --git a/www/main.js b/www/main.js index 04ffd1d..c62cd7b 100644 --- a/www/main.js +++ b/www/main.js @@ -8,9 +8,10 @@ window.addEventListener('load', function() { var messaging = Messaging(); var session = Session({messaging: messaging}); var room = Room({dom: dom, messaging: messaging, session: session, fun: fun}); - var login = Login({dom: dom, i18n: i18n, messaging: messaging, room: room, screen: screen, session: session}); + var statusHandler = StatusHandler(); + var login = Login({dom: dom, i18n: i18n, messaging: messaging, room: room, screen: screen, session: session, statusHandler: statusHandler}); var hanafuda = Hanafuda({fun: fun}); - var game = Game({async: async, dom: dom, i18n: i18n, fun: fun, hanafuda: hanafuda, messaging: messaging, room: room, screen: screen, session: session}); + var game = Game({async: async, dom: dom, i18n: i18n, fun: fun, hanafuda: hanafuda, messaging: messaging, room: room, screen: screen, session: session, statusHandler: statusHandler}); var domElems = { join: document.getElementById('login').join, diff --git a/www/statusHandler.js b/www/statusHandler.js new file mode 100644 index 0000000..c304aa1 --- /dev/null +++ b/www/statusHandler.js @@ -0,0 +1,20 @@ +function StatusHandler() { + var baseTitle = document.title; + window.addEventListener('focus', reset); + + return { + reset: reset, + set: set + }; + + function reset() { + document.title = baseTitle; + } + + function set(newStatus) { + if(!document.hasFocus()) { + document.title = newStatus + " - " + baseTitle; + } + } + +}