diff --git a/baba.png b/baba.png new file mode 100644 index 0000000..a16b3b4 Binary files /dev/null and b/baba.png differ diff --git a/babka.png b/babka.png new file mode 100644 index 0000000..ac734a1 Binary files /dev/null and b/babka.png differ diff --git a/cup.png b/cup.png new file mode 100644 index 0000000..a5baa2c Binary files /dev/null and b/cup.png differ diff --git a/flag.png b/flag.png new file mode 100644 index 0000000..f58aa4d Binary files /dev/null and b/flag.png differ diff --git a/flour.png b/flour.png new file mode 100644 index 0000000..d3c4bae Binary files /dev/null and b/flour.png differ diff --git a/is.png b/is.png new file mode 100644 index 0000000..386e1c9 Binary files /dev/null and b/is.png differ diff --git a/nodes.js b/nodes.js index 8b0e6e5..dd39baa 100644 --- a/nodes.js +++ b/nodes.js @@ -183,3 +183,98 @@ window.onload = function() { }; // ACT1SCENE2 }}} +// INTERMISSION {{{ + +class World extends ECS { + constructor() { + super(); + this.listeners = {}; + } + + listen(type, listener) { + (this.listeners[type] ||= []).push(listener); + } + + signal(type, data) { + for (const listener of this.listeners[type] || []) { + listener(data); + } + } + + detach(entity, componentClass) { + delete this.components[componentClass.name]?.[entity]; + } + + destroy(entity) { + for (const c of Object.values(this.components)) { + delete c[entity]; + } + } + + queryComponent(componentClass) { + const components = this.components[componentClass.name] || {}; + return Object.entries(components); + } + + cast(entity, componentClass) { + return this.components[componentClass.name]?.[entity]; + } +} + +// INTERMISSION }}} +// POSTMATTER {{{ + +function rot13(s) { + let r = []; + for (const c of s) { + r.push(c < 'a' ? c : String.fromCharCode((c.charCodeAt(0) - 97 + 13) % 26 + 97)); + } + return r.join(''); +} + +function yourImage(src) { + const img = document.createElement('img'); + img.src = src; + img.addEventListener('load', () => { + for (const entity in world.components.ComponentYou) { + world.attach(entity, new ComponentSprite(img)); + } + world.signal('recomposite'); + }); +} + +function babka() { + for (const [entity, subject] of world.queryComponent(ComponentSubject)) { + let standin; + switch (subject.noun) { + case 'baba': standin = 'babka'; break; + case 'rock': standin = 'scone'; break; + case 'wall': standin = 'tin'; break; + case 'water': standin = 'cup'; break; + case 'flag': standin = 'flour'; break; + } + const img = document.createElement('img'); + img.src = standin + '.png'; + img.addEventListener('load', () => { + world.attach(entity, new ComponentSprite(img)); + world.signal('recomposite'); + }); + } +} + +document.addEventListener('keydown', e => { + if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) + return; + switch (e.key) { + case 'r': { loadLevel(false); break; } + case 'w': { loadLevel(true); break; } + case 's': { const x = alert; alert = console.log; loadLevel(true); alert = x; break; } + case 'h': { document.body.classList.toggle('hit'); break; } + case 'l': { document.body.classList.toggle('rules'); break; } + case 'b': { yourImage('babka.png'); break; } + case 'n': { loadLevel(false); babka(); break; } + } +}); + +// set fdm=marker foldtext=v:folddashes.substitute(getline(v:foldstart),'//\ ','','') +// POSTMATTER }}} diff --git a/noun-baba.png b/noun-baba.png new file mode 100644 index 0000000..0970b35 Binary files /dev/null and b/noun-baba.png differ diff --git a/noun-flag.png b/noun-flag.png new file mode 100644 index 0000000..3c0efd0 Binary files /dev/null and b/noun-flag.png differ diff --git a/noun-rock.png b/noun-rock.png new file mode 100644 index 0000000..e0f0b4e Binary files /dev/null and b/noun-rock.png differ diff --git a/noun-wall.png b/noun-wall.png new file mode 100644 index 0000000..a335c9f Binary files /dev/null and b/noun-wall.png differ diff --git a/noun-water.png b/noun-water.png new file mode 100644 index 0000000..8bedd39 Binary files /dev/null and b/noun-water.png differ diff --git a/rj.png b/rj.png new file mode 100644 index 0000000..854d569 Binary files /dev/null and b/rj.png differ diff --git a/rock.png b/rock.png new file mode 100644 index 0000000..4c4ac52 Binary files /dev/null and b/rock.png differ diff --git a/scone.png b/scone.png new file mode 100644 index 0000000..f52034e Binary files /dev/null and b/scone.png differ diff --git a/tin.png b/tin.png new file mode 100644 index 0000000..b2f3efd Binary files /dev/null and b/tin.png differ diff --git a/verb-push.png b/verb-push.png new file mode 100644 index 0000000..f95582c Binary files /dev/null and b/verb-push.png differ diff --git a/verb-sink.png b/verb-sink.png new file mode 100644 index 0000000..b664ef4 Binary files /dev/null and b/verb-sink.png differ diff --git a/verb-stop.png b/verb-stop.png new file mode 100644 index 0000000..9f10c0e Binary files /dev/null and b/verb-stop.png differ diff --git a/verb-win.png b/verb-win.png new file mode 100644 index 0000000..3e77ff2 Binary files /dev/null and b/verb-win.png differ diff --git a/verb-you.png b/verb-you.png new file mode 100644 index 0000000..9b4564d Binary files /dev/null and b/verb-you.png differ diff --git a/wall.png b/wall.png new file mode 100644 index 0000000..d467c4e Binary files /dev/null and b/wall.png differ diff --git a/water.png b/water.png new file mode 100644 index 0000000..ba8bcb5 Binary files /dev/null and b/water.png differ