Skip to content

Commit

Permalink
fix: add dropdown with settings for rulesets
Browse files Browse the repository at this point in the history
Previously the users needed to reference the documentation in order to
set the correct values for a given rulset. This change adds a dropdown
containing supported rulesets and populates the corresponding settings
fields.

Part of xdy#183
  • Loading branch information
jonepatr authored and xdy committed Jan 2, 2021
1 parent 516c481 commit 0f6b767
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 1 deletion.
46 changes: 46 additions & 0 deletions src/module/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,52 @@ TWODSIX.VARIANTS = {
"CEL": "CEL",
};

TWODSIX.RULESETS = {
"CE": {
"name": "Cepheus Engine",
"setttings": {
"initiativeFormula": "2d6 + @characteristics.dexterity.mod",
"difficultyListUsed": "CE",
"difficultiesAsTargetNumber": false,
"autofireRulesUsed": "CE",
"modifierForZeroCharacteristic": -2,
"termForAdvantage": "advantage",
"termForDisadvantage": "disadvantage",
"absoluteBonusValueForEachTimeIncrement": 1
}
},
"CEL": {
"name": "Cepheus Light",
"setttings": {
"initiativeFormula": "2d6",
"difficultyListUsed": "CEL",
"difficultiesAsTargetNumber": true,
"autofireRulesUsed": "CEL",
"modifierForZeroCharacteristic": -2,
"termForAdvantage": "advantage",
"termForDisadvantage": "disadvantage",
"absoluteBonusValueForEachTimeIncrement": 1
}
},
"CEFTL": {
"name": "Cepheus Faster Than Light",
"setttings": {
"initiativeFormula": "2d6",
"difficultyListUsed": "CEL",
"difficultiesAsTargetNumber": true,
"autofireRulesUsed": "CE",
"modifierForZeroCharacteristic": -2,
"termForAdvantage": "advantage",
"termForDisadvantage": "disadvantage",
"absoluteBonusValueForEachTimeIncrement": 1
}
},
"OTHER": {
"name": "Other",
"setttings": {}
}
};

TWODSIX.ROLLTYPES = {
Advantage: "3d6kh2",
Normal: "2d6",
Expand Down
14 changes: 14 additions & 0 deletions src/module/hooks/renderSettingsConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {TWODSIX} from "../config";

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Hooks.on('renderSettingsConfig', async (app, html, data) => {
html.find('[name="twodsix.ruleset"]').on('change', ev => {
const ruleset = ev.target.value;
const rulesetSettings = TWODSIX.RULESETS[ruleset].setttings;

// Step through each option and update the corresponding field
Object.entries(rulesetSettings).forEach(([settingName, value]) => {
html.find(`[name="twodsix.${settingName}"]`).val(value);
});
});
});
5 changes: 5 additions & 0 deletions src/module/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ export const registerSettings = function ():void {
//Foundry default behaviour related settings
_booleanSetting('defaultTokenSettings', true);

const rulesetOptions = Object.entries(TWODSIX.RULESETS).map(([id, ruleset]) => {
return [id, ruleset["name"]];
});
_stringChoiceSetting('ruleset', TWODSIX.RULESETS["CE"].name, Object.fromEntries(rulesetOptions), 'twodsix');

//House rules/variant related settings
const DEFAULT_INITIATIVE_FORMULA = "2d6 + @characteristics.dexterity.mod";
_stringSetting('initiativeFormula', DEFAULT_INITIATIVE_FORMULA, 'world', formula => CONFIG.Combat.initiative = {
Expand Down
4 changes: 4 additions & 0 deletions static/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@
"using": "using {characteristic}"
},
"Settings": {
"ruleset": {
"hint": "This will configure the below settings with the best options for the given ruleset.",
"name": "Ruleset"
},
"absoluteBonusValueForEachTimeIncrement": {
"hint": "Leave empty to use default (+/-1). Not currently used.",
"name": "What bonus/penalty to give per each time increment change in a task."
Expand Down
4 changes: 4 additions & 0 deletions static/lang/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@
"using": "med {characteristic}"
},
"Settings": {
"ruleset": {
"hint": "Detta kommer att ställa in nedanstående fält med de bästa inställningarna för angiven spelvariant.",
"name": "Spelvariant"
},
"absoluteBonusValueForEachTimeIncrement": {
"hint": "Lämna tomt för att använda default (+/-1). Används inte för närvarande.",
"name": "Vilken bonus/malus som ges för varje tidsintervallsteg."
Expand Down
3 changes: 2 additions & 1 deletion webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import MiniCssExtractPlugin from "mini-css-extract-plugin";

//Only a partial type, not sure what else can be in this, and haven't looked into it.
type FoundryConfig = { dataPath:string, systemName:string };
const hookDir = './src/module/hooks/';

function getFoundryConfig():FoundryConfig {
const configPath = path.resolve(process.cwd(), 'foundryconfig.json');
Expand All @@ -20,7 +21,7 @@ module.exports = (env, argv) => {
const config:Configuration = {
context: __dirname,
entry: {
main: ["./src/twodsix.ts", "./src/module/hooks/ready.ts", "./src/module/hooks/setup.ts", "./src/module/hooks/preCreateActor.ts", "./src/module/hooks/createItem.ts", "./src/module/hooks/renderItemSheet.ts", "./src/module/hooks/renderChatMessage.ts"]
main: ["./src/twodsix.ts"].concat(fs.readdirSync(hookDir).map(file => hookDir + file))
},
mode: "development",
module: {
Expand Down

0 comments on commit 0f6b767

Please sign in to comment.