-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquest-log.js
105 lines (91 loc) · 2.76 KB
/
quest-log.js
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
const MODULE = 'quest-log';
/**
* Quest state patterns.
*/
const ACTIVE_PATTERN = /\(((in progress)|(active))\)/i;
const COMPLETE_PATTERN = /\(((completed?)|(done))\)/i;
/**
* Quest types & icons.
*/
const questTypes = [
{
name: 'Main Quest',
pattern: /Main Quest: /i,
icon: (status, color) => `modules/quest-log/icons/Main_${status}_${color}.png`,
},
{
name: 'Side Quest',
pattern: /(Side )?Quest: /i,
icon: status => `modules/quest-log/icons/Side_${status}.png`,
}
];
/**
* Initialize the module.
*/
Hooks.once('init', () => {
game.settings.register(MODULE, 'color', {
name: "Color Scheme",
hint: "The color to use for main quest icons.",
choices: {Red: "Red", Purple: "Purple", Green: "Green" },
default: "Red",
scope: "world",
config: true,
type: String,
onChange: () => ui.sidebar.render(),
});
});
/**
* This hook is fired when rendering Foundry's
* journal sidebar interface.
*
* @param {JournalDirectory} app - https://foundryvtt.com/api/JournalDirectory.html
* @param {jQuery} html
* @param {*} data
*/
Hooks.on("renderJournalDirectory", (app, html, data) => {
const color = game.settings.get(MODULE, 'color');
app.entities.forEach(j => {
const questType = questTypes.find(t => j.name.match(t.pattern));
const isHidden = j.data.permission.default === 0;
// If it's not a quest, we don't need to do anything...
if (!questType) {
return;
}
// If it's not in the log, we don't need to do anything...
const htmlEntry = html.find(`.directory-item.entity[data-entity-id="${j.id}"]`);
if (htmlEntry.length !== 1) {
return;
}
const statuses = [];
let icon = questType.icon('New', color);
if (j.name.match(ACTIVE_PATTERN)) {
statuses.push('In Progress');
icon = questType.icon('Progress', color);
} else if (j.name.match(COMPLETE_PATTERN)) {
statuses.push('Complete');
icon = questType.icon('Complete', color);
}
if (isHidden) {
statuses.push('Hidden');
}
const title = j.name
.replace(questType.pattern, '')
.replace(ACTIVE_PATTERN, '')
.replace(COMPLETE_PATTERN, '')
// Prepend with quest icon:
htmlEntry.prepend(`
<img
class="journal-quest-log-icon"
src="${icon}" title="${questType.name}"
style="${isHidden ? 'opacity: 0.5' : ''}; "
/>
`);
// Replace title & add subtitle:
htmlEntry.find('.entity-name a').text(title);
htmlEntry.find('h4.entity-name').append(`
<span class="journal-quest-log-subtitle">
${questType.name} ${statuses.length > 0 ? `(${statuses.join(', ')})` : ''}
</span>
`);
});
});