-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdndbeyond-character-sheet.js
175 lines (137 loc) · 4.63 KB
/
dndbeyond-character-sheet.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
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
class DNDBeyondCharacterSheet5e extends dnd5e.applications.actor.ActorSheet5eCharacter {
constructor(...args) {
super(...args);
/**
* Track the set of item filters which are applied
* @type {Set}
*/
this._filters = {
inventory: new Set(),
spellbook: new Set(),
features: new Set(),
actions: new Set()
};
}
get template() {
if (!game.user.isGM && this.actor.limited) return "systems/dnd5e/templates/actors/limited-sheet.hbs";
return "modules/dndbeyond-character-sheet/template/dndbeyond-character-sheet.html";
}
static get defaultOptions() {
const options = super.defaultOptions;
mergeObject(options, {
classes: ["dnd5e", "sheet", "actor", "character", "dndbcs"],
width: 1220,
height: 940,
blockActionsTab: true
});
return options;
}
/**
* Iinitialize Item list filters by activating the set of filters which are currently applied
* @private
*/
_initializeFilterItemList(i, ul) {
const set = this._filters[ul.dataset.filter];
const filters = ul.querySelectorAll(".filter-item");
for (let li of filters) {
if (set.has(li.dataset.filter)) li.classList.add("active");
}
}
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
let searchInput = html.find(".filter-search input");
searchInput.on("input", function() {
filterInventoryList(this, html);
});
}
async getData() {
const sheetData = await super.getData();
// Temporary HP
console.log("dndb", sheetData);
let hp = sheetData.system.attributes.hp;
if (hp.temp === 0) delete hp.temp;
if (hp.tempmax === 0) delete hp.tempmax;
// Resources
sheetData["resources"] = ["primary", "secondary", "tertiary"].reduce((arr, r) => {
const res = sheetData.system.resources[r] || {};
res.name = r;
res.placeholder = game.i18n.localize("DND5E.Resource" + r.titleCase());
if (res && res.value === 0) delete res.value;
if (res && res.max === 0) delete res.max;
return arr.concat([res]);
}, []);
// Experience Tracking
sheetData["disableExperience"] = game.settings.get("dnd5e", "disableExperienceTracking");
console.log("DNDBeyond-Character-Sheet | sheetData", sheetData);
return sheetData;
}
}
async function filterInventoryList(input, html) {
let id = $(input).attr("id");
let value = $(input).val().toLowerCase();
let searchTarget;
switch (id) {
case "inventory-search":
searchTarget = html.find(
".inventory-list:not(.actions-list):not(.spellbook-list):not(.features-list) .item-name.rollable"
);
break;
case "actions-search":
searchTarget = html.find(
".actions-list:not(.spellbook-list):not(.features-list) .item-name.rollable"
);
break;
case "spellbook-search":
searchTarget = html.find(
".spellbook-list .item-name.rollable"
);
break;
case "features-search":
searchTarget = html.find(".features-list .item-name.rollable");
break;
}
searchTarget.each(function() {
let itemName = $(this).text().toLowerCase().trim();
console.log(itemName, itemName.indexOf(value.toLowerCase()));
if (itemName.indexOf(value.toLowerCase()) >= 0) {
$(this).closest(".item").removeClass("filtered").show();
} else {
$(this).closest(".item").addClass("filtered").hide();
}
});
}
Hooks.once('init', async function () {
Handlebars.registerHelper('ifeq', function (a, b, options) {
if (a == b) {
return options.fn(this);
}
return options.inverse(this);
});
Handlebars.registerHelper('ifprepared', function (preparedmode, isprepared, options) {
if (preparedmode == "atwill" || preparedmode == "innate" || preparedmode == "always" || isprepared) {
return options.fn(this);
}
return options.inverse(this);
});
Handlebars.registerHelper('ifnoteq', function (a, b, options) {
if (a != b) {
return options.fn(this);
}
return options.inverse(this);
});
console.log("DNDBeyond-Character-Sheet | Loaded");
Actors.registerSheet('dnd5e', DNDBeyondCharacterSheet5e, {
types: ['character'],
makeDefault: false
});
});
Hooks.on('ready', () => {
try {
window.BetterRolls.hooks.addActorSheet("DNDBeyondCharacterSheet5e");
window.BetterRolls.hooks.addItemSheet("DNDBeyondCharacterSheet5e");
console.log("DNDBeyond-Character-Sheet | Enabled support for Better Rolls 5e");
} catch (error) {
console.log("DNDBeyond-Character-Sheet | Better Rolls 5e module not installed - no big deal, carry on!");
}
});