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

Commit

Permalink
fixed bugs with empty game/scene titles and resolving incorrect scene…
Browse files Browse the repository at this point in the history
…s with conditions
  • Loading branch information
rudism committed May 9, 2020
1 parent c517587 commit f8876c7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions src/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
}
Expand Down

0 comments on commit f8876c7

Please sign in to comment.