From 0d8737627008660b1c17336f21946c26d1a7de5f Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Mon, 12 May 2025 16:20:03 +0200 Subject: [PATCH] move quests to a single file --- public/data/quests.json | 106 ++++++++++++++++++++++++++++++++++ public/data/quests/RankA.json | 14 ----- public/data/quests/RankB.json | 14 ----- public/data/quests/RankC.json | 14 ----- public/data/quests/RankD.json | 14 ----- public/data/quests/RankE.json | 14 ----- public/data/quests/RankF.json | 18 ------ public/data/quests/RankS.json | 14 ----- src/GameData.ts | 39 +++++++------ src/classes/Quest.ts | 6 +- 10 files changed, 131 insertions(+), 122 deletions(-) create mode 100644 public/data/quests.json delete mode 100644 public/data/quests/RankA.json delete mode 100644 public/data/quests/RankB.json delete mode 100644 public/data/quests/RankC.json delete mode 100644 public/data/quests/RankD.json delete mode 100644 public/data/quests/RankE.json delete mode 100644 public/data/quests/RankF.json delete mode 100644 public/data/quests/RankS.json diff --git a/public/data/quests.json b/public/data/quests.json new file mode 100644 index 0000000..f37eff3 --- /dev/null +++ b/public/data/quests.json @@ -0,0 +1,106 @@ +{ + "ranks": { + "A": [ + { + "title": "Ogre king", + "text": "Ogres have chosen a new king through democratic vote. They all voted for the strongest ogre." + }, + { + "title": "Devilish dungeon", + "text": "New dungeon was discovered. It needs to be mapped and explored so lower rank adventurers can enter." + }, + { + "title": "Eater of Worlds", + "text": "A giant worm emerged from the ground and appears to be consuming the ground itself." + } + ], + "B": [ + { + "title": "Undead horde", + "text": "Due to the spillage of necromancy potion at nearby graveyard we now have an undead army on our doorstep." + }, + { + "title": "Runaway prisoner", + "text": "During the last prison guard strike a prisoner managed to escape. Bring them back to their cell." + }, + { + "title": "The aristocrats", + "text": "Royalty wants an escort for one of their carriages." + } + ], + "C": [ + { + "title": "Scratchy, the butcher", + "text": "Scratchy turned evil and is terrorizing its victims. Put a stop to it!" + }, + { + "title": "Hobgnoblin subjugation", + "text": "Gnoblins evolved and are back for vengeance." + }, + { + "title": "Holy", + "text": "Gnoblins summoned their machine god and it started going haywire on everything around it. Destroy it!" + } + ], + "D": [ + { + "title": "Caravan escort", + "text": "Escort a merchant caravan." + }, + { + "title": "Rare ore", + "text": "Obtain laudanium ore for town's blacksmith." + }, + { + "title": "Demonic pests!", + "text": "Clear the fields from cabbage imps." + } + ], + "E": [ + { + "title": "Gnoblin subjugation", + "text": "Kill 3 gnoblins." + }, + { + "title": "Phantom menace", + "text": "Exorcise ghosts out of someone's apartment." + }, + { + "title": "Scratchy in peril", + "text": "Get Scratchy the cat from the tree safe onto the ground." + } + ], + "F": [ + { + "title": "Frog Frenzy", + "text": "Kill 10 demon frogs." + }, + { + "title": "Rats!", + "text": "Get rid of the rats from someone's basement." + }, + { + "title": "Herb gathering", + "text": "Collect medicinal herbs." + }, + { + "title": "Big pile of rubble", + "text": "Tavern collapsed. Again. Help clean up the debris." + } + ], + "S": [ + { + "title": "The Demon King", + "text": "Demon King has awoken and is a threat to whole existence. Heroes needed." + }, + { + "title": "Scratchy, Destruction Incarnate", + "text": "Scratchy was reborn as a machine of pure destruction and needs to be stopped." + }, + { + "title": "Jiggly Jungle", + "text": "A jungle south began rapidly expanding and experts think arson is our only option." + } + ] + } +} diff --git a/public/data/quests/RankA.json b/public/data/quests/RankA.json deleted file mode 100644 index a389942..0000000 --- a/public/data/quests/RankA.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "title": "Ogre king", - "text": "Ogres have chosen a new king through democratic vote. They all voted for the strongest ogre." - }, - { - "title": "Devilish dungeon", - "text": "New dungeon was discovered. It needs to be mapped and explored so lower rank adventurers can enter." - }, - { - "title": "Eater of Worlds", - "text": "A giant worm emerged from the ground and appears to be consuming the ground itself." - } -] \ No newline at end of file diff --git a/public/data/quests/RankB.json b/public/data/quests/RankB.json deleted file mode 100644 index a5725cd..0000000 --- a/public/data/quests/RankB.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "title": "Undead horde", - "text": "Due to the spillage of necromancy potion at nearby graveyard we now have an undead army on our doorstep." - }, - { - "title": "Runaway prisoner", - "text": "During the last prison guard strike a prisoner managed to escape. Bring them back to their cell." - }, - { - "title": "The aristocrats", - "text": "Royalty wants an escort for one of their carriages." - } -] \ No newline at end of file diff --git a/public/data/quests/RankC.json b/public/data/quests/RankC.json deleted file mode 100644 index 1faa4e7..0000000 --- a/public/data/quests/RankC.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "title": "Scratchy, the butcher", - "text": "Scratchy turned evil and is terrorizing its victims. Put a stop to it!" - }, - { - "title": "Hobgnoblin subjegation", - "text": "Gnoblins evolved and are back for vengeance." - }, - { - "title": "Holy", - "text": "Gnoblins summoned their machine god and it started going haywire on everything around it. Destroy it!" - } -] \ No newline at end of file diff --git a/public/data/quests/RankD.json b/public/data/quests/RankD.json deleted file mode 100644 index 5dba33a..0000000 --- a/public/data/quests/RankD.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "title": "Caravan escort", - "text": "Escort a merchant caravan." - }, - { - "title": "Rare ore", - "text": "Obtain laudanium ore for town's blacksmith." - }, - { - "title": "Demonic pests!", - "text": "Clear the fields from cabbage imps." - } -] \ No newline at end of file diff --git a/public/data/quests/RankE.json b/public/data/quests/RankE.json deleted file mode 100644 index 01b0803..0000000 --- a/public/data/quests/RankE.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "title": "Gnoblin subjegation", - "text": "Kill 3 gnoblins." - }, - { - "title": "Phantom menace", - "text": "Exorcise ghosts out of someone's apartment." - }, - { - "title": "Scratchy in peril", - "text": "Get Scratchy the cat from the tree safe onto the ground." - } -] \ No newline at end of file diff --git a/public/data/quests/RankF.json b/public/data/quests/RankF.json deleted file mode 100644 index 7ebd9e2..0000000 --- a/public/data/quests/RankF.json +++ /dev/null @@ -1,18 +0,0 @@ -[ - { - "title": "Frog Frenzy", - "text": "Kill 10 demon frogs." - }, - { - "title": "Rats!", - "text": "Get rid of the rats from someone's basement." - }, - { - "title": "Herb gathering", - "text": "Collect medicinal herbs." - }, - { - "title": "Big pile of rubble", - "text": "Tavern collapsed. Again. Help clean up the debris." - } -] \ No newline at end of file diff --git a/public/data/quests/RankS.json b/public/data/quests/RankS.json deleted file mode 100644 index 283aa5a..0000000 --- a/public/data/quests/RankS.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "title": "The Demon King", - "text": "Demon King has awoken and is a threat to whole existence. Heroes needed." - }, - { - "title": "Scratchy, Destruction Incarnate", - "text": "Scratchy was reborn as a machine of pure destruction and needs to be stopped." - }, - { - "title": "Jiggly Jungle", - "text": "A jungle south began rapidly expanding and experts think arson is our only option." - } -] \ No newline at end of file diff --git a/src/GameData.ts b/src/GameData.ts index d574c24..05aa62a 100644 --- a/src/GameData.ts +++ b/src/GameData.ts @@ -68,26 +68,31 @@ export async function loadAvailableQuests(): Promise<{ [key: string]: { [key: st F: {} as { [key: string]: Quest }, } as { [key: string]: { [key: string]: Quest } }; - for (const rank in quests) { - const response = await fetch(`data/quests/Rank${rank}.json`); - if (response.status !== 200) { - console.error("Failed to load quests"); - alert("Failed to load quests. Please try refreshing the page."); - return quests; - } - const questData = await response.json(); + const questsResponse = await fetch(`data/quests.json`); - let id = 0; - for (const quest of questData) { - id++; - quests[rank.toString()][id] = new Quest( - id.toString(), - getFromString(rank as QuestRank), + if (questsResponse.status !== 200) { + console.error("Failed to load quests"); + alert("Failed to load quests. Please try refreshing the page."); + return quests; + } + + const questsData = await questsResponse.json(); + + for (const rank of Object.keys(questsData.ranks)) { + const questRank = getFromString(rank as keyof typeof QuestRank); + if (!questRank) { + console.error(`Invalid quest rank: ${rank}`); + continue; + } + const questRankData = questsData.ranks[questRank]; + + for (const quest of questRankData) { + const id = quest.id; + quests[questRank][id] = new Quest( + id, + questRank, quest.title, quest.text, - 1, - 0, - 0 ); } } diff --git a/src/classes/Quest.ts b/src/classes/Quest.ts index 131b61c..e54a7af 100644 --- a/src/classes/Quest.ts +++ b/src/classes/Quest.ts @@ -18,9 +18,9 @@ export class Quest { rank: QuestRank, title: string, text: string, - maxProgress: number, - expReward: number, - goldReward: number, + maxProgress: number = 1, + expReward: number = 0, + goldReward: number = 0, maxAdventurers: number = 1 ) { this.id = id;