Skip to content
Snippets Groups Projects
Commit ca24bffc authored by Jonas Zohren's avatar Jonas Zohren :speech_balloon:
Browse files

Show problems with dialog in debugger

parent 9828e712
No related branches found
No related tags found
No related merge requests found
<script lang="ts">
import { gameFactsStore, addGameFactToFactArray, toggleFactInFactArray } from './gameFacts'
import type { Dialog, DialogMap, DialogSet } from './types';
import {findDialogSetProblems} from "./utils"
export let currentDialog: Dialog;
export let dialogSet: DialogSet;
......@@ -28,7 +29,16 @@
{dialogName}
</option>
{/each}
</select>
</select>
<br>
<ol>
{#each findDialogSetProblems(dialogSet) as {sourceDialog, text}}
<li>
{sourceDialog}: <code style="color: orange">{text}</code>
</li>
{/each}
</ol>
<hr>
<h3>Quest-Debugger</h3>
......
import type { DialogSet } from "./types";
import type { DialogMap, DialogOption, DialogSet } from "./types";
/**
* Returns true, if input is a valid name of a dialogSet.
......@@ -39,3 +39,58 @@ export async function fetchDialogSet(): Promise<DialogSet> {
throw error;
}
}
export function findDialogSetProblems(dialogSet: DialogSet) {
const dialogReferenceProblems = checkForInvalidDialogReferences(dialogSet);
return [...dialogReferenceProblems];
}
interface DialogReferenceProblem {
type: "DialogReferenceProblem";
sourceDialog: string;
text: string;
}
function checkForInvalidDialogReferences(
dialogSet: DialogSet
): DialogReferenceProblem[] {
const dialogs = dialogSet.dialogs;
const problems: DialogReferenceProblem[] = [];
const allDialogKeys = Object.keys(dialogs);
const allLinkedToDialogKeys: Set<string> = new Set();
for (const dialogName of allDialogKeys) {
// TODO check all buttons for invalid references
for (const { text, linksToDialog } of dialogs[dialogName].options) {
allLinkedToDialogKeys.add(linksToDialog);
if (!allDialogKeys.includes(linksToDialog)) {
problems.push({
type: "DialogReferenceProblem",
sourceDialog: dialogName,
text: `Dialog ${dialogName}'s option "${text}" links to unknown dialog '${linksToDialog}'`,
});
}
if (linksToDialog === dialogName) {
problems.push({
type: "DialogReferenceProblem",
sourceDialog: dialogName,
text: `Dialog ${dialogName}'s option "${text}" links to itself!`,
});
}
}
}
for (const dialogName of allDialogKeys) {
if (
!allLinkedToDialogKeys.has(dialogName) &&
dialogSet.startDialogName !== dialogName
) {
problems.push({
type: "DialogReferenceProblem",
sourceDialog: dialogName,
text: `Dialog ${dialogName} is unreachable: Neither linked to from any other dialog, nor startDialog`,
});
}
}
return problems;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment