Skip to content

Commit f4b006c

Browse files
committed
rename tapper to generator
1 parent 7905ea7 commit f4b006c

File tree

2 files changed

+154
-101
lines changed

2 files changed

+154
-101
lines changed

src/components/BusinessTapper.vue

Lines changed: 0 additions & 101 deletions
This file was deleted.

src/components/IncomeGenerator.vue

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<template>
2+
<v-card>
3+
<v-card-title primary-title class="headline text-md-center">
4+
<div class="headline">{{ currentValue | currency(income.symbol) }}</div>
5+
<div class="headline">{{ name }}</div>
6+
</v-card-title>
7+
<v-card-text class="text-md-center text-xs-center" >
8+
<v-progress-circular v-model="progress" v-bind:size="100" v-bind:rotate="-90" v-on:click="generateIncome()" color="primary">{{ owned }}</v-progress-circular>
9+
</v-card-text>
10+
<v-card-actions>
11+
<v-btn round block color="primary" v-on:click="build()" v-bind:disabled="tooExpensive">Build {{ currentCost | currency(income.symbol) }}</v-btn>
12+
</v-card-actions>
13+
</v-card>
14+
</template>
15+
16+
<script>
17+
export default {
18+
name: 'income-generator',
19+
components: {
20+
21+
},
22+
data () {
23+
return {
24+
name: 'Home',
25+
owned: 0,
26+
lastStarted: 0,
27+
cost: 1.00,
28+
costMultiplier: 1.00,
29+
costPerUnit: 0.01, // next generator cost is cost * (owned * costPerUnit)
30+
income: {
31+
name: 'dollar',
32+
pluralName: 'dollars',
33+
symbol: '$',
34+
iconName: 'attach_money',
35+
perUnit: 1.00,
36+
perUnitMultiplier: 0.01
37+
},
38+
currentValue: 0.00,
39+
speed: 1000,
40+
progress: 0,
41+
currentCost: 1.00,
42+
autoTapper: false
43+
}
44+
},
45+
filters: {
46+
currency (val, symbol) {
47+
return symbol + val.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,')
48+
}
49+
},
50+
computed: {
51+
tooExpensive: function () {
52+
return this.currentCost > this.currentValue
53+
}
54+
},
55+
watch: {
56+
currentValue: function (val) {
57+
this._storeValue(val)
58+
},
59+
owned: function (val) {
60+
this.currentCost = (this.cost + (val * this.costPerUnit * this.costMultiplier))
61+
this._storeOwned(val)
62+
},
63+
costMultiplier: function (val) {
64+
this.currentCost = (this.cost + (this.owned * this.costPerUnit * val))
65+
},
66+
autoTapper: function (val) {
67+
if (val) {
68+
this.startIncomeTimer()
69+
} else {
70+
this.stopIncomeTimer()
71+
}
72+
}
73+
},
74+
mounted () {
75+
this._loadData()
76+
// this.setNewValue(this.calculateValueSince())
77+
this.startTimers()
78+
},
79+
methods: {
80+
/* attached () {
81+
this.owned = Number.parseInt(this._getValue())
82+
}, */
83+
// setNewValue (new_val) {},
84+
// calculateValueSince () {},
85+
startTimers () {
86+
// this.incrementIncome()
87+
// this._incomeLoop = setInterval(this.incrementIncome, this.speed)
88+
// this.startIncomeTimer()
89+
},
90+
generateIncome (fraction = 1) {
91+
// if progress loop is active, do nothing.
92+
if (this._progressLoopIsRunning) {
93+
return
94+
}
95+
96+
this.startProgressLoop(() => {
97+
this.currentValue += (this.owned * this.income.perUnit) / fraction
98+
})
99+
},
100+
startProgressLoop (cb) {
101+
this._progressLoop = setInterval(() => {
102+
this._progressLoopIsRunning = true
103+
this.progress = this.progress + 1
104+
if (this.progress >= 100) {
105+
this._progressLoopIsRunning = false
106+
this.progress = 0
107+
this.stopIncomeTimer()
108+
cb()
109+
}
110+
}, this.speed / 100)
111+
},
112+
stopIncomeTimer () {
113+
clearTimeout(this._progressLoop)
114+
},
115+
build (evt) {
116+
if (this.currentValue < this.currentCost) {
117+
return
118+
}
119+
this.owned += 1
120+
this._storeOwned(this.owned)
121+
this.currentValue -= this.currentCost
122+
},
123+
_loadData () {
124+
this._loadOwned()
125+
this._loadValue()
126+
},
127+
_loadOwned () {
128+
this.owned = Number.parseInt(this.$localStorage.get('owned', 0))
129+
},
130+
_storeOwned (val) {
131+
return this.$localStorage.set('owned', val || this.owned)
132+
},
133+
_loadValue () {
134+
this.currentValue = Number.parseInt(this.$localStorage.get('value', 0.00))
135+
},
136+
_storeValue (val) {
137+
this.$localStorage.set('value', val || this.currentValue)
138+
}
139+
}
140+
}
141+
</script>
142+
143+
<!-- Add "scoped" attribute to limit CSS to this component only -->
144+
<style scoped>
145+
.headline{
146+
text-align: center;
147+
width: 100%;
148+
}
149+
.progress-circular__overlay {
150+
stroke: currentColor;
151+
z-index: 2;
152+
transition: all 0s ease-in-out;
153+
}
154+
</style>

0 commit comments

Comments
 (0)