mirror of
https://github.com/Acamaeda/The-Modding-Tree.git
synced 2024-11-21 16:13:55 +00:00
Added buyable purchase limit
This commit is contained in:
parent
4af32d5c71
commit
87a32fbcce
6 changed files with 20 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
@ -50,6 +50,8 @@ Features:
|
|||
|
||||
- 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.
|
||||
|
|
|
@ -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 += "<br>" + formatWhole(player[this.layer].buyables[11]) + " Exhancers"
|
||||
if (player[this.layer].buyables[11].gt(0)) tooltip += "<br><i>" + formatWhole(player[this.layer].buyables[11]) + " Exhancers</i>"
|
||||
return tooltip
|
||||
},
|
||||
shouldNotify() { // Optional, layer will be highlighted on the tree if true.
|
||||
|
|
|
@ -257,8 +257,8 @@ function loadVue() {
|
|||
props: ['layer', 'data', 'size'],
|
||||
template: `
|
||||
<div v-if="tmp[layer].buyables && tmp[layer].buyables[data]!== undefined && tmp[layer].buyables[data].unlocked" style="display: grid">
|
||||
<button v-bind:class="{ buyable: true, can: tmp[layer].buyables[data].canAfford, locked: !tmp[layer].buyables[data].canAfford}"
|
||||
v-bind:style="[tmp[layer].buyables[data].canAfford ? {'background-color': tmp[layer].color} : {}, size ? {'height': size, 'width': size} : {}, tmp[layer].componentStyles.buyable, tmp[layer].buyables[data].style]"
|
||||
<button v-bind:class="{ buyable: true, can: tmp[layer].buyables[data].canBuy, locked: !tmp[layer].buyables[data].canAfford, bought: player[layer].buyables[data].gte(tmp[layer].buyables[data].purchaseLimit)}"
|
||||
v-bind:style="[tmp[layer].buyables[data].canBuy ? {'background-color': tmp[layer].color} : {}, size ? {'height': size, 'width': size} : {}, tmp[layer].componentStyles.buyable, tmp[layer].buyables[data].style]"
|
||||
v-on:click="buyBuyable(layer, data)">
|
||||
<span v-if= "tmp[layer].buyables[data].title"><h2 v-html="tmp[layer].buyables[data].title"></h2><br></span>
|
||||
<span v-bind:style="{'white-space': 'pre-line'}" v-html="tmp[layer].buyables[data].display"></span>
|
||||
|
@ -469,6 +469,7 @@ function loadVue() {
|
|||
maxedChallenge,
|
||||
inChallenge,
|
||||
canAffordUpgrade,
|
||||
canBuyBuyable,
|
||||
canCompleteChallenge,
|
||||
subtabShouldNotify,
|
||||
subtabResetNotify,
|
||||
|
|
|
@ -119,6 +119,8 @@ function setupLayer(layer){
|
|||
if (layers[layer].buyables[thing].unlocked === undefined)
|
||||
layers[layer].buyables[thing].unlocked = true
|
||||
}
|
||||
layers[layer].buyables[thing].canBuy = function() {return canBuyBuyable(this.layer, this.id)}
|
||||
if (layers[layer].buyables[thing].purchaseLimit === undefined) layers[layer].buyables[thing].purchaseLimit = new Decimal(Infinity)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,11 @@ function canAffordUpgrade(layer, id) {
|
|||
return canAffordPurchase(layer, upg, cost)
|
||||
}
|
||||
|
||||
function canBuyBuyable(layer, id) {
|
||||
let b = temp[layer].buyables[id]
|
||||
return (b.unlocked && b.canAfford && player[layer].buyables[id].lt(b.purchaseLimit))
|
||||
}
|
||||
|
||||
function hasUpgrade(layer, id) {
|
||||
return (player[layer].upgrades.includes(toNumber(id)) || player[layer].upgrades.includes(id.toString()))
|
||||
}
|
||||
|
@ -152,7 +157,7 @@ function buyMaxBuyable(layer, id) {
|
|||
function buyBuyable(layer, id) {
|
||||
if (!player[layer].unlocked) return
|
||||
if (!tmp[layer].buyables[id].unlocked) return
|
||||
if (!tmp[layer].buyables[id].canAfford) return
|
||||
if (!tmp[layer].buyables[id].canBuy) return
|
||||
|
||||
run(layers[layer].buyables[id].buy, layers[layer].buyables[id])
|
||||
updateBuyableTemp(layer)
|
||||
|
|
Loading…
Reference in a new issue