61 lines
1.6 KiB
Mason
61 lines
1.6 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;
|
|
}
|
|
WatchUi.requestUpdate();
|
|
}
|
|
|
|
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();
|
|
}
|
|
for (var i = 0; i < $.gMatch.cards.size(); i++) {
|
|
if($.gMatch.cards[i].isActive){
|
|
$.gMatch.cards[i].update();
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
} |