Some tests

This commit is contained in:
Aaron Fischer 2017-08-28 23:51:21 +02:00
parent e08c4b2bb3
commit 9abd6a4663
2 changed files with 36 additions and 16 deletions

View file

@ -1,47 +1,67 @@
(function() { (function() {
var bubble = {}; var bubble = {};
var show = function(text, position) { var activeTalk = false;
return new Promise(function(resolve) { var skip = false;
muri.get('mouse').disable(); 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.display = '';
dom.style.left = position[0]*8; dom.style.left = position[0]*8;
dom.style.top = position[1]*8; dom.style.top = position[1]*8;
dom.innerHTML = ''; dom.innerHTML = '';
parts = text.split(' '); 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) { if (parts.length === 0) {
setTimeout(function() { setTimeout(function() {
muri.get('mouse').enable();
dom.style.display = 'none'; dom.style.display = 'none';
return resolve(); return resolve();
}, 2000); }, 1500);
return; return;
} }
dom.innerHTML += parts.shift() + ' '; 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) { bubble.talk = function(texts, position) {
if (texts.length === 0) return; if (texts.length === 0) return;
var text = texts.shift(); var text = texts.shift();
return show(text, position || [5, 44]).then(function() { return show(text, position || [5, 44])
return bubble.talk(texts, position); .then(function() {return bubble.talk(texts, position);})
}); .catch(function() { return; });
}; };
bubble.story = function(talkList) { bubble.story = function(talkList) {
if (talkList.length === 0) return; if (talkList.length === 0) return;
var params = talkList.shift(); var params = talkList.shift();
return bubble.talk(params[0], params[1]).then(function() { var activeTalk = bubble.talk(params[0], params[1])
return bubble.story(talkList); .then(function() {return bubble.story(talkList);})
}); .catch(function() { return; });
return activeTalk;
}; };
bubble.name = 'bubble'; bubble.name = 'bubble';

View file

@ -30,7 +30,7 @@
muri.get('entity') muri.get('entity')
.create('stasis.lightSwitch', .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})) image: kontra.assets.images.stasis_lightSwitch}))
.addCallback(function() { .addCallback(function() {
if (!roomState.isLightOn) { if (!roomState.isLightOn) {