mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-22 07:23:37 +02:00
DiceSoNice Animation Overrides (#1726)
* . * . * Fixed hope/fear animation input
This commit is contained in:
parent
dd376705a9
commit
308a04e6c5
12 changed files with 242 additions and 95 deletions
|
|
@ -1,19 +1,19 @@
|
|||
export default class DhAppearance extends foundry.abstract.DataModel {
|
||||
static LOCALIZATION_PREFIXES = ['DAGGERHEART.SETTINGS.Appearance'];
|
||||
|
||||
static sfxSchema = () =>
|
||||
new foundry.data.fields.SchemaField({
|
||||
class: new foundry.data.fields.StringField({
|
||||
nullable: true,
|
||||
initial: null,
|
||||
blank: true,
|
||||
choices: CONFIG.DH.GENERAL.diceSoNiceSFXClasses
|
||||
})
|
||||
});
|
||||
|
||||
static defineSchema() {
|
||||
const { StringField, ColorField, BooleanField, SchemaField } = foundry.data.fields;
|
||||
|
||||
const sfxSchema = () =>
|
||||
new SchemaField({
|
||||
class: new StringField({
|
||||
nullable: true,
|
||||
initial: null,
|
||||
blank: true,
|
||||
choices: CONFIG.DH.GENERAL.diceSoNiceSFXClasses
|
||||
})
|
||||
});
|
||||
|
||||
// helper to create dice style schema
|
||||
const diceStyle = ({ fg, bg, outline, edge }) =>
|
||||
new SchemaField({
|
||||
|
|
@ -27,7 +27,7 @@ export default class DhAppearance extends foundry.abstract.DataModel {
|
|||
system: new StringField({ initial: 'standard', required: true, blank: false }),
|
||||
font: new StringField({ initial: 'auto', required: true, blank: false }),
|
||||
sfx: new SchemaField({
|
||||
higher: sfxSchema()
|
||||
higher: DhAppearance.sfxSchema()
|
||||
})
|
||||
});
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ export default class DhAppearance extends foundry.abstract.DataModel {
|
|||
advantage: diceStyle({ fg: '#ffffff', bg: '#008000', outline: '#000000', edge: '#ffffff' }),
|
||||
disadvantage: diceStyle({ fg: '#000000', bg: '#b30000', outline: '#ffffff', edge: '#000000' }),
|
||||
sfx: new SchemaField({
|
||||
critical: sfxSchema()
|
||||
critical: DhAppearance.sfxSchema()
|
||||
})
|
||||
}),
|
||||
extendCharacterDescriptions: new BooleanField(),
|
||||
|
|
@ -81,4 +81,48 @@ export default class DhAppearance extends foundry.abstract.DataModel {
|
|||
showGenericStatusEffects: new BooleanField({ initial: true })
|
||||
};
|
||||
}
|
||||
|
||||
get diceSoNiceData() {
|
||||
const globalOverrides = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.GlobalOverrides);
|
||||
const getSFX = (baseClientData, overrideKey) => {
|
||||
if (!globalOverrides.diceSoNice.sfx.overrideEnabled) return baseClientData;
|
||||
const overrideData = globalOverrides.diceSoNice.sfx[overrideKey];
|
||||
const clientData = foundry.utils.deepClone(baseClientData);
|
||||
return Object.keys(clientData).reduce((acc, key) => {
|
||||
const data = clientData[key];
|
||||
acc[key] = Object.keys(data).reduce((acc, dataKey) => {
|
||||
const value = data[dataKey];
|
||||
acc[dataKey] = value ? value : overrideData[key][dataKey];
|
||||
return acc;
|
||||
}, {});
|
||||
return acc;
|
||||
}, {});
|
||||
};
|
||||
|
||||
return {
|
||||
...this.diceSoNice,
|
||||
sfx: getSFX(this.diceSoNice.sfx, 'global'),
|
||||
hope: {
|
||||
...this.diceSoNice.hope,
|
||||
sfx: getSFX(this.diceSoNice.hope.sfx, 'hope')
|
||||
},
|
||||
fear: {
|
||||
...this.diceSoNice.fear,
|
||||
sfx: getSFX(this.diceSoNice.fear.sfx, 'fear')
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** Invoked by the setting when data changes */
|
||||
handleChange() {
|
||||
if (this.displayFear) {
|
||||
if (ui.resources) {
|
||||
if (this.displayFear === 'hide') ui.resources.close({ allowed: true });
|
||||
else ui.resources.render({ force: true });
|
||||
}
|
||||
}
|
||||
|
||||
const globalOverrides = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.GlobalOverrides);
|
||||
globalOverrides.diceSoNiceSFXUpdate(this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
55
module/data/settings/GlobalOverrides.mjs
Normal file
55
module/data/settings/GlobalOverrides.mjs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import DhAppearance from './Appearance.mjs';
|
||||
|
||||
/**
|
||||
* A setting to handle cases where we want to allow the GM to set a global default for client settings.
|
||||
*/
|
||||
export default class DhGlobalOverrides extends foundry.abstract.DataModel {
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
return {
|
||||
diceSoNice: new fields.SchemaField({
|
||||
sfx: new fields.SchemaField({
|
||||
overrideEnabled: new fields.BooleanField(),
|
||||
global: new fields.SchemaField({
|
||||
critical: DhAppearance.sfxSchema()
|
||||
}),
|
||||
hope: new fields.SchemaField({
|
||||
higher: DhAppearance.sfxSchema()
|
||||
}),
|
||||
fear: new fields.SchemaField({
|
||||
higher: DhAppearance.sfxSchema()
|
||||
})
|
||||
})
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
async diceSoNiceSFXUpdate(appearanceSettings, enabled) {
|
||||
if (!game.user.isGM) return;
|
||||
|
||||
const newEnabled = enabled !== undefined ? enabled : this.diceSoNice.sfx.overrideEnabled;
|
||||
if (newEnabled) {
|
||||
const newOverrides = foundry.utils.mergeObject(this.toObject(), {
|
||||
diceSoNice: {
|
||||
sfx: {
|
||||
overrideEnabled: true,
|
||||
global: appearanceSettings.diceSoNice.sfx,
|
||||
hope: appearanceSettings.diceSoNice.hope.sfx,
|
||||
fear: appearanceSettings.diceSoNice.fear.sfx
|
||||
}
|
||||
}
|
||||
});
|
||||
await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.GlobalOverrides, newOverrides);
|
||||
} else {
|
||||
const newOverrides = {
|
||||
...this.toObject(),
|
||||
diceSoNice: {
|
||||
sfx: {
|
||||
overrideEnabled: false
|
||||
}
|
||||
}
|
||||
};
|
||||
await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.GlobalOverrides, newOverrides);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,3 +3,4 @@ export { default as DhAutomation } from './Automation.mjs';
|
|||
export { default as DhHomebrew } from './Homebrew.mjs';
|
||||
export { default as DhMetagaming } from './Metagaming.mjs';
|
||||
export { default as DhVariantRules } from './VariantRules.mjs';
|
||||
export { default as DhGlobalOverrides } from './GlobalOverrides.mjs';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue