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",
|
||||
"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",
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 = '';
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue