migrate virtual augments to native Daggerheart weapon features and remove legacy injection logic

This commit is contained in:
CPTN Cosmo 2026-04-26 18:43:24 +02:00
parent 689a9ec2ff
commit 5e14c2a178
15 changed files with 62 additions and 137 deletions

View file

@ -44,18 +44,15 @@ export function patchIkonisSheet() {
const doc = this.document;
if (!doc) return context;
const installedIds = doc.getFlag('dh-ikonis', 'installedAugments') || [];
const weaponFeatures = doc.system.weaponFeatures || [];
const allAugmentsList = getAugments() || [];
const processedAugments = [];
for (const id of installedIds) {
for (const featureRef of weaponFeatures) {
const id = featureRef.value;
const base = allAugmentsList.find(a => String(a.id) === String(id));
if (!base) continue;
const aug = { ...base, installed: true };
if (aug.featureUuid) {
const item = await getAttachedFeature(aug.featureUuid);
if (item) aug.feature = { name: item.name, img: item.img, uuid: item.uuid };
}
processedAugments.push(aug);
}
@ -97,17 +94,18 @@ export function patchIkonisSheet() {
// 5. Add custom methods
Weapon.prototype._onAddAugment = async function(event, target) {
const installedIds = this.document.getFlag('dh-ikonis', 'installedAugments') || [];
const weaponFeatures = this.document.system.weaponFeatures || [];
const allAugments = getAugments();
const validInstalled = installedIds.filter(id => allAugments.some(a => String(a.id) === String(id)));
// Filter out native features that aren't Ikonis augments if needed,
// but for now we'll just count total weapon features against slots
const maxSlots = getSlotCount(this.document);
if (validInstalled.length >= maxSlots) {
if (weaponFeatures.length >= maxSlots) {
ui.notifications.warn(`No more augment slots available! (Max: ${maxSlots})`);
return;
}
const available = allAugments.filter(a => !validInstalled.includes(String(a.id)));
const available = allAugments.filter(a => !weaponFeatures.some(f => f.value === a.id));
const content = `
<div class="augment-picker" style="max-height: 500px; display: flex; flex-direction: column; background: #0f0f1b; padding: 1rem; border-radius: 8px;">
@ -163,16 +161,16 @@ export function patchIkonisSheet() {
});
if (res && res !== "cancel") {
const newIds = [...validInstalled, String(res)];
await this.document.update({ "flags.dh-ikonis.installedAugments": newIds });
const newFeatures = [...weaponFeatures, { value: res }];
await this.document.update({ "system.weaponFeatures": newFeatures });
this.render(true);
}
};
Weapon.prototype._onRemoveAugment = async function(event, target) {
const installedIds = this.document.getFlag('dh-ikonis', 'installedAugments') || [];
const newIds = installedIds.filter(id => id !== String(target.dataset.id));
await this.document.update({ "flags.dh-ikonis.installedAugments": newIds });
const weaponFeatures = this.document.system.weaponFeatures || [];
const newFeatures = weaponFeatures.filter(f => f.value !== String(target.dataset.id));
await this.document.update({ "system.weaponFeatures": newFeatures });
this.render(true);
};