assassin-bug/app_web/game.js

2 lines
53 KiB
JavaScript
Raw Normal View History

2021-11-04 22:55:56 +00:00
(()=>{"use strict";const t=new class{constructor(){this.states=new Map}get(t){return this.states.get(t)}set(t,e){return this.states.set(t,e)}};class e{constructor(){this.inventory=[],this.currentRoom="start",this.context=null}addItem(t){this.inventory.push(t)}removeItem(t){this.inventory=this.inventory.filter((e=>e!=t))}getInventory(){return this.inventory.map((t=>this.context.getItem(t)))}}class i{speak(t){}stop(){}setOptions(t){}}class s extends i{constructor(t={}){super(),this.timeout=100,this.timeout=t.timeout||100,this.init()}init(){this.container=document.createElement("div"),this.container.setAttribute("aria-live","polite"),this.speechDisplay=document.createElement("div"),this.speechDisplay.setAttribute("aria-live","polite"),this.container.append(this.speechDisplay),document.body.appendChild(this.container),document.body.insertBefore(this.container,document.body.firstChild)}speak(t){this.clearDisplay();const e=document.createTextNode(t),i=document.createElement("p");i.appendChild(e),this.speechDisplay.appendChild(i),setTimeout(this.clearDisplay.bind(this),this.timeout)}stop(){this.clearDisplay()}clearDisplay(){this.speechDisplay.innerHTML=""}}class n extends i{}class o{constructor(t=function(t="aria"){return"webtts"===t?n:s}()){this.output=t}speak(t){this.output.speak(t)}stop(){this.output.stop()}}class a{constructor(){this.tts=new o(new s),this.history=document.getElementById("output-area")}say(t){const e=document.createElement("p");e.appendChild(document.createTextNode(t)),this.history.appendChild(e)}}class r{constructor(t,e){this.handler=t,this.output=e,this.echoInput=!0,this.inputField=document.getElementById("input-area"),this.init()}setEcho(t){this.echoInput=t}init(){this.inputField.addEventListener("keydown",(t=>{if(13==t.which){const t=this.inputField.value;this.inputField.value="",this.echoInput&&this.output.say(`> ${t}`),this.handler.doCommand(t)}}))}}const h=[[["look","l"],function(t,e){if(1==t.length)e.examineRoom();else{const i=e.getRoom(e.player.currentRoom).getItems();let s=null;for(let e of i)if(e.name.includes(t[1])){s=e;break}s?(e.output.say(s.name),e.output.say(s.description)):e.output.say(`I could not find a ${t[1]}`)}}],[["use","interact"],async function(t,e){const i=e.getRoom(e.player.currentRoom).getItems();let s=null;for(let e of i)if(e.name.includes(t[1])){s=e;break}s?await s.onUse():e.output.say(`I could not find a ${t[1]}`)}],[["take","get"],function(t,e){const i=e.getRoom(e.player.currentRoom),s=i.getItems();let n=null;for(let e of s)if(e.name.includes(t[1])){n=e;break}n?n.takeable?(i.removeItem(n.id),e.player.addItem(n.id),e.print(`You take ${n.name}`),n.onTake()):e.print(`You can't take ${n.name}`):e.print(`You can't find any ${t[1]}`)}],[["drop","put"],function(t,e){const i=e.getRoom(e.player.currentRoom),s=e.player.getInventory();let n=null;for(let e of s)if(e.name.includes(t[1])){n=e;break}n?(e.player.removeItem(n.id),i.addItem(n.id),e.print(`You set ${n.name} down on the floor.`),n.onDrop()):e.print(`You're not carrying a ${t[1]}`)}],["echo",function(t,e){"on"!=t[1]&&"off"!=t[1]?e.print("Usage: echo <on/off>"):(e.setInputEcho("on"==t[1]),e.print(`Command echo is now ${t[1]}`))}]],c=[["n","north"],["ne","northeast"],["e","east"],["se","southeast"],["s","south"],["sw","southwest"],["w","west"],["nw","northwest"],["u","up"],["d","down"]];class l{constructor(t,e){this.context=t,this.commands=e||new Map,this.enabled=!0,this.addDefaultCommands()}doCommand(t){if(!this.enabled)return void this.context.print("You can't seem to do anything at the moment.");const e=this.context.getRoom(this.context.player.currentRoom),i=t.split(" ");this.commands.get(i[0])&&this.commands.get(i[0])(i,this.context);const s=this.matchDirection(i[0]);e.getExit(s)&&this.context.move(e.getExit(s))}addCommand(t,e){Array.isArray(t)?t.forEach((t=>this.commands.set(t,e))):this.commands.set(t,e)}addCommands(t){t.forEach((t=>{this.addCommand(t[0],t[1])}))}addDefaultCommands(){this.addCommands(h)}matchDirection(t){for(let e of c)if(e[0]==t)return e[1]}}class u{constructor(){this.id="room",this.title="A room",this.descri
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2FtZS5qcyIsIm1hcHBpbmdzIjoibUJBY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