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

Prettier run

parent dc7295dd
No related branches found
No related tags found
No related merge requests found
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<head> <title>OH14 Work Adventure Story</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>OH14 Work Adventure Story</title> <link rel="icon" type="image/png" href="./favicon.png" />
<link rel="stylesheet" href="./global.css" />
<link rel="stylesheet" href="./build/bundle.css" />
<link rel="icon" type="image/png" href="./favicon.png" /> <script defer src="./build/bundle.js"></script>
<link rel="stylesheet" href="./global.css" /> </head>
<link rel="stylesheet" href="./build/bundle.css" />
<script defer src="./build/bundle.js"></script> <body></body>
</head> </html>
<body></body>
</html>
\ No newline at end of file
...@@ -10,14 +10,15 @@ ...@@ -10,14 +10,15 @@
<main> <main>
{#await dialogSetPromise then dialogSet} {#await dialogSetPromise then dialogSet}
<DialogSetComponent bind:currentDialog={currentDialog} {...dialogSet} /> <DialogSetComponent bind:currentDialog {...dialogSet} />
<br> <br />
<Debugger dialogSet={dialogSet} bind:currentDialog={currentDialog}/> <Debugger {dialogSet} bind:currentDialog />
{:catch _error} {:catch _error}
<h3>Oh no :(</h3> <h3>Oh no :(</h3>
<p> <p>
We could not load that dialogSet that you specified in the url. Sorry. Please go complain to your friendly admin(s). We could not load that dialogSet that you specified in the url. Sorry.
Please go complain to your friendly admin(s).
</p> </p>
{/await} {/await}
</main> </main>
<script lang="ts"> <script lang="ts">
import { gameFactsStore, addGameFactToFactArray, toggleFactInFactArray } from './gameFacts' import {
import type { Dialog, DialogMap, DialogSet } from './types'; gameFactsStore,
import {findDialogSetProblems} from "./utils" addGameFactToFactArray,
toggleFactInFactArray,
} from "./gameFacts";
import type { Dialog, DialogMap, DialogSet } from "./types";
import { findDialogSetProblems } from "./utils";
export let currentDialog: Dialog; export let currentDialog: Dialog;
export let dialogSet: DialogSet; export let dialogSet: DialogSet;
$: dialogNames = Object.keys(dialogSet.dialogs) $: dialogNames = Object.keys(dialogSet.dialogs);
export let selectedDialogName: string export let selectedDialogName: string;
/** /**
* Collect all facts referenced in these dialogs * Collect all facts referenced in these dialogs
*/ */
function getDialogFacts(dialogMap: DialogMap): String[] { function getDialogFacts(dialogMap: DialogMap): String[] {
const dialogs: Dialog[] = []; const dialogs: Dialog[] = [];
for (const dmKey of Object.keys(dialogMap)) dialogs.push(dialogMap[dmKey]); for (const dmKey of Object.keys(dialogMap)) dialogs.push(dialogMap[dmKey]);
const allFacts = dialogs const allFacts = dialogs
.map((dialog) => [ .map((dialog) => [
...(dialog.addFacts || []), ...(dialog.addFacts || []),
...@@ -27,57 +31,74 @@ ...@@ -27,57 +31,74 @@
return [...factsSet]; return [...factsSet];
} }
let seenFactIds = new Set<String>([...$gameFactsStore, ...getDialogFacts(dialogSet.dialogs)]); let seenFactIds = new Set<String>([
$: seenFactIdsArray = Array.from(seenFactIds) ...$gameFactsStore,
...getDialogFacts(dialogSet.dialogs),
]);
$: seenFactIdsArray = Array.from(seenFactIds);
let addFactInputValue: string; let addFactInputValue: string;
</script> </script>
<div> <div>
<h3>Dialog-Debugger</h3> <h3>Dialog-Debugger</h3>
Jump to dialog: Jump to dialog:
<!-- svelte-ignore a11y-no-onchange --> <!-- svelte-ignore a11y-no-onchange -->
<select bind:value={selectedDialogName} on:change="{() => currentDialog = dialogSet.dialogs[selectedDialogName]}"> <select
{#each dialogNames as dialogName} bind:value={selectedDialogName}
<option value={dialogName} selected={dialogName === selectedDialogName}> on:change={() => (currentDialog = dialogSet.dialogs[selectedDialogName])}
{dialogName} >
</option> {#each dialogNames as dialogName}
{/each} <option value={dialogName} selected={dialogName === selectedDialogName}>
</select> {dialogName}
<br> </option>
<ol> {/each}
{#each findDialogSetProblems(dialogSet) as {sourceDialog, text}} </select>
<li> <br />
{sourceDialog}: <code style="color: orange">{text}</code> <ol>
</li> {#each findDialogSetProblems(dialogSet) as { sourceDialog, text }}
<li>
{sourceDialog}: <code style="color: orange">{text}</code>
</li>
{/each} {/each}
</ol> </ol>
<hr>
<h3>Quest-Debugger</h3> <hr />
<b>GameFacts:</b>
<ul>
{#each seenFactIdsArray as gameFact}
<li>
<input type="checkbox" checked={$gameFactsStore.includes(gameFact)} on:change={() => gameFactsStore.set(toggleFactInFactArray(gameFact, $gameFactsStore))}>
{gameFact}
</li>
{/each}
</ul>
Add fact:
<input type="text" bind:value={addFactInputValue}>
<button style="width: 3rem;" on:click={() => {
gameFactsStore.set(addGameFactToFactArray(addFactInputValue, $gameFactsStore));
seenFactIds = seenFactIds.add(addFactInputValue);
addFactInputValue = '';
}}>Add</button>
<h3>Quest-Debugger</h3>
<b>GameFacts:</b>
<ul>
{#each seenFactIdsArray as gameFact}
<li>
<input
type="checkbox"
checked={$gameFactsStore.includes(gameFact)}
on:change={() =>
gameFactsStore.set(
toggleFactInFactArray(gameFact, $gameFactsStore)
)}
/>
{gameFact}
</li>
{/each}
</ul>
Add fact:
<input type="text" bind:value={addFactInputValue} />
<button
style="width: 3rem;"
on:click={() => {
gameFactsStore.set(
addGameFactToFactArray(addFactInputValue, $gameFactsStore)
);
seenFactIds = seenFactIds.add(addFactInputValue);
addFactInputValue = "";
}}>Add</button
>
</div> </div>
<style> <style>
div { div {
border: 1px solid; border: 1px solid;
padding: 10px; padding: 10px;
margin: 5px; margin: 5px;
} }
</style> </style>
\ No newline at end of file
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
</script> </script>
<SingleDialogComponent <SingleDialogComponent
imageUrl={imageUrl} title={title} {...currentDialog} {imageUrl}
{title}
{...currentDialog}
on:switchToDialog={(event) => switchDialog(event.detail)} on:switchToDialog={(event) => switchDialog(event.detail)}
/> />
<script lang="ts"> <script lang="ts">
import type { DialogOption } from "./types"; import type { DialogOption } from "./types";
import { createEventDispatcher } from "svelte"; import { createEventDispatcher } from "svelte";
import { gameFactsStore, addGameFactToFactArray } from './gameFacts' import { gameFactsStore, addGameFactToFactArray } from "./gameFacts";
import Typewriter from 'svelte-typewriter' import Typewriter from "svelte-typewriter";
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
...@@ -10,26 +10,39 @@ ...@@ -10,26 +10,39 @@
export let title: string | undefined; export let title: string | undefined;
export let text: string; export let text: string;
export let options: DialogOption[] = []; export let options: DialogOption[] = [];
$: usableOptions = options.filter(option => isDialogOptionAllowedByGameFacts(option, $gameFactsStore)) $: usableOptions = options.filter((option) =>
isDialogOptionAllowedByGameFacts(option, $gameFactsStore)
);
export let addFacts: String[] = []; export let addFacts: String[] = [];
$: { $: {
if (Array.isArray(addFacts)) { if (Array.isArray(addFacts)) {
const gameFactsAfterAddedFacts = addFacts.reduce((accFacts, factToAdd) => addGameFactToFactArray(factToAdd, accFacts), $gameFactsStore) const gameFactsAfterAddedFacts = addFacts.reduce(
(accFacts, factToAdd) => addGameFactToFactArray(factToAdd, accFacts),
$gameFactsStore
);
$gameFactsStore = gameFactsAfterAddedFacts; $gameFactsStore = gameFactsAfterAddedFacts;
} }
} }
export let removeFacts: String[] = []; export let removeFacts: String[] = [];
$: { $: {
if (Array.isArray(removeFacts)) { if (Array.isArray(removeFacts)) {
const gameFactsAfterRemovedFacts = removeFacts.reduce((accFacts, factToRemove) => accFacts.filter(f => f !== factToRemove), $gameFactsStore) const gameFactsAfterRemovedFacts = removeFacts.reduce(
(accFacts, factToRemove) => accFacts.filter((f) => f !== factToRemove),
$gameFactsStore
);
$gameFactsStore = gameFactsAfterRemovedFacts; $gameFactsStore = gameFactsAfterRemovedFacts;
} }
} }
function isDialogOptionAllowedByGameFacts(option: DialogOption, gameFacts: String[]): boolean { function isDialogOptionAllowedByGameFacts(
option: DialogOption,
gameFacts: String[]
): boolean {
// Check if all required facts are given // Check if all required facts are given
if (Array.isArray(option.requiredFacts)) { if (Array.isArray(option.requiredFacts)) {
const isOk = option.requiredFacts.every(requiredFact => gameFacts.includes(requiredFact)); const isOk = option.requiredFacts.every((requiredFact) =>
gameFacts.includes(requiredFact)
);
if (!isOk) { if (!isOk) {
return false; return false;
} }
...@@ -37,7 +50,9 @@ ...@@ -37,7 +50,9 @@
// Check if no forbidden facts are given // Check if no forbidden facts are given
if (Array.isArray(option.forbiddenFacts)) { if (Array.isArray(option.forbiddenFacts)) {
const isOk = option.forbiddenFacts.every(forbiddenFact => !gameFacts.includes(forbiddenFact)); const isOk = option.forbiddenFacts.every(
(forbiddenFact) => !gameFacts.includes(forbiddenFact)
);
if (!isOk) { if (!isOk) {
return false; return false;
} }
...@@ -47,7 +62,7 @@ ...@@ -47,7 +62,7 @@
} }
function handleDialogOptionClick(option: DialogOption): void { function handleDialogOptionClick(option: DialogOption): void {
dispatch("switchToDialog", option.linksToDialog) dispatch("switchToDialog", option.linksToDialog);
} }
</script> </script>
...@@ -62,7 +77,7 @@ ...@@ -62,7 +77,7 @@
<div> <div>
<Typewriter cascade interval={10} cursor={false}> <Typewriter cascade interval={10} cursor={false}>
{#each text.split("\n") as para} {#each text.split("\n") as para}
<p>{para}</p> <p>{para}</p>
{/each} {/each}
</Typewriter> </Typewriter>
</div> </div>
......
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"definitions": { "definitions": {
"Dialog": { "Dialog": {
"description": "A dialog situation that a player can encounter in this dialogSet.\n\nPrinciple: NPC says something, user has options how to react.", "description": "A dialog situation that a player can encounter in this dialogSet.\n\nPrinciple: NPC says something, user has options how to react.",
"properties": { "properties": {
"addFacts": { "addFacts": {
"description": "Upon entering this dialog, register these facts for the user.\n\nFacts are texts and may unlock or block dialog options across the game.\nE.g. The fact \"acceptedMissionX\" could unlock a dialog option regarding Mission X with another NPC.", "description": "Upon entering this dialog, register these facts for the user.\n\nFacts are texts and may unlock or block dialog options across the game.\nE.g. The fact \"acceptedMissionX\" could unlock a dialog option regarding Mission X with another NPC.",
"items": { "items": {
"additionalProperties": false, "additionalProperties": false,
"description": "Allows manipulation and formatting of text strings and determination and location of substrings within strings.", "description": "Allows manipulation and formatting of text strings and determination and location of substrings within strings.",
"patternProperties": { "patternProperties": {
"^[0-9]+$": { "^[0-9]+$": {
"type": "string" "type": "string"
} }
},
"type": "object"
},
"type": "array"
},
"imageUrl": {
"description": "Can be used to overwrite imageUrl from DialogSet.\nE.g. when a different emotion should be shown for this dialog,",
"type": "string"
},
"options": {
"description": "Choices of what the user might say in this dialog and where those choices lead to.\nThe player should be given between 0 and 4 options.",
"items": {
"$ref": "#/definitions/DialogOption"
},
"type": "array"
},
"removeFacts": {
"description": "Upon entering this dialog, remove these facts from the user.\n\nFacts are texts and may unlock or block dialog options across the game.\nE.g. The fact \"acceptedMissionX\" could unlock a dialog option regarding Mission X with another NPC.",
"items": {
"additionalProperties": false,
"description": "Allows manipulation and formatting of text strings and determination and location of substrings within strings.",
"patternProperties": {
"^[0-9]+$": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
},
"text": {
"description": "What the characters says to the player.\nLine breaks (\\n) are rendered as paragraphs.\nYou may leave this empty or omit it completely.",
"type": "string"
},
"title": {
"description": "The title is displayed at the very top of the dialog screen\nand usually corresponds to the name of the NPC the player is speaking to.\n\nCan be used to overwrite title from DialogSet.",
"type": "string"
}
}, },
"type": "object" "type": "object"
},
"type": "array"
}, },
"DialogOption": { "imageUrl": {
"properties": { "description": "Can be used to overwrite imageUrl from DialogSet.\nE.g. when a different emotion should be shown for this dialog,",
"forbiddenFacts": { "type": "string"
"description": "All facts in this array must *not* be registered for this player for this option to show up.\n\nFacts are texts and may unlock or block dialog options across the game.\nE.g. The fact \"acceptedMissionX\" could unlock a dialog option regarding Mission X with another NPC.", },
"items": { "options": {
"additionalProperties": false, "description": "Choices of what the user might say in this dialog and where those choices lead to.\nThe player should be given between 0 and 4 options.",
"description": "Allows manipulation and formatting of text strings and determination and location of substrings within strings.", "items": {
"patternProperties": { "$ref": "#/definitions/DialogOption"
"^[0-9]+$": { },
"type": "string" "type": "array"
} },
}, "removeFacts": {
"type": "object" "description": "Upon entering this dialog, remove these facts from the user.\n\nFacts are texts and may unlock or block dialog options across the game.\nE.g. The fact \"acceptedMissionX\" could unlock a dialog option regarding Mission X with another NPC.",
}, "items": {
"type": "array" "additionalProperties": false,
}, "description": "Allows manipulation and formatting of text strings and determination and location of substrings within strings.",
"linksToDialog": { "patternProperties": {
"description": "Which dialog in this dialogSet to jump to if this option is chosen.", "^[0-9]+$": {
"type": "string" "type": "string"
}, }
"requiredFacts": {
"description": "All facts in this array must be registered for this player for this option to show up.\n\nFacts are texts and may unlock or block dialog options across the game.\nE.g. The fact \"acceptedMissionX\" could unlock a dialog option regarding Mission X with another NPC.",
"items": {
"additionalProperties": false,
"description": "Allows manipulation and formatting of text strings and determination and location of substrings within strings.",
"patternProperties": {
"^[0-9]+$": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
},
"text": {
"description": "Text on option button.\nShould be rather short and not have line breaks.",
"type": "string"
}
}, },
"type": "object" "type": "object"
},
"type": "array"
},
"text": {
"description": "What the characters says to the player.\nLine breaks (\\n) are rendered as paragraphs.\nYou may leave this empty or omit it completely.",
"type": "string"
},
"title": {
"description": "The title is displayed at the very top of the dialog screen\nand usually corresponds to the name of the NPC the player is speaking to.\n\nCan be used to overwrite title from DialogSet.",
"type": "string"
} }
},
"type": "object"
}, },
"description": "Set of dialogs, beginning with startDialogName.\nThis should be", "DialogOption": {
"properties": { "properties": {
"dialogs": { "forbiddenFacts": {
"additionalProperties": { "description": "All facts in this array must *not* be registered for this player for this option to show up.\n\nFacts are texts and may unlock or block dialog options across the game.\nE.g. The fact \"acceptedMissionX\" could unlock a dialog option regarding Mission X with another NPC.",
"$ref": "#/definitions/Dialog" "items": {
"additionalProperties": false,
"description": "Allows manipulation and formatting of text strings and determination and location of substrings within strings.",
"patternProperties": {
"^[0-9]+$": {
"type": "string"
}
}, },
"description": "All dialogs in this dialogSet.",
"type": "object" "type": "object"
},
"type": "array"
}, },
"imageUrl": { "linksToDialog": {
"description": "Url of image.\n\nShould link to image in this repo, to avoid CORS errors.", "description": "Which dialog in this dialogSet to jump to if this option is chosen.",
"type": "string" "type": "string"
}, },
"startDialogName": { "requiredFacts": {
"description": "At which dialog to start when the dialogSet is first opened by the player.", "description": "All facts in this array must be registered for this player for this option to show up.\n\nFacts are texts and may unlock or block dialog options across the game.\nE.g. The fact \"acceptedMissionX\" could unlock a dialog option regarding Mission X with another NPC.",
"type": "string" "items": {
"additionalProperties": false,
"description": "Allows manipulation and formatting of text strings and determination and location of substrings within strings.",
"patternProperties": {
"^[0-9]+$": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
}, },
"title": { "text": {
"description": "The title is displayed at the very top of the dialog screen\nand usually corresponds to the name of the NPC the player is speaking to.", "description": "Text on option button.\nShould be rather short and not have line breaks.",
"type": "string" "type": "string"
} }
},
"type": "object"
}
},
"description": "Set of dialogs, beginning with startDialogName.\nThis should be",
"properties": {
"dialogs": {
"additionalProperties": {
"$ref": "#/definitions/Dialog"
},
"description": "All dialogs in this dialogSet.",
"type": "object"
},
"imageUrl": {
"description": "Url of image.\n\nShould link to image in this repo, to avoid CORS errors.",
"type": "string"
},
"startDialogName": {
"description": "At which dialog to start when the dialogSet is first opened by the player.",
"type": "string"
}, },
"type": "object" "title": {
"description": "The title is displayed at the very top of the dialog screen\nand usually corresponds to the name of the NPC the player is speaking to.",
"type": "string"
}
},
"type": "object"
} }
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