mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
Finalized functionality
This commit is contained in:
parent
f47a869af3
commit
27d49d35fa
11 changed files with 296 additions and 128 deletions
|
|
@ -1,5 +1,4 @@
|
|||
const fields = foundry.data.fields;
|
||||
import DHSummonDialog from '../../../applications/dialogs/summonDialog.mjs';
|
||||
|
||||
export default class DHSummonField extends fields.ArrayField {
|
||||
/**
|
||||
|
|
@ -24,71 +23,47 @@ export default class DHSummonField extends fields.ArrayField {
|
|||
}
|
||||
|
||||
static async execute() {
|
||||
if(!canvas.scene){
|
||||
ui.notifications.warn(game.i18n.localize("DAGGERHEART.ACTIONS.TYPES.summon.error"));
|
||||
if (!canvas.scene) {
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.ACTIONS.TYPES.summon.error'));
|
||||
return;
|
||||
}
|
||||
const validSummons = this.summon.filter(entry => entry.actorUUID);
|
||||
if (validSummons.length === 0) {
|
||||
console.log("No actors configured for this Summon action.");
|
||||
|
||||
if (this.summon.length === 0) {
|
||||
ui.notifications.warn('No actors configured for this Summon action.');
|
||||
return;
|
||||
}
|
||||
|
||||
for (const entry of validSummons) {
|
||||
const actor = await fromUuid(entry.actorUUID);
|
||||
}
|
||||
|
||||
// //Open Summon Dialog
|
||||
// const summonData = { summons: validSummons };
|
||||
// console.log(summonData);
|
||||
// const dialog = new DHSummonDialog(summonData);
|
||||
// dialog.render(true);
|
||||
const summonData = [];
|
||||
for (const summon of this.summon) {
|
||||
/* Possibly check for any available instances in the world with prepared images */
|
||||
let actor = await foundry.utils.fromUuid(summon.actorUUID);
|
||||
|
||||
// Create folder and add tokens to actor folder
|
||||
const rootFolderName = game.i18n.localize("DAGGERHEART.APPLICATIONS.Summon.title");
|
||||
let rootFolder = game.folders.find(f => f.name === rootFolderName && f.type === 'Actor');
|
||||
if (!rootFolder) {
|
||||
rootFolder = await Folder.create({
|
||||
name: rootFolderName,
|
||||
type: 'Actor',
|
||||
});
|
||||
}
|
||||
const parentName = this.item.name ?? "Unkown Feature";
|
||||
const actionName = this.name ?? "Unkown Action";
|
||||
const subFolderName = `${parentName} - ${actionName}`;
|
||||
|
||||
let subFolder = game.folders.find(f => f.name === subFolderName && f.type === 'Actor' && f.folder?.id === rootFolder.id);
|
||||
if (!subFolder) {
|
||||
subFolder = await Folder.create({
|
||||
name: subFolderName,
|
||||
type: 'Actor',
|
||||
folder: rootFolder.id
|
||||
});
|
||||
const actorsToSummon = [];
|
||||
for (const entry of validSummons) {
|
||||
const sourceActor = await fromUuid(entry.actorUUID);
|
||||
if (!sourceActor) {
|
||||
console.warn('DHSummonField: Could not find actor for UUID', entry.actorUUID);
|
||||
continue;
|
||||
}
|
||||
const actorData = sourceActor.toObject();
|
||||
delete actorData._id; // Remove _id to create a new Actor
|
||||
actorData.folder = subFolder.id;
|
||||
|
||||
for (let i = 0; i < entry.count; i++) {
|
||||
const newActor = foundry.utils.deepClone(actorData);
|
||||
if (entry.count > 1) {
|
||||
newActor.name = `${actorData.name} ${i + 1}`;
|
||||
}
|
||||
actorsToSummon.push(newActor);
|
||||
}
|
||||
/* Check for any available instances of the actor present in the world if we're missing artwork in the compendium */
|
||||
const dataType = game.system.api.data.actors[`Dh${actor.type.capitalize()}`];
|
||||
if (actor.inCompendium && dataType && actor.img === dataType.DEFAULT_ICON) {
|
||||
const worldActorCopy = game.actors.find(x => x.name === actor.name);
|
||||
actor = worldActorCopy ?? actor;
|
||||
}
|
||||
if (actorsToSummon.length > 0) {
|
||||
await Actor.createDocuments(actorsToSummon);
|
||||
ui.notifications.info(`Summoned ${actorsToSummon.length} actors successfully in folder ${subFolder.name}.`);
|
||||
}
|
||||
} else {
|
||||
ui.notifications.info(`Summon actors already exist in folder ${subFolder.name}.`);
|
||||
|
||||
summonData.push({ actor, count: summon.count });
|
||||
}
|
||||
|
||||
const handleSummon = async summonIndex => {
|
||||
const summon = summonData[summonIndex];
|
||||
const result = await CONFIG.ux.TokenManager.createPreviewAsync(summon.actor, {
|
||||
name: `${summon.actor.prototypeToken.name}${summon.count > 1 ? ` (${summon.count}x)` : ''}`
|
||||
});
|
||||
if (!result) return;
|
||||
|
||||
summon.count--;
|
||||
if (summon.count === 0) {
|
||||
summonIndex++;
|
||||
if (summonIndex === summonData.length) return;
|
||||
}
|
||||
|
||||
handleSummon(summonIndex);
|
||||
};
|
||||
|
||||
handleSummon(0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue