Files
garminApp/source/matchPeriod.mc
T
2026-10-01 19:29:14 +01:00

54 lines
1.4 KiB
Mason

import Toybox.Lang;
import Toybox.WatchUi;
import Toybox.Time;
import Toybox.Timer;
import Toybox.System;
class Period{
public var name as String?;
public var type as enPeriod?;
public var duration as Number?;
public var remaining as Number?;
public var elapsed as Number?;
public var play as Boolean = false;
private var _dur as Number = 0;
private var _acc as Number = 0;
private var _start as Number = 0;
function initialize(Name as String, Type as enPeriod, Duration as Number){
name = Name;
type = Type;
duration = Duration;
remaining = Duration;
elapsed = 0;
}
function playPause() as Void{
play = !play;
if (play){
$.gMatch.state = INGAME;
_start = System.getTimer();
}
else{
_acc += System.getTimer() - _start;
}
}
function update() as Void{
if (play){
_dur = System.getTimer() - _start + _acc;
elapsed = _dur / 1000;
remaining = duration - elapsed;
if (type == PLAY){
$.gMatch.elapsed = $.gMatch.completed + elapsed;
}
if (remaining <= 0) {
play = false;
$.gMatch.method(:nextPeriod).invoke();
}
}
}
}