From f8876c7175b7772075753725ed70a6689074b739 Mon Sep 17 00:00:00 2001 From: Rudis Muiznieks Date: Fri, 8 May 2020 20:01:22 -0500 Subject: [PATCH] fixed bugs with empty game/scene titles and resolving incorrect scenes with conditions --- package.json | 2 +- src/Parser.ts | 4 ++-- src/Player.ts | 11 ++++++----- src/Util.ts | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 70aad07..5c06a0c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ficdown.js", - "version": "2.0.1", + "version": "2.0.2", "description": "A parser and player for Interactive Fiction written in Ficdown", "scripts": { "build": "rm -rf ./build && tsc", diff --git a/src/Parser.ts b/src/Parser.ts index aea7010..be9c19a 100644 --- a/src/Parser.ts +++ b/src/Parser.ts @@ -57,7 +57,7 @@ export class Parser { if(!storyHref) throw new ParseError('no link to first scene', storyBlock.lineNumber); const story: Story = { - name: storyName.text, + name: storyName.title != null ? storyName.title : storyName.text, description: Util.trimText(storyBlock.lines.map(l => l.text).join("\n")), firstScene: storyHref.target, scenes: {}, @@ -87,7 +87,7 @@ export class Parser { let key: string; let conditions: BoolHash | undefined = undefined; if(sceneName) { - name = sceneName.title + name = sceneName.title != null ? Util.trimText(sceneName.title) : Util.trimText(sceneName.text); key = Util.normalize(sceneName.text); diff --git a/src/Player.ts b/src/Player.ts index 80babc6..69fef5a 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -42,7 +42,7 @@ export class Player { public play(): void { this.container.html( - this.converter.render(`# ${ this.story.name }\n\n${ this.story.description }\n\n[${ this.startText }](/${ this.story.firstScene })`)); + this.converter.render(`${ this.story.name ? `# ${this.story.name}\n\n` : '' }${ this.story.description }\n\n[${ this.startText }](/${ this.story.firstScene })`)); this.wireLinks(); } @@ -65,10 +65,11 @@ export class Player { if(this.story.scenes[match.target]) { for(let scene of this.story.scenes[match.target]) { if(Util.conditionsMet(this.playerState, scene.conditions)) { - if(!matchedScene - || !scene.conditions - || !matchedScene.conditions - || Object.keys(scene.conditions).length > Object.keys(matchedScene.conditions).length) { + const sceneConds = scene.conditions + ? Object.keys(scene.conditions).length : 0; + const matchConds = matchedScene && matchedScene.conditions + ? Object.keys(matchedScene.conditions).length : 0; + if(!matchedScene || sceneConds > matchConds) { matchedScene = scene; } } diff --git a/src/Util.ts b/src/Util.ts index 9f3542f..a942fce 100644 --- a/src/Util.ts +++ b/src/Util.ts @@ -16,13 +16,13 @@ export class Util { }; private static matchToAnchor(match: RegExpExecArray): Anchor { - const result: Anchor = { + const result = { anchor: match[1], text: match[2], href: match[3], title: match[6], }; - if(result.href.indexOf('"') === 0) { + if(result.href.indexOf('"') === 0 || result.href.indexOf("'") === 0) { result.title = result.href.substring(1, result.href.length - 1); result.href = ''; }