mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-21 23:13:39 +02:00
.
This commit is contained in:
parent
514ee13d9a
commit
154b518383
9 changed files with 156 additions and 22 deletions
|
|
@ -2755,6 +2755,7 @@
|
||||||
"globalAnimations": "Global Animations",
|
"globalAnimations": "Global Animations",
|
||||||
"diceAppearance": "Dice Appearance",
|
"diceAppearance": "Dice Appearance",
|
||||||
"animations": "Animations",
|
"animations": "Animations",
|
||||||
|
"defaultAnimations": "Set Animations As Player Defaults",
|
||||||
"previewAnimation": "Preview Animation",
|
"previewAnimation": "Preview Animation",
|
||||||
"diceSoNice": {
|
"diceSoNice": {
|
||||||
"title": "Dice So Nice",
|
"title": "Dice So Nice",
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,14 @@ export default class DHAppearanceSettings extends HandlebarsApplicationMixin(App
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_attachPartListeners(partId, htmlElement, options) {
|
||||||
|
super._attachPartListeners(partId, htmlElement, options);
|
||||||
|
|
||||||
|
htmlElement
|
||||||
|
.querySelector('.default-animations-input')
|
||||||
|
?.addEventListener('change', this.toggleSFXOverride.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
_configureRenderParts(options) {
|
_configureRenderParts(options) {
|
||||||
const parts = super._configureRenderParts(options);
|
const parts = super._configureRenderParts(options);
|
||||||
|
|
@ -83,14 +91,18 @@ export default class DHAppearanceSettings extends HandlebarsApplicationMixin(App
|
||||||
/**@inheritdoc */
|
/**@inheritdoc */
|
||||||
async _prepareContext(options) {
|
async _prepareContext(options) {
|
||||||
const context = await super._prepareContext(options);
|
const context = await super._prepareContext(options);
|
||||||
if (options.isFirstRender)
|
if (options.isFirstRender) {
|
||||||
this.setting = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance);
|
this.setting = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance);
|
||||||
|
this.globalOverrides = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.GlobalOverrides);
|
||||||
|
}
|
||||||
|
|
||||||
context.setting = this.setting;
|
context.setting = this.setting;
|
||||||
|
context.globalOverrides = this.globalOverrides;
|
||||||
context.fields = this.setting.schema.fields;
|
context.fields = this.setting.schema.fields;
|
||||||
|
|
||||||
context.tabs = this._prepareTabs('general');
|
context.tabs = this._prepareTabs('general');
|
||||||
context.dsnTabs = this._prepareTabs('diceSoNice');
|
context.dsnTabs = this._prepareTabs('diceSoNice');
|
||||||
|
context.isGM = game.user.isGM;
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
@ -188,6 +200,12 @@ export default class DHAppearanceSettings extends HandlebarsApplicationMixin(App
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
|
|
||||||
|
async toggleSFXOverride(event) {
|
||||||
|
await this.globalOverrides.diceSoNiceSFXUpdate(this.setting, event.target.checked);
|
||||||
|
this.globalOverrides = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.GlobalOverrides);
|
||||||
|
this.render();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Submit the configuration form.
|
* Submit the configuration form.
|
||||||
* @this {DHAppearanceSettings}
|
* @this {DHAppearanceSettings}
|
||||||
|
|
|
||||||
|
|
@ -699,7 +699,7 @@ export const daggerheartDiceAnimationEvents = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const getDiceSoNiceSFX = sfxOptions => {
|
const getDiceSoNiceSFX = sfxOptions => {
|
||||||
const { diceSoNice } = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance);
|
const diceSoNice = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance).diceSoNiceData;
|
||||||
const criticalAnimationData = diceSoNice.sfx.critical;
|
const criticalAnimationData = diceSoNice.sfx.critical;
|
||||||
if (sfxOptions.critical && criticalAnimationData.class) {
|
if (sfxOptions.critical && criticalAnimationData.class) {
|
||||||
return {
|
return {
|
||||||
|
|
@ -753,7 +753,7 @@ export const getDiceSoNicePresets = async (
|
||||||
advantageFaces = 'd6',
|
advantageFaces = 'd6',
|
||||||
disadvantageFaces = 'd6'
|
disadvantageFaces = 'd6'
|
||||||
) => {
|
) => {
|
||||||
const { diceSoNice } = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance);
|
const diceSoNice = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance).diceSoNiceData;
|
||||||
|
|
||||||
const { isCritical, withHope, withFear } = result;
|
const { isCritical, withHope, withFear } = result;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ export const gameSettings = {
|
||||||
Metagaming: 'Metagaming',
|
Metagaming: 'Metagaming',
|
||||||
Homebrew: 'Homebrew',
|
Homebrew: 'Homebrew',
|
||||||
appearance: 'Appearance',
|
appearance: 'Appearance',
|
||||||
|
GlobalOverrides: 'GlobalOverrides',
|
||||||
variantRules: 'VariantRules',
|
variantRules: 'VariantRules',
|
||||||
Resources: {
|
Resources: {
|
||||||
Fear: 'ResourcesFear'
|
Fear: 'ResourcesFear'
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,19 @@
|
||||||
export default class DhAppearance extends foundry.abstract.DataModel {
|
export default class DhAppearance extends foundry.abstract.DataModel {
|
||||||
static LOCALIZATION_PREFIXES = ['DAGGERHEART.SETTINGS.Appearance'];
|
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() {
|
static defineSchema() {
|
||||||
const { StringField, ColorField, BooleanField, SchemaField } = foundry.data.fields;
|
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
|
// helper to create dice style schema
|
||||||
const diceStyle = ({ fg, bg, outline, edge }) =>
|
const diceStyle = ({ fg, bg, outline, edge }) =>
|
||||||
new SchemaField({
|
new SchemaField({
|
||||||
|
|
@ -27,7 +27,7 @@ export default class DhAppearance extends foundry.abstract.DataModel {
|
||||||
system: new StringField({ initial: 'standard', required: true, blank: false }),
|
system: new StringField({ initial: 'standard', required: true, blank: false }),
|
||||||
font: new StringField({ initial: 'auto', required: true, blank: false }),
|
font: new StringField({ initial: 'auto', required: true, blank: false }),
|
||||||
sfx: new SchemaField({
|
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' }),
|
advantage: diceStyle({ fg: '#ffffff', bg: '#008000', outline: '#000000', edge: '#ffffff' }),
|
||||||
disadvantage: diceStyle({ fg: '#000000', bg: '#b30000', outline: '#ffffff', edge: '#000000' }),
|
disadvantage: diceStyle({ fg: '#000000', bg: '#b30000', outline: '#ffffff', edge: '#000000' }),
|
||||||
sfx: new SchemaField({
|
sfx: new SchemaField({
|
||||||
critical: sfxSchema()
|
critical: DhAppearance.sfxSchema()
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
extendCharacterDescriptions: new BooleanField(),
|
extendCharacterDescriptions: new BooleanField(),
|
||||||
|
|
@ -81,4 +81,48 @@ export default class DhAppearance extends foundry.abstract.DataModel {
|
||||||
showGenericStatusEffects: new BooleanField({ initial: true })
|
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 DhHomebrew } from './Homebrew.mjs';
|
||||||
export { default as DhMetagaming } from './Metagaming.mjs';
|
export { default as DhMetagaming } from './Metagaming.mjs';
|
||||||
export { default as DhVariantRules } from './VariantRules.mjs';
|
export { default as DhVariantRules } from './VariantRules.mjs';
|
||||||
|
export { default as DhGlobalOverrides } from './GlobalOverrides.mjs';
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,13 @@
|
||||||
import { defaultLevelTiers, DhLevelTiers } from '../data/levelTier.mjs';
|
import { defaultLevelTiers, DhLevelTiers } from '../data/levelTier.mjs';
|
||||||
import DhCountdowns from '../data/countdowns.mjs';
|
import DhCountdowns from '../data/countdowns.mjs';
|
||||||
import { DhAppearance, DhAutomation, DhHomebrew, DhMetagaming, DhVariantRules } from '../data/settings/_module.mjs';
|
import {
|
||||||
|
DhAppearance,
|
||||||
|
DhAutomation,
|
||||||
|
DhGlobalOverrides,
|
||||||
|
DhHomebrew,
|
||||||
|
DhMetagaming,
|
||||||
|
DhVariantRules
|
||||||
|
} from '../data/settings/_module.mjs';
|
||||||
import {
|
import {
|
||||||
DhAppearanceSettings,
|
DhAppearanceSettings,
|
||||||
DhAutomationSettings,
|
DhAutomationSettings,
|
||||||
|
|
@ -54,17 +61,18 @@ const registerMenuSettings = () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
game.settings.register(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.GlobalOverrides, {
|
||||||
|
scope: 'world',
|
||||||
|
config: false,
|
||||||
|
type: DhGlobalOverrides
|
||||||
|
});
|
||||||
|
|
||||||
game.settings.register(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance, {
|
game.settings.register(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance, {
|
||||||
scope: 'client',
|
scope: 'client',
|
||||||
config: false,
|
config: false,
|
||||||
type: DhAppearance,
|
type: DhAppearance,
|
||||||
onChange: value => {
|
onChange: value => {
|
||||||
if (value.displayFear) {
|
value.handleChange();
|
||||||
if (ui.resources) {
|
|
||||||
if (value.displayFear === 'hide') ui.resources.close({ allowed: true });
|
|
||||||
else ui.resources.render({ force: true });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,12 @@
|
||||||
<label>{{localize "DAGGERHEART.CONFIG.DaggerheartDiceAnimationEvents.critical.name"}}</label>
|
<label>{{localize "DAGGERHEART.CONFIG.DaggerheartDiceAnimationEvents.critical.name"}}</label>
|
||||||
{{formInput fields.diceSoNice.fields.sfx.fields.critical.fields.class value=setting.diceSoNice.sfx.critical.class blank="" localize=true}}
|
{{formInput fields.diceSoNice.fields.sfx.fields.critical.fields.class value=setting.diceSoNice.sfx.critical.class blank="" localize=true}}
|
||||||
</div>
|
</div>
|
||||||
|
{{#if isGM}}
|
||||||
|
<div class="label-container">
|
||||||
|
<label>{{localize "DAGGERHEART.SETTINGS.Menu.appearance.defaultAnimations"}}</label>
|
||||||
|
<input type="checkbox" class="default-animations-input" {{checked globalOverrides.diceSoNice.sfx.overrideEnabled}} />
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<section class='tab-navigation'>
|
<section class='tab-navigation'>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue