Document markup and improve choice tags
This commit is contained in:
Vendored
+35
-2
@@ -120,10 +120,12 @@ class InkEngine {
|
||||
}
|
||||
const paragraphs = [];
|
||||
const globalTags = [];
|
||||
const turnTags = [];
|
||||
while (this.story.canContinue) {
|
||||
const rawText = this.story.Continue();
|
||||
const text = String(rawText || '').trim();
|
||||
const tags = (0, tag_parser_1.parseTags)(this.story.currentTags || []);
|
||||
turnTags.push(...tags);
|
||||
tags
|
||||
.filter((tag) => tag.key === 'title' || tag.key === 'author')
|
||||
.forEach((tag) => globalTags.push(tag));
|
||||
@@ -137,7 +139,7 @@ class InkEngine {
|
||||
const choices = this.story.currentChoices.map((choice) => {
|
||||
const tags = (0, tag_parser_1.parseTags)(choice.tags || []);
|
||||
const category = (0, tag_parser_1.getTagValue)(tags, 'action');
|
||||
const letter = (0, tag_parser_1.getTagValue)(tags, 'letter');
|
||||
const letter = (0, tag_parser_1.getTagValue)(tags, 'letter') || (0, tag_parser_1.getTagValue)(tags, 'key');
|
||||
return {
|
||||
index: choice.index,
|
||||
text: String(choice.text || '').trim(),
|
||||
@@ -146,12 +148,43 @@ class InkEngine {
|
||||
letter,
|
||||
};
|
||||
});
|
||||
const inputMode = choices.length > 0 ? 'choice' : 'end';
|
||||
const gameState = {};
|
||||
if (inputMode === 'end') {
|
||||
const errorTag = turnTags.find((tag) => tag.key === 'error');
|
||||
const scoreTag = turnTags.find((tag) => tag.key === 'score');
|
||||
if (!errorTag && !scoreTag) {
|
||||
const message = 'Ink story ended without an explicit #score ending tag.';
|
||||
const generatedErrorTag = { key: 'error', value: message };
|
||||
globalTags.push(generatedErrorTag);
|
||||
turnTags.push(generatedErrorTag);
|
||||
}
|
||||
const finalErrorTag = turnTags.find((tag) => tag.key === 'error');
|
||||
const finalScoreTag = turnTags.find((tag) => tag.key === 'score');
|
||||
if (finalErrorTag) {
|
||||
gameState.endState = {
|
||||
type: 'error',
|
||||
message: finalErrorTag.value || finalErrorTag.param,
|
||||
};
|
||||
}
|
||||
else if (finalScoreTag) {
|
||||
const numericScore = Number(finalScoreTag?.value);
|
||||
if (Number.isFinite(numericScore)) {
|
||||
gameState.score = numericScore;
|
||||
}
|
||||
gameState.endState = {
|
||||
type: 'intended',
|
||||
message: finalScoreTag.value || finalScoreTag.param,
|
||||
};
|
||||
}
|
||||
}
|
||||
return {
|
||||
turnId: this.nextTurnId++,
|
||||
paragraphs,
|
||||
choices,
|
||||
inputMode: choices.length > 0 ? 'choice' : 'end',
|
||||
inputMode,
|
||||
globalTags: globalTags.length > 0 ? globalTags : undefined,
|
||||
gameState: Object.keys(gameState).length > 0 ? gameState : undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user