aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/session.ts
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.com>2024-02-15 18:39:01 +0000
committerLeonardo Bishop <me@leonardobishop.com>2024-02-15 18:39:01 +0000
commit1869b5c5f9565b5e9e20697c4401a2f9ba9f2c3a (patch)
tree96411620ad766e4d27df5077ad3870bdda6aa8c5 /src/stores/session.ts
parent0f2240c87a5c0a22e2db97e4d2b82a52401be668 (diff)
Add quest rename and delete functionality
Diffstat (limited to 'src/stores/session.ts')
-rw-r--r--src/stores/session.ts28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/stores/session.ts b/src/stores/session.ts
index 22db332..1cc8dc7 100644
--- a/src/stores/session.ts
+++ b/src/stores/session.ts
@@ -81,8 +81,8 @@ export const useSessionStore = defineStore('session', {
},
editor: {
selected: {
- type: '' as 'Quest' | 'Category',
- id: '',
+ type: '' as 'Quest' | 'Category' | null,
+ id: '' as string | null,
}
}
}),
@@ -97,12 +97,15 @@ export const useSessionStore = defineStore('session', {
return this.session.categories
},
getQuestById: (state) => (id: string) => {
+ if (!id) return null;
return state.session.quests.find(quest => quest.id === id)
},
getCategoryById: (state) => (id: string) => {
+ if (!id) return null;
return state.session.categories.find(quest => quest.id === id)
},
getQuestsInCategory: (state) => (id: string) => {
+ if (!id) return [];
return state.session.quests.filter(quest => quest.options.category === id)
},
getTaskDefinitions: (state) => {
@@ -138,12 +141,31 @@ export const useSessionStore = defineStore('session', {
// })
// this.editor.categories = categories;
// },
- setEditorSelected(type: 'Quest' | 'Category', id: string) {
+ setEditorSelected(type: 'Quest' | 'Category' | null, id: string | null) {
this.editor.selected.type = type
this.editor.selected.id = id
},
setTaskDefinitions(definitions: { [key: string]: TaskDefinition }) {
this.session.taskDefinitions = definitions
+ },
+ changeQuestId(oldId: string, newId: string) {
+ const quest = this.getQuestById(oldId);
+ if (!quest) return;
+
+ quest.id = newId
+ },
+ deleteQuest(id: string) {
+ const index = this.session.quests.findIndex(quest => quest.id === id)
+ if (index === -1) return;
+ this.session.quests.splice(index, 1)
+ },
+ duplicateQuest(id: string, newQuestId: string) {
+ const quest = this.getQuestById(id);
+ if (!quest) return;
+
+ const newQuest = JSON.parse(JSON.stringify(quest));
+ newQuest.id = newQuestId;
+ this.session.quests.push(newQuest);
}
}
});