From 87a32fbcce3f46d6584271af4a0c1c7028affb42 Mon Sep 17 00:00:00 2001 From: Harley White Date: Fri, 30 Apr 2021 22:40:59 -0400 Subject: [PATCH] Added buyable purchase limit --- changelog.md | 1 + docs/buyables.md | 6 ++++-- js/Demo/demoLayers.js | 5 +++-- js/components.js | 5 +++-- js/technical/layerSupport.js | 4 +++- js/utils.js | 7 ++++++- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/changelog.md b/changelog.md index 6e3395e..0e0ce42 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ # The Modding Tree changelog: +- Added buyable purchaseLimit. - Amount is automatically supplied to buyable cost and effect functions. # v2.4.1 - 4/29/21 diff --git a/docs/buyables.md b/docs/buyables.md index 97c39de..30e217d 100644 --- a/docs/buyables.md +++ b/docs/buyables.md @@ -35,7 +35,7 @@ Features: - cost(): cost for buying the next buyable. Can have an optional argument "x" to calculate the cost of the x+1th purchase. (x is a `Decimal`). Can return an object if there are multiple currencies. -- effect(): **optional**. A function that calculates and returns the current values of bonuses of this buyable. Can have an optional argument "x", similar to cost. +- effect(): **optional**. A function that calculates and returns the current values of bonuses of this buyable. Can have an optional argument "x" to calculate the effect of having x of the buyable.. Can return a value or an object containing multiple values. - display(): A function returning everything that should be displayed on the buyable after the title, likely including the description, amount bought, cost, and current effect. Can use basic HTML. @@ -49,7 +49,9 @@ Features: - buyMax(): **optional**. A function that implements buying as many of the buyable as possible. - style: **optional**. Applies CSS to this buyable, in the form of an object where the keys are CSS attributes, and the values are the values for those attributes (both as strings). - + +- purchaseLimit: **optional**. The limit on how many of the buyable can be bought. The default is no limit. + - layer: **assigned automagically**. It's the same value as the name of this layer, so you can do `player[this.layer].points` or similar. - id: **assigned automagically**. It's the "key" which the buyable was stored under, for convenient access. The buyable in the example's id is 11. diff --git a/js/Demo/demoLayers.js b/js/Demo/demoLayers.js index b54d3d6..8787a49 100644 --- a/js/Demo/demoLayers.js +++ b/js/Demo/demoLayers.js @@ -175,7 +175,7 @@ addLayer("c", { display() { // Everything else displayed in the buyable button after the title let data = tmp[this.layer].buyables[this.id] return "Cost: " + format(data.cost) + " lollipops\n\ - Amount: " + player[this.layer].buyables[this.id] + "\n\ + Amount: " + player[this.layer].buyables[this.id] + "/4\n\ Adds + " + format(data.effect.first) + " things and multiplies stuff by " + format(data.effect.second) }, unlocked() { return player[this.layer].unlocked }, @@ -189,6 +189,7 @@ addLayer("c", { }, buyMax() {}, // You'll have to handle this yourself if you want style: {'height':'222px'}, + purchaseLimit: new Decimal(4), sellOne() { let amount = getBuyableAmount(this.layer, this.id) if (amount.lte(0)) return // Only sell one if there is at least one @@ -360,7 +361,7 @@ addLayer("c", { }, tooltip() { // Optional, tooltip displays when the layer is unlocked let tooltip = formatWhole(player[this.layer].points) + " " + this.resource - if (player[this.layer].buyables[11].gt(0)) tooltip += "
" + formatWhole(player[this.layer].buyables[11]) + " Exhancers" + if (player[this.layer].buyables[11].gt(0)) tooltip += "
" + formatWhole(player[this.layer].buyables[11]) + " Exhancers" return tooltip }, shouldNotify() { // Optional, layer will be highlighted on the tree if true. diff --git a/js/components.js b/js/components.js index b53f088..e111c03 100644 --- a/js/components.js +++ b/js/components.js @@ -257,8 +257,8 @@ function loadVue() { props: ['layer', 'data', 'size'], template: `
-