mirror of
https://github.com/GuerillaStudio/souvenir.git
synced 2025-01-20 22:10:20 +00:00
fix(timer): now wait for the correct duration
This commit is contained in:
parent
b416ec47f3
commit
6daaa915ae
3 changed files with 19 additions and 31 deletions
|
@ -25,48 +25,41 @@ class Countdown extends EventEmitter {
|
||||||
if (!this._running && !this._started) {
|
if (!this._running && !this._started) {
|
||||||
this._running = true
|
this._running = true
|
||||||
this._started = true
|
this._started = true
|
||||||
|
|
||||||
this.emit('started')
|
this.emit('started')
|
||||||
|
this._update()
|
||||||
|
|
||||||
this.emit('progress', 0)
|
this._intervalId = setInterval(() => {
|
||||||
this.emit('update', this._n)
|
this._count++
|
||||||
|
this._update()
|
||||||
|
|
||||||
this._intervalId = setInterval(() => this._update(), this._delay)
|
if (this._count >= this._n) {
|
||||||
|
this._cleanup()
|
||||||
|
this.done = true
|
||||||
|
this.emit('done')
|
||||||
|
this._end()
|
||||||
|
}
|
||||||
|
}, this._delay)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cancel () {
|
cancel () {
|
||||||
if (this._running && !this._ended) {
|
if (this._running && !this._ended) {
|
||||||
this._cleanup()
|
this._cleanup()
|
||||||
|
|
||||||
this._cancelled = true
|
this._cancelled = true
|
||||||
this.emit('cancelled')
|
this.emit('cancelled')
|
||||||
|
this._end()
|
||||||
this.ended = true
|
|
||||||
this.emit('ended')
|
|
||||||
|
|
||||||
this.running = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_update () {
|
_update () {
|
||||||
if (this._running) {
|
|
||||||
if (this._count < this._n) {
|
|
||||||
this._count++
|
|
||||||
this.emit('progress', this._count / this._n)
|
this.emit('progress', this._count / this._n)
|
||||||
this.emit('update', this._n - this._count)
|
this.emit('update', this._n - this._count)
|
||||||
} else {
|
}
|
||||||
this._cleanup()
|
|
||||||
|
|
||||||
this.done = true
|
|
||||||
this.emit('done')
|
|
||||||
|
|
||||||
|
_end () {
|
||||||
this.ended = true
|
this.ended = true
|
||||||
this.emit('ended')
|
this.emit('ended')
|
||||||
|
this._running = false
|
||||||
this.running = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_cleanup () {
|
_cleanup () {
|
||||||
|
|
|
@ -31,7 +31,6 @@ export default new Vuex.Store({
|
||||||
state.boomerang = value
|
state.boomerang = value
|
||||||
},
|
},
|
||||||
updateTimer (state, value) {
|
updateTimer (state, value) {
|
||||||
console.log(typeof value)
|
|
||||||
state.timer = value
|
state.timer = value
|
||||||
},
|
},
|
||||||
updateCamera (state, camera) {
|
updateCamera (state, camera) {
|
||||||
|
|
|
@ -104,10 +104,6 @@ export default {
|
||||||
this.countdown = null
|
this.countdown = null
|
||||||
})
|
})
|
||||||
|
|
||||||
this.countdown.on('cancelled', () => {
|
|
||||||
console.log('cancelled')
|
|
||||||
})
|
|
||||||
|
|
||||||
this.countdown.on('done', () => {
|
this.countdown.on('done', () => {
|
||||||
this.runCapture()
|
this.runCapture()
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue