mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
[PR][Feature] 798 - Attribution (#986)
* Added attribution for items, adversary and environment * Added Attribution to all adversaries * Added attribution to environments * Added attribution for class and subclass * Added Attribution to Ancestry/Community * Added Attribution for Beastforms * Added Attribution to DomainCards * Added Attribution for wepaons * Attribution for Armor/Loot/Consumables * Added a setting to hide attribution
This commit is contained in:
parent
495575fba4
commit
8c84edddad
982 changed files with 9082 additions and 3996 deletions
|
|
@ -1,3 +1,4 @@
|
|||
export { default as AttributionDialog } from './attributionDialog.mjs';
|
||||
export { default as BeastformDialog } from './beastformDialog.mjs';
|
||||
export { default as d20RollDialog } from './d20RollDialog.mjs';
|
||||
export { default as DamageDialog } from './damageDialog.mjs';
|
||||
|
|
|
|||
93
module/applications/dialogs/attributionDialog.mjs
Normal file
93
module/applications/dialogs/attributionDialog.mjs
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
import autocomplete from 'autocompleter';
|
||||
|
||||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||
|
||||
export default class AttriubtionDialog extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
constructor(item) {
|
||||
super({});
|
||||
|
||||
this.item = item;
|
||||
this.sources = Object.keys(CONFIG.DH.GENERAL.attributionSources).flatMap(groupKey => {
|
||||
const group = CONFIG.DH.GENERAL.attributionSources[groupKey];
|
||||
return group.values.map(x => ({ group: group.label, ...x }));
|
||||
});
|
||||
}
|
||||
|
||||
get title() {
|
||||
return game.i18n.localize('DAGGERHEART.APPLICATIONS.Attribution.title');
|
||||
}
|
||||
|
||||
static DEFAULT_OPTIONS = {
|
||||
tag: 'form',
|
||||
classes: ['daggerheart', 'dh-style', 'dialog', 'views', 'attribution'],
|
||||
position: { width: 'auto', height: 'auto' },
|
||||
window: { icon: 'fa-solid fa-signature' },
|
||||
form: { handler: this.updateData, submitOnChange: false, closeOnSubmit: true }
|
||||
};
|
||||
|
||||
static PARTS = {
|
||||
main: { template: 'systems/daggerheart/templates/dialogs/attribution.hbs' }
|
||||
};
|
||||
|
||||
_attachPartListeners(partId, htmlElement, options) {
|
||||
super._attachPartListeners(partId, htmlElement, options);
|
||||
const sources = this.sources;
|
||||
|
||||
htmlElement.querySelectorAll('.attribution-input').forEach(element => {
|
||||
autocomplete({
|
||||
input: element,
|
||||
fetch: function (text, update) {
|
||||
if (!text) {
|
||||
update(sources);
|
||||
} else {
|
||||
text = text.toLowerCase();
|
||||
var suggestions = sources.filter(n => n.label.toLowerCase().includes(text));
|
||||
update(suggestions);
|
||||
}
|
||||
},
|
||||
render: function (item, search) {
|
||||
const label = game.i18n.localize(item.label);
|
||||
const matchIndex = label.toLowerCase().indexOf(search);
|
||||
|
||||
const beforeText = label.slice(0, matchIndex);
|
||||
const matchText = label.slice(matchIndex, matchIndex + search.length);
|
||||
const after = label.slice(matchIndex + search.length, label.length);
|
||||
|
||||
const element = document.createElement('li');
|
||||
element.innerHTML = `${beforeText}${matchText ? `<strong>${matchText}</strong>` : ''}${after}`;
|
||||
if (item.hint) {
|
||||
element.dataset.tooltip = game.i18n.localize(item.hint);
|
||||
}
|
||||
|
||||
return element;
|
||||
},
|
||||
renderGroup: function (label) {
|
||||
const itemElement = document.createElement('div');
|
||||
itemElement.textContent = game.i18n.localize(label);
|
||||
return itemElement;
|
||||
},
|
||||
onSelect: function (item) {
|
||||
element.value = item.label;
|
||||
},
|
||||
click: e => e.fetch(),
|
||||
customize: function (_input, _inputRect, container) {
|
||||
container.style.zIndex = foundry.applications.api.ApplicationV2._maxZ;
|
||||
},
|
||||
minLength: 0
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
context.item = this.item;
|
||||
context.data = this.item.system.attribution;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
static async updateData(_event, _element, formData) {
|
||||
await this.item.update({ 'system.attribution': formData.object });
|
||||
this.item.sheet.refreshFrame();
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import DHBaseActorSheet from '../api/base-actor.mjs';
|
|||
/**@typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction */
|
||||
|
||||
export default class AdversarySheet extends DHBaseActorSheet {
|
||||
/** @inheritDoc */
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: ['adversary'],
|
||||
position: { width: 660, height: 766 },
|
||||
|
|
@ -12,7 +13,14 @@ export default class AdversarySheet extends DHBaseActorSheet {
|
|||
reactionRoll: AdversarySheet.#reactionRoll
|
||||
},
|
||||
window: {
|
||||
resizable: true
|
||||
resizable: true,
|
||||
controls: [
|
||||
{
|
||||
icon: 'fa-solid fa-signature',
|
||||
label: 'DAGGERHEART.UI.Tooltip.configureAttribution',
|
||||
action: 'editAttribution'
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -8,10 +8,17 @@ export default class DhpEnvironment extends DHBaseActorSheet {
|
|||
classes: ['environment'],
|
||||
position: {
|
||||
width: 500,
|
||||
height: 725
|
||||
height: 740
|
||||
},
|
||||
window: {
|
||||
resizable: true
|
||||
resizable: true,
|
||||
controls: [
|
||||
{
|
||||
icon: 'fa-solid fa-signature',
|
||||
label: 'DAGGERHEART.UI.Tooltip.configureAttribution',
|
||||
action: 'editAttribution'
|
||||
}
|
||||
]
|
||||
},
|
||||
actions: {},
|
||||
dragDrop: [{ dragSelector: '.action-section .inventory-item', dropSelector: null }]
|
||||
|
|
@ -42,6 +49,7 @@ export default class DhpEnvironment extends DHBaseActorSheet {
|
|||
switch (partId) {
|
||||
case 'header':
|
||||
await this._prepareHeaderContext(context, options);
|
||||
|
||||
break;
|
||||
case 'notes':
|
||||
await this._prepareNotesContext(context, options);
|
||||
|
|
|
|||
|
|
@ -85,6 +85,8 @@ export default function DHApplicationMixin(Base) {
|
|||
this._dragDrop = this._createDragDropHandlers();
|
||||
}
|
||||
|
||||
#nonHeaderAttribution = ['environment', 'ancestry', 'community', 'domainCard'];
|
||||
|
||||
/**
|
||||
* The default options for the sheet.
|
||||
* @type {DHSheetV2Configuration}
|
||||
|
|
@ -101,7 +103,8 @@ export default function DHApplicationMixin(Base) {
|
|||
toggleEffect: DHSheetV2.#toggleEffect,
|
||||
toggleExtended: DHSheetV2.#toggleExtended,
|
||||
addNewItem: DHSheetV2.#addNewItem,
|
||||
browseItem: DHSheetV2.#browseItem
|
||||
browseItem: DHSheetV2.#browseItem,
|
||||
editAttribution: DHSheetV2.#editAttribution
|
||||
},
|
||||
contextMenus: [
|
||||
{
|
||||
|
|
@ -125,6 +128,43 @@ export default function DHApplicationMixin(Base) {
|
|||
tagifyConfigs: []
|
||||
};
|
||||
|
||||
/**@inheritdoc */
|
||||
async _renderFrame(options) {
|
||||
const frame = await super._renderFrame(options);
|
||||
|
||||
const hideAttribution = game.settings.get(
|
||||
CONFIG.DH.id,
|
||||
CONFIG.DH.SETTINGS.gameSettings.appearance
|
||||
).hideAttribution;
|
||||
const headerAttribution = !this.#nonHeaderAttribution.includes(this.document.type);
|
||||
if (!hideAttribution && this.document.system.metadata.hasAttribution && headerAttribution) {
|
||||
const { source, page } = this.document.system.attribution;
|
||||
const attribution = [source, page ? `pg ${page}.` : null].filter(x => x).join('. ');
|
||||
const element = `<label class="attribution-header-label">${attribution}</label>`;
|
||||
this.window.controls.insertAdjacentHTML('beforebegin', element);
|
||||
}
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the custom parts of the application frame
|
||||
*/
|
||||
refreshFrame() {
|
||||
const hideAttribution = game.settings.get(
|
||||
CONFIG.DH.id,
|
||||
CONFIG.DH.SETTINGS.gameSettings.appearance
|
||||
).hideAttribution;
|
||||
const headerAttribution = !this.#nonHeaderAttribution.includes(this.document.type);
|
||||
if (!hideAttribution && this.document.system.metadata.hasAttribution && headerAttribution) {
|
||||
const { source, page } = this.document.system.attribution;
|
||||
const attribution = [source, page ? `pg ${page}.` : null].filter(x => x).join('. ');
|
||||
|
||||
const label = this.window.header.querySelector('.attribution-header-label');
|
||||
label.innerHTML = attribution;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Related documents that should cause a rerender of this application when updated.
|
||||
*/
|
||||
|
|
@ -548,6 +588,14 @@ export default function DHApplicationMixin(Base) {
|
|||
return new ItemBrowser({ presets }).render({ force: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the attribution dialog
|
||||
* @type {ApplicationClickAction}
|
||||
*/
|
||||
static async #editAttribution() {
|
||||
new game.system.api.applications.dialogs.AttributionDialog(this.document).render({ force: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an embedded document.
|
||||
* @type {ApplicationClickAction}
|
||||
|
|
|
|||
|
|
@ -55,6 +55,9 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
|
|||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
context.isNPC = this.document.isNPC;
|
||||
context.showAttribution = !game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance)
|
||||
.hideAttribution;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,16 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
|
|||
static DEFAULT_OPTIONS = {
|
||||
classes: ['item'],
|
||||
position: { width: 600 },
|
||||
window: { resizable: true },
|
||||
window: {
|
||||
resizable: true,
|
||||
controls: [
|
||||
{
|
||||
icon: 'fa-solid fa-signature',
|
||||
label: 'DAGGERHEART.UI.Tooltip.configureAttribution',
|
||||
action: 'editAttribution'
|
||||
}
|
||||
]
|
||||
},
|
||||
form: {
|
||||
submitOnChange: true
|
||||
},
|
||||
|
|
@ -55,6 +64,15 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
|
|||
/* Prepare Context */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**@inheritdoc */
|
||||
async _prepareContext(options) {
|
||||
const context = super._prepareContext(options);
|
||||
context.showAttribution = !game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance)
|
||||
.hideAttribution;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
/**@inheritdoc */
|
||||
async _preparePartContext(partId, context, options) {
|
||||
await super._preparePartContext(partId, context, options);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue