using System;
using RobocraftX.Blocks;
using Gamecraft.Blocks.TimerBlock;
using Svelto.ECS;
using Unity.Mathematics;
using GamecraftModdingAPI;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Blocks
{
public class Timer : Block
{
///
/// Places a new timer block.
///
public static Timer PlaceNew(float3 position,
float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
int uscale = 1, float3 scale = default, Player player = null)
{
if (PlacementEngine.IsInGame && GameState.IsBuildMode())
{
try
{
EGID id = PlacementEngine.PlaceBlock(BlockIDs.Timer, color, darkness,
position, uscale, scale, player, rotation);
Sync();
return new Timer(id);
}
catch (Exception e)
{
Logging.MetaDebugLog(e);
}
}
return null;
}
public Timer(EGID id) : base(id)
{
if (!BlockEngine.GetBlockInfoExists(this.Id))
{
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
}
}
public Timer(uint id) : base(id)
{
if (!BlockEngine.GetBlockInfoExists(this.Id))
{
throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
}
}
// custom timer properties
///
/// The player-specified start time.
///
public float Start
{
get
{
return BlockEngine.GetBlockInfo(Id).startTime;
}
set
{
ref TimerBlockDataStruct tbds = ref BlockEngine.GetBlockInfo(Id);
tbds.startTime = value;
}
}
///
/// The player-specified end time.
///
public float End
{
get
{
return BlockEngine.GetBlockInfo(Id).endTime;
}
set
{
ref TimerBlockDataStruct tbds = ref BlockEngine.GetBlockInfo(Id);
tbds.endTime = value;
}
}
///
/// Whether to display time with millisecond precision.
///
public bool DisplayMilliseconds
{
get
{
return BlockEngine.GetBlockInfo(Id).outputFormatHasMS;
}
set
{
ref TimerBlockDataStruct tbds = ref BlockEngine.GetBlockInfo(Id);
tbds.outputFormatHasMS = value;
}
}
///
/// Current time (as of the last video frame), in milliseconds.
///
public int CurrentTime
{
get
{
return BlockEngine.GetBlockInfo(Id).timeLastRenderFrameMS;
}
set
{
ref TimerBlockLabelCacheEntityStruct tblces = ref BlockEngine.GetBlockInfo(Id);
tblces.timeLastRenderFrameMS = value;
}
}
}
}