From 9abd6a4663017f11759652a47550f13644ce48ac Mon Sep 17 00:00:00 2001 From: Aaron Fischer Date: Mon, 28 Aug 2017 23:51:21 +0200 Subject: [PATCH] Some tests --- src/bubble.js | 50 +++++++++++++++++++++++++++++++++++--------------- src/stasis.js | 2 +- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/bubble.js b/src/bubble.js index fa5167a..7ce0660 100644 --- a/src/bubble.js +++ b/src/bubble.js @@ -1,47 +1,67 @@ (function() { var bubble = {}; - var show = function(text, position) { - return new Promise(function(resolve) { - muri.get('mouse').disable(); + var activeTalk = false; + var skip = false; + var dom = document.getElementById('bubble'); - var dom = document.getElementById('bubble'); + var show = function(text, position) { + return new Promise(function(resolve, reject) { dom.style.display = ''; dom.style.left = position[0]*8; dom.style.top = position[1]*8; dom.innerHTML = ''; parts = text.split(' '); - var show = function() { + var showFragment = function() { + if (skip) { + dom.innerHTML = ''; + dom.style.display = 'none'; + skip = false; + throw new Error('dfad'); + } if (parts.length === 0) { setTimeout(function() { - muri.get('mouse').enable(); dom.style.display = 'none'; return resolve(); - }, 2000); + }, 1500); return; } dom.innerHTML += parts.shift() + ' '; - setTimeout(show, 150); + setTimeout(showFragment, 150); }; - show(); + showFragment(); }); }; + + bubble.skip = function() { + dom.innerHTML = ''; + skip = true; + }; + + bubble.stop = function() { + bubble.skip(); + if (!activeTalk) return; + activeTalk.reject(); + activeTalk = false; + }; bubble.talk = function(texts, position) { if (texts.length === 0) return; var text = texts.shift(); - return show(text, position || [5, 44]).then(function() { - return bubble.talk(texts, position); - }); + return show(text, position || [5, 44]) + .then(function() {return bubble.talk(texts, position);}) + .catch(function() { return; }); }; bubble.story = function(talkList) { if (talkList.length === 0) return; var params = talkList.shift(); - return bubble.talk(params[0], params[1]).then(function() { - return bubble.story(talkList); - }); + var activeTalk = bubble.talk(params[0], params[1]) + .then(function() {return bubble.story(talkList);}) + .catch(function() { return; }); + + return activeTalk; }; bubble.name = 'bubble'; diff --git a/src/stasis.js b/src/stasis.js index 5e88b1e..2947036 100644 --- a/src/stasis.js +++ b/src/stasis.js @@ -30,7 +30,7 @@ muri.get('entity') .create('stasis.lightSwitch', - kontra.sprite({x: 16, y: 13, width: 3, height: 2, + kontra.sprite({x: 15, y: 12, width: 3, height: 2, image: kontra.assets.images.stasis_lightSwitch})) .addCallback(function() { if (!roomState.isLightOn) {