2020-05-21 00:42:02 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
using RobocraftX.Blocks;
|
2020-07-10 22:30:58 +00:00
|
|
|
|
using RobocraftX.Common;
|
2020-05-21 00:42:02 +00:00
|
|
|
|
using Gamecraft.Blocks.TimerBlock;
|
|
|
|
|
using Svelto.ECS;
|
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
|
|
|
|
|
using GamecraftModdingAPI;
|
|
|
|
|
using GamecraftModdingAPI.Utility;
|
|
|
|
|
|
|
|
|
|
namespace GamecraftModdingAPI.Blocks
|
|
|
|
|
{
|
|
|
|
|
public class Timer : Block
|
|
|
|
|
{
|
|
|
|
|
public Timer(EGID id) : base(id)
|
|
|
|
|
{
|
|
|
|
|
if (!BlockEngine.GetBlockInfoExists<TimerBlockDataStruct>(this.Id))
|
|
|
|
|
{
|
|
|
|
|
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 22:30:58 +00:00
|
|
|
|
public Timer(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_TIMER_BLOCK_GROUP))
|
2020-05-21 00:42:02 +00:00
|
|
|
|
{
|
|
|
|
|
if (!BlockEngine.GetBlockInfoExists<TimerBlockDataStruct>(this.Id))
|
|
|
|
|
{
|
|
|
|
|
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// custom timer properties
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The player-specified start time.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float Start
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id).startTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
ref TimerBlockDataStruct tbds = ref BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id);
|
|
|
|
|
tbds.startTime = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The player-specified end time.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float End
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id).endTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
ref TimerBlockDataStruct tbds = ref BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id);
|
|
|
|
|
tbds.endTime = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether to display time with millisecond precision.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool DisplayMilliseconds
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id).outputFormatHasMS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
ref TimerBlockDataStruct tbds = ref BlockEngine.GetBlockInfo<TimerBlockDataStruct>(Id);
|
|
|
|
|
tbds.outputFormatHasMS = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Current time (as of the last video frame), in milliseconds.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int CurrentTime
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return BlockEngine.GetBlockInfo<TimerBlockLabelCacheEntityStruct>(Id).timeLastRenderFrameMS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
ref TimerBlockLabelCacheEntityStruct tblces = ref BlockEngine.GetBlockInfo<TimerBlockLabelCacheEntityStruct>(Id);
|
|
|
|
|
tblces.timeLastRenderFrameMS = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|