fix: kevin comments and victory ring animation

This commit is contained in:
Diego F. Goberna
2018-11-14 18:33:04 +01:00
parent 67a370d31f
commit c61ab2241c
5 changed files with 56 additions and 53 deletions

View File

@@ -1,16 +1,21 @@
AFRAME.registerComponent('text-counter', {
dependencies: ['text'],
schema: {
value: {default: 0.0, type: 'float'},
decimals: {default: 0},
dur: {default: 2000, type: 'int'},
emit: {default: false},
prefix: {default: ''},
suffix: {default: ''},
decimals: {default: 0}
value: {default: 0.0, type: 'float'}
},
init: function () {
this.startTime = null;
this.currentValue = -1;
this.currentValue = 0;
this.textValue = {value : ''};
this.victoryInfoRank = document.getElementById('victoryInfoRank');
this.victoryButtons = document.getElementById('victoryButtons');
},
decimals: function (n) {
@@ -20,27 +25,26 @@ AFRAME.registerComponent('text-counter', {
update: function (oldData) {
this.startTime = null;
this.currentValue = -1;
this.el.setAttribute('text', {
value: `${this.data.prefix} ${this.decimals(0)} ${this.data.suffix}`
});
this.currentValue = 0;
this.textValue.value = `${this.data.prefix} ${this.decimals(0)} ${this.data.suffix}`;
this.el.setAttribute('text', this.textValue);
},
tick: function (time) {
if (this.currentValue < this.data.value) {
if (this.startTime === null) { this.startTime = time};
const prevValue = Math.floor(this.currentValue);
this.currentValue = this.data.value * (time - this.startTime) / this.data.dur;
if (Math.floor(this.currentValue) !== prevValue) {
if (this.currentValue >= this.data.value) {
this.currentValue = this.data.value;
document.getElementById('victoryInfoRank').emit('appear');
document.getElementById('victoryButtons').emit('appear');
}
this.el.setAttribute('text', {
value: `${this.data.prefix} ${this.decimals(this.currentValue)} ${this.data.suffix}`
});
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; }
if (this.currentValue >= this.data.value) {
this.currentValue = this.data.value;
if (this.data.emit) {
console.log(this.currentValue, this.data.value);
this.victoryInfoRank.emit('textcounterdone', null, false);
this.victoryButtons.emit('textcounterdone', null, false);
}
}
this.textValue.value = `${this.data.prefix} ${this.decimals(this.currentValue)} ${this.data.suffix}`;
this.el.setAttribute('text', this.textValue);
}
})

View File

@@ -10,7 +10,7 @@ AFRAME.registerComponent('victory-accuracy-ring', {
update: function () {
this.el.getObject3D('mesh').material.uniforms.progress.value = 0;
this.el.setAttribute('animation', 'to', this.data.accuracy);
this.el.setAttribute('animation', 'to', this.data.accuracy / 100);
this.el.components['animation'].beginAnimation();
}
});