fixed bugs with empty game/scene titles and resolving incorrect scenes with conditions
This commit is contained in:
parent
c517587ee1
commit
f8876c7175
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "ficdown.js",
|
"name": "ficdown.js",
|
||||||
"version": "2.0.1",
|
"version": "2.0.2",
|
||||||
"description": "A parser and player for Interactive Fiction written in Ficdown",
|
"description": "A parser and player for Interactive Fiction written in Ficdown",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "rm -rf ./build && tsc",
|
"build": "rm -rf ./build && tsc",
|
||||||
|
|
|
@ -57,7 +57,7 @@ export class Parser {
|
||||||
if(!storyHref) throw new ParseError('no link to first scene', storyBlock.lineNumber);
|
if(!storyHref) throw new ParseError('no link to first scene', storyBlock.lineNumber);
|
||||||
|
|
||||||
const story: Story = {
|
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")),
|
description: Util.trimText(storyBlock.lines.map(l => l.text).join("\n")),
|
||||||
firstScene: storyHref.target,
|
firstScene: storyHref.target,
|
||||||
scenes: {},
|
scenes: {},
|
||||||
|
@ -87,7 +87,7 @@ export class Parser {
|
||||||
let key: string;
|
let key: string;
|
||||||
let conditions: BoolHash | undefined = undefined;
|
let conditions: BoolHash | undefined = undefined;
|
||||||
if(sceneName) {
|
if(sceneName) {
|
||||||
name = sceneName.title
|
name = sceneName.title != null
|
||||||
? Util.trimText(sceneName.title)
|
? Util.trimText(sceneName.title)
|
||||||
: Util.trimText(sceneName.text);
|
: Util.trimText(sceneName.text);
|
||||||
key = Util.normalize(sceneName.text);
|
key = Util.normalize(sceneName.text);
|
||||||
|
|
|
@ -42,7 +42,7 @@ export class Player {
|
||||||
|
|
||||||
public play(): void {
|
public play(): void {
|
||||||
this.container.html(
|
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();
|
this.wireLinks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,10 +65,11 @@ export class Player {
|
||||||
if(this.story.scenes[match.target]) {
|
if(this.story.scenes[match.target]) {
|
||||||
for(let scene of this.story.scenes[match.target]) {
|
for(let scene of this.story.scenes[match.target]) {
|
||||||
if(Util.conditionsMet(this.playerState, scene.conditions)) {
|
if(Util.conditionsMet(this.playerState, scene.conditions)) {
|
||||||
if(!matchedScene
|
const sceneConds = scene.conditions
|
||||||
|| !scene.conditions
|
? Object.keys(scene.conditions).length : 0;
|
||||||
|| !matchedScene.conditions
|
const matchConds = matchedScene && matchedScene.conditions
|
||||||
|| Object.keys(scene.conditions).length > Object.keys(matchedScene.conditions).length) {
|
? Object.keys(matchedScene.conditions).length : 0;
|
||||||
|
if(!matchedScene || sceneConds > matchConds) {
|
||||||
matchedScene = scene;
|
matchedScene = scene;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,13 +16,13 @@ export class Util {
|
||||||
};
|
};
|
||||||
|
|
||||||
private static matchToAnchor(match: RegExpExecArray): Anchor {
|
private static matchToAnchor(match: RegExpExecArray): Anchor {
|
||||||
const result: Anchor = {
|
const result = {
|
||||||
anchor: match[1],
|
anchor: match[1],
|
||||||
text: match[2],
|
text: match[2],
|
||||||
href: match[3],
|
href: match[3],
|
||||||
title: match[6],
|
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.title = result.href.substring(1, result.href.length - 1);
|
||||||
result.href = '';
|
result.href = '';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue