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
{
///
/// [EXPERIMENTAL] Common block signal operations
///
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();
///
/// Set a channel to a value in the block's conductive block cluster
///
/// The block's id
/// The channel (1 to 99)
/// The signal value (-1 to 1; not enforced)
public static void SetSignalConnectedBlocks(uint id, uint channel, float signal)
{
if (signalEngine.IsInGame && signalEngine.IsSimulationMode())
{
signalEngine.SetSignal(id, channel, signal, out EGID _);
}
}
///
/// Set a conductive cluster channel to a value
///
/// The channel cluster's id
/// The signal value (-1 to 1; not enforced)
public static void SetSignalCluster(EGID clusterID, float signal)
{
if (signalEngine.IsInGame && signalEngine.IsSimulationMode())
{
signalEngine.SetSignal(clusterID, signal);
}
}
///
/// Add a value to a channel signal in the block's conductive block cluster
///
/// The block's id
/// The channel (1 to 99)
/// The signal value to add
/// Whether to clamp the resulting signal value between -1 and 1
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);
}
}
///
/// Add a value to a conductive cluster channel
///
/// The channel cluster's id
/// The signal value to add
/// Whether to clamp the resulting signal value between -1 and 1
public static void AddSignalCluster(EGID clusterID, float signal, bool clamp = true)
{
if (signalEngine.IsInGame && signalEngine.IsSimulationMode())
{
signalEngine.AddSignal(clusterID, signal, clamp);
}
}
///
/// Get a channel's signal value from the block's conductive block cluster
///
/// The block's id
/// The channel (1 to 99)
/// The signal value
public static float GetSignalConnectedBlocks(uint id, uint channel)
{
if (signalEngine.IsInGame && signalEngine.IsSimulationMode())
{
return signalEngine.GetSignal(id, channel, out EGID _);
}
return 0f;
}
///
/// Get a conductive cluster channel's signal value
///
/// The channel cluster's id
/// The signal value
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);
}
}
}