Skip to content

Commit

Permalink
Merge branch 'allow-negative-resource-values'
Browse files Browse the repository at this point in the history
  • Loading branch information
davelens committed Dec 12, 2020
2 parents 9a5a105 + 946cee6 commit 592feec
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
* Made it so longer resource labels (19+ characters) are properly word-wrapped
instead of bleeding through the +/- buttons.
* Allow for negative values when decrementing resource values.
* Add functionality to not let negative values exceed a given minimum.
2 changes: 2 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"FvttPartyResources.ResourceForm.IdentifierHint": "The identifier that represents this resource in API requests. Should not contain spaces or numbers, and should be lowercase.",
"FvttPartyResources.ResourceForm.MaxValue": "Maximum value",
"FvttPartyResources.ResourceForm.MaxValueHint": "When this (optional) integer is provided, you won't be able to increase the resource's value above the given number.",
"FvttPartyResources.ResourceForm.MinValue": "Minimum value",
"FvttPartyResources.ResourceForm.MinValueHint": "When this (optional) integer is provided, you won't be able to lower the resource's value below the given number.",
"FvttPartyResources.ResourceForm.Name": "Resource name",
"FvttPartyResources.ResourceForm.NameHint": "The name shown in the resource dashboard.",
"FvttPartyResources.ResourceForm.PlayerManaged": "Allow players to manage this resource.",
Expand Down
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"author": "Dave Lens",
"url": "https://github.com/davelens/fvtt-party-resources",
"manifest": "https://raw.githubusercontent.com/davelens/fvtt-party-resources/master/module.json",
"download": "https://github.com/davelens/fvtt-party-resources/archive/1.1.0.zip",
"version": "1.1.0",
"download": "https://github.com/davelens/fvtt-party-resources/archive/1.1.1.zip",
"version": "1.1.1",
"minimumCoreVersion": "0.7.0",
"compatibleCoreVersion":"0.7.8",
"languages": [
Expand Down
2 changes: 2 additions & 0 deletions modules/apps/resource_form.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ export default class ResourceForm extends FormApplication {
PartyResourcesApi.register(id.concat('_name'))
PartyResourcesApi.register(id.concat('_visible'), { default: true })
PartyResourcesApi.register(id.concat('_max'))
PartyResourcesApi.register(id.concat('_min'))
PartyResourcesApi.register(id.concat('_player_managed'), { default: false })

PartyResourcesApi.set(id, data['resource[default_value]'])
PartyResourcesApi.set(id.concat('_name'), data['resource[name]'])
PartyResourcesApi.set(id.concat('_visible'), data['resource[visible]'])
PartyResourcesApi.set(id.concat('_max'), data['resource[max_value]'])
PartyResourcesApi.set(id.concat('_min'), data['resource[min_value]'])
PartyResourcesApi.set(id.concat('_player_managed'), data['resource[player_managed]'])
}

Expand Down
1 change: 1 addition & 0 deletions modules/apps/resources_dashboard.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default class ResourcesDashboard extends Application {
default_value: PartyResourcesApi.get(id),
name: PartyResourcesApi.get(id.concat('_name')),
max_value: PartyResourcesApi.get(id.concat('_max')),
min_value: PartyResourcesApi.get(id.concat('_min')),
player_managed: PartyResourcesApi.get(id.concat('_player_managed')),
allowed_to_modify_settings: game.permissions.SETTINGS_MODIFY.includes(1),
visible: PartyResourcesApi.get(id.concat('_visible'))
Expand Down
6 changes: 5 additions & 1 deletion modules/resources_api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import ResourcesList from "./resources_list.mjs";

export default class ResourcesApi {
decrement(name) {
this.set(name, this.get(name) - 1)
let value = this.get(name)
let min = this.get(name.concat('_min'))
this.set(name, min && value <= min ? value : value - 1)
}

get(name) {
Expand Down Expand Up @@ -37,13 +39,15 @@ export default class ResourcesApi {
this.register(resource.concat('_name'))
this.register(resource.concat('_visible'), { default: true })
this.register(resource.concat('_max'))
this.register(resource.concat('_min'))
this.register(resource.concat('_player_managed'))

results.push({
id: resource,
value: this.get(resource),
name: this.get(resource.concat('_name')),
max_value: this.get(resource.concat('_max')),
min_value: this.get(resource.concat('_min')),
player_managed: this.get(resource.concat('_player_managed')),
manageable: game.user.isGM || this.get(resource.concat('_player_managed')),
visible: this.get(resource.concat('_visible')),
Expand Down
8 changes: 8 additions & 0 deletions templates/resource_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
<p class="notes">{{ localize 'FvttPartyResources.ResourceForm.DefaultValueHint' }}</p>
</div>

<div class="form-group">
<label for="min_value">{{ localize 'FvttPartyResources.ResourceForm.MinValue' }}</label>
<div class="form-fields">
<input type="number" id="min_value" name="resource[min_value]" value="{{ min_value }}" data-dtype="Number">
</div>
<p class="notes">{{ localize 'FvttPartyResources.ResourceForm.MinValueHint' }}</p>
</div>

<div class="form-group">
<label for="max_value">{{ localize 'FvttPartyResources.ResourceForm.MaxValue' }}</label>
<div class="form-fields">
Expand Down

0 comments on commit 592feec

Please sign in to comment.