mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-22 09:37:17 +00:00
Implement timer (#909)
* Implement timer * change isRunning in objects to match Winamp behavior, std.mi is wrong * need to set start time for timer * add comment to updated objects array
This commit is contained in:
parent
3df76aef6d
commit
3743868cc6
3 changed files with 37 additions and 22 deletions
|
|
@ -2171,7 +2171,7 @@ const objects = {
|
|||
{
|
||||
parameters: [],
|
||||
name: "isRunning",
|
||||
result: "",
|
||||
result: "boolean", // The std.mi has this set as void, but we checked in Winamp and confirmed it returns 0/1
|
||||
},
|
||||
{
|
||||
parameters: [],
|
||||
|
|
|
|||
|
|
@ -208,12 +208,6 @@ Set {
|
|||
"Region.getboundingboxy",
|
||||
"Region.getboundingboxw",
|
||||
"Region.getboundingboxh",
|
||||
"Timer.setdelay",
|
||||
"Timer.start",
|
||||
"Timer.stop",
|
||||
"Timer.ontimer",
|
||||
"Timer.getdelay",
|
||||
"Timer.isrunning",
|
||||
"Timer.getskipped",
|
||||
"Group.getnumobjects",
|
||||
"Group.enumobject",
|
||||
|
|
|
|||
|
|
@ -2,6 +2,28 @@ import MakiObject from "./MakiObject";
|
|||
import { unimplementedWarning } from "../utils";
|
||||
|
||||
class Timer extends MakiObject {
|
||||
_speed: number;
|
||||
_animationStartTime: number;
|
||||
_animationCancelID: number;
|
||||
|
||||
constructor(node, parent, annotations, store) {
|
||||
super(node, parent, annotations, store);
|
||||
|
||||
this._speed = 200;
|
||||
this._animationStartTime = 0;
|
||||
this._animationCancelID = null;
|
||||
}
|
||||
|
||||
_animationLoop(): void {
|
||||
this._animationCancelID = window.requestAnimationFrame(currentTime => {
|
||||
if (currentTime > this._animationStartTime + this._speed) {
|
||||
this._animationStartTime = currentTime;
|
||||
this.ontimer();
|
||||
}
|
||||
this._animationLoop();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* getclassname()
|
||||
*
|
||||
|
|
@ -12,31 +34,30 @@ class Timer extends MakiObject {
|
|||
return "Timer";
|
||||
}
|
||||
|
||||
setdelay(millisec: number) {
|
||||
unimplementedWarning("setDelay");
|
||||
setdelay(millisec: number): void {
|
||||
this._speed = millisec;
|
||||
}
|
||||
|
||||
start() {
|
||||
unimplementedWarning("start");
|
||||
start(): void {
|
||||
this._animationStartTime = performance.now();
|
||||
this._animationLoop();
|
||||
}
|
||||
|
||||
stop() {
|
||||
unimplementedWarning("stop");
|
||||
stop(): void {
|
||||
window.cancelAnimationFrame(this._animationCancelID);
|
||||
this._animationCancelID = null;
|
||||
}
|
||||
|
||||
ontimer() {
|
||||
unimplementedWarning("ontimer");
|
||||
return;
|
||||
ontimer(): void {
|
||||
this.js_trigger("onTimer");
|
||||
}
|
||||
|
||||
getdelay() {
|
||||
unimplementedWarning("getdelay");
|
||||
return;
|
||||
getdelay(): number {
|
||||
return this._speed;
|
||||
}
|
||||
|
||||
isrunning() {
|
||||
unimplementedWarning("isrunning");
|
||||
return;
|
||||
isrunning(): boolean {
|
||||
return this._animationCancelID != null;
|
||||
}
|
||||
|
||||
getskipped() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue