mirror of
https://github.com/YouHaveTrouble/GuildMaster.git
synced 2026-05-11 22:16:59 +00:00
saving and loading the game
This commit is contained in:
+13
-10
@@ -1,16 +1,19 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<link rel="icon" href="/favicon.ico">
|
<link rel="icon" href="/favicon.ico">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Vite App</title>
|
<title>Guild Master - Adventurer's guild management game</title>
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
<link href="https://fonts.googleapis.com/css2?family=EB+Garamond&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=EB+Garamond&display=swap" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<script type="module" src="/src/main.ts"></script>
|
<noscript>
|
||||||
</body>
|
This is a javascript game. You need to enable javascript for it to work.
|
||||||
|
</noscript>
|
||||||
|
<script type="module" src="/src/main.ts"></script>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+32
@@ -52,6 +52,11 @@ export default defineComponent({
|
|||||||
"2": new Quest("2", QuestRank.F, "Rats!", "Get rid of the rats in someone's basement.", 21, 1, 15),
|
"2": new Quest("2", QuestRank.F, "Rats!", "Get rid of the rats in someone's basement.", 21, 1, 15),
|
||||||
"3": new Quest("3", QuestRank.F, "Herb gethering", "Colect medicinal herbs.", 25, 1, 19),
|
"3": new Quest("3", QuestRank.F, "Herb gethering", "Colect medicinal herbs.", 25, 1, 19),
|
||||||
} as { [key: string]: Quest },
|
} as { [key: string]: Quest },
|
||||||
|
E: {
|
||||||
|
"1": new Quest("1", QuestRank.F, "Frog Frenzy", "Kill 10 demon frogs.", 30, 1, 25),
|
||||||
|
"2": new Quest("2", QuestRank.F, "Rats!", "Get rid of the rats in someone's basement.", 21, 1, 15),
|
||||||
|
"3": new Quest("3", QuestRank.F, "Herb gethering", "Colect medicinal herbs.", 25, 1, 19),
|
||||||
|
} as { [key: string]: Quest },
|
||||||
} as { [key: string]: { [key: string]: Quest } },
|
} as { [key: string]: { [key: string]: Quest } },
|
||||||
missives: {
|
missives: {
|
||||||
F: {} as { [key: string]: Quest },
|
F: {} as { [key: string]: Quest },
|
||||||
@@ -92,6 +97,7 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
missive.adventurers = [];
|
missive.adventurers = [];
|
||||||
delete this.missives[missive.rank.toString() as QuestRank][missive.id];
|
delete this.missives[missive.rank.toString() as QuestRank][missive.id];
|
||||||
|
this.saveGame();
|
||||||
},
|
},
|
||||||
getRandomQuest(rank: QuestRank): Quest | null {
|
getRandomQuest(rank: QuestRank): Quest | null {
|
||||||
const keys = Object.keys(this.quests[rank]);
|
const keys = Object.keys(this.quests[rank]);
|
||||||
@@ -106,9 +112,35 @@ export default defineComponent({
|
|||||||
const newId = Math.random().toString(16).slice(2).toString();
|
const newId = Math.random().toString(16).slice(2).toString();
|
||||||
quest.id = newId;
|
quest.id = newId;
|
||||||
this.missives[rank][newId] = quest;
|
this.missives[rank][newId] = quest;
|
||||||
|
},
|
||||||
|
saveGame() {
|
||||||
|
window.localStorage.setItem("savedGame", JSON.stringify({
|
||||||
|
guild: this.guild,
|
||||||
|
adventurers: this.adventurers,
|
||||||
|
missives: this.missives,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
loadGame() {
|
||||||
|
const rawData = window.localStorage.getItem("savedGame");
|
||||||
|
if (!rawData) return;
|
||||||
|
const saveData = JSON.parse(rawData);
|
||||||
|
this.guild = saveData.guild;
|
||||||
|
|
||||||
|
const adventurers = {} as { [key: string]: Adventurer };
|
||||||
|
|
||||||
|
for (const id in saveData.adventurers) {
|
||||||
|
const data = saveData.adventurers[id];
|
||||||
|
adventurers[data.id] = new Adventurer(data.id, data.name, data.portrait, data.attackPerLevel, data.defensePerLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.adventurers = adventurers;
|
||||||
|
this.missives = saveData.missives;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
|
||||||
|
this.loadGame();
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
this.updateMissives();
|
this.updateMissives();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|||||||
Reference in New Issue
Block a user