From 5aa06ceb6be27d912fcd76a5e147b2c4e32c909f Mon Sep 17 00:00:00 2001 From: marvin9257 <72580196+marvin9257@users.noreply.github.com> Date: Wed, 9 Aug 2023 14:05:08 -0500 Subject: [PATCH 1/5] feat: add settings divisions --- src/module/settings/AdvancedSettings.ts | 38 ++++--- src/module/settings/DebugSettings.ts | 24 ++-- src/module/settings/DisplaySettings.ts | 55 +++++----- src/module/settings/ItemSettings.ts | 29 ++--- src/module/settings/RulsetSettings.ts | 110 ++++++++++--------- static/lang/en.json | 27 ++++- static/templates/misc/advanced-settings.html | 64 ++++++----- 7 files changed, 203 insertions(+), 144 deletions(-) diff --git a/src/module/settings/AdvancedSettings.ts b/src/module/settings/AdvancedSettings.ts index 577eb3777..b594e7028 100644 --- a/src/module/settings/AdvancedSettings.ts +++ b/src/module/settings/AdvancedSettings.ts @@ -1,8 +1,11 @@ +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-nocheck This turns off *all* typechecking, make sure to remove this once foundry-vtt-types are updated to cover v10. + export default class AdvancedSettings extends FormApplication { - settings: string[]; - static settings:string[]; + settings: any; + static settings:any; - constructor(object, settings:string[], options?) { + constructor(object, settings:any, options?) { super(object, options); this.settings = settings; } @@ -19,19 +22,22 @@ export default class AdvancedSettings extends FormApplication { /** @override */ getData(): any { const data: any = super.getData(); - const settings = this.settings.map((settingName) => { - const setting: any = game.settings.settings.get("twodsix." + settingName); - setting.value = game.settings.get(setting.namespace ?? setting.module, settingName); - if (setting.choices === "Color") { - setting.htmlType = "Color"; - } else if (setting.choices) { - setting.htmlType = "Select"; - } else { - setting.htmlType = setting.type.name; - } - return [settingName, setting]; - }); - data.settings = Object.fromEntries(settings); + data.settings = {}; + for(const group in this.settings) { + const settings = this.settings[group].map((settingName) => { + const setting: any = game.settings.settings.get("twodsix." + settingName); + setting.value = game.settings.get(setting.namespace ?? setting.module, settingName); + if (setting.choices === "Color") { + setting.htmlType = "Color"; + } else if (setting.choices) { + setting.htmlType = "Select"; + } else { + setting.htmlType = setting.type.name; + } + return [settingName, setting]; + }); + data.settings[group] = Object.fromEntries(settings); + } return data; } diff --git a/src/module/settings/DebugSettings.ts b/src/module/settings/DebugSettings.ts index c47976fad..90e4b4a2f 100644 --- a/src/module/settings/DebugSettings.ts +++ b/src/module/settings/DebugSettings.ts @@ -23,16 +23,20 @@ export default class DebugSettings extends AdvancedSettings { return data; } - static registerSettings(): string[] { - const settings: string[] = []; - settings.push(booleanSetting('ExperimentalFeatures', false)); - settings.push(stringSetting('systemMigrationVersion', game.system.version)); - settings.push(booleanSetting('useModuleFixStyle', false, false, 'world', refreshWindow)); - settings.push(booleanSetting('useShipAutoCalcs', false, false, 'world', refreshWindow)); - settings.push(booleanSetting('useProseMirror', false)); - settings.push(booleanSetting('allowDropOnIcon', false)); - settings.push(booleanSetting('allowDragDropOfLists', false)); - settings.push(booleanSetting('useItemActiveEffects', false, false, 'world', deactivateActorAE)); + static registerSettings(): any { + const settings = { + general: [], + style: [], + dragDrop: [] + }; + settings.general.push(booleanSetting('ExperimentalFeatures', false)); + settings.general.push(stringSetting('systemMigrationVersion', game.system.version)); + settings.style.push(booleanSetting('useModuleFixStyle', false, false, 'world', refreshWindow)); + settings.general.push(booleanSetting('useShipAutoCalcs', false, false, 'world', refreshWindow)); + settings.style.push(booleanSetting('useProseMirror', false)); + settings.dragDrop.push(booleanSetting('allowDropOnIcon', false)); + settings.dragDrop.push(booleanSetting('allowDragDropOfLists', false)); + settings.general.push(booleanSetting('useItemActiveEffects', false, false, 'world', deactivateActorAE)); return settings; } } diff --git a/src/module/settings/DisplaySettings.ts b/src/module/settings/DisplaySettings.ts index ff33d2aaf..05df67edb 100644 --- a/src/module/settings/DisplaySettings.ts +++ b/src/module/settings/DisplaySettings.ts @@ -20,32 +20,37 @@ export default class DisplaySettings extends AdvancedSettings { return data; } - static registerSettings(): string[] { + static registerSettings(): any { - const settings: string[] = []; - settings.push(booleanSetting('defaultTokenSettings', true)); - settings.push(booleanSetting('useSystemDefaultTokenIcon', false)); - settings.push(booleanSetting('showSingleComponentColumn', false)); - settings.push(booleanSetting('showBandwidth', false)); - settings.push(booleanSetting('useFoundryStandardStyle', false, false, 'world', refreshWindow)); - settings.push(booleanSetting('useWoundedStatusIndicators', false)); - settings.push(booleanSetting('useEncumbranceStatusIndicators', false)); - settings.push(booleanSetting('showWeightUsage', false)); - settings.push(booleanSetting('usePDFPagerForRefs', false)); - settings.push(booleanSetting('showIcons', false)); - settings.push(booleanSetting('useEncumbrance', false)); - settings.push(booleanSetting('showStatusIcons', true)); - settings.push(booleanSetting('showRangeSpeedNoUnits', false)); - settings.push(booleanSetting('showInitiativeButton', false)); - settings.push(booleanSetting('showSkillCountsRanks', true)); - settings.push(booleanSetting('showComponentSummaryIcons', false)); - settings.push(booleanSetting('showSpells', false)); - settings.push(booleanSetting('showModifierDetails', false)); - settings.push(booleanSetting('showFeaturesInChat', false)); - settings.push(colorSetting('defaultColor', "#29aae1", "Color", false, 'world', changeDefaultColor)); - settings.push(colorSetting('lightColor', "#00e5ff", "Color", false, 'world', changeLightColor)); - settings.push(booleanSetting('showHitsChangesInChat', false)); - settings.push(booleanSetting('reduceStatusIcons', false, false, "world", updateStatusIcons)); + const settings = { + general: [], + token: [], + actor: [], + ship: [] + }; + settings.token.push(booleanSetting('defaultTokenSettings', true)); + settings.token.push(booleanSetting('useSystemDefaultTokenIcon', false)); + settings.ship.push(booleanSetting('showSingleComponentColumn', false)); + settings.ship.push(booleanSetting('showBandwidth', false)); + settings.general.push(booleanSetting('useFoundryStandardStyle', false, false, 'world', refreshWindow)); + settings.actor.push(booleanSetting('useWoundedStatusIndicators', false)); + settings.actor.push(booleanSetting('useEncumbranceStatusIndicators', false)); + settings.ship.push(booleanSetting('showWeightUsage', false)); + settings.general.push(booleanSetting('usePDFPagerForRefs', false)); + settings.actor.push(booleanSetting('showIcons', false)); + settings.actor.push(booleanSetting('useEncumbrance', false)); + settings.actor.push(booleanSetting('showStatusIcons', true)); + settings.actor.push(booleanSetting('showRangeSpeedNoUnits', false)); + settings.actor.push(booleanSetting('showInitiativeButton', false)); + settings.actor.push(booleanSetting('showSkillCountsRanks', true)); + settings.ship.push(booleanSetting('showComponentSummaryIcons', false)); + settings.actor.push(booleanSetting('showSpells', false)); + settings.general.push(booleanSetting('showModifierDetails', false)); + settings.general.push(booleanSetting('showFeaturesInChat', false)); + settings.general.push(colorSetting('defaultColor', "#29aae1", "Color", false, 'world', changeDefaultColor)); + settings.general.push(colorSetting('lightColor', "#00e5ff", "Color", false, 'world', changeLightColor)); + settings.general.push(booleanSetting('showHitsChangesInChat', false)); + settings.token.push(booleanSetting('reduceStatusIcons', false, false, "world", updateStatusIcons)); return settings; } } diff --git a/src/module/settings/ItemSettings.ts b/src/module/settings/ItemSettings.ts index 15f91e525..3ee706569 100644 --- a/src/module/settings/ItemSettings.ts +++ b/src/module/settings/ItemSettings.ts @@ -20,19 +20,22 @@ export default class ItemSettings extends AdvancedSettings { return data; } - static registerSettings(): string[] { - const settings: string[] = []; - settings.push(booleanSetting('ShowLawLevel', false)); - settings.push(booleanSetting('ShowRangeBandAndHideRange', false)); - settings.push(booleanSetting('ShowWeaponType', false)); - settings.push(booleanSetting('ShowDamageType', false)); - settings.push(booleanSetting('ShowRateOfFire', true)); - settings.push(booleanSetting('ShowRecoil', false)); - settings.push(booleanSetting('ShowDoubleTap', false)); - settings.push(booleanSetting('addEffectToManualDamage', false)); - settings.push(booleanSetting('showComponentRating', true)); - settings.push(booleanSetting('showComponentDM', true)); - settings.push(booleanSetting('useTabbedViews', false)); + static registerSettings(): any { + const settings = { + general: [], + weapon: [], + ship: [] + }; + settings.general.push(booleanSetting('ShowLawLevel', false)); + settings.weapon.push(booleanSetting('ShowRangeBandAndHideRange', false)); + settings.weapon.push(booleanSetting('ShowWeaponType', false)); + settings.weapon.push(booleanSetting('ShowDamageType', false)); + settings.weapon.push(booleanSetting('ShowRateOfFire', true)); + settings.weapon.push(booleanSetting('ShowRecoil', false)); + settings.weapon.push(booleanSetting('ShowDoubleTap', false)); + settings.ship.push(booleanSetting('showComponentRating', true)); + settings.ship.push(booleanSetting('showComponentDM', true)); + settings.general.push(booleanSetting('useTabbedViews', false)); return settings; } } diff --git a/src/module/settings/RulsetSettings.ts b/src/module/settings/RulsetSettings.ts index b29e1ba25..d5d71ae12 100644 --- a/src/module/settings/RulsetSettings.ts +++ b/src/module/settings/RulsetSettings.ts @@ -30,60 +30,72 @@ export default class RulesetSettings extends AdvancedSettings { return data; } - static registerSettings(): string[] { + static registerSettings(): any { const DEFAULT_INITIATIVE_FORMULA = "2d6 + @characteristics.dexterity.mod"; // TODO: With the new ship positions this should be changed to take the pilot's piloting skill into consideration. const DEFAULT_SHIP_INITIATIVE_FORMULA = "2d6"; const DEFAULT_MAX_ENCUMBRANCE_FORMULA = "12 * @characteristics.strength.current"; - const settings: string[] = []; - settings.push(stringSetting('initiativeFormula', DEFAULT_INITIATIVE_FORMULA, false, 'world')); - settings.push(stringSetting('armorDamageFormula', "@damage - @effectiveArmor", false, 'world')); - settings.push(stringSetting('shipInitiativeFormula', DEFAULT_SHIP_INITIATIVE_FORMULA, false, 'world')); - settings.push(stringChoiceSetting('difficultyListUsed', TWODSIX.RULESETS.CE.key, false, TWODSIX.VARIANTS)); - settings.push(booleanSetting('difficultiesAsTargetNumber', false)); - settings.push(stringChoiceSetting('autofireRulesUsed', TWODSIX.RULESETS.CE.key, false, TWODSIX.VARIANTS)); - settings.push(numberSetting('modifierForZeroCharacteristic', -2)); - settings.push(stringSetting('termForAdvantage', 'advantage')); - settings.push(stringSetting('termForDisadvantage', 'disadvantage')); - settings.push(numberSetting('absoluteBonusValueForEachTimeIncrement', -1)); - settings.push(numberSetting('maxSkillLevel', 9)); - settings.push(booleanSetting('criticalNaturalAffectsEffect', false)); - settings.push(numberSetting('absoluteCriticalEffectValue', 99)); - settings.push(booleanSetting('showLifebloodStamina', false)); - settings.push(numberSetting('minorWoundsRollModifier', 0)); - settings.push(numberSetting('seriousWoundsRollModifier', 0)); - settings.push(booleanSetting('lifebloodInsteadOfCharacteristics', false)); - settings.push(booleanSetting('showContaminationBelowLifeblood', true)); - settings.push(booleanSetting('showHeroPoints', false)); - settings.push(stringChoiceSetting('showAlternativeCharacteristics', "base", false, TWODSIX.CharacteristicDisplayTypes)); - settings.push(stringSetting("alternativeShort1", "ALT1")); - settings.push(stringSetting("alternativeShort2", "ALT2")); - settings.push(numberSetting('maxComponentHits', 3)); - settings.push(numberSetting('mortgagePayment', 240, false)); - settings.push(numberSetting('massProductionDiscount', 0.10, false)); - settings.push(booleanSetting('reverseHealingOrder', false)); - settings.push(stringSetting("maxEncumbrance", DEFAULT_MAX_ENCUMBRANCE_FORMULA, false, "world")); - settings.push(stringSetting('encumbranceFraction', "0.5", false)); //Should be a number setting, but FVTT unhappy with values other than 0.5 - settings.push(numberSetting('encumbranceModifier', -1, false)); - settings.push(numberSetting('encumbFractionOneSquare', 0.5)); - settings.push(numberSetting('encumbFraction75pct', 0.33)); - settings.push(numberSetting('defaultMovement', 10)); - settings.push(stringChoiceSetting('defaultMovementUnits', "m", true, TWODSIX.MovementUnits)); - settings.push(booleanSetting('addEffectForShipDamage', false)); - settings.push(stringSetting("unarmedDamage", "1d6", false, "world")); - settings.push(booleanSetting("showTimeframe", false)); - settings.push(stringChoiceSetting('showHullAndArmor', "armorOnly", true, TWODSIX.VehicleProtection)); - settings.push(stringSetting("sorcerySkill", "Sorcery", false, "world")); - settings.push(booleanSetting("useNationality", false)); - settings.push(booleanSetting("animalsUseHits", false)); - settings.push(booleanSetting("robotsUseHits", false)); - settings.push(booleanSetting("animalsUseLocations", false)); - settings.push(booleanSetting("animalTypesIndependentofNiche", false)); - settings.push(booleanSetting("displayReactionMorale", false)); - settings.push(booleanSetting("useDodgeParry", false)); - settings.push(stringSetting("damageTypeOptions", "", false, "world")); - settings.push(stringChoiceSetting('useDegreesOfSuccess', "none", true, TWODSIX.SuccessTypes)); + const settings = { + general: [], + roll: [], + characteristics: [], + damage: [], + movement: [], + encumbrance: [], + wounds: [], + ship: [], + animals_robots: [] + }; + settings.general.push(stringSetting('initiativeFormula', DEFAULT_INITIATIVE_FORMULA, false, 'world')); + settings.damage.push(stringSetting('armorDamageFormula', "@damage - @effectiveArmor", false, 'world')); + settings.ship.push(stringSetting('shipInitiativeFormula', DEFAULT_SHIP_INITIATIVE_FORMULA, false, 'world')); + settings.general.push(stringChoiceSetting('difficultyListUsed', TWODSIX.RULESETS.CE.key, false, TWODSIX.VARIANTS)); + settings.general.push(booleanSetting('difficultiesAsTargetNumber', false)); + settings.general.push(stringChoiceSetting('autofireRulesUsed', TWODSIX.RULESETS.CE.key, false, TWODSIX.VARIANTS)); + settings.characteristics.push(numberSetting('modifierForZeroCharacteristic', -2)); + settings.roll.push(stringSetting('termForAdvantage', 'advantage')); + settings.roll.push(stringSetting('termForDisadvantage', 'disadvantage')); + settings.roll.push(numberSetting('absoluteBonusValueForEachTimeIncrement', -1)); + settings.general.push(numberSetting('maxSkillLevel', 9)); + settings.roll.push(booleanSetting('criticalNaturalAffectsEffect', false)); + settings.roll.push(numberSetting('absoluteCriticalEffectValue', 99)); + settings.characteristics.push(booleanSetting('showLifebloodStamina', false)); + settings.wounds.push(numberSetting('minorWoundsRollModifier', 0)); + settings.wounds. push(numberSetting('seriousWoundsRollModifier', 0)); + settings.characteristics.push(booleanSetting('lifebloodInsteadOfCharacteristics', false)); + settings.characteristics.push(booleanSetting('showContaminationBelowLifeblood', true)); + settings.characteristics.push(booleanSetting('showHeroPoints', false)); + settings.characteristics.push(stringChoiceSetting('showAlternativeCharacteristics', "base", false, TWODSIX.CharacteristicDisplayTypes)); + settings.characteristics.push(stringSetting("alternativeShort1", "ALT1")); + settings.characteristics.push(stringSetting("alternativeShort2", "ALT2")); + settings.ship.push(numberSetting('maxComponentHits', 3)); + settings.ship.push(numberSetting('mortgagePayment', 240, false)); + settings.ship.push(stringSetting('massProductionDiscount', "0.10", false)); //Should be a number setting, but FVTT unhappy with values other than 0.5 + settings.wounds.push(booleanSetting('reverseHealingOrder', false)); + settings.encumbrance.push(stringSetting("maxEncumbrance", DEFAULT_MAX_ENCUMBRANCE_FORMULA, false, "world")); + settings.encumbrance.push(stringSetting('encumbranceFraction', "0.5", false)); //Should be a number setting, but FVTT unhappy with values other than 0.5 + settings.encumbrance.push(numberSetting('encumbranceModifier', -1, false)); + settings.movement.push(numberSetting('defaultMovement', 10)); + settings.movement.push(stringChoiceSetting('defaultMovementUnits', "m", true, TWODSIX.MovementUnits)); + settings.movement.push(stringSetting('encumbFractionOneSquare', "0.5")); //Should be a number setting, but FVTT unhappy with values other than 0.5 + settings.movement.push(stringSetting('encumbFraction75pct', "0.33")); //Should be a number setting, but FVTT unhappy with values other than 0.5 + settings.ship.push(booleanSetting('addEffectForShipDamage', false)); + settings.damage.push(stringSetting("unarmedDamage", "1d6", false, "world")); + settings.roll.push(booleanSetting("showTimeframe", false)); + settings.general.push(stringChoiceSetting('showHullAndArmor', "armorOnly", true, TWODSIX.VehicleProtection)); + settings.general.push(stringSetting("sorcerySkill", "Sorcery", false, "world")); + settings.general.push(booleanSetting("useNationality", false)); + settings.animals_robots.push(booleanSetting("animalsUseHits", false)); + settings.animals_robots.push(booleanSetting("robotsUseHits", false)); + settings.animals_robots.push(booleanSetting("animalsUseLocations", false)); + settings.animals_robots.push(booleanSetting("animalTypesIndependentofNiche", false)); + settings.animals_robots.push(booleanSetting("displayReactionMorale", false)); + settings.damage.push(booleanSetting("useDodgeParry", false)); + settings.damage.push(stringSetting("damageTypeOptions", "", false, "world")); + settings.damage.push(booleanSetting('addEffectToManualDamage', false)); + settings.roll.push(stringChoiceSetting('useDegreesOfSuccess', "none", true, TWODSIX.SuccessTypes)); + settings.roll.push(booleanSetting("overrideSuccessWithNaturalCrit", false)); return settings; } } diff --git a/static/lang/en.json b/static/lang/en.json index c2bcd73fb..8c36839c5 100644 --- a/static/lang/en.json +++ b/static/lang/en.json @@ -1089,8 +1089,8 @@ "name": "Protection values on vehicle sheets" }, "addEffectToManualDamage": { - "hint": "This option addts the effect to a manual damage roll from the most recent chat message.", - "name": "Add effect when making manual damage" + "hint": "This option adds the effect from the most recent chat message to a manual damage roll.", + "name": "Add effect when rolling manual damage" }, "showRangeSpeedNoUnits": { "hint": "Omit the range and speed units (e.g. km/hr) on vehicle sheet.", @@ -1228,7 +1228,28 @@ "hint": "Show degrees of success. The 'Other' setting uses exceptional, marginal, and average descriptions for success & failure. The 'Cepheus Engine' setting does not use the marginal descriptor (per rules). The 'None' setting omits all success or failure descriptions.", "name": "Show degrees of success for non-attack rolls" }, - "defaultDamageOptions": "Ballistic, Bludgeoning, Corrosive, EMP, Energy, Fire, Laser, Piercing, Poison, Plasma, Psionic, Rad, Slashing, Smoke, Stun" + "overrideSuccessWithNaturalCrit": { + "hint": "Override the degree of success to be exceptional on a natural 2 or 12 - independent of effect.", + "name": "Override degree of success on critical roll (2 or 12)" + }, + "defaultDamageOptions": "Ballistic, Bludgeoning, Corrosive, EMP, Energy, Fire, Laser, Piercing, Poison, Plasma, Psionic, Rad, Slashing, Smoke, Stun", + "menuLabels": { + "general": "General", + "roll": "Rolls", + "characteristics": "Characteristics", + "formulas": "Formulas", + "damage": "Damage", + "movement": "Movement", + "encumbrance": "Encumbrance", + "wounds": "Wounds", + "ship": "Ship", + "animals_robots": "Animals & Robots", + "weapon": "Weapon", + "token": "Token", + "actor": "Actor", + "dragDrop": "Drag & Drop", + "style": "Style" + } }, "CloseAndCreateNew": "Close and create new", "Copy": "Copy", diff --git a/static/templates/misc/advanced-settings.html b/static/templates/misc/advanced-settings.html index c71cdbf45..ac6843458 100644 --- a/static/templates/misc/advanced-settings.html +++ b/static/templates/misc/advanced-settings.html @@ -1,37 +1,45 @@ +{{log this}}
{{{intro}}} - {{#each settings as |setting key|}} -
- -
- {{#iff setting.htmlType "===" "Number"}} - - {{/iff}} - {{#iff setting.htmlType "===" "String"}} - - {{/iff}} + {{#each settings as |group|}} +
+ {{localize (concat "TWODSIX.Settings.menuLabels." @key)}} + {{#each group as |setting key|}} +
+ +
+ {{#iff setting.htmlType "===" "Number"}} + + {{/iff}} + {{#iff setting.htmlType "===" "String"}} + + {{/iff}} - {{#iff setting.htmlType "===" "Select"}} - - {{/iff}} + {{#iff setting.htmlType "===" "Select"}} + + {{/iff}} - {{#iff setting.htmlType "===" "Boolean"}} - - - - {{/iff}} + {{#iff setting.htmlType "===" "Boolean"}} + + + + {{/iff}} - {{#iff setting.htmlType "===" "Color"}} - - {{colorPicker name=key value = setting.value default=setting.value}} - - {{/iff}} -
-

{{{localize setting.hint}}}

-
+ {{#iff setting.htmlType "===" "Color"}} + + {{colorPicker name=key value = setting.value default=setting.value}} + + {{/iff}} +
+

{{{localize setting.hint}}}

+
+ {{/each}} + +
{{/each}} +