Skip to content

Commit

Permalink
#9, #10, #11, open() parameters, jscolor
Browse files Browse the repository at this point in the history
- #9: Fix challenge tracker appearing momentarily when user does
  not have permission to show to others.
- #10: Add user options for background colours of the outer ring and
  inner circle.
- #11: Fix 'Error: User 'Player' lacks permission to update User' error.
- open() parameters: Support exclusion of outerTotal and innerTotal
  parameters from open() method.
- jscolor:  Use modified jscolor.js to add alpha channel to color
  pickers.
  • Loading branch information
Larkinabout committed Jul 21, 2022
1 parent b7a84d2 commit 40a9ba5
Show file tree
Hide file tree
Showing 13 changed files with 3,581 additions and 69 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ An interactive aid to track successes and failures in challenges à la D&D 4e-in
## How to Use
### Using the Player List
![challenge-tracker-macro](./images/challenge-tracker-player-list.png)
1. Click the button ![challenge-tracker-macro](./images/challenge-tracker-player-list-button.png) in the player list.
1. Click the ![challenge-tracker-macro](./images/challenge-tracker-player-list-button.png) button in the player list.

![challenge-tracker-macro](./images/challenge-tracker-list.png)

Expand All @@ -32,10 +32,12 @@ An interactive aid to track successes and failures in challenges à la D&D 4e-in
More options can be set using an optional array parameter: `ChallengeTracker.open(successes failures, {options})` where options is a comma-separated list of any of the following parameters in the format `option: value`:
- **outerCurrent:** Set the number of completed segments on the outer ring (successes). Default is `0`. Example: `outerCurrent: 3
- **innerCurrent:** Set the number of completed segments on the inner circle (failures). Default is `0`. Example: `innerCurrent:
- **outerBackgroundColor:** Set the background hex color of the outer ring (successes). The 'Outer Background Color' module setting will be ignored. Example: `outerBackgroundColor: '#1B6F1B66'`
- **outerColor:** Set the hex color of the outer ring (successes). The 'Outer Color' module setting will be ignored. Example: `outerColor: '#0000FF'`
- **innerColor:** Set the hex color of the inner circle (failures). The 'Inner Color' module setting will be ignored. Example: `innerColor: '#0000FF'`
- **innerColor:** Set the hex color of the inner circle (failures). The 'Inner Color' module setting will be ignored.
- **innerBackgroundColor:** Set the background hex color of the inner circle (failures). The 'Inner Background Color' module setting will be ignored. Example: `innerBackgroundColor: '#B0000066'`
- **frameColor:** Set the hex color of the frame. The 'Frame Color' module setting will be ignored. Example: `frameColor: '#0000FF'`
- **persist:** Set to `true` to persist the Challenge Tracker across sessions. Default is `false`. Example: `persist: true`
- **persist:** Set to `true` to persist the Challenge Tracker across sessions. Default is `false`. This option will be ignored when the user's role is not equal to or greater than the role selected in the 'Allow Show to Others' module setting. Example: `persist: true`
- **show:** Set to `true` to show the Challenge Tracker to your players. Default is `false`. Example: `show: true`
- **size:** Set the size of the Challenge Tracker in pixels between 200 to 600. The 'Size' module setting will be ignored. Example: `size: 400`
- **title:** Set the title of the Challenge Tracker in the window header. Default is `Challenge Tracker`. Example: `title: 'Skill Challenge 1'`
Expand Down
12 changes: 11 additions & 1 deletion languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@
},
"settings": {
"allowShow" : {
"name": "Show to Others",
"name": "Allow Show to Others",
"hint": "Allow users with this role (and above) to show Challenge Trackers to others (Requires reload)"
},
"outerBackgroundColor" : {
"name": "Outer Background Color",
"hint": "Set the default background color for the outer ring",
"label": "Color Picker"
},
"outerColor" : {
"name": "Outer Color",
"hint": "Set the default color for the outer ring",
"label": "Color Picker"
},
"innerBackgroundColor" : {
"name": "Inner Background Color",
"hint": "Set the default background color for the inner circle",
"label": "Color Picker"
},
"innerColor" : {
"name": "Inner Color",
"hint": "Set the default color for the inner circle",
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "challenge-tracker",
"title": "Challenge Tracker",
"description": "An interactive aid to track successes and failures in challenges à la D&D 4e-inspired skill challenges and Blades in the Dark progress clocks",
"version": "0.7",
"version": "0.8",
"library": "false",
"manifestPlusVersion": "1.0.0",
"minimumCoreVersion": "9",
Expand Down
2 changes: 2 additions & 0 deletions scripts/challenge-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Hooks.once('ready', async () => {
}
}

ChallengeTrackerFlag.setOwner()

// Initialize Challenge Tracker
window.ChallengeTracker = {
open: ChallengeTracker.open,
Expand Down
14 changes: 14 additions & 0 deletions scripts/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ export class ChallengeTrackerFlag {
* @param {array} challengeTrackerOptions Challenge Tracker Options
* @param {string} challengeTrackerOptions.frameColor Hex color of the frame
* @param {string} challengeTrackerOptions.id Unique identifier of the challenge tracker
* @param {string} challengeTrackerOptions.innerBackgroundColor Hex color of the inner circle background
* @param {string} challengeTrackerOptions.innerColor Hex color of the inner circle
* @param {number} challengeTrackerOptions.innerCurrent Number of filled segments of the inner circle
* @param {number} challengeTrackerOptions.innerTotal Number of segments for the inner circle
* @param {string} challengeTrackerOptions.outerBackgroundColor Hex color of the outer ring background
* @param {string} challengeTrackerOptions.outerColor Hex color of the outer ring
* @param {number} challengeTrackerOptions.outerCurrent Number of filled segments of the outer ring
* @param {number} challengeTrackerOptions.outerTotal Number of segments for the outer ring
Expand Down Expand Up @@ -67,4 +69,16 @@ export class ChallengeTrackerFlag {
ui.notifications.info(`Challenge Tracker '${challengeTrackerId}' deleted.`)
return deletedFlag
}

static async setOwner () {
if (!game.user.data.flags['challenge-tracker']) return
const flagKeys = Object.keys(game.user.data.flags['challenge-tracker'])
for (const flagKey of flagKeys) {
const flag = await game.user.getFlag(ChallengeTrackerSettings.id, flagKey)
if (flag.ownerId !== game.userId) {
const challengeTrackerOptions = foundry.utils.mergeObject(flag, { ownerId: game.userId })
await game.user.setFlag(ChallengeTrackerSettings.id, flagKey, challengeTrackerOptions)
}
}
}
}
7 changes: 6 additions & 1 deletion scripts/form.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ChallengeTrackerSettings, ChallengeTracker } from './main.js'
import { ChallengeTrackerFlag } from './flags.js'
import jscolor from './lib/jscolor.js'

/* Display challenge trackers in a list with options */
export class ChallengeTrackerForm extends FormApplication {
Expand Down Expand Up @@ -88,14 +89,15 @@ export class ChallengeTrackerEditForm extends FormApplication {
super()
this.ownerId = ownerId
this.challengeTrackerId = challengeTrackerId
this.jscolor = jscolor
}

static get defaultOptions () {
const defaults = super.defaultOptions

const overrides = {
height: 'auto',
width: 'auto',
width: '300px',
id: 'challenge-tracker-edit-form',
template: ChallengeTrackerSettings.templates.challengeTrackerEditForm,
title: `Edit ${ChallengeTrackerSettings.title}`,
Expand All @@ -116,9 +118,11 @@ export class ChallengeTrackerEditForm extends FormApplication {
challengeTracker: {
frameColor: null,
id: `${ChallengeTrackerSettings.id}-${Math.random().toString(16).slice(2)}`,
innerBackgroundColor: null,
innerColor: null,
innerCurrent: 0,
innerTotal: 3,
outerBackgroundColor: null,
outerColor: null,
outerCurrent: 0,
outerTotal: 4,
Expand Down Expand Up @@ -151,6 +155,7 @@ export class ChallengeTrackerEditForm extends FormApplication {

activateListeners (html) {
super.activateListeners(html)
this.jscolor.install()
}

/**
Expand Down
Loading

0 comments on commit 40a9ba5

Please sign in to comment.