fix animate setup message handling
This commit is contained in:
parent
1a9d27b488
commit
0dcd7a5e21
1 changed files with 26 additions and 32 deletions
|
|
@ -48,8 +48,8 @@ kiri.load(() => {
|
||||||
function animate(api, delay) {
|
function animate(api, delay) {
|
||||||
let alert = api.alerts.show("building animation");
|
let alert = api.alerts.show("building animation");
|
||||||
kiri.client.animate_setup(api.conf.get(), data => {
|
kiri.client.animate_setup(api.conf.get(), data => {
|
||||||
checkMeshCommands(data);
|
handleUpdate(data);
|
||||||
if (!(data && data.mesh_add)) {
|
if (data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const UC = api.uc;
|
const UC = api.uc;
|
||||||
|
|
@ -139,7 +139,7 @@ kiri.load(() => {
|
||||||
|
|
||||||
function step() {
|
function step() {
|
||||||
updateSpeed();
|
updateSpeed();
|
||||||
kiri.client.animate({speed, steps: 1}, handleGridUpdate);
|
kiri.client.animate({speed, steps: 1}, handleUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
function play(opts) {
|
function play(opts) {
|
||||||
|
|
@ -154,7 +154,7 @@ kiri.load(() => {
|
||||||
speed,
|
speed,
|
||||||
steps: steps || Infinity,
|
steps: steps || Infinity,
|
||||||
pause: speedPauses[speedIndex]
|
pause: speedPauses[speedIndex]
|
||||||
}, handleGridUpdate);
|
}, handleUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
function fast(opts) {
|
function fast(opts) {
|
||||||
|
|
@ -167,44 +167,19 @@ kiri.load(() => {
|
||||||
speed,
|
speed,
|
||||||
steps: steps || Infinity,
|
steps: steps || Infinity,
|
||||||
pause: speedPauses[speedIndex]
|
pause: speedPauses[speedIndex]
|
||||||
}, handleGridUpdate);
|
}, handleUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
function pause() {
|
function pause() {
|
||||||
playButton.style.display = '';
|
playButton.style.display = '';
|
||||||
pauseButton.style.display = 'none';
|
pauseButton.style.display = 'none';
|
||||||
kiri.client.animate({speed: 0}, handleGridUpdate);
|
kiri.client.animate({speed: 0}, handleUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleGridUpdate(data) {
|
function handleUpdate(data) {
|
||||||
checkMeshCommands(data);
|
|
||||||
if (data && data.progress) {
|
|
||||||
progress.innerText = (data.progress * 100).toFixed(1) + '%'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateSpeed(inc = 0) {
|
|
||||||
if (inc === Infinity) {
|
|
||||||
speedIndex = speedMax;
|
|
||||||
} else if (inc > 0) {
|
|
||||||
speedIndex = (speedIndex + inc) % speedValues.length;
|
|
||||||
}
|
|
||||||
speed = speedValues[speedIndex];
|
|
||||||
speedLabel.innerText = speedNames[speedIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
function replay() {
|
|
||||||
CAM.animate_clear(api);
|
|
||||||
setTimeout(() => {
|
|
||||||
CAM.animate(api, 50);
|
|
||||||
}, 250);
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkMeshCommands(data) {
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// console.log({mesh_cmd: data});
|
|
||||||
if (data.mesh_add) {
|
if (data.mesh_add) {
|
||||||
const { id, ind, pos, len } = data.mesh_add;
|
const { id, ind, pos, len } = data.mesh_add;
|
||||||
meshAdd(id, ind, pos, len);
|
meshAdd(id, ind, pos, len);
|
||||||
|
|
@ -227,8 +202,27 @@ kiri.load(() => {
|
||||||
const { id, ind, pos, len } = data.mesh_update;
|
const { id, ind, pos, len } = data.mesh_update;
|
||||||
meshUpdate(id, ind, pos, len);
|
meshUpdate(id, ind, pos, len);
|
||||||
}
|
}
|
||||||
|
if (data && data.progress) {
|
||||||
|
progress.innerText = (data.progress * 100).toFixed(1) + '%'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateSpeed(inc = 0) {
|
||||||
|
if (inc === Infinity) {
|
||||||
|
speedIndex = speedMax;
|
||||||
|
} else if (inc > 0) {
|
||||||
|
speedIndex = (speedIndex + inc) % speedValues.length;
|
||||||
|
}
|
||||||
|
speed = speedValues[speedIndex];
|
||||||
|
speedLabel.innerText = speedNames[speedIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
function replay() {
|
||||||
|
CAM.animate_clear(api);
|
||||||
|
setTimeout(() => {
|
||||||
|
CAM.animate(api, 50);
|
||||||
|
}, 250);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// ---( WORKER FUNCTIONS )---
|
// ---( WORKER FUNCTIONS )---
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue