feat: add _id to Bonded effect and improve homebrew seeding logic with logging and object cloning
This commit is contained in:
parent
66f34b39dc
commit
21b5a5a481
1 changed files with 20 additions and 3 deletions
|
|
@ -7,6 +7,7 @@ export const DEFAULT_AUGMENTS = [
|
||||||
img: "icons/magic/control/debuff-energy-hold-blue-yellow.webp",
|
img: "icons/magic/control/debuff-energy-hold-blue-yellow.webp",
|
||||||
effects: [
|
effects: [
|
||||||
{
|
{
|
||||||
|
_id: "ikonisBondedEff",
|
||||||
name: "Ikonis: Bonded",
|
name: "Ikonis: Bonded",
|
||||||
type: "base",
|
type: "base",
|
||||||
img: "icons/magic/control/debuff-energy-hold-blue-yellow.webp",
|
img: "icons/magic/control/debuff-energy-hold-blue-yellow.webp",
|
||||||
|
|
@ -55,7 +56,7 @@ const _featureCache = new Map();
|
||||||
*/
|
*/
|
||||||
export function registerIkonisFeatures() {
|
export function registerIkonisFeatures() {
|
||||||
if (!CONFIG.DH?.ITEM?.weaponFeatures) return;
|
if (!CONFIG.DH?.ITEM?.weaponFeatures) return;
|
||||||
|
console.log("DH-Ikonis | Registering features in CONFIG...");
|
||||||
for (const aug of DEFAULT_AUGMENTS) {
|
for (const aug of DEFAULT_AUGMENTS) {
|
||||||
const nativeId = `ikonis-${aug.id}`;
|
const nativeId = `ikonis-${aug.id}`;
|
||||||
CONFIG.DH.ITEM.weaponFeatures[nativeId] = {
|
CONFIG.DH.ITEM.weaponFeatures[nativeId] = {
|
||||||
|
|
@ -75,8 +76,19 @@ export function registerIkonisFeatures() {
|
||||||
export async function seedIkonisHomebrew() {
|
export async function seedIkonisHomebrew() {
|
||||||
if (!game.user.isGM) return;
|
if (!game.user.isGM) return;
|
||||||
|
|
||||||
const homebrewKey = game.settings.settings.has('daggerheart.Homebrew') ? 'Homebrew' : 'homebrew';
|
let homebrewKey = 'Homebrew';
|
||||||
const homebrew = foundry.utils.deepClone(game.settings.get('daggerheart', homebrewKey) || {});
|
if (!game.settings.settings.has('daggerheart.Homebrew')) {
|
||||||
|
if (game.settings.settings.has('daggerheart.homebrew')) homebrewKey = 'homebrew';
|
||||||
|
else {
|
||||||
|
console.warn("DH-Ikonis | Daggerheart Homebrew setting not found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const current = game.settings.get('daggerheart', homebrewKey) || {};
|
||||||
|
const homebrew = (typeof current.toObject === 'function') ? current.toObject() : foundry.utils.deepClone(current);
|
||||||
|
|
||||||
|
console.log(`DH-Ikonis | Seeding homebrew features (key: ${homebrewKey})...`);
|
||||||
|
|
||||||
if (!homebrew.itemFeatures) homebrew.itemFeatures = { weaponFeatures: {}, armorFeatures: {} };
|
if (!homebrew.itemFeatures) homebrew.itemFeatures = { weaponFeatures: {}, armorFeatures: {} };
|
||||||
if (!homebrew.itemFeatures.weaponFeatures) homebrew.itemFeatures.weaponFeatures = {};
|
if (!homebrew.itemFeatures.weaponFeatures) homebrew.itemFeatures.weaponFeatures = {};
|
||||||
|
|
@ -85,10 +97,13 @@ export async function seedIkonisHomebrew() {
|
||||||
for (const aug of DEFAULT_AUGMENTS) {
|
for (const aug of DEFAULT_AUGMENTS) {
|
||||||
const nativeId = `ikonis-${aug.id}`;
|
const nativeId = `ikonis-${aug.id}`;
|
||||||
const existing = homebrew.itemFeatures.weaponFeatures[nativeId];
|
const existing = homebrew.itemFeatures.weaponFeatures[nativeId];
|
||||||
|
|
||||||
|
// We update if it's missing OR if it's an Ikonis feature that needs an update (like Bonded getting effects)
|
||||||
const hasEffects = aug.effects && aug.effects.length > 0;
|
const hasEffects = aug.effects && aug.effects.length > 0;
|
||||||
const needsUpdate = !existing || (hasEffects && (!existing.effects || existing.effects.length === 0));
|
const needsUpdate = !existing || (hasEffects && (!existing.effects || existing.effects.length === 0));
|
||||||
|
|
||||||
if (needsUpdate) {
|
if (needsUpdate) {
|
||||||
|
console.log(`DH-Ikonis | Seeding/Updating feature: ${aug.name}`);
|
||||||
homebrew.itemFeatures.weaponFeatures[nativeId] = {
|
homebrew.itemFeatures.weaponFeatures[nativeId] = {
|
||||||
name: `Ikonis: ${aug.name}`,
|
name: `Ikonis: ${aug.name}`,
|
||||||
img: aug.img || "systems/daggerheart/assets/icons/documents/items/chip.svg",
|
img: aug.img || "systems/daggerheart/assets/icons/documents/items/chip.svg",
|
||||||
|
|
@ -103,6 +118,8 @@ export async function seedIkonisHomebrew() {
|
||||||
if (updates) {
|
if (updates) {
|
||||||
await game.settings.set('daggerheart', homebrewKey, homebrew);
|
await game.settings.set('daggerheart', homebrewKey, homebrew);
|
||||||
console.log("DH-Ikonis | Default blueprints seeded into Homebrew settings.");
|
console.log("DH-Ikonis | Default blueprints seeded into Homebrew settings.");
|
||||||
|
} else {
|
||||||
|
console.log("DH-Ikonis | Homebrew features are already up to date.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue