migrate virtual augments to native Daggerheart weapon features and remove legacy injection logic
This commit is contained in:
parent
689a9ec2ff
commit
5e14c2a178
15 changed files with 62 additions and 137 deletions
|
|
@ -128,112 +128,65 @@ export function patchIkonisLogic() {
|
|||
}
|
||||
|
||||
/**
|
||||
* Internal helper to generate and cache virtual features for an actor.
|
||||
* Safe to call multiple times; uses a cache to keep it fast.
|
||||
* Synchronizes Ikonis Augments into the Daggerheart Homebrew settings.
|
||||
* This makes them "Real" Weapon Features to the system.
|
||||
*/
|
||||
function _injectIkonisFeatures(actor) {
|
||||
if (!actor || actor._isIkonisInjecting) return [];
|
||||
|
||||
// Initialize the cache if it doesn't exist
|
||||
if (!actor._ikonisCache) actor._ikonisCache = new Map();
|
||||
|
||||
const ikonisFeatures = [];
|
||||
actor._isIkonisInjecting = true;
|
||||
|
||||
try {
|
||||
const weapons = actor.items.filter(i => i.type === 'weapon');
|
||||
const allAugs = getAugments();
|
||||
export async function syncIkonisToHomebrew() {
|
||||
if (!game.user.isGM) return;
|
||||
|
||||
for (const item of weapons) {
|
||||
const isEquipped = item.system.equipped;
|
||||
const installedIds = item.getFlag('dh-ikonis', 'installedAugments') || [];
|
||||
const bondedUuid = item.getFlag('dh-ikonis', 'bondedFeatureUuid');
|
||||
const MODULE_ID = 'dh-ikonis';
|
||||
const homebrewKey = game.settings.settings.has('daggerheart.Homebrew') ? 'Homebrew' : 'homebrew';
|
||||
const homebrew = game.settings.get('daggerheart', homebrewKey);
|
||||
|
||||
if (!homebrew.itemFeatures) homebrew.itemFeatures = { weaponFeatures: {}, armorFeatures: {} };
|
||||
if (!homebrew.itemFeatures.weaponFeatures) homebrew.itemFeatures.weaponFeatures = {};
|
||||
|
||||
const processFeature = (uuid, type) => {
|
||||
if (!uuid) return;
|
||||
|
||||
// Extract original feature ID from UUID to build our virtual ID
|
||||
const featureId = uuid.split('.').pop();
|
||||
const virtualId = `ikonis-${item.id}-${featureId}`;
|
||||
let updates = false;
|
||||
const allAugments = getAugments();
|
||||
|
||||
// Check cache first
|
||||
if (actor._ikonisCache.has(virtualId)) {
|
||||
if (isEquipped) ikonisFeatures.push(actor._ikonisCache.get(virtualId));
|
||||
return;
|
||||
for (const aug of allAugments) {
|
||||
const feature = _featureCache.get(aug.featureUuid) || await fromUuid(aug.featureUuid);
|
||||
if (feature && !homebrew.itemFeatures.weaponFeatures[aug.id]) {
|
||||
console.log(`DH-Ikonis | Registering ${aug.name} as native weapon feature...`);
|
||||
|
||||
// Format actions for the system's Homebrew model
|
||||
const actions = {};
|
||||
if (feature.system.actions) {
|
||||
for (const [id, action] of Object.entries(feature.system.actions)) {
|
||||
actions[id] = action.toObject();
|
||||
}
|
||||
|
||||
// Resolve original and clone
|
||||
const feature = _featureCache.get(uuid) || fromUuidSync(uuid);
|
||||
if (feature) {
|
||||
const featureClone = feature.clone({ parent: actor }, { keepId: true });
|
||||
featureClone.system.type = "ikonis";
|
||||
Object.defineProperty(featureClone, "id", { value: virtualId, enumerable: true });
|
||||
|
||||
actor._ikonisCache.set(virtualId, featureClone);
|
||||
if (isEquipped) ikonisFeatures.push(featureClone);
|
||||
}
|
||||
};
|
||||
|
||||
if (bondedUuid) processFeature(bondedUuid, "bonded");
|
||||
for (const id of installedIds) {
|
||||
const aug = allAugs.find(a => String(a.id) === String(id));
|
||||
if (aug?.featureUuid) processFeature(aug.featureUuid, "augment");
|
||||
}
|
||||
|
||||
homebrew.itemFeatures.weaponFeatures[aug.id] = {
|
||||
name: aug.name,
|
||||
img: aug.img || feature.img,
|
||||
description: feature.system.description,
|
||||
actions: actions,
|
||||
effects: Array.from(feature.effects || []).map(e => e.toObject())
|
||||
};
|
||||
updates = true;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("DH-Ikonis | Error during feature injection:", err);
|
||||
} finally {
|
||||
actor._isIkonisInjecting = false;
|
||||
}
|
||||
|
||||
return ikonisFeatures;
|
||||
|
||||
if (updates) {
|
||||
await game.settings.set('daggerheart', homebrewKey, homebrew);
|
||||
console.log("DH-Ikonis | Homebrew settings synchronized.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Patches the Character Data Model to show features in the UI lists.
|
||||
* Patches the system's weapon data preparation to handle slot counts.
|
||||
*/
|
||||
export function patchIkonisLogic() {
|
||||
// We no longer need to patch Actor.allApplicableEffects
|
||||
// because the system handles native weapon features automatically.
|
||||
}
|
||||
|
||||
/**
|
||||
* Placeholder for character patching - no longer needed for virtual items
|
||||
*/
|
||||
export function patchDhCharacter(DhCharacter) {
|
||||
console.log("DH-Ikonis | Applying DhCharacter.sheetLists patch...");
|
||||
|
||||
const descriptor = Object.getOwnPropertyDescriptor(DhCharacter.prototype, 'sheetLists');
|
||||
if (!descriptor) {
|
||||
console.error("DH-Ikonis | FAILED to find sheetLists descriptor on DhCharacter prototype!");
|
||||
return;
|
||||
}
|
||||
|
||||
const originalSheetLists = descriptor.get;
|
||||
Object.defineProperty(DhCharacter.prototype, 'sheetLists', {
|
||||
get: function() {
|
||||
const lists = originalSheetLists.call(this); // This is an Array
|
||||
if (!this.parent || !Array.isArray(lists)) return lists;
|
||||
|
||||
const ikonisFeatures = _injectIkonisFeatures(this.parent);
|
||||
|
||||
if (ikonisFeatures.length > 0) {
|
||||
// Add our custom category to the end of the lists array
|
||||
lists.push({
|
||||
title: "Ikonis Augments",
|
||||
type: "ikonis",
|
||||
values: ikonisFeatures
|
||||
});
|
||||
}
|
||||
|
||||
return lists;
|
||||
},
|
||||
configurable: true
|
||||
});
|
||||
|
||||
// Patch getEmbeddedDocument to resolve our virtual features
|
||||
const originalGetEmbedded = Actor.prototype.getEmbeddedDocument;
|
||||
Actor.prototype.getEmbeddedDocument = function(embeddedName, id, options) {
|
||||
if (embeddedName === "Item" && typeof id === "string" && id.startsWith("ikonis-")) {
|
||||
if (!this._ikonisCache?.has(id) && !this._isIkonisInjecting) {
|
||||
_injectIkonisFeatures(this);
|
||||
}
|
||||
return this._ikonisCache?.get(id);
|
||||
}
|
||||
return originalGetEmbedded.call(this, embeddedName, id, options);
|
||||
};
|
||||
// Injection is deprecated in favor of native weapon features
|
||||
}
|
||||
|
||||
export function patchDHWeapon() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue