mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
Added support for wildcard paths in beastform token paths
This commit is contained in:
parent
a7d035bcdb
commit
200349be3b
11 changed files with 171 additions and 2 deletions
|
|
@ -441,6 +441,10 @@
|
|||
"genericEffects": "Foundry Effects"
|
||||
}
|
||||
},
|
||||
"ImageSelect": {
|
||||
"title": "Select Image",
|
||||
"selectImage": "Select Image"
|
||||
},
|
||||
"Levelup": {
|
||||
"actions": {
|
||||
"creatureComfort": {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ export { default as DamageDialog } from './damageDialog.mjs';
|
|||
export { default as DamageReductionDialog } from './damageReductionDialog.mjs';
|
||||
export { default as DeathMove } from './deathMove.mjs';
|
||||
export { default as Downtime } from './downtime.mjs';
|
||||
export { default as ImageSelectDialog } from './imageSelectDialog.mjs';
|
||||
export { default as MulticlassChoiceDialog } from './multiclassChoiceDialog.mjs';
|
||||
export { default as OwnershipSelection } from './ownershipSelection.mjs';
|
||||
export { default as RerollDamageDialog } from './rerollDamageDialog.mjs';
|
||||
|
|
|
|||
|
|
@ -276,7 +276,22 @@ export default class BeastformDialog extends HandlebarsApplicationMixin(Applicat
|
|||
const featureItem = item;
|
||||
app.addEventListener(
|
||||
'close',
|
||||
() => resolve({ selected: app.selected, evolved: app.evolved, hybrid: app.hybrid, item: featureItem }),
|
||||
async () => {
|
||||
const selected = app.selected.toObject();
|
||||
const data = await game.system.api.data.items.DHBeastform.getWildcardImage(
|
||||
app.configData.data.parent,
|
||||
app.selected
|
||||
);
|
||||
if (data) {
|
||||
if (!data.selectedImage) selected = null;
|
||||
else {
|
||||
if (data.usesDynamicToken) selected.system.tokenRingImg = data.selectedImage;
|
||||
else selected.system.tokenImg = data.selectedImage;
|
||||
}
|
||||
}
|
||||
|
||||
resolve({ selected: selected, evolved: app.evolved, hybrid: app.hybrid, item: featureItem });
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
app.render({ force: true });
|
||||
|
|
|
|||
67
module/applications/dialogs/imageSelectDialog.mjs
Normal file
67
module/applications/dialogs/imageSelectDialog.mjs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api;
|
||||
|
||||
export default class ImageSelectDialog extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
constructor(titleName, images) {
|
||||
super();
|
||||
|
||||
this.titleName = titleName;
|
||||
this.images = images;
|
||||
}
|
||||
|
||||
static DEFAULT_OPTIONS = {
|
||||
tag: 'form',
|
||||
classes: ['daggerheart', 'dialog', 'dh-style', 'image-select'],
|
||||
position: {
|
||||
width: 600,
|
||||
height: 'auto'
|
||||
},
|
||||
window: {
|
||||
icon: 'fa-solid fa-paw'
|
||||
},
|
||||
actions: {
|
||||
selectImage: ImageSelectDialog.#selectImage,
|
||||
finishSelection: ImageSelectDialog.#finishSelection
|
||||
}
|
||||
};
|
||||
|
||||
get title() {
|
||||
return this.titleName;
|
||||
}
|
||||
|
||||
/** @override */
|
||||
static PARTS = {
|
||||
main: { template: 'systems/daggerheart/templates/dialogs/image-select/main.hbs' },
|
||||
footer: { template: 'systems/daggerheart/templates/dialogs/image-select/footer.hbs' }
|
||||
};
|
||||
|
||||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
context.images = this.images;
|
||||
context.selectedImage = this.selectedImage;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
static #selectImage(_event, button) {
|
||||
this.selectedImage = button.dataset.image ?? button.querySelector('img').dataset.image;
|
||||
this.render();
|
||||
}
|
||||
|
||||
static #finishSelection() {
|
||||
this.close({ submitted: true });
|
||||
}
|
||||
|
||||
async close(options = {}) {
|
||||
if (!options.submitted) this.selectedImage = null;
|
||||
|
||||
await super.close();
|
||||
}
|
||||
|
||||
static async configure(title, images) {
|
||||
return new Promise(resolve => {
|
||||
const app = new this(title, images);
|
||||
app.addEventListener('close', () => resolve(app.selectedImage), { once: true });
|
||||
app.render({ force: true });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -844,6 +844,23 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
itemData.system.inVault = true;
|
||||
}
|
||||
|
||||
if (item.type === 'beastform') {
|
||||
if (this.document.effects.find(x => x.type === 'beastform')) {
|
||||
return ui.notifications.warn(
|
||||
game.i18n.localize('DAGGERHEART.UI.Notifications.beastformAlreadyApplied')
|
||||
);
|
||||
}
|
||||
|
||||
const data = await game.system.api.data.items.DHBeastform.getWildcardImage(this.document, itemData);
|
||||
if (data) {
|
||||
if (!data.selectedImage) return;
|
||||
else {
|
||||
if (data.usesDynamicToken) itemData.system.tokenRingImg = data.selectedImage;
|
||||
else itemData.system.tokenImg = data.selectedImage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.document.uuid === item.parent?.uuid) return this._onSortItem(event, itemData);
|
||||
const createdItem = await this._onDropItemCreate(itemData);
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ export default class BeastformField extends fields.SchemaField {
|
|||
* @returns
|
||||
*/
|
||||
static async transform(selectedForm, evolvedData, hybridData) {
|
||||
const formData = evolvedData?.form ? evolvedData.form.toObject() : selectedForm.toObject();
|
||||
const formData = evolvedData?.form ? evolvedData.form.toObject() : selectedForm;
|
||||
const beastformEffect = formData.effects.find(x => x.type === 'beastform');
|
||||
if (!beastformEffect) {
|
||||
ui.notifications.error('DAGGERHEART.UI.Notifications.beastformMissingEffect');
|
||||
|
|
|
|||
|
|
@ -33,11 +33,13 @@ export default class DHBeastform extends BaseDataItem {
|
|||
tokenImg: new fields.FilePathField({
|
||||
initial: 'icons/svg/mystery-man.svg',
|
||||
categories: ['IMAGE'],
|
||||
wildcard: true,
|
||||
base64: false
|
||||
}),
|
||||
tokenRingImg: new fields.FilePathField({
|
||||
initial: 'icons/svg/mystery-man.svg',
|
||||
categories: ['IMAGE'],
|
||||
wildcard: true,
|
||||
base64: false
|
||||
}),
|
||||
tokenSize: new fields.SchemaField({
|
||||
|
|
@ -108,6 +110,25 @@ export default class DHBeastform extends BaseDataItem {
|
|||
};
|
||||
}
|
||||
|
||||
static async getWildcardImage(actor, beastform) {
|
||||
const usesDynamicToken = actor.prototypeToken.ring.enabled && beastform.system.tokenRingImg;
|
||||
const tokenPath = usesDynamicToken ? beastform.system.tokenRingImg : beastform.system.tokenImg;
|
||||
const usesWildcard = tokenPath.includes('*');
|
||||
if (usesWildcard) {
|
||||
const { files } = await foundry.applications.apps.FilePicker.implementation.browse('data', tokenPath, {
|
||||
wildcard: true,
|
||||
type: 'image'
|
||||
});
|
||||
const selectedImage = await game.system.api.applications.dialogs.ImageSelectDialog.configure(
|
||||
game.i18n.localize('DAGGERHEART.APPLICATIONS.ImageSelect.title'),
|
||||
files
|
||||
);
|
||||
return { usesDynamicToken, selectedImage };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
async _preCreate() {
|
||||
if (!this.actor) return;
|
||||
|
||||
|
|
|
|||
33
styles/less/dialog/image-select/sheet.less
Normal file
33
styles/less/dialog/image-select/sheet.less
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
.daggerheart.dh-style.dialog.image-select {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.images-container {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
|
||||
img {
|
||||
width: 136px;
|
||||
height: 136px;
|
||||
border: 1px solid light-dark(@dark-blue, @golden);
|
||||
border-radius: 6px;
|
||||
opacity: 0.4;
|
||||
|
||||
&.selected {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.footer {
|
||||
margin-top: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
button {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -30,3 +30,5 @@
|
|||
@import './multiclass-choice/sheet.less';
|
||||
|
||||
@import './reroll-dialog/sheet.less';
|
||||
|
||||
@import './image-select/sheet.less';
|
||||
|
|
|
|||
4
templates/dialogs/image-select/footer.hbs
Normal file
4
templates/dialogs/image-select/footer.hbs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<div class="footer">
|
||||
<button data-action="close">{{localize "Cancel"}}</button>
|
||||
<button type="button" data-action="finishSelection">{{localize "DAGGERHEART.APPLICATIONS.ImageSelect.selectImage"}}</button>
|
||||
</div>
|
||||
5
templates/dialogs/image-select/main.hbs
Normal file
5
templates/dialogs/image-select/main.hbs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<div class="images-container">
|
||||
{{#each images as |image|}}
|
||||
<a data-action="selectImage"><img {{#if (eq image @root.selectedImage)}}class="selected"{{/if}} src="{{image}}" data-image="{{image}}" /></a>
|
||||
{{/each}}
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue