Fix up the room refactoring

This commit is contained in:
Aaron Fischer 2017-08-25 21:53:22 +02:00
parent 22d4f6bcee
commit 3ee8048bc9
2 changed files with 20 additions and 16 deletions

View file

@ -53,12 +53,16 @@ var muri = (function() {
}; };
muri.currentRoom = 'stasis'; muri.currentRoom = 'stasis';
muri.modules = []; muri.modules = [];
muri.rooms = {}; muri.rooms = [];
muri.get = function(moduleName) { var fetchObject = function(type) {
for (var i in muri.modules) return function(name) {
if (muri.modules[i].name === moduleName) for (var i in muri[type])
return muri.modules[i]; if (muri[type][i].name === name)
return muri[type][i];
};
}; };
muri.get = fetchObject('modules');
muri.room = fetchObject('rooms');
muri.setup = function() { muri.setup = function() {
kontra.assets.load( kontra.assets.load(
@ -67,28 +71,27 @@ var muri = (function() {
'stasis_door-sheet.png' 'stasis_door-sheet.png'
).then(function() { ).then(function() {
document.getElementById('loading').style.display = 'none'; document.getElementById('loading').style.display = 'none';
muri.modules.forEach(function(m) {
if (m.init !== undefined) m.init();
});
muri.rooms.forEach(function(r) {
if (r.init !== undefined) r.init();
});
kontra.gameLoop({ kontra.gameLoop({
update: function() { update: function() {
muri.rooms[muri.currentRoom].update(); muri.room(muri.currentRoom).update();
muri.modules.forEach(function(m) { muri.modules.forEach(function(m) {
if (m.update !== undefined) m.update(); if (m.update !== undefined) m.update();
}); });
}, },
render: function() { render: function() {
muri.rooms[muri.currentRoom].render(); muri.room(muri.currentRoom).render();
muri.modules.forEach(function(m) { muri.modules.forEach(function(m) {
if (m.render !== undefined) m.render(); if (m.render !== undefined) m.render();
}); });
} }
}).start(); }).start();
muri.modules.forEach(function(m) {
if (m.init !== undefined) m.init();
});
muri.rooms.forEach(function(r) {
....
if (r.init !== undefined) r.init();
});
}); });
}; };

View file

@ -94,5 +94,6 @@
} }
}; };
muri.rooms['stasis'] = stasis; stasis.name = 'stasis';
muri.rooms.push(stasis);
}()); }());