diff --git a/changelog.md b/changelog.md index 3e760d8..6e3395e 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,7 @@ # The Modding Tree changelog: +- Amount is automatically supplied to buyable cost and effect functions. + # v2.4.1 - 4/29/21 - A number of minor fixes, many thanks to thepaperpilot. - The respec confirmation checkbox is now part of the respec-button component. diff --git a/demo.html b/demo.html index 1ec44e9..aa73dda 100644 --- a/demo.html +++ b/demo.html @@ -14,6 +14,8 @@ + + diff --git a/docs/buyables.md b/docs/buyables.md index 1a827bc..97c39de 100644 --- a/docs/buyables.md +++ b/docs/buyables.md @@ -32,9 +32,11 @@ Features: - title: **optional**. displayed at the top in a larger font. It can also be a function that returns updating text. -- cost(): cost for buying the next buyable. Can have an optional argument "x" to calculate the cost of the x+1th object, but needs to use "current amount" as a default value for x. (x is a `Decimal`). Can return an object if there are multiple currencies. +- 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 return a value or an object containing multiple values. +- 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. + 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. diff --git a/index.html b/index.html index f95bb3d..89c9fc4 100644 --- a/index.html +++ b/index.html @@ -14,6 +14,7 @@ + diff --git a/js/Demo/demoLayers.js b/js/Demo/demoLayers.js index 4657669..b54d3d6 100644 --- a/js/Demo/demoLayers.js +++ b/js/Demo/demoLayers.js @@ -158,12 +158,12 @@ addLayer("c", { respecMessage: "Are you sure? Respeccing these doesn't accomplish much.", 11: { title: "Exhancers", // Optional, displayed at the top in a larger font - cost(x=player[this.layer].buyables[this.id]) { // cost for buying xth buyable, can be an object if there are multiple currencies + cost(x) { // cost for buying xth buyable, can be an object if there are multiple currencies if (x.gte(25)) x = x.pow(2).div(25) let cost = Decimal.pow(2, x.pow(1.5)) return cost.floor() }, - effect(x=player[this.layer].buyables[this.id]) { // Effects of owning x of the items, x is a decimal + effect(x) { // Effects of owning x of the items, x is a decimal let eff = {} if (x.gte(0)) eff.first = Decimal.pow(25, x.pow(1.1)) else eff.first = Decimal.pow(1/25, x.times(-1).pow(1.1)) diff --git a/js/technical/displays.js b/js/technical/displays.js new file mode 100644 index 0000000..e69de29 diff --git a/js/technical/temp.js b/js/technical/temp.js index 9b83527..c1bb302 100644 --- a/js/technical/temp.js +++ b/js/technical/temp.js @@ -7,7 +7,7 @@ var NaNalert = false; var activeFunctions = [ "startData", "onPrestige", "doReset", "update", "automate", "buy", "buyMax", "respec", "onComplete", "onPurchase", "onPress", "onClick", "masterButtonPress", - "sellOne", "sellAll", "pay", + "sellOne", "sellAll", "pay", "actualCostFunction", "actualEffectFunction", ] var noCall = doNotCallTheseFunctionsEveryTick @@ -36,6 +36,7 @@ function setupTemp() { tmp[layer].prestigeButtonText = {} tmp[layer].computedNodeStyle = [] setupBarStyles(layer) + setupBuyables(layer) } temp = tmp } @@ -229,4 +230,22 @@ function setupBarStyles(layer){ bar.dims = {} bar.fillDims = {} } +} + +function setupBuyables(layer) { + for (id in layers[layer].buyables) { + if (!isNaN(id)) { + let b = layers[layer].buyables[id] + b.actualCostFunction = b.cost + b.cost = function(x) { + x = x ?? player[this.layer].buyables[this.id] + return layers[this.layer].buyables[this.id].actualCostFunction(x) + } + b.actualEffectFunction = b.effect + b.effect = function(x) { + x = x ?? player[this.layer].buyables[this.id] + return layers[this.layer].buyables[this.id].actualEffectFunction(x) + } + } + } } \ No newline at end of file