aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/session.ts
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.com>2024-02-15 14:01:30 +0000
committerLeonardo Bishop <me@leonardobishop.com>2024-02-15 14:01:30 +0000
commit2aca4247c5d0c7061a300517178dd31316b65fab (patch)
tree10e145c2b57d76c778bdf1a11191495dcfe191f3 /src/stores/session.ts
Initial commit
Diffstat (limited to 'src/stores/session.ts')
-rw-r--r--src/stores/session.ts149
1 files changed, 149 insertions, 0 deletions
diff --git a/src/stores/session.ts b/src/stores/session.ts
new file mode 100644
index 0000000..22db332
--- /dev/null
+++ b/src/stores/session.ts
@@ -0,0 +1,149 @@
+import { defineStore } from 'pinia'
+
+export interface EditorQuest {
+ id: string;
+ display: {
+ name: string;
+ lore: {
+ normal: string[];
+ started: string[];
+ }
+ type: string;
+ }
+ tasks: { [key: string]: EditorTask };
+ rewards: string[];
+ startCommands?: string[];
+ startString?: string[];
+ rewardString?: string[];
+ placeholders?: { [key: string]: string };
+ options: {
+ category: string;
+ requirements: string[];
+ permissionRequired: boolean;
+ cancellable: boolean;
+ countsTowardsLimit: boolean;
+ repeatable: boolean;
+ cooldown: {
+ enabled: boolean;
+ time: number;
+ }
+ timeLimit: {
+ enabled: boolean;
+ time: number;
+ }
+ sortOrder: number;
+ autostart: boolean;
+ completedDisplay?: string;
+ cooldownDisplay?: string;
+ permissionDisplay?: string;
+ lockedDisplay?: string;
+ }
+}
+
+export interface EditorTask {
+ id: string;
+ config: {
+ type: string;
+ [key: string]: any;
+ }
+}
+
+export interface EditorCategory {
+ id: string;
+ display: {
+ name: string;
+ lore: string[];
+ type: string;
+ }
+ permissionRequired: string;
+}
+
+export interface TaskDefinition {
+ description: string;
+ configuration: {
+ [key: string]: {
+ type: string | string[];
+ description: string;
+ default?: any;
+ required?: boolean;
+ note?: string;
+ }
+ }
+}
+
+export const useSessionStore = defineStore('session', {
+ state: () => ({
+ sessionType: '',
+ session: {
+ quests: [] as EditorQuest[],
+ categories: [] as EditorCategory[],
+ taskDefinitions: {} as { [key: string]: TaskDefinition },
+ },
+ editor: {
+ selected: {
+ type: '' as 'Quest' | 'Category',
+ id: '',
+ }
+ }
+ }),
+ getters: {
+ getSessionType(): string {
+ return this.sessionType
+ },
+ getQuests(): EditorQuest[] {
+ return this.session.quests
+ },
+ getCategories(): EditorCategory[] {
+ return this.session.categories
+ },
+ getQuestById: (state) => (id: string) => {
+ return state.session.quests.find(quest => quest.id === id)
+ },
+ getCategoryById: (state) => (id: string) => {
+ return state.session.categories.find(quest => quest.id === id)
+ },
+ getQuestsInCategory: (state) => (id: string) => {
+ return state.session.quests.filter(quest => quest.options.category === id)
+ },
+ getTaskDefinitions: (state) => {
+ return state.session.taskDefinitions
+ },
+ getTaskDefinitionByTaskType: (state) => (type: string) => {
+ return state.session.taskDefinitions[type]
+ },
+ getKnownTaskTypes: (state) => () => {
+ return Object.keys(state.session.taskDefinitions)
+ }
+ // getEditorCategories: (state) => {
+ // return state.editor.categories
+ // }
+ },
+ actions: {
+ setSessionType(type: string) {
+ this.sessionType = type
+ },
+ setQuests(quests: EditorQuest[]) {
+ this.session.quests = quests
+ },
+ setCategories(categories: EditorCategory[]) {
+ this.session.categories = categories
+ },
+ // updateEditorCategories() {
+ // const categories: { [key: string]: { quests: string[] } } = {}
+ // this.session.categories.forEach(category => {
+ // categories[category.id] = { quests: [] }
+ // })
+ // this.session.quests.forEach(quest => {
+ // categories[quest.options.category].quests.push(quest.id)
+ // })
+ // this.editor.categories = categories;
+ // },
+ setEditorSelected(type: 'Quest' | 'Category', id: string) {
+ this.editor.selected.type = type
+ this.editor.selected.id = id
+ },
+ setTaskDefinitions(definitions: { [key: string]: TaskDefinition }) {
+ this.session.taskDefinitions = definitions
+ }
+ }
+});