Added new dialog settings to configure default skill list.
Added uuid compatibility for tooltips
This commit is contained in:
148
system/scripts/settings/default-skills-dialog.js
Normal file
148
system/scripts/settings/default-skills-dialog.js
Normal file
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* L5R Settings dialog for default skills list
|
||||
* @extends {FormApplication}
|
||||
*/
|
||||
export class DefaultSkillsDialogL5r5e extends FormApplication {
|
||||
/**
|
||||
* Key for skills list in Settings
|
||||
* @type {string}
|
||||
*/
|
||||
static skillsLisKey = "defaultSkillsList";
|
||||
|
||||
/**
|
||||
* Assign the default options
|
||||
* @override
|
||||
*/
|
||||
static get defaultOptions() {
|
||||
return foundry.utils.mergeObject(super.defaultOptions, {
|
||||
id: "l5r5e-settings-default-skills-dialog",
|
||||
classes: ["l5r5e", "settings", "default-skills"],
|
||||
template: CONFIG.l5r5e.paths.templates + "settings/default-skills-dialog.html",
|
||||
title: game.i18n.localize("SETTINGS.DefaultSkillsList.Label"),
|
||||
width: 500,
|
||||
height: 680,
|
||||
resizable: true,
|
||||
closeOnSubmit: false,
|
||||
submitOnClose: false,
|
||||
submitOnChange: false,
|
||||
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent non GM to render this windows
|
||||
* @override
|
||||
*/
|
||||
render(force = false, options = {}) {
|
||||
if (!this.isEditable) {
|
||||
console.log("L5R5E | You don't have the rights to display this application");
|
||||
return false;
|
||||
}
|
||||
return super.render(force, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the Form Application currently editable?
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isEditable() {
|
||||
return game.user.isGM;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct and return the data object used to render the HTML template for this form application.
|
||||
* @param options
|
||||
* @return {Object}
|
||||
*/
|
||||
async getData(options = null) {
|
||||
// Transform skills uuids to items by categories
|
||||
let skillList = await game.l5r5e.HelpersL5r5e.getDefaultSkillsItems();
|
||||
skillList = game.l5r5e.HelpersL5r5e.splitSkillByCategory(skillList);
|
||||
|
||||
return {
|
||||
...(await super.getData(options)),
|
||||
skillList,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle dropped data on the Actor sheet
|
||||
* @param {DragEvent} event
|
||||
*/
|
||||
async _onDrop(event) {
|
||||
// *** Everything below here is only needed if the sheet is editable ***
|
||||
if (!this.isEditable) {
|
||||
console.log("L5R5E | This sheet is not editable");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check item type and subtype
|
||||
const item = await game.l5r5e.HelpersL5r5e.getDragnDropTargetObject(event);
|
||||
if (!item || item.documentName !== "Item" || item?.type !== "skill") {
|
||||
console.log(`L5R5E | Item dropped must be a Skill Item : ${item?.type}`, item);
|
||||
return;
|
||||
}
|
||||
|
||||
// EmbedItem actor item ?
|
||||
if (item.uuid.startsWith('Actor.')) {
|
||||
console.log("L5R5E | This element has been ignored because it's a EmbedItem actor item", item.uuid);
|
||||
return;
|
||||
}
|
||||
|
||||
const skillListUuids = game.settings.get(CONFIG.l5r5e.systemName, DefaultSkillsDialogL5r5e.skillsLisKey) || [];
|
||||
|
||||
// Dropped an item with same "id" as one owned
|
||||
if (skillListUuids.some((embedItem) => embedItem.uuid === item.uuid)) {
|
||||
console.log("L5R5E | This element has been ignored because it already exists", item.uuid);
|
||||
return;
|
||||
}
|
||||
|
||||
// Add the uuid and save
|
||||
skillListUuids.push(item.uuid);
|
||||
await game.settings.set(CONFIG.l5r5e.systemName, DefaultSkillsDialogL5r5e.skillsLisKey, skillListUuids);
|
||||
|
||||
// Refresh
|
||||
this.render(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to events from the sheet.
|
||||
* @param {jQuery} html HTML content of the sheet.
|
||||
*/
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
// Commons
|
||||
game.l5r5e.HelpersL5r5e.commonListeners(html);
|
||||
|
||||
// *** Everything below here is only needed if the sheet is editable ***
|
||||
if (!this.isEditable) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Delete an item
|
||||
html.find(`.item-delete`).on("click", this._removeSkill.bind(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from it's uuid
|
||||
* @param {Event} event
|
||||
* @private
|
||||
*/
|
||||
async _removeSkill(event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
const itemUuid = $(event.currentTarget).data("item-uuid");
|
||||
if (!itemUuid) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove and save
|
||||
const skillListUuids = game.settings.get(CONFIG.l5r5e.systemName, DefaultSkillsDialogL5r5e.skillsLisKey) || [];
|
||||
await game.settings.set(CONFIG.l5r5e.systemName, DefaultSkillsDialogL5r5e.skillsLisKey, skillListUuids.filter((uuid) => uuid !== itemUuid));
|
||||
|
||||
// Refresh
|
||||
this.render(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user