refactor: update Bonded feature identification to support multiple IDs and improve augment slot calculation logic
This commit is contained in:
parent
073ba927c0
commit
b16efc5373
1 changed files with 17 additions and 10 deletions
|
|
@ -48,13 +48,15 @@ export function patchIkonisSheet() {
|
||||||
const processedAugments = [];
|
const processedAugments = [];
|
||||||
let bondedFeature = null;
|
let bondedFeature = null;
|
||||||
|
|
||||||
// Search for "Ikonis: Bonded" globally
|
// Identify "Bonded" features by name
|
||||||
const allNativeFeatures = CONFIG.DH.ITEM.allWeaponFeatures() || {};
|
const allNativeFeatures = CONFIG.DH.ITEM.allWeaponFeatures() || {};
|
||||||
const bondedId = Object.keys(allNativeFeatures).find(k => allNativeFeatures[k].name === "Ikonis: Bonded");
|
const bondedIds = Object.keys(allNativeFeatures).filter(k => allNativeFeatures[k].name === "Ikonis: Bonded");
|
||||||
|
|
||||||
// Auto-install if missing
|
// Auto-install if missing (check by name/presence of any bonded ID)
|
||||||
if (bondedId && !weaponFeatures.some(f => f.value === bondedId)) {
|
const hasBonded = weaponFeatures.some(f => bondedIds.includes(f.value));
|
||||||
|
if (bondedIds.length > 0 && !hasBonded) {
|
||||||
console.log(`DH-Ikonis | Auto-installing Bonded feature on ${doc.name}`);
|
console.log(`DH-Ikonis | Auto-installing Bonded feature on ${doc.name}`);
|
||||||
|
const bondedId = bondedIds.includes("ikonis-bonded") ? "ikonis-bonded" : bondedIds[0];
|
||||||
const newFeatures = [...weaponFeatures, { value: bondedId }];
|
const newFeatures = [...weaponFeatures, { value: bondedId }];
|
||||||
doc.update({ "system.weaponFeatures": newFeatures });
|
doc.update({ "system.weaponFeatures": newFeatures });
|
||||||
}
|
}
|
||||||
|
|
@ -63,10 +65,10 @@ export function patchIkonisSheet() {
|
||||||
const nativeId = featureRef.value;
|
const nativeId = featureRef.value;
|
||||||
|
|
||||||
// Special handling for Bonded
|
// Special handling for Bonded
|
||||||
if (nativeId === bondedId) {
|
if (bondedIds.includes(nativeId)) {
|
||||||
const feature = allNativeFeatures[bondedId];
|
const feature = allNativeFeatures[nativeId];
|
||||||
bondedFeature = {
|
bondedFeature = {
|
||||||
id: bondedId,
|
id: nativeId,
|
||||||
name: "Bonded",
|
name: "Bonded",
|
||||||
fullName: feature.name,
|
fullName: feature.name,
|
||||||
effect: feature.description ? feature.description.replace(/<[^>]*>?/gm, '').substring(0, 100) + "..." : "Primary module",
|
effect: feature.description ? feature.description.replace(/<[^>]*>?/gm, '').substring(0, 100) + "..." : "Primary module",
|
||||||
|
|
@ -114,11 +116,16 @@ export function patchIkonisSheet() {
|
||||||
Weapon.prototype._onAddAugment = async function(event, target) {
|
Weapon.prototype._onAddAugment = async function(event, target) {
|
||||||
const weaponFeatures = this.document.system.weaponFeatures || [];
|
const weaponFeatures = this.document.system.weaponFeatures || [];
|
||||||
const allAugments = getAugments();
|
const allAugments = getAugments();
|
||||||
|
const augmentIds = allAugments.map(a => a.id);
|
||||||
|
|
||||||
// Exclude Bonded from slot count
|
// Identify all features that are recognized as augments (and NOT "Bonded")
|
||||||
const allNativeFeatures = CONFIG.DH.ITEM.allWeaponFeatures() || {};
|
const allNativeFeatures = CONFIG.DH.ITEM.allWeaponFeatures() || {};
|
||||||
const bondedId = Object.keys(allNativeFeatures).find(k => allNativeFeatures[k].name === "Ikonis: Bonded");
|
const bondedIds = Object.keys(allNativeFeatures).filter(k => allNativeFeatures[k].name === "Ikonis: Bonded");
|
||||||
const usedSlotsCount = weaponFeatures.filter(f => f.value !== bondedId).length;
|
|
||||||
|
const usedSlotsCount = weaponFeatures.filter(f => {
|
||||||
|
if (bondedIds.includes(f.value)) return false;
|
||||||
|
return augmentIds.includes(f.value);
|
||||||
|
}).length;
|
||||||
|
|
||||||
const maxSlots = getSlotCount(this.document);
|
const maxSlots = getSlotCount(this.document);
|
||||||
if (usedSlotsCount >= maxSlots) {
|
if (usedSlotsCount >= maxSlots) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue