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 = [];
|
||||
let bondedFeature = null;
|
||||
|
||||
// Search for "Ikonis: Bonded" globally
|
||||
// Identify "Bonded" features by name
|
||||
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
|
||||
if (bondedId && !weaponFeatures.some(f => f.value === bondedId)) {
|
||||
// Auto-install if missing (check by name/presence of any bonded ID)
|
||||
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}`);
|
||||
const bondedId = bondedIds.includes("ikonis-bonded") ? "ikonis-bonded" : bondedIds[0];
|
||||
const newFeatures = [...weaponFeatures, { value: bondedId }];
|
||||
doc.update({ "system.weaponFeatures": newFeatures });
|
||||
}
|
||||
|
|
@ -63,10 +65,10 @@ export function patchIkonisSheet() {
|
|||
const nativeId = featureRef.value;
|
||||
|
||||
// Special handling for Bonded
|
||||
if (nativeId === bondedId) {
|
||||
const feature = allNativeFeatures[bondedId];
|
||||
if (bondedIds.includes(nativeId)) {
|
||||
const feature = allNativeFeatures[nativeId];
|
||||
bondedFeature = {
|
||||
id: bondedId,
|
||||
id: nativeId,
|
||||
name: "Bonded",
|
||||
fullName: feature.name,
|
||||
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) {
|
||||
const weaponFeatures = this.document.system.weaponFeatures || [];
|
||||
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 bondedId = Object.keys(allNativeFeatures).find(k => allNativeFeatures[k].name === "Ikonis: Bonded");
|
||||
const usedSlotsCount = weaponFeatures.filter(f => f.value !== bondedId).length;
|
||||
const bondedIds = Object.keys(allNativeFeatures).filter(k => allNativeFeatures[k].name === "Ikonis: Bonded");
|
||||
|
||||
const usedSlotsCount = weaponFeatures.filter(f => {
|
||||
if (bondedIds.includes(f.value)) return false;
|
||||
return augmentIds.includes(f.value);
|
||||
}).length;
|
||||
|
||||
const maxSlots = getSlotCount(this.document);
|
||||
if (usedSlotsCount >= maxSlots) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue