aboutsummaryrefslogtreecommitdiffstats
path: root/src/server/VideoTimer.hx
blob: 4bc29db6e3f3ab7a3c029c27938252ec6f88af70 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package server;

import haxe.Timer;

class VideoTimer {

	public var isStarted(default, null) = false;
	var startTime = 0.0;
	var pauseStartTime = 0.0;

	public function new() {}

	public function start():Void {
		isStarted = true;
		startTime = Timer.stamp();
		pauseStartTime = 0;
	}

	public function stop():Void {
		isStarted = false;
		startTime = 0;
		pauseStartTime = 0;
	}

	public function pause():Void {
		pauseStartTime = Timer.stamp();
	}

	public function play():Void {
		if (!isStarted) start();
		startTime += pauseTime();
		pauseStartTime = 0;
	}

	public function getTime():Float {
		if (startTime == 0) return 0;
		return Timer.stamp() - startTime - pauseTime();
	}

	public function setTime(secs:Float):Void {
		startTime = Timer.stamp() - secs;
		if (isPaused()) pause();
	}

	public function isPaused():Bool {
		return !isStarted || pauseStartTime != 0;
	}

	function pauseTime():Float {
		if (pauseStartTime == 0) return 0;
		return Timer.stamp() - pauseStartTime;
	}

}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage