miserjs 1.0.0 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,24 +1,2 @@
1
- import e from"node:readline/promises";import{stdin as t,stdout as s,argv as o,exit as n}from"node:process";import{readFileSync as i}from"node:fs";import r from"node:path";import{open as l,writeFile as a}from"node:fs/promises";import c from"../engine/miserjs-engine.min.js";class MiserJS{
2
- /** @type {string} */
3
- #e="miserjs-savegame.txt";
4
- /** @type {MiserJSEngine} */
5
- #t;
6
- /** @type {readline.Interface} */
7
- #s;constructor(){this.#t=new c}async play(){
8
- // Could also restore a previously saved game.
9
- // let jsonData = await readFileSync(this.#SAVEGAME_FILENAME, 'utf8');
10
- // this.#miserState = JSON.parse(jsonData);
11
- // console.log('Game restored.');
12
- console.log(this.#o("look").text),this.#s=e.createInterface({input:t,output:s}),this.#s.setPrompt(""),this.#s.on("line",this.#n.bind(this))}
13
- /**
14
- *
15
- * @param {string} input
16
- */async#n(e){let t;switch(e){case"save":await a(this.#e,JSON.stringify(this.#t.getGameState(),null,4),"utf8"),console.log("Game saved.\n");break;case"load":let s=i(this.#e,"utf8");this.#t.setGameState(JSON.parse(s)),console.log("Game restored."),t=this.#o("look"),console.log(t.text);break;default:if(!e)return;if(t=this.#o(e),t.gameOver)switch(t.gameOver){case"died":console.log(t.text),this.#s.close();break;case"quit":t=this.#t.showFinalOutcome(),console.log(`\n${t.text}\n`),this.#s.close();break;case"escaped":console.log(`\n${t.text}\n`),t=this.#t.showFinalOutcome(),this.#s.close()}else t.text.endsWith("\n")?console.log(`${t.text}`):console.log(`${t.text}\n`)}}
17
- /**
18
- * Send player input to MiserEngine.
19
- * @param {string} input
20
- * @returns {MiserResponse}
21
- */#o(e){return this.#t.request(e)}static async speedrun(){const e=new c,t=import.meta.dirname;let s,o=r.join(t,"speedrun/speedrun-commands.txt"),n=i(o,"utf8");
22
- // Read commands from file.
23
- // Strip the carriage returns (CR) and linefeeds (LF).
24
- n=n.replace(/[\r\n]+/g,"");const a=n.split(",");let m=r.join(t,"speedrun/speedrun-output.txt"),u=await l(m,"w");for(const t of a)console.log(`>> ${t}`),await u.write(`\n>> ${t}\n`,null,"utf8"),s=e.request(t).text,console.log(s),await u.write(s,null,"utf8");await u.close()}}let m=new MiserJS,u=o[2]?.trim();if(u)if("speedrun"===u)await MiserJS.speedrun(),n(0);else console.log("Unrecognized command."),n(1);else m.play();
1
+ #!/usr/bin/env node
2
+ import e from"node:readline/promises";import{stdin as t,stdout as s,argv as o,exit as n}from"node:process";import{readFileSync as i}from"node:fs";import r from"node:path";import{open as l,writeFile as a}from"node:fs/promises";import c from"../engine/miserjs-engine.min.js";class MiserJS{#e="miserjs-savegame.txt";#t;#s;constructor(){this.#t=new c}async play(){console.log(this.#o("look").text),this.#s=e.createInterface({input:t,output:s}),this.#s.setPrompt(""),this.#s.on("line",this.#n.bind(this))}async#n(e){let t;switch(e){case"save":await a(this.#e,JSON.stringify(this.#t.getGameState()),"utf8"),console.log("Game saved.\n");break;case"load":let s=i(this.#e,"utf8");this.#t.setGameState(JSON.parse(s)),console.log("Game restored."),t=this.#o("look"),console.log(t.text);break;default:if(!e)return;if(t=this.#o(e),t.gameOver)switch(t.gameOver){case"died":console.log(t.text),this.#s.close();break;case"quit":t=this.#t.showFinalOutcome(),console.log(`\n${t.text}\n`),this.#s.close();break;case"escaped":console.log(`\n${t.text}\n`),t=this.#t.showFinalOutcome(),console.log(`\n${t.text}\n`),this.#s.close()}else t.text.endsWith("\n")?console.log(`${t.text}`):console.log(`${t.text}\n`)}}#o(e){return this.#t.request(e)}static async speedrun(){const e=new c,t=import.meta.dirname;let s,o=r.join(t,"speedrun/speedrun-commands.txt"),n=i(o,"utf8");n=n.replace(/[\r\n]+/g,"");const a=n.split(",");let m=r.join(t,"speedrun/speedrun-output.txt"),u=await l(m,"w");for(const t of a)console.log(`>> ${t}`),await u.write(`\n>> ${t}\n`,null,"utf8"),s=e.request(t).text,console.log(s),await u.write(s,null,"utf8");await u.close()}}let m=new MiserJS,u=o[2]?.trim();if(u)if("speedrun"===u)await MiserJS.speedrun(),n(0);else console.log("Unrecognized command."),n(1);else m.play();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miserjs",
3
- "version": "1.0.0",
3
+ "version": "1.0.4",
4
4
  "description": "JavaScript port of Mary Jean Winter's Miser text adventure game, originally released in 1981 for the Commodore PET series of computers.",
5
5
  "keywords": [
6
6
  "text adventure",