Skip to content

Commit c2eab04

Browse files
committed
Reduce duplication in TrackEncounter settings config
- Extract five option arrays as module-level constants (SHOW_HIDE, NPC_HEALTH, NPC_AC, PLAYER_HEALTH, DEATH_SAVES) to eliminate repeated inline definitions - Extract npcTypeSettings() factory to generate the identical allies/enemies setting blocks from a single source, parameterised by entity and label - Fix bug: player Conditions entry used 'condition' key instead of 'key', breaking displaySetting lookup and setSetting calls
1 parent a7fe072 commit c2eab04

1 file changed

Lines changed: 43 additions & 300 deletions

File tree

src/components/settings/TrackEncounter.vue

Lines changed: 43 additions & 300 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,42 @@
9595
<script>
9696
import { mapGetters, mapActions } from "vuex";
9797
98+
const SHOW_HIDE = [
99+
{ value: false, name: "Hidden", action: "Hide", icon: "fas fa-eye-slash", color: "red" },
100+
{ value: undefined, name: "Shown", action: "Show", icon: "fas fa-eye", color: "green" },
101+
];
102+
103+
const NPC_HEALTH = [
104+
{ value: undefined, name: "Hidden", action: "Hide", icon: "fas fa-eye-slash", color: "red" },
105+
{ value: "obscured", name: "Obsc", action: "Obsc", icon: "fas fa-question-circle", color: "orange" },
106+
{ value: true, name: "Shown", action: "Show", icon: "fas fa-eye", color: "green" },
107+
];
108+
109+
const NPC_AC = [
110+
{ value: undefined, name: "Hidden", action: "Hide", icon: "fas fa-eye-slash", color: "red" },
111+
{ value: true, name: "Shown", action: "Show", icon: "fas fa-eye", color: "green" },
112+
];
113+
114+
const PLAYER_HEALTH = [
115+
{ value: false, name: "Hidden", action: "Hide", icon: "fas fa-eye-slash", color: "red" },
116+
{ value: "obscured", name: "Obsc", action: "Obsc", icon: "fas fa-question-circle", color: "orange" },
117+
{ value: undefined, name: "Shown", action: "Show", icon: "fas fa-eye", color: "green" },
118+
];
119+
120+
const DEATH_SAVES = [
121+
{ value: true, name: "Hidden", action: "Hide", icon: "fas fa-eye-slash", color: "red" },
122+
{ value: undefined, name: "Shown", action: "Show", icon: "fas fa-eye", color: "green" },
123+
];
124+
125+
function npcTypeSettings(entity, label) {
126+
return [
127+
{ key: "name", entity, name: "Name", icon: "fas fa-helmet-battle", info: `Players can see the names of ${label}.`, options: SHOW_HIDE },
128+
{ key: "health", entity, name: "Health", icon: "fas fa-heart", info: `Players can see the health of ${label}.`, options: NPC_HEALTH },
129+
{ key: "ac", entity, name: "Armor Class", icon: "fas fa-shield", info: `Players can see the armor class of ${label}.`, options: NPC_AC },
130+
{ key: "conditions", entity, name: "Conditions", icon: "fas fa-flame", info: `Players can see the conditions on ${label}.`, options: SHOW_HIDE },
131+
];
132+
}
133+
98134
export default {
99135
name: "TrackEncounterSettings",
100136
data() {
@@ -103,317 +139,24 @@ export default {
103139
types: {
104140
general: {
105141
type_settings: [
106-
{
107-
key: "meters",
108-
entity: "player",
109-
name: "Damage Meters",
110-
icon: "fas fa-swords",
111-
info: "Players can see the damage meters.",
112-
options: [
113-
{
114-
value: false,
115-
name: "Hidden",
116-
action: "Hide",
117-
icon: "fas fa-eye-slash",
118-
color: "red",
119-
},
120-
{
121-
value: undefined,
122-
name: "Shown",
123-
action: "Show",
124-
icon: "fas fa-eye",
125-
color: "green",
126-
},
127-
],
128-
},
142+
{ key: "meters", entity: "player", name: "Damage Meters", icon: "fas fa-swords", info: "Players can see the damage meters.", options: SHOW_HIDE },
129143
],
130144
},
131145
npcs: {
132146
name: "Enemies",
133-
type_settings: [
134-
{
135-
key: "name",
136-
entity: "npc",
137-
name: "Name",
138-
icon: "fas fa-helmet-battle",
139-
info: "Players can see the names of NPC's.",
140-
options: [
141-
{
142-
value: false,
143-
name: "Hidden",
144-
action: "Hide",
145-
icon: "fas fa-eye-slash",
146-
color: "red",
147-
},
148-
{
149-
value: undefined,
150-
name: "Shown",
151-
action: "Show",
152-
icon: "fas fa-eye",
153-
color: "green",
154-
},
155-
],
156-
},
157-
{
158-
key: "health",
159-
entity: "npc",
160-
name: "Health",
161-
icon: "fas fa-heart",
162-
info: "Players can see the health of NPC's.",
163-
options: [
164-
{
165-
value: undefined,
166-
name: "Hidden",
167-
action: "Hide",
168-
icon: "fas fa-eye-slash",
169-
color: "red",
170-
},
171-
{
172-
value: "obscured",
173-
name: "Obsc",
174-
action: "Obsc",
175-
icon: "fas fa-question-circle",
176-
color: "orange",
177-
},
178-
{ value: true, name: "Shown", action: "Show", icon: "fas fa-eye", color: "green" },
179-
],
180-
},
181-
{
182-
key: "ac",
183-
entity: "npc",
184-
name: "Armor Class",
185-
icon: "fas fa-shield",
186-
info: "Players can see the armor class of NPC's.",
187-
options: [
188-
{
189-
value: undefined,
190-
name: "Hidden",
191-
action: "Hide",
192-
icon: "fas fa-eye-slash",
193-
color: "red",
194-
},
195-
{ value: true, name: "Shown", action: "Show", icon: "fas fa-eye", color: "green" },
196-
],
197-
},
198-
{
199-
key: "conditions",
200-
entity: "npc",
201-
name: "Conditions",
202-
icon: "fas fa-flame",
203-
info: "Players can see the conditions on NPC's.",
204-
options: [
205-
{
206-
value: false,
207-
name: "Hidden",
208-
action: "Hide",
209-
icon: "fas fa-eye-slash",
210-
color: "red",
211-
},
212-
{
213-
value: undefined,
214-
name: "Shown",
215-
action: "Show",
216-
icon: "fas fa-eye",
217-
color: "green",
218-
},
219-
],
220-
},
221-
],
147+
type_settings: npcTypeSettings("npc", "NPC's"),
222148
},
223149
allies: {
224150
name: "Allies",
225-
type_settings: [
226-
{
227-
key: "name",
228-
entity: "ally",
229-
name: "Name",
230-
icon: "fas fa-helmet-battle",
231-
info: "Players can see the names of allied NPC's.",
232-
options: [
233-
{
234-
value: false,
235-
name: "Hidden",
236-
action: "Hide",
237-
icon: "fas fa-eye-slash",
238-
color: "red",
239-
},
240-
{
241-
value: undefined,
242-
name: "Shown",
243-
action: "Show",
244-
icon: "fas fa-eye",
245-
color: "green",
246-
},
247-
],
248-
},
249-
{
250-
key: "health",
251-
entity: "ally",
252-
name: "Health",
253-
icon: "fas fa-heart",
254-
info: "Players can see the health of allied NPC's.",
255-
options: [
256-
{
257-
value: undefined,
258-
name: "Hidden",
259-
action: "Hide",
260-
icon: "fas fa-eye-slash",
261-
color: "red",
262-
},
263-
{
264-
value: "obscured",
265-
name: "Obsc",
266-
action: "Obsc",
267-
icon: "fas fa-question-circle",
268-
color: "orange",
269-
},
270-
{ value: true, name: "Shown", action: "Show", icon: "fas fa-eye", color: "green" },
271-
],
272-
},
273-
{
274-
key: "ac",
275-
entity: "ally",
276-
name: "Armor Class",
277-
icon: "fas fa-shield",
278-
info: "Players can see the armor class of allied NPC's.",
279-
options: [
280-
{
281-
value: undefined,
282-
name: "Hidden",
283-
action: "Hide",
284-
icon: "fas fa-eye-slash",
285-
color: "red",
286-
},
287-
{ value: true, name: "Shown", action: "Show", icon: "fas fa-eye", color: "green" },
288-
],
289-
},
290-
{
291-
key: "conditions",
292-
entity: "ally",
293-
name: "Conditions",
294-
icon: "fas fa-flame",
295-
info: "Players can see the conditions on allied NPC's.",
296-
options: [
297-
{
298-
value: false,
299-
name: "Hidden",
300-
action: "Hide",
301-
icon: "fas fa-eye-slash",
302-
color: "red",
303-
},
304-
{
305-
value: undefined,
306-
name: "Shown",
307-
action: "Show",
308-
icon: "fas fa-eye",
309-
color: "green",
310-
},
311-
],
312-
},
313-
],
151+
type_settings: npcTypeSettings("ally", "allied NPC's"),
314152
},
315153
players: {
316154
name: "Players",
317155
type_settings: [
318-
{
319-
key: "health",
320-
entity: "player",
321-
name: "Health",
322-
icon: "fas fa-heart",
323-
info: "Players can see the health of players.",
324-
options: [
325-
{
326-
value: false,
327-
name: "Hidden",
328-
action: "Hide",
329-
icon: "fas fa-eye-slash",
330-
color: "red",
331-
},
332-
{
333-
value: "obscured",
334-
name: "Obsc",
335-
action: "Obsc",
336-
icon: "fas fa-question-circle",
337-
color: "orange",
338-
},
339-
{
340-
value: undefined,
341-
name: "Shown",
342-
action: "Show",
343-
icon: "fas fa-eye",
344-
color: "green",
345-
},
346-
],
347-
},
348-
{
349-
key: "ac",
350-
entity: "player",
351-
name: "Armor Class",
352-
icon: "fas fa-shield",
353-
info: "Players can see the armor class of players.",
354-
options: [
355-
{
356-
value: false,
357-
name: "Hidden",
358-
action: "Hide",
359-
icon: "fas fa-eye-slash",
360-
color: "red",
361-
},
362-
{
363-
value: undefined,
364-
name: "Shown",
365-
action: "Show",
366-
icon: "fas fa-eye",
367-
color: "green",
368-
},
369-
],
370-
},
371-
{
372-
condition: "conditions",
373-
entity: "player",
374-
name: "Conditions",
375-
icon: "fas fa-flame",
376-
info: "Players can see the conditions of players.",
377-
options: [
378-
{
379-
value: false,
380-
name: "Hidden",
381-
action: "Hide",
382-
icon: "fas fa-eye-slash",
383-
color: "red",
384-
},
385-
{
386-
value: undefined,
387-
name: "Shown",
388-
action: "Show",
389-
icon: "fas fa-eye",
390-
color: "green",
391-
},
392-
],
393-
},
394-
{
395-
key: "hide_death_saves",
396-
entity: "player",
397-
name: "Death Saves",
398-
icon: "fas fa-skull-crossbones",
399-
info: "Players can see the death saves/fails of other players.",
400-
options: [
401-
{
402-
value: true,
403-
name: "Hidden",
404-
action: "Hide",
405-
icon: "fas fa-eye-slash",
406-
color: "red",
407-
},
408-
{
409-
value: undefined,
410-
name: "Shown",
411-
action: "Show",
412-
icon: "fas fa-eye",
413-
color: "green",
414-
},
415-
],
416-
},
156+
{ key: "health", entity: "player", name: "Health", icon: "fas fa-heart", info: "Players can see the health of players.", options: PLAYER_HEALTH },
157+
{ key: "ac", entity: "player", name: "Armor Class", icon: "fas fa-shield", info: "Players can see the armor class of players.", options: SHOW_HIDE },
158+
{ key: "conditions", entity: "player", name: "Conditions", icon: "fas fa-flame", info: "Players can see the conditions of players.", options: SHOW_HIDE },
159+
{ key: "hide_death_saves", entity: "player", name: "Death Saves", icon: "fas fa-skull-crossbones", info: "Players can see the death saves/fails of other players.", options: DEATH_SAVES },
417160
],
418161
},
419162
},

0 commit comments

Comments
 (0)