diff --git a/CHANGELOG.md b/CHANGELOG.md index bbcc4e5..0bcd52e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/lang/en.json b/lang/en.json index 7012f31..f376fa8 100644 --- a/lang/en.json +++ b/lang/en.json @@ -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.", diff --git a/module.json b/module.json index f4d91b6..6bbd87a 100755 --- a/module.json +++ b/module.json @@ -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": [ diff --git a/modules/apps/resource_form.mjs b/modules/apps/resource_form.mjs index 51847fc..5481cf9 100644 --- a/modules/apps/resource_form.mjs +++ b/modules/apps/resource_form.mjs @@ -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]']) } diff --git a/modules/apps/resources_dashboard.mjs b/modules/apps/resources_dashboard.mjs index 201998f..767f3e3 100755 --- a/modules/apps/resources_dashboard.mjs +++ b/modules/apps/resources_dashboard.mjs @@ -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')) diff --git a/modules/resources_api.mjs b/modules/resources_api.mjs index c3db83f..7081a73 100644 --- a/modules/resources_api.mjs +++ b/modules/resources_api.mjs @@ -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) { @@ -37,6 +39,7 @@ 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({ @@ -44,6 +47,7 @@ export default class ResourcesApi { 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')), diff --git a/templates/resource_form.html b/templates/resource_form.html index 5d35724..90bd370 100644 --- a/templates/resource_form.html +++ b/templates/resource_form.html @@ -25,6 +25,14 @@

{{ localize 'FvttPartyResources.ResourceForm.DefaultValueHint' }}

+
+ +
+ +
+

{{ localize 'FvttPartyResources.ResourceForm.MinValueHint' }}

+
+