remove prevValue logic from text-counter causing it to not run
This commit is contained in:
@@ -14,45 +14,33 @@ AFRAME.registerComponent('text-counter', {
|
||||
},
|
||||
|
||||
init: function () {
|
||||
this.startTime = null;
|
||||
this.currentValue = 0;
|
||||
this.textValue = {value : ''};
|
||||
},
|
||||
|
||||
decimals: function (n) {
|
||||
var d = Math.pow(10, this.data.decimals);
|
||||
return (parseInt(n * d) / d).toFixed(this.data.decimals);
|
||||
},
|
||||
|
||||
update: function (oldData) {
|
||||
this.startTime = null;
|
||||
this.currentValue = 0;
|
||||
this.textValue.value = `${this.data.prefix} ${this.decimals(0)} ${this.data.suffix}`;
|
||||
this.el.setAttribute('text', this.textValue);
|
||||
},
|
||||
|
||||
tick: function (time) {
|
||||
tick: function (time, timeDelta) {
|
||||
if (this.currentValue >= this.data.value) { return; }
|
||||
|
||||
if (this.startTime === null) {
|
||||
this.startTime = time;
|
||||
return;
|
||||
};
|
||||
|
||||
const prevValue = Math.floor(this.currentValue);
|
||||
this.currentValue = this.data.value * (time - this.startTime) / this.data.dur;
|
||||
|
||||
if (Math.floor(this.currentValue) === prevValue) { return; }
|
||||
this.currentValue += this.data.value * (timeDelta / this.data.dur);
|
||||
|
||||
if (this.currentValue >= this.data.value) {
|
||||
this.currentValue = this.data.value;
|
||||
if (this.data.emit) {
|
||||
this.el.emit('textcounterdone', null, false);
|
||||
}
|
||||
if (this.data.emit) { this.el.emit('textcounterdone', null, false); }
|
||||
}
|
||||
|
||||
this.textValue.value =
|
||||
`${this.data.prefix} ${this.decimals(this.currentValue)} ${this.data.suffix}`;
|
||||
this.el.setAttribute('text', this.textValue);
|
||||
},
|
||||
|
||||
decimals: function (n) {
|
||||
var d = Math.pow(10, this.data.decimals);
|
||||
return (parseInt(n * d) / d).toFixed(this.data.decimals);
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user