From 49261be16441afb8b7eab332d86cb75bd047f3d1 Mon Sep 17 00:00:00 2001 From: Nicky Case Date: Sun, 28 Apr 2019 12:02:55 -0400 Subject: [PATCH] text speed --- index.html | 5 +++ scenes/act1-end.md | 6 +-- scenes/act1.md | 2 +- scripts/game/Game.js | 50 ++++++++++++++++++++- scripts/game/Options.js | 99 +++++++++++++++++++++++++++++++++++++++++ scripts/main.js | 6 +-- styles/game.css | 84 ++++++++++++++++++++++++++++++++++ 7 files changed, 244 insertions(+), 8 deletions(-) create mode 100644 scripts/game/Options.js diff --git a/index.html b/index.html index b82af13..f3755bf 100644 --- a/index.html +++ b/index.html @@ -53,6 +53,10 @@
+
+
+ +
@@ -71,6 +75,7 @@ + diff --git a/scenes/act1-end.md b/scenes/act1-end.md index 4b78b4b..05c6a17 100644 --- a/scenes/act1-end.md +++ b/scenes/act1-end.md @@ -6,11 +6,11 @@ n: TOTAL FEARS USED -n: #harm# *BEING HARMED:* 3 +n: #harm# *BEING HARMED:* {{Game.TEXT_SPEED}} -n: #alone# *BEING UNLOVED:* 1 +n: #alone# *BEING UNLOVED:* {{2+2}} -n: #bad# *BEING A BAD PERSON:* 4 +n: #bad# *BEING A BAD PERSON:* {{window.dick}} (...4000) diff --git a/scenes/act1.md b/scenes/act1.md index f3b204b..1c395e0 100644 --- a/scenes/act1.md +++ b/scenes/act1.md @@ -75,7 +75,7 @@ b: You should multi-task and study during meals! `hong({eyes:"0_annoyed"})` -h: Um, I'd rather not get crumbs on my textbook. +h: Um, I'd rather not get crumbs on my textboo-- ``` bb({mouth:"normal", eyes:"fear"}); diff --git a/scripts/game/Game.js b/scripts/game/Game.js index 4d5f5bb..c8cab1a 100644 --- a/scripts/game/Game.js +++ b/scripts/game/Game.js @@ -103,6 +103,9 @@ Game.update = function(){ } + // Options update + Options.update(); + }; // PAUSING THE GAME @@ -482,6 +485,9 @@ Game.executeText = function(line){ // Return promise var nextLineDelay = Game.TEXT_SPEED*7; // don't override this if(dialogue.slice(-1)=="-") nextLineDelay=0; // sudden interrupt! + if(Game.TEXT_SPEED<10){ // IF IT'S CLICK-TO-ADVANCE, INFINITE TIMEOUT. + nextLineDelay = 1000*1000; // one thousand seconds + } Game.setTimeout(function(){ Game.WHO_IS_SPEAKING = null; // DONE WITH IT. resolve(); @@ -596,6 +602,11 @@ Game.executeWait = function(line){ // Get integer from (...NN) var waitTime = parseInt(line.match(/^\(\.\.\.(\d+)\)/)[1].trim()); + + // Unless it's click to advance, then IGNORE ALL WAITS + if(Game.TEXT_SPEED<10){ + waitTime = 0; // TODO: Tag anim-waits, do not ignore. + } // Delayed promise return new RSVP.Promise(function(resolve){ @@ -642,12 +653,12 @@ Game.parseLine = function(line){ // Get the IFs, if any var lookForIfs = true; + var regex = /\{\{if[^\/]*\/if\}\}/ig; while(lookForIfs){ lookForIfs = false; // Look for an IF! - var regex = /\{\{if[^\/]*\/if\}\}/ig; var regexResult = regex.exec(line); if(regexResult){ @@ -681,6 +692,43 @@ Game.parseLine = function(line){ } + // Evaluate {{expressions}}, if any + var lookForExpressions = true; + var regex = /\{\{[^\}]*\}\}/ig; + while(lookForExpressions){ + + lookForExpressions = false; + + // Look for an IF! + var regexResult = regex.exec(line); + if(regexResult){ + + // The result... + var fullExpression = regexResult[0]; + var startsAtIndex = regexResult.index; + var endsAtIndex = startsAtIndex + fullExpression.length; + + // Extract the expression + var expression = fullExpression.match(/\{\{([^\}]*)\}\}/)[1]; + + // Eval condition! + var evaluated = ""; + try{ + evaluated = eval(expression); + }catch(e){ + console.log(e); + } + + // Edit the line + line = line.slice(0,startsAtIndex) + evaluated + line.slice(endsAtIndex); + + // Keep searching... + lookForExpressions = true; + + } + + } + // Return line! return line; diff --git a/scripts/game/Options.js b/scripts/game/Options.js new file mode 100644 index 0000000..d247206 --- /dev/null +++ b/scripts/game/Options.js @@ -0,0 +1,99 @@ +window.Options = {}; + +(function(){ + + var text_speed_slider = $("#text_speed_slider"); + var text_speed_preview = $("#text_speed_preview"); + + var SPEED_TEXTS = [ + "Show text slowlyyyyy", + "Show text at a relaxed speed", + "Show text at the default speed", + "Show text at a brisk speed", + "Show text NOW! (& click-to-advance)" + ]; + var SPEEDS = [ + 120, + 80, + 60, + 40, + 0 + ]; + text_speed_slider.oninput = function(){ + updateText(); + }; + + /////////////////////////////////// + // For previewing the text speed // + /////////////////////////////////// + + Options.update = function(){ + + // Timeout callbacks... + for(var i=0; i<_timeoutCallbacks.length; i++){ + var tc = _timeoutCallbacks[i]; + tc.timeLeft -= 1000/60; + if(tc.timeLeft<=0){ + tc.callback(); + _timeoutCallbacks.splice(i,1); // delete that one + i -= 1; // set index back one + } + } + + }; + + var _timeoutCallbacks = []; + var _setTimeout = function(callback, interval){ + _timeoutCallbacks.push({ + callback: callback, + timeLeft: interval + }); + }; + var _clearAllTimeouts = function(){ + _timeoutCallbacks = []; + }; + + var updateText = function(){ + + var i = parseInt(text_speed_slider.value); + var div = text_speed_preview; + + Game.TEXT_SPEED = SPEEDS[i]; + + // Clear previous crap + _clearAllTimeouts(); + div.innerHTML = ""; + + // What's the dialogue? + var dialogue = SPEED_TEXTS[i]; + + // Put in the text + var span, chr; + for(var i=0; i