1
0
Fork 0
mirror of https://github.com/Acamaeda/The-Modding-Tree.git synced 2024-11-21 16:13:55 +00:00

Buyable and clickable trees

This commit is contained in:
Harley White 2021-06-07 19:40:34 -04:00
parent d015d0177c
commit ff2fc625f7
6 changed files with 45 additions and 10 deletions

View file

@ -1,5 +1,7 @@
# The Modding Tree changelog:
- Added buyable and clickable trees.
## v2.6.1 - 6/7/21
- Added global background style to mod.js.
- Tree branches can have custom line widths.

View file

@ -77,4 +77,8 @@ You can use these features along with it:
- showRespec(): **optional**. A function determining whether or not to show the button, if respecBuyables is defined. Defaults to true if absent.
- respecMessage: **optional**. A custom confirmation message on respec, in place of the default one.
- respecMessage: **optional**. A custom confirmation message on respec, in place of the default one.
- branches: **optional**, This is primarially useful for buyable trees. An array of buyable ids. A line will appear from this buyable to all of the buyables in the list. Alternatively, an entry in the array can be a 2-element array consisting of the buyable id and a color value. The color value can either be a string with a hex color code, or a number from 1-3 (theme-affected colors). A third element in the array optionally specifies line width.

View file

@ -55,3 +55,7 @@ You can also use these features on the clickables object to add a button above a
- masterButtonText: **optional**. Text to display on the Master Button.
- showMasterButton(): **optional**. A function determining whether or not to show the button, if masterButtonPress is defined. Defaults to true if absent.
- branches: **optional**, This is primarially useful for clickable trees. An array of clickable ids. A line will appear from this clickable to all of the clickables in the list. Alternatively, an entry in the array can be a 2-element array consisting of the clickable id and a color value. The color value can either be a string with a hex color code, or a number from 1-3 (theme-affected colors). A third element in the array optionally specifies line width.

View file

@ -62,7 +62,7 @@ These are the existing components, but you can create more in [components.js](/j
- tree: Displays a tree. The argument is an array of arrays containing the names of the nodes in the tree (first by row, then by column)
[See here for more information on tree layouts and nodes!](trees-and-tree-customization.md)
- upgrade-tree: Displays a of upgrades from this layer. The argument is an array of arrays containing the ids of the upgrades in the tree (first by row, then by column)
- upgrade-tree, buyable-tree, clickable-tree: Displays a tree of upgrades/buyables/clickables from this layer. The argument is an array of arrays containing the ids of the upgrade/etc in the tree (first by row, then by column). A tree can only have one type of component in it.
- toggle: A toggle button that toggles a bool value. The argument is a pair that identifies the location in player of the bool to toggle, e.g. `[layer, id]`. 'layer' also affects the color of the toggle.

View file

@ -273,7 +273,7 @@ function loadVue() {
<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].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="if(!interval) buyBuyable(layer, data)" @mousedown="start" @mouseleave="stop" @mouseup="stop" @touchstart="start" @touchend="stop" @touchcancel="stop">
v-on:click="if(!interval) buyBuyable(layer, data)" :id='"buyable-" + layer + "-" + data' @mousedown="start" @mouseleave="stop" @mouseup="stop" @touchstart="start" @touchend="stop" @touchcancel="stop">
<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="run(layers[layer].buyables[data].display, layers[layer].buyables[data])"></span>
<node-mark :layer='layer' :data='tmp[layer].buyables[data].marked'></node-mark>
@ -335,7 +335,7 @@ function loadVue() {
v-if="tmp[layer].clickables && tmp[layer].clickables[data]!== undefined && tmp[layer].clickables[data].unlocked"
v-bind:class="{ upg: true, can: tmp[layer].clickables[data].canClick, locked: !tmp[layer].clickables[data].canClick}"
v-bind:style="[tmp[layer].clickables[data].canClick ? {'background-color': tmp[layer].color} : {}, size ? {'height': size, 'width': size} : {}, tmp[layer].clickables[data].style]"
v-on:click="if(!interval) clickClickable(layer, data)" @mousedown="start" @mouseleave="stop" @mouseup="stop" @touchstart="start" @touchend="stop" @touchcancel="stop">
v-on:click="if(!interval) clickClickable(layer, data)" :id='"clickable-" + layer + "-" + data' @mousedown="start" @mouseleave="stop" @mouseup="stop" @touchstart="start" @touchend="stop" @touchcancel="stop">
<span v-if= "tmp[layer].clickables[data].title"><h2 v-html="tmp[layer].clickables[data].title"></h2><br></span>
<span v-bind:style="{'white-space': 'pre-line'}" v-html="run(layers[layer].clickables[data].display, layers[layer].clickables[data])"></span>
<node-mark :layer='layer' :data='tmp[layer].clickables[data].marked'></node-mark>
@ -514,6 +514,23 @@ function loadVue() {
})
// Data is an array with the structure of the tree
Vue.component('buyable-tree', {
props: ['layer', 'data'],
computed: {
key() {return this.$vnode.key}
},
template: `<thing-tree :layer="layer" :data = "data" :type = "'buyable'"></thing-tree>`
})
// Data is an array with the structure of the tree
Vue.component('clickable-tree', {
props: ['layer', 'data'],
computed: {
key() {return this.$vnode.key}
},
template: `<thing-tree :layer="layer" :data = "data" :type = "'clickable'"></thing-tree>`
})
Vue.component('thing-tree', {
props: ['layer', 'data', 'type'],
computed: {

View file

@ -34,16 +34,24 @@ function drawTree() {
drawTreeBranch(layer, tmp[layer].branches[branch])
}
}
for(id in layers[layer].upgrades) {
if (tmp[layer].upgrades[id].branches) {
for (branch in tmp[layer].upgrades[id].branches)
{
drawTreeBranch(id, tmp[layer].upgrades[id].branches[branch], "upgrade-" + layer + "-")
}
drawComponentBranches(layer, tmp[layer].upgrades, "upgrade-")
drawComponentBranches(layer, tmp[layer].buyables, "buyable-")
drawComponentBranches(layer, tmp[layer].clickables, "clickable-")
}
}
function drawComponentBranches(layer, data, prefix) {
for(id in data) {
if (data[id].branches) {
for (branch in data[id].branches)
{
drawTreeBranch(id, data[id].branches[branch], prefix + layer + "-")
}
}
}
}
function drawTreeBranch(num1, data, prefix) { // taken from Antimatter Dimensions & adjusted slightly