Introduction
Usage
Changelog
Game Clock v1.0.0.7
It allows you format the time and get the elapsed time.
vJASS:
//! zinc
library GameClock { /* v1.0.0.7
*************************************************************************************
*
* Game Clock
* by nel
*
* It allows you format the time and get the elapsed time.
*
************************************************************************************
*
* SETTING
*
*/
private constant string DELIMITER = " : "; /* It used to seperate the hour,
minute, and second */
/*
************************************************************************************
*
* struct GameClock extends array
*
* static method FormatTime takes real seconds return string
* - It returns time as hh/mm/ss format.
*
* static method operator ElapsedTime takes nothing returns real
* - It returns elapsed time.
*
* static method operator ElapsedTimeEx takes nothing returns string
* - It returns elapsed time as hh/mm/ss format.
*
* static method operator Delimiter takes nothing returns string
* - It returns GameClock's delimiter.
*
*************************************************************************************
*
* Issue:
*
* This library will not give you an exact current elapsed time.
*
************************************************************************************/
//! textmacro GAMECLOCK_TIMEFORMAT takes Time, delimiter
if( $Time$ < 10 ) {
format = format + "0" + I2S( $Time$ ) $delimiter$;
} else {
format = format + I2S( $Time$ ) $delimiter$;
}
//! endtextmacro
private constant timer TIMER = CreateTimer();
public { struct GameClock [] {
public {
static method FormatTime( real seconds ) -> string {
integer s = R2I( ModuloReal( seconds, 60 ) );
integer m = R2I( ModuloReal( seconds, 3600 ) / 60 );
integer h = R2I( seconds / 3600 );
string format = "";
//! runtextmacro GAMECLOCK_TIMEFORMAT( "h", "+ DELIMITER" )
//! runtextmacro GAMECLOCK_TIMEFORMAT( "m", "+ DELIMITER" )
//! runtextmacro GAMECLOCK_TIMEFORMAT( "s", "" )
return format;
}
static method operator ElapsedTime() -> real {
return TimerGetElapsed( TIMER );
}
static method operator ElapsedTimeEx() -> string {
return thistype.FormatTime( TimerGetElapsed(TIMER) );
}
static method operator Delimiter() -> string {
return DELIMITER;
}
}
private static method onInit() {
TimerStart( TIMER, 100000000, true, null );
}
}}
}
//! endzinc
vJASS:
scope Test initializer Initialization
private function Display takes nothing returns boolean
local real r = GetRandomReal(0, 99999)
local player p = GetLocalPlayer()
call ClearTextMessages()
call DisplayTimedTextToPlayer(p, 0, 0, 60, /*
*/ "|cffffcc00Format This time:|r " + R2S(r) + " seconds --> " + GameClock.FormatTime(r) + "\r\n" + /*
*/ "|cffffcc00Current Game Time in second:|r " + R2S( GameClock.ElapsedTime ) + "\r\n" + /*
*/ "|cffffcc00Current Game Time in hh/mm/ss format:|r " + GameClock.ElapsedTimeEx + "\r\n" + /*
*/ "|cffffcc00GameClock delimiter:|r " + GameClock.Delimiter /*
*/ )
set p = null
return false
endfunction
private function Initialization takes nothing returns nothing
local trigger trg = CreateTrigger()
call TriggerRegisterPlayerEvent(trg, Player(0), EVENT_PLAYER_END_CINEMATIC)
call TriggerAddCondition(trg, Condition(function Display))
set trg = null
endfunction
endscope
Update: v1.0.0.7
Update: v1.0.0.6
Update: v1.0.0.5
Update: v1.0.0.4
Update: v1.0.0.3
Update: v1.0.0.2
Update: v1.0.0.1
Update: v1.0.0.0
- Little fixed in
method onInit()
Update: v1.0.0.6
- Added private keyword at constant timer TIMER = CreateTimer(); (I forgot)
Update: v1.0.0.5
private { constant string delimiter = " : "; }
->private constant string DELIMITER = " : "; }
.private { constant timer TIMER = CreateTimer(); }
->private constant timer TIMER = CreateTimer();
- Improved comments.
Update: v1.0.0.4
- Code Reworked. Use struct [] for readability.
public { constant string delimiter = " : "; }
->private { constant string delimiter = " : "; }
.
Update: v1.0.0.3
- Added new function:
function FormatTime( real seconds ) -> real
. - Function
GetElapsedTimeFormatted()
returnsFormatTime(TimerGetElapsed(TIMER))
.
Update: v1.0.0.2
public function GetElapsedTime() -> string
->public function GetElapsedTimeFormatted() -> string
- Added new function:
function GetElapsedTime() -> real
.
Update: v1.0.0.1
TimerStart(TIMER, 86400, true, null);
->TimerStart(TIMER, 100000000, true, null);
- Fixed the minute calculation.
Update: v1.0.0.0
- Released
Note
This library will not give you an exact current elapsed time.
Last edited: