Skip to content
This repository was archived by the owner on Feb 22, 2022. It is now read-only.

Commit f8876c7

Browse files
committed
fixed bugs with empty game/scene titles and resolving incorrect scenes with conditions
1 parent c517587 commit f8876c7

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ficdown.js",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "A parser and player for Interactive Fiction written in Ficdown",
55
"scripts": {
66
"build": "rm -rf ./build && tsc",

src/Parser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class Parser {
5757
if(!storyHref) throw new ParseError('no link to first scene', storyBlock.lineNumber);
5858

5959
const story: Story = {
60-
name: storyName.text,
60+
name: storyName.title != null ? storyName.title : storyName.text,
6161
description: Util.trimText(storyBlock.lines.map(l => l.text).join("\n")),
6262
firstScene: storyHref.target,
6363
scenes: {},
@@ -87,7 +87,7 @@ export class Parser {
8787
let key: string;
8888
let conditions: BoolHash | undefined = undefined;
8989
if(sceneName) {
90-
name = sceneName.title
90+
name = sceneName.title != null
9191
? Util.trimText(sceneName.title)
9292
: Util.trimText(sceneName.text);
9393
key = Util.normalize(sceneName.text);

src/Player.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class Player {
4242

4343
public play(): void {
4444
this.container.html(
45-
this.converter.render(`# ${ this.story.name }\n\n${ this.story.description }\n\n[${ this.startText }](/${ this.story.firstScene })`));
45+
this.converter.render(`${ this.story.name ? `# ${this.story.name}\n\n` : '' }${ this.story.description }\n\n[${ this.startText }](/${ this.story.firstScene })`));
4646
this.wireLinks();
4747
}
4848

@@ -65,10 +65,11 @@ export class Player {
6565
if(this.story.scenes[match.target]) {
6666
for(let scene of this.story.scenes[match.target]) {
6767
if(Util.conditionsMet(this.playerState, scene.conditions)) {
68-
if(!matchedScene
69-
|| !scene.conditions
70-
|| !matchedScene.conditions
71-
|| Object.keys(scene.conditions).length > Object.keys(matchedScene.conditions).length) {
68+
const sceneConds = scene.conditions
69+
? Object.keys(scene.conditions).length : 0;
70+
const matchConds = matchedScene && matchedScene.conditions
71+
? Object.keys(matchedScene.conditions).length : 0;
72+
if(!matchedScene || sceneConds > matchConds) {
7273
matchedScene = scene;
7374
}
7475
}

src/Util.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ export class Util {
1616
};
1717

1818
private static matchToAnchor(match: RegExpExecArray): Anchor {
19-
const result: Anchor = {
19+
const result = {
2020
anchor: match[1],
2121
text: match[2],
2222
href: match[3],
2323
title: match[6],
2424
};
25-
if(result.href.indexOf('"') === 0) {
25+
if(result.href.indexOf('"') === 0 || result.href.indexOf("'") === 0) {
2626
result.title = result.href.substring(1, result.href.length - 1);
2727
result.href = '';
2828
}

0 commit comments

Comments
 (0)