Profectus-Demo/src/components/tree/TreeNode.vue

145 lines
3.7 KiB
Vue
Raw Normal View History

2021-06-12 04:38:16 +00:00
<template>
<tooltip :display="tooltip" :force="forceTooltip" :class="{
2021-06-12 04:38:16 +00:00
ghost: layer.layerShown === 'ghost',
treeNode: true,
[id]: true,
hidden: !layer.layerShown,
locked: !unlocked,
notify: layer.notify && unlocked,
resetNotify: layer.resetNotify,
can: unlocked,
small
}">
<LayerProvider :index="tab.index" :layer="id">
<button v-if="layer.shown" @click="clickTab" :style="style" :disabled="!unlocked">
2021-06-12 04:38:16 +00:00
<component :is="display" />
<branch-node :branches="layer.branches" :id="id" featureType="tree-node" />
</button>
<mark-node :mark="layer.mark" />
</LayerProvider>
</tooltip>
</template>
<script>
import { layers } from '../../store/layers';
import { player } from '../../store/proxies';
import { coerceComponent } from '../../util/vue';
export default {
name: 'tree-node',
props: {
id: [ String, Number ],
2021-06-12 04:55:52 +00:00
small: Boolean,
append: Boolean
2021-06-12 04:38:16 +00:00
},
inject: [ 'tab' ],
computed: {
layer() {
return layers[this.id];
},
unlocked() {
if (this.layer.canClick != undefined) {
return this.layer.canClick;
}
return this.layer.unlocked;
},
style() {
return [
this.unlocked ? { backgroundColor: this.layer.color } : null,
this.layer.notify && this.unlocked ?
{ boxShadow: `-4px -4px 4px rgba(0, 0, 0, 0.25) inset, 0 0 20px ${this.layer.trueGlowColor}` } : null,
this.layer.nodeStyle
];
},
display() {
if (this.layer.display != undefined) {
return coerceComponent(this.layer.display);
} else if (this.layer.image != undefined) {
return coerceComponent(`<img src=${this.layer.image}/>`);
} else {
return coerceComponent(this.layer.symbol);
}
},
forceTooltip() {
return player[this.id].forceTooltip;
},
tooltip() {
if (this.layer.canClick != undefined) {
if (this.layer.canClick) {
return this.layer.tooltip || 'I am a button!';
} else {
return this.layer.tooltipLocked || this.layer.tooltip || 'I am a button!';
}
}
if (player[this.id].unlocked) {
2021-06-27 19:48:43 +00:00
return this.layer.tooltip || `{{ formatWhole(player.${this.id}.points) }} {{ layers.${this.id}.resource }}`;
2021-06-12 04:38:16 +00:00
} else {
return this.layer.tooltipLocked ||
2021-06-27 19:48:43 +00:00
`Reach {{ formatWhole(layers.${this.id}.requires) }} {{ layers.${this.id}.baseResource }} to unlock (You have {{ formatWhole(layers.${this.id}.baseAmount) }} {{ layers.${this.id}.baseResource }})`;
2021-06-12 04:38:16 +00:00
}
},
components() {
return Object.keys(layers).reduce((acc, curr) => {
acc[curr] = layers[curr].component || false;
return acc;
}, {});
}
},
methods: {
clickTab(e) {
if (e.shiftKey) {
player[this.id].forceTooltip = !player[this.id].forceTooltip;
} else if (this.layer.onClick != undefined) {
this.layer.onClick();
} else if (this.layer.modal) {
this.$emit('show-modal', this.id);
2021-06-12 04:55:52 +00:00
} else if (this.append) {
if (player.tabs.includes(this.id)) {
const index = player.tabs.lastIndexOf(this.id);
player.tabs = [...player.tabs.slice(0, index), ...player.tabs.slice(index + 1)];
} else {
player.tabs = [...player.tabs, this.id];
}
2021-06-12 04:38:16 +00:00
} else {
player.tabs = [...player.tabs.slice(0, this.tab.index + 1), this.id];
}
}
}
};
</script>
<style scoped>
.treeNode {
height: 100px;
width: 100px;
border-radius: 50%;
padding: 0;
margin: 0 10px 0 10px;
}
.treeNode button {
width: 100%;
height: 100%;
border: 2px solid rgba(0, 0, 0, 0.125);
border-radius: inherit;
font-size: 40px;
color: rgba(0, 0, 0, 0.5);
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.25);
box-shadow: -4px -4px 4px rgba(0, 0, 0, 0.25) inset, 0px 0px 20px var(--background);
}
.treeNode.small {
height: 60px;
width: 60px;
}
.treeNode.small button {
font-size: 30px;
}
.ghost {
visibility: hidden;
pointer-events: none;
}
</style>