aboutsummaryrefslogtreecommitdiffstats
path: root/components/editor/quest/EditorQuestTasksOptionsPanel.vue
blob: a9e3ac3cee98f9ba01f811963b81785390ea9dc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<script setup lang="ts">
import { useSessionStore, type EditorQuest } from '@/stores/session';
import { computed, ref } from 'vue';

const props = defineProps<{
  questId: string;
}>();

const sessionStore = useSessionStore();

const quest = computed(() => {
  return sessionStore.getQuestById(props.questId) as EditorQuest;
});

const showAddTaskModal = ref(false);

const addTask = (newId: string, newType: string) => {
  sessionStore.getQuestById(props.questId)!.tasks[newId] = {
    id: newId,
    config: {
      type: newType,
    },
  };

  showAddTaskModal.value = false;
};
</script>

<template>
  <EditorOptionsPanel v-if="quest">
    <div id="options">
      <h2>
        Tasks <code>({{ Object.keys(quest.tasks).length }})</code>
      </h2>

      <p v-if="Object.keys(quest.tasks).length === 0" class="error-text">
        This quest does not have any tasks.
      </p>
      <EditorTaskConfiguration
        v-for="(task, taskId) in quest.tasks"
        :key="taskId"
        :taskId="String(taskId)"
        :quest="quest"
      />

      <div id="controls">
        <Button
          id="add-task"
          :icon="['fas', 'plus']"
          type="solid"
          label="Add task"
          @click="showAddTaskModal = true"
        />
      </div>
    </div>
  </EditorOptionsPanel>

  <EditorTaskModalCreate
    v-if="quest"
    v-model="showAddTaskModal"
    :questId="questId"
    @add="addTask"
  />
</template>

<style scoped>
#options {
  display: flex;
  flex-direction: column;
  gap: 1rem;

  #controls {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
  }
}

.option-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.description {
  font-size: 0.8em;
}

label {
  font-weight: 700;
}

h2 {
  border-bottom: 1px solid var(--color-border);

  code {
    font-size: 0.8em;
    color: var(--color-text-mute);
  }
}
</style>