blob: 2a53926e9bc13258b40e68908869d2286136bd1b (
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
<script setup lang="ts">
import { computed, ref } from 'vue';
import materials from '@/lib/materials';
const model = defineModel();
const emit = defineEmits(['confirm']);
const props = defineProps<{
value: any
}>();
const session = useSessionStore();
//TODO unshitify
const value = ref<any>(props.value);
const isQuestItem = computed(() => {
return value.value?.['quest-item'] !== undefined;
});
const isItemStack = computed(() => {
return (
typeof value.value === 'object'
&& (
value.value?.item !== undefined
|| value.value?.type !== undefined
|| value.value?.material !== undefined
))
});
const isMaterial = computed(() => {
return typeof value.value === 'string' && materials.includes(value.value)
});
const selectedType = ref(
isQuestItem.value
? 'questitem'
: isItemStack.value
? 'itemstack'
: isMaterial.value
? 'material'
: ''
);
const noTypeSelected = computed(() => selectedType.value === '');
const noValue = computed(() => !isQuestItem.value && !isItemStack.value && !isMaterial.value);
const selectedQuestItem = computed({
get() {
return value.value?.['quest-item'];
},
set(newValue: string) {
value.value = {}
if (newValue) {
value.value['quest-item'] = newValue;
}
}
})
const knownQuestItems = computed(() => { return session.session.items.map((item) => item.id) });
const setSelectedType = (type: string) => {
if (type === 'questitem') {
value.value = {};
} else if (type === 'itemstack') {
value.value = {};
} else if (type === 'material') {
value.value = '';
}
selectedType.value = type;
};
const confirm = () => {
emit('confirm', value.value);
};
</script>
<template>
<Modal v-model="model">
<template v-slot:header>
<h2>Edit ItemStack</h2>
</template>
<template v-slot:body>
<div id="type">
<span class="option" @click="setSelectedType('questitem')" :class="{ selected: selectedType === 'questitem' }">
<span>
<font-awesome-icon :icon="['fas', 'tag']" />
Quest Item
</span>
<p v-if="noTypeSelected">Re-use a quest item.</p>
</span>
<span class="option" @click="setSelectedType('itemstack')" :class="{ selected: selectedType === 'itemstack' }">
<span>
<font-awesome-icon :icon="['fas', 'cube']" />
ItemStack
</span>
<p v-if="noTypeSelected">Define a new item stack.</p>
</span>
<span class="option" @click="setSelectedType('material')" :class="{ selected: selectedType === 'material' }">
<span>
<font-awesome-icon :icon="['fas', 'apple-whole']" />
Material
</span>
<p v-if="noTypeSelected">Define a specific item type.</p>
</span>
</div>
<div id="material" class="option-group" v-if="selectedType === 'material'">
<label for="material">Material</label>
<multiselect v-model="value" :options="materials" :searchable="true" placeholder="Enter material name" />
<p>Any items of this material will be matched.</p>
</div>
<div id="itemstack" class="option-group" v-if="selectedType === 'itemstack'">
<ItemStackForm v-model="value" />
</div>
<div id="quest-item" class="option-group" v-if="selectedType === 'questitem'">
<label for="quest-item">Quest Item</label>
<multiselect v-model="selectedQuestItem" :options="knownQuestItems" :searchable="true"
placeholder="Enter quest item" />
</div>
<div id="confirm" class="control-group">
<Button :icon="['fas', 'times']" :label="'Cancel'" @click="model = false"></Button>
<Button type="solid" :icon="['fas', 'check']" :label="'Confirm'" @click="confirm"></Button>
<!-- :disabled="noTypeSelected || noValue" -->
</div>
</template>
</Modal>
</template>
<style scoped>
#confirm {
display: flex;
justify-content: flex-end;
margin-top: 1rem;
}
#type {
display: flex;
justify-content: space-around;
gap: 0.25rem;
user-select: none;
margin-bottom: 1rem;
.option {
border: 1px solid var(--color-border);
cursor: pointer;
display: flex;
flex-direction: column;
flex-basis: 0;
flex-grow: 1;
align-items: center;
gap: 0.5rem;
padding: 0.5rem;
background-color: var(--color-background-soft);
transition: background-color 0.3s;
span {
display: flex;
align-items: center;
gap: 0.5rem;
font-weight: 700;
}
p {
text-align: center;
font-size: 0.8rem;
}
&:hover {
background-color: var(--color-hover);
}
&.selected {
background-color: var(--color-primary-mute);
}
}
}
</style>
|