From 2243a5a788556f410b75d4e22dc353599abb734d Mon Sep 17 00:00:00 2001 From: Aaron Fischer Date: Tue, 29 Aug 2017 23:21:18 +0200 Subject: [PATCH] Fix the bubble thin with the mouse ... --- src/bubble.js | 68 ++++++++++++++++++++++------------------------ src/index_dev.html | 2 +- src/mouse.js | 4 +++ src/muri.js | 5 ++++ 4 files changed, 42 insertions(+), 37 deletions(-) diff --git a/src/bubble.js b/src/bubble.js index 7ce0660..82f3dcb 100644 --- a/src/bubble.js +++ b/src/bubble.js @@ -1,67 +1,63 @@ (function() { + "use strict"; + var bubble = {}; - var activeTalk = false; - var skip = false; var dom = document.getElementById('bubble'); + var resolveFn, fragmentTimer, delayTimer = null; var show = function(text, position) { - return new Promise(function(resolve, reject) { - dom.style.display = ''; + return new Promise(function(resolve) { + resolveFn = resolve; + + dom.innerHTML = ''; dom.style.left = position[0]*8; dom.style.top = position[1]*8; - dom.innerHTML = ''; - parts = text.split(' '); + var parts = text.split(' '); var showFragment = function() { - if (skip) { - dom.innerHTML = ''; - dom.style.display = 'none'; - skip = false; - throw new Error('dfad'); - } if (parts.length === 0) { - setTimeout(function() { - dom.style.display = 'none'; - return resolve(); - }, 1500); + delayTimer = setTimeout(resolve, 3000); return; } dom.innerHTML += parts.shift() + ' '; - setTimeout(showFragment, 150); + fragmentTimer = setTimeout(showFragment, 140); }; showFragment(); }); }; - bubble.skip = function() { - dom.innerHTML = ''; - skip = true; + bubble.skip = function(what) { + clearTimeout(fragmentTimer); + clearTimeout(delayTimer); + if (resolveFn) resolveFn(what || 'line'); }; - bubble.stop = function() { - bubble.skip(); - if (!activeTalk) return; - activeTalk.reject(); - activeTalk = false; - }; - bubble.talk = function(texts, position) { - if (texts.length === 0) return; + if (texts.length === 0) { + dom.innerHTML = ''; + return; + } var text = texts.shift(); return show(text, position || [5, 44]) - .then(function() {return bubble.talk(texts, position);}) - .catch(function() { return; }); + .then(function(what) { + if (what !== undefined) return Promise.resolve(what); + return bubble.talk(texts, position); + }); }; bubble.story = function(talkList) { - if (talkList.length === 0) return; + if (talkList.length === 0) { + dom.innerHTML = ''; + return; + } + bubble.skip('story'); var params = talkList.shift(); - var activeTalk = bubble.talk(params[0], params[1]) - .then(function() {return bubble.story(talkList);}) - .catch(function() { return; }); - - return activeTalk; + return bubble.talk(params[0], params[1]) + .then(function(what) { + if (what === 'story') return Promise.resolve(); + return bubble.story(talkList); + }); }; bubble.name = 'bubble'; diff --git a/src/index_dev.html b/src/index_dev.html index 2fa1ead..af0d085 100644 --- a/src/index_dev.html +++ b/src/index_dev.html @@ -6,7 +6,7 @@
- +

loading game ...

diff --git a/src/mouse.js b/src/mouse.js index 9919fc9..972f7f6 100644 --- a/src/mouse.js +++ b/src/mouse.js @@ -25,6 +25,10 @@ return sprite.collidesWith(mouseSprite); }; + mouse.isClickReleased = function() { + return mouseSprite.x === -1 && mouseSprite.y === -1; + }; + mouse.releaseClick = function() { mouseSprite.x = -1; mouseSprite.y = -1; diff --git a/src/muri.js b/src/muri.js index 066fbd9..f422bd1 100644 --- a/src/muri.js +++ b/src/muri.js @@ -85,6 +85,11 @@ var muri = (function() { muri.modules.forEach(function(m) { if (m.update !== undefined) m.update(); }); + + if (!muri.get('mouse').isClickReleased()) { + muri.get('mouse').releaseClick(); + muri.get('bubble').skip(); + } }, render: function() { muri.room(muri.currentRoom).render();