TechbloxModdingAPI/GamecraftModdingAPI/Blocks/Signals.cs
2019-12-25 14:25:53 -05:00

122 lines
4.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Svelto.ECS;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Blocks
{
/// <summary>
/// [EXPERIMENTAL] Common block signal operations
/// </summary>
public static class Signals
{
// Signal constants
public static readonly float HIGH = 1.0f;
public static readonly float POSITIVE_HIGH = HIGH;
public static readonly float NEGATIVE_HIGH = -1.0f;
public static readonly float LOW = 0.0f;
private static SignalEngine signalEngine = new SignalEngine();
/// <summary>
/// Set a channel to a value in the block's conductive block cluster
/// </summary>
/// <param name="id">The block's id</param>
/// <param name="channel">The channel (1 to 99)</param>
/// <param name="signal">The signal value (-1 to 1; not enforced)</param>
public static void SetSignalConnectedBlocks(uint id, uint channel, float signal)
{
if (signalEngine.IsInGame && signalEngine.IsSimulationMode())
{
signalEngine.SetSignal(id, channel, signal, out EGID _);
}
}
/// <summary>
/// Set a conductive cluster channel to a value
/// </summary>
/// <param name="clusterID">The channel cluster's id</param>
/// <param name="signal">The signal value (-1 to 1; not enforced)</param>
public static void SetSignalCluster(EGID clusterID, float signal)
{
if (signalEngine.IsInGame && signalEngine.IsSimulationMode())
{
signalEngine.SetSignal(clusterID, signal);
}
}
/// <summary>
/// Add a value to a channel signal in the block's conductive block cluster
/// </summary>
/// <param name="id">The block's id</param>
/// <param name="channel">The channel (1 to 99)</param>
/// <param name="signal">The signal value to add</param>
/// <param name="clamp">Whether to clamp the resulting signal value between -1 and 1</param>
public static void AddSignalConnectedBlocks(uint id, uint channel, float signal, bool clamp = true)
{
if (signalEngine.IsInGame && signalEngine.IsSimulationMode())
{
signalEngine.AddSignal(id, channel, signal, out EGID _, clamp);
}
}
/// <summary>
/// Add a value to a conductive cluster channel
/// </summary>
/// <param name="clusterID">The channel cluster's id</param>
/// <param name="signal">The signal value to add</param>
/// <param name="clamp">Whether to clamp the resulting signal value between -1 and 1</param>
public static void AddSignalCluster(EGID clusterID, float signal, bool clamp = true)
{
if (signalEngine.IsInGame && signalEngine.IsSimulationMode())
{
signalEngine.AddSignal(clusterID, signal, clamp);
}
}
/// <summary>
/// Get a channel's signal value from the block's conductive block cluster
/// </summary>
/// <param name="id">The block's id</param>
/// <param name="channel">The channel (1 to 99)</param>
/// <returns>The signal value</returns>
public static float GetSignalConnectedBlocks(uint id, uint channel)
{
if (signalEngine.IsInGame && signalEngine.IsSimulationMode())
{
return signalEngine.GetSignal(id, channel, out EGID _);
}
return 0f;
}
/// <summary>
/// Get a conductive cluster channel's signal value
/// </summary>
/// <param name="clusterID">The channel cluster's id</param>
/// <returns>The signal value</returns>
public static float GetSignalCluster(EGID clusterID)
{
if (signalEngine.IsInGame && signalEngine.IsSimulationMode())
{
return signalEngine.GetSignal(clusterID);
}
return 0f;
}
public static EGID GetClusterID(uint id, uint channel)
{
return signalEngine.GetClusterEGID(id, channel);
}
public static void Init()
{
GameEngineManager.AddGameEngine(signalEngine);
}
}
}