From aaaa87899b1078a76fcbb068f72f83e345961f19 Mon Sep 17 00:00:00 2001 From: Daniel Bulant Date: Fri, 11 Jun 2021 16:55:03 +0200 Subject: [PATCH] proper chapter loading --- src/game/input.js | 1 - src/pages/dialog.svelte | 25 ++++++++++++++++++++----- src/stores/dialog.js | 14 +++++++++++++- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/game/input.js b/src/game/input.js index 7eb23da..a786505 100644 --- a/src/game/input.js +++ b/src/game/input.js @@ -99,7 +99,6 @@ class KeyHandler { x *= multiplier; y *= multiplier; var direction; - console.log(x, y); if(x >= 0.5) { direction = "right"; } else if(x <= -0.5) { diff --git a/src/pages/dialog.svelte b/src/pages/dialog.svelte index cde089c..ae44bb0 100644 --- a/src/pages/dialog.svelte +++ b/src/pages/dialog.svelte @@ -29,10 +29,16 @@ var activeButton = -1; function select(i) { - console.log("Switching", i); if(!allowSwitch) return; var next; - if(d.buttons) { + if(d.flags && d.flags.includes("chapters")) { + const keys = Object.keys(chapters); + console.log(keys); + if(!keys[i]) return; + const key = keys[i]; + if(!chaptersDone.includes(key)) return; + next = dialog.findIndex(t => t.chapterStart === key); + } else if(d.buttons) { if(!d.buttons[i]) return; next = dialog.findIndex(t => t.name === d.buttons[i].next); } else { @@ -80,6 +86,7 @@ } } + /** @type {string[]}*/ var chaptersDone = JSON.parse(localStorage.getItem("chapters") || "[]"); function keydown(e) { @@ -92,11 +99,16 @@ case "ArrowRight": case "ArrowDown": activeButton++; - if(d.buttons && activeButton > d.buttons.length - 1) activeButton = d.buttons.length - 1; + if(d.flags && d.flags.includes("chapters")) { + if(activeButton > Object.keys(chapters).length - 1) activeButton = Object.keys(chapters).length - 1; + } else if(d.buttons && activeButton > d.buttons.length - 1) { + activeButton = d.buttons.length - 1; + } break; case "Enter": case " ": select(activeButton); + reset(); break; } } @@ -175,8 +187,8 @@ {/if} {#if d && d.flags && d.flags.includes("chapters") && chaptersDone.length}
- {#each Object.keys(chapters) as chapter} -
+ {#each Object.keys(chapters) as chapter, i} +
select(i)} class:active={chaptersDone && chaptersDone.includes(chapter)}> {toRoman(chapters[chapter])}
{/each} @@ -203,6 +215,9 @@ margin: 3px; cursor: not-allowed; } + .chapter.selected, .chapter:hover { + box-shadow: 0 0 2px 1px rgba(255, 255, 255, 0.705); + } .chapter.active { cursor: pointer; border-color: red; diff --git a/src/stores/dialog.js b/src/stores/dialog.js index b791d20..cb540d6 100644 --- a/src/stores/dialog.js +++ b/src/stores/dialog.js @@ -16,6 +16,7 @@ export const chapters = { * pose?: string, * map?: string, * chapter?: keyof typeof chapters, + * chapterStart?: keyof typeof chapters, * buttons: { text: string, next: string }[], * flags?: string[] * }[]} @@ -41,6 +42,12 @@ export const dialog = [{ character: "Hadraniel", text: "Wait where are you going? That's not the way to the main gate-", next: "uriel_entrance" +}, { + name: "restart", + background: "/sprite/menu.webp", + character: "Hadraniel", + text: "Welcome back. What do you desire now?", + next: "menu" }, { name: "menu", background: "/sprite/menu.webp", @@ -64,6 +71,7 @@ export const dialog = [{ flags: ["chapters", "nosave"] }, { name: "uriel_entrance", + chapterStart: "uriel", background: "/sprite/backg.webp", character: "Uriel", pose: "side_normal", @@ -101,6 +109,7 @@ export const dialog = [{ next: "michael_heretic" }, { name: "michael_heretic", + chapterStart: "michael", background: "/sprite/backg.webp", character: "Michael", text: "How did you... You know what I don't even care. Heretic like you needs to be punished.", @@ -133,6 +142,7 @@ export const dialog = [{ name: "uziel_start", background: "/sprite/backg.webp", character: "Uziel", + chapterStart: "uziel", text: "(she appear out of nowhere and suddenly approaches you.)", buttons: [{ text: "oh, you're approaching me? Had you heard of my harem proposal.", @@ -162,6 +172,7 @@ export const dialog = [{ name: "gabriel_start", background: "/sprite/backg.webp", character: "Gabriel", + chapterStart: "gabriel", text: "Hello sir. My name is Gabriel, Heaven's administration department. How may I help you?", buttons: [{ text: "You look tired, how about let me help you instead.", @@ -202,6 +213,7 @@ export const dialog = [{ name: "azrael_start", background: "/sprite/backg.webp", character: "Azrael", + chapterStart: "azrael", text: "Oh my my, what do we have here a lost soul wandering around heaven with an intent lust for angel.", buttons: [{ text: "You're god damn right.", @@ -221,7 +233,7 @@ export const dialog = [{ }, { name: "azrael_win", chapter: "azrael", - next: "menu", + next: "restart", background: "/sprite/backg.webp", character: "Azrael", pose: "happy",