From d6a6a7a000cd94e4412bad52d8cbae74a4859515 Mon Sep 17 00:00:00 2001 From: Blake Grotewold Date: Wed, 23 Jul 2014 02:43:06 -0400 Subject: [PATCH 1/3] Add title blinking on events When there is an event, blink the title so that a user can know when an event happens, even if they aren't on that tab. From discussion in #121 --- script/events.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/script/events.js b/script/events.js index e72991e..2aff9eb 100644 --- a/script/events.js +++ b/script/events.js @@ -726,6 +726,19 @@ var Events = { } } }, + + //blinks the browser window title + blinkTitle: function() { + var title = document.title; + blinkInterval = setInterval(function() { + document.title = '*** EVENT ***'; + setTimeout(function() {document.title = title;}, 1500); + }, 3000); + }, + + stopTitleBlink: function() { + clearInterval(blinkInterval); + }, // Makes an event happen! triggerEvent: function() { @@ -789,6 +802,7 @@ var Events = { Events.loadScene('start'); $('div#wrapper').append(Events.eventPanel()); Events.eventPanel().animate({opacity: 1}, Events._PANEL_FADE, 'linear'); + Events.blinkTitle(); } }, @@ -806,6 +820,7 @@ var Events = { Events.eventStack.shift(); Engine.log(Events.eventStack.length + ' events remaining'); Engine.keyLock = false; + Events.stopTitleBlink(); // Force refocus on the body. I hate you, IE. $('body').focus(); }); From 79e765eb080096b3206b325ed43d534cc9d0f587 Mon Sep 17 00:00:00 2001 From: skj3gg Date: Thu, 24 Jul 2014 12:00:51 -0400 Subject: [PATCH 2/3] Blink only happens on specified events Now event objects must have a blink flag if they want to use the title blink. For starters, this is only global, outside, and room events. --- script/events.js | 9 +++++++-- script/events/global.js | 1 + script/events/outside.js | 13 ++++++++++--- script/events/room.js | 9 +++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/script/events.js b/script/events.js index 2aff9eb..c10ab43 100644 --- a/script/events.js +++ b/script/events.js @@ -802,7 +802,10 @@ var Events = { Events.loadScene('start'); $('div#wrapper').append(Events.eventPanel()); Events.eventPanel().animate({opacity: 1}, Events._PANEL_FADE, 'linear'); - Events.blinkTitle(); + var currentSceneInformation = Events.activeEvent().scenes[Events.activeScene]; + if (typeof currentSceneInformation.blink == 'boolean' && currentSceneInformation.blink == true) { + Events.blinkTitle(); + } } }, @@ -820,7 +823,9 @@ var Events = { Events.eventStack.shift(); Engine.log(Events.eventStack.length + ' events remaining'); Engine.keyLock = false; - Events.stopTitleBlink(); + if (typeof blinkInterval != 'undefined') { + Events.stopTitleBlink(); + } // Force refocus on the body. I hate you, IE. $('body').focus(); }); diff --git a/script/events/global.js b/script/events/global.js index 8178b9e..87ad421 100644 --- a/script/events/global.js +++ b/script/events/global.js @@ -15,6 +15,7 @@ Events.Global = [ _('say he should be strung up as an example.') ], notification: _('a thief is caught'), + blink: true, buttons: { 'kill': { text: _('hang him'), diff --git a/script/events/outside.js b/script/events/outside.js index 7015849..3028423 100644 --- a/script/events/outside.js +++ b/script/events/outside.js @@ -20,6 +20,7 @@ Events.Outside = [ Outside.updateTrapButton(); }, notification: _('some traps have been destroyed'), + blink: true, buttons: { 'track': { text: _('track them'), @@ -74,6 +75,8 @@ Events.Outside = [ _('a sickness is spreading through the village.'), _('medicine is needed immediately.') ], + + blink: true, buttons: { 'heal': { text: _('1 medicine'), @@ -128,6 +131,7 @@ Events.Outside = [ _('a terrible plague is fast spreading through the village.'), _('medicine is needed immediately.') ], + blink: true, buttons: { 'heal': { text: _('5 medicine'), @@ -193,12 +197,13 @@ Events.Outside = [ var numKilled = Math.floor(Math.random() * 10) + 1; Outside.killVillagers(numKilled); }, - reward: { + reward: { fur: 100, meat: 100, teeth: 10 - }, - buttons: { + }, + blink: true, + buttons: { 'end': { text: _('go home'), nextScene: 'end' @@ -228,6 +233,8 @@ Events.Outside = [ bullets: 10, 'cured meat': 50 }, + + blink: true, buttons: { 'end': { text: _('go home'), diff --git a/script/events/room.js b/script/events/room.js index ab09284..b1020b1 100644 --- a/script/events/room.js +++ b/script/events/room.js @@ -14,6 +14,7 @@ Events.Room = [ _("won't say from where he came, but it's clear that he's not staying.") ], notification: _('a nomad arrives, looking to trade'), + blink: true, buttons: { 'buyScales': { text: _('buy scales'), @@ -60,6 +61,7 @@ Events.Room = [ _("can't tell what they're up to.") ], notification: _('strange noises can be heard through the walls'), + blink: true, buttons: { 'investigate': { text: _('investigate'), @@ -110,6 +112,7 @@ Events.Room = [ _('something\'s in there.') ], notification: _('something\'s in the store room'), + blink: true, buttons: { 'investigate': { text: _('investigate'), @@ -195,6 +198,7 @@ Events.Room = [ _('asks for any spare furs to keep him warm at night.') ], notification: _('a beggar arrives'), + blink: true, buttons: { '50furs': { text: _('give 50'), @@ -266,6 +270,7 @@ Events.Room = [ _("builder's not sure he's to be trusted.") ], notification: _('a mysterious wanderer arrives'), + blink: true, buttons: { '100wood': { text: _('give 100'), @@ -336,6 +341,7 @@ Events.Room = [ _("builder's not sure she's to be trusted.") ], notification: _('a mysterious wanderer arrives'), + blink: true, buttons: { '100fur': { text: _('give 100'), @@ -406,6 +412,7 @@ Events.Room = [ _("willing to talk about it, for a price.") ], notification: _('a scout stops for the night'), + blink: true, buttons: { 'buyMap': { text: _('buy map'), @@ -444,6 +451,7 @@ Events.Room = [ _('he smiles warmly and asks for lodgings for the night.') ], notification: _('an old wanderer arrives'), + blink: true, buttons: { 'agree': { text: _('agree'), @@ -516,6 +524,7 @@ Events.Room = [ _("he begs for medicine.") ], notification: _('a sick man hobbles up'), + blink: true, buttons: { 'help': { text: _('give 1 medicine'), From e1f3d31dead19ee5858f1ba921ea7eab6ab6b4ac Mon Sep 17 00:00:00 2001 From: skj3gg Date: Mon, 28 Jul 2014 13:42:11 -0400 Subject: [PATCH 3/3] Add variable for blink interval and remove unnecessary type checking Cleans up global variable that was introduced in favor of a variable in Events. Removes type checking from conditionals and instead sets BLINK_INTERVAL variable to false when stopped. --- script/events.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/script/events.js b/script/events.js index c10ab43..dff0ef7 100644 --- a/script/events.js +++ b/script/events.js @@ -9,6 +9,7 @@ var Events = { _EAT_COOLDOWN: 5, _MEDS_COOLDOWN: 7, STUN_DURATION: 4000, + BLINK_INTERVAL: false, init: function(options) { this.options = $.extend( @@ -727,17 +728,20 @@ var Events = { } }, - //blinks the browser window title + // blinks the browser window title blinkTitle: function() { var title = document.title; - blinkInterval = setInterval(function() { - document.title = '*** EVENT ***'; - setTimeout(function() {document.title = title;}, 1500); + + // every 3 seconds change title to '*** EVENT ***', then 1.5 seconds later, change it back to the original title. + Events.BLINK_INTERVAL = setInterval(function() { + document.title = _('*** EVENT ***'); + setTimeout(function() {document.title = title;}, 1500); }, 3000); }, stopTitleBlink: function() { - clearInterval(blinkInterval); + clearInterval(Events.BLINK_INTERVAL); + Events.BLINK_INTERVAL = false; }, // Makes an event happen! @@ -803,7 +807,7 @@ var Events = { $('div#wrapper').append(Events.eventPanel()); Events.eventPanel().animate({opacity: 1}, Events._PANEL_FADE, 'linear'); var currentSceneInformation = Events.activeEvent().scenes[Events.activeScene]; - if (typeof currentSceneInformation.blink == 'boolean' && currentSceneInformation.blink == true) { + if (currentSceneInformation.blink) { Events.blinkTitle(); } } @@ -823,7 +827,7 @@ var Events = { Events.eventStack.shift(); Engine.log(Events.eventStack.length + ' events remaining'); Engine.keyLock = false; - if (typeof blinkInterval != 'undefined') { + if (Events.BLINK_INTERVAL) { Events.stopTitleBlink(); } // Force refocus on the body. I hate you, IE.