Skip to content

Commit

Permalink
Merge pull request #199 from sasquach45932/master
Browse files Browse the repository at this point in the history
Add colour to DSN! D6s, now with colour picker
  • Loading branch information
ClipplerBlood authored Sep 5, 2024
2 parents dbd8f1a + 0be32e7 commit 9b560fc
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 12 deletions.
10 changes: 8 additions & 2 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,14 @@
"DL.SettingAttackShowEnemyAttributeHint": "Show the Creatures target number you are rolling against in the chat.",
"DL.SettingAutoDeleteEffects": "Auto delete Active Effects",
"DL.SettingAutoDeleteEffectsHint": "Automatically delete Active Effects from non-player items when they expire.",
"DL.SettingColourBoBDieDSNMessage": "Add Colour to Boon/Bane Die",
"DL.SettingColourBoBDieDSNMessageHint": "Add colour to used die (green for banes, red for boons) in Dice So Nice!.",
"DL.SettingDSNBaneDieColour": "Bane dice",
"DL.SettingDSNBaneDieColourHint": "The colour that will be used to colour bane dice.",
"DL.SettingDSNBoonDieColour": "Boon dice",
"DL.SettingDSNBoonDieColourHint": "The colour that will be used to colour boon dice.",
"DL.SettingDSNColourDie": "Enable dice colouring",
"DL.SettingDSNLabel": "Settings",
"DL.SettingDSNName": "Add colour to Boons/banes dice",
"DL.SettingDSNNameHint": "Change the colour of the Dice So Nice! boons/banes dice.",
"DL.SettingConfirmAncestryPathRemoval": "Confirm ancestry/path removal",
"DL.SettingConfirmAncestryPathRemovalHint": "Show a confirmation dialog when attempting to remove an ancestry or path from a character of level 1 or higher.",
"DL.SettingGMEffectsControls": "GM Effects Controls",
Expand Down
4 changes: 2 additions & 2 deletions src/module/chat/roll-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ function changeBobDieColour (attackRoll)
if (attackRoll === null || attackRoll === undefined ) return attackRoll
if (game.settings.get('demonlord', 'colourBoBDieDSN')) {
let d6Index = 0
let bgColor = '#bf0202'
let bgColor = game.settings.get('demonlord', 'baneColour')
if (game.modules.get('dice-so-nice')?.active) {
if (attackRoll._formula.includes('d6kh') || attackRoll._formula.includes('d6r1kh')) {
let operator = attackRoll.terms[attackRoll.terms.length - 2].operator

if (operator === '+') bgColor = '#104f09'
if (operator === '+') bgColor = game.settings.get('demonlord', 'boonColour')

for (let die of attackRoll.dice) {
if (die._faces === 6) d6Index++
Expand Down
94 changes: 86 additions & 8 deletions src/module/settings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,90 @@
export class AdvancedSettings extends FormApplication {
constructor() {
super();
}

static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {
id: "advanced-settings",
title: game.i18n.localize("DL.SettingDSNLabel"),
template: 'systems/demonlord/templates/setting/advancedsettings.hbs',
width: 520
});
}

getData() {
return {
colourBoBDieDSN: game.settings.get('demonlord', 'colourBoBDieDSN'),
colourBane: game.settings.get('demonlord', 'baneColour'),
colourBoon: game.settings.get('demonlord', 'boonColour')
};
}

async resetToDefault(key) {
const defaultValue = game.settings.settings.get(`demonlord.${key}`).default;
await game.settings.set("demonlord", key, defaultValue);
}

async _updateObject(event, formData) {
for (let [k, v] of Object.entries(foundry.utils.flattenObject(formData))) {
let s = game.settings.settings.get(`demonlord.${k}`);
let current = game.user.isGM
? game.settings.get('demonlord', s.key)
: game.user.getFlag('demonlord', k);
if (v === current) continue;
await game.settings.set('demonlord', s.key, v);
}
}

async activateListeners(html) {
super.activateListeners(html);
html.find('button').on('click', async (event) => {
if (event.currentTarget?.dataset?.action === 'reset') {
const keys = ['colourBoBDieDSN', 'boonColour','baneColour'];
await Promise.all(
keys.map(async (key) => {
await this.resetToDefault(key);
})
);
this.close();
}
});
}
}

export const registerSettings = function () {
game.settings.registerMenu('demonlord', 'advancedSettings', {
name: game.i18n.localize("DL.SettingDSNName"),
label: game.i18n.localize("DL.SettingDSNLabel"),
hint: game.i18n.localize("DL.SettingDSNNameHint"),
icon: "fas fa-sliders-h",
type: AdvancedSettings
});

game.settings.register('demonlord', 'colourBoBDieDSN', {
name: game.i18n.localize('DL.SettingColourBoBDieDSNMessage'),
hint: game.i18n.localize('DL.SettingColourBoBDieDSNMessageHint'),
default: false,
scope: 'client',
type: Boolean,
config: false,
})

game.settings.register('demonlord', 'boonColour', {
name: game.i18n.localize('DL.SettingBoonDieColour'),
scope: 'client',
type: new foundry.data.fields.ColorField({ required: true, blank: false }),
default: '#104f09',
config: false
})
game.settings.register('demonlord', 'baneColour', {
name: game.i18n.localize('DL.SettingBaneDieColour'),
scope: 'client',
type: new foundry.data.fields.ColorField({ required: true, blank: false }),
default: '#bf0202',
config: false
})

game.settings.register('demonlord', 'systemMigrationVersion', {
name: 'System Migration Version',
scope: 'world',
Expand All @@ -14,14 +100,6 @@ export const registerSettings = function () {
type: Boolean,
config: true,
})
game.settings.register('demonlord', 'colourBoBDieDSN', {
name: game.i18n.localize('DL.SettingColourBoBDieDSNMessage'),
hint: game.i18n.localize('DL.SettingColourBoBDieDSNMessageHint'),
default: false,
scope: 'client',
type: Boolean,
config: true,
})
game.settings.register('demonlord', 'initMessage', {
name: game.i18n.localize('DL.SettingInitMessage'),
hint: game.i18n.localize('DL.SettingInitMessageHint'),
Expand Down
28 changes: 28 additions & 0 deletions src/templates/setting/advancedsettings.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<form autocomplete="off">

<div class="form-group">
<label>{{localize "DL.SettingDSNColourDie"}}</label>
<input type="checkbox" name="colourBoBDieDSN" {{checked colourBoBDieDSN}} data-dtype="Boolean"/>
</div>
<hr>
<div class="form-group">
<label>{{localize "DL.SettingDSNBoonDieColour"}}</label>
<input type="color" name="boonColour" data-dtype="string" value="{{colourBoon}}"/>
<p class="notes">{{localize "DL.SettingDSNBoonDieColourHint"}}</p>
</div>
<div class="form-group">
<label>{{localize "DL.SettingDSNBaneDieColour"}}</label>
<input type="color" name="baneColour" data-dtype="string" value="{{colourBane}}"/>
<p class="notes">{{localize "DL.SettingDSNBaneDieColourHint"}}</p>
</div>
<footer class="sheet-footer flexrow">
<button type="submit" name="submit">
<i class="far fa-save"></i>
{{localize "SETTINGS.Save"}}
</button>
<button type="button" data-action="reset">
<i class="fas fa-undo"></i>
{{localize "SETTINGS.Reset"}}
</button>
</footer>
</form>

0 comments on commit 9b560fc

Please sign in to comment.