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
/// The functionality in this class only works when in a game.
///
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 the electric block's (first) signal value.
///
/// The block's id.
/// The signal value (-1 to 1; not enforced).
/// Whether to retrieve input IDs (true) or output IDs (false).
/// Whether the block is in the owned group (true) or functional group (false)
public static void SetSignalByBlock(uint blockID, float signal, bool input = true, bool owned = true)
{
EGID egid = new EGID(blockID, owned ? BlockIdentifiers.OWNED_BLOCKS : BlockIdentifiers.FUNCTIONAL_BLOCK_PARTS);
if (signalEngine.IsInGame && GameState.IsSimulationMode())
{
signalEngine.SetSignal(egid, signal, out uint _, input);
}
}
public static void SetSignalByBlock(EGID blockID, float signal, bool input = true)
{
if (signalEngine.IsInGame && GameState.IsSimulationMode())
{
signalEngine.SetSignal(blockID, signal, out uint _, input);
}
}
///
/// Set the signal's value.
///
/// The channel cluster's id.
/// The signal value (-1 to 1; not enforced).
/// Whether to retrieve input IDs (true) or output IDs (false).
public static void SetSignalByID(uint signalID, float signal, bool input = true)
{
if (signalEngine.IsInGame && GamecraftModdingAPI.Utility.GameState.IsSimulationMode())
{
signalEngine.SetSignal(signalID, signal, input);
}
}
///
/// Add a value to an electric block's signal.
///
/// The block's id.
/// The signal value to add.
/// Whether to clamp the resulting signal value between -1 and 1.
/// Whether to retrieve input IDs (true) or output IDs (false).
/// Whether the block is in the owned group (true) or functional group (false)
/// The signal's new value.
public static float AddSignalByBlock(uint blockID, float signal, bool clamp = true, bool input = true, bool owned = true)
{
EGID egid = new EGID(blockID, owned ? BlockIdentifiers.OWNED_BLOCKS : BlockIdentifiers.FUNCTIONAL_BLOCK_PARTS);
if (signalEngine.IsInGame && GamecraftModdingAPI.Utility.GameState.IsSimulationMode())
{
return signalEngine.AddSignal(egid, signal, out uint _, clamp, input);
}
return 0f;
}
public static float AddSignalByBlock(EGID blockID, float signal, bool clamp = true, bool input = true)
{
if (signalEngine.IsInGame && GamecraftModdingAPI.Utility.GameState.IsSimulationMode())
{
return signalEngine.AddSignal(blockID, signal, out uint _, clamp, input);
}
return 0f;
}
///
/// 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.
/// Whether to retrieve input IDs (true) or output IDs (false).
/// The signal's new value.
public static float AddSignalByID(uint signalID, float signal, bool clamp = true, bool input = true)
{
if (signalEngine.IsInGame && GamecraftModdingAPI.Utility.GameState.IsSimulationMode())
{
return signalEngine.AddSignal(signalID, signal, clamp, input);
}
return 0f;
}
///
/// Get a electric block's signal's (first) value.
///
/// The block's id.
/// Whether to retrieve input IDs (true) or output IDs (false).
/// Whether the block is in the owned group (true) or functional group (false)
/// The signal's value.
public static float GetSignalByBlock(uint blockID, bool input = true, bool owned = true)
{
EGID egid = new EGID(blockID, owned? BlockIdentifiers.OWNED_BLOCKS : BlockIdentifiers.FUNCTIONAL_BLOCK_PARTS);
if (signalEngine.IsInGame && GamecraftModdingAPI.Utility.GameState.IsSimulationMode())
{
return signalEngine.GetSignal(egid, out uint _, input);
}
return 0f;
}
public static float GetSignalByBlock(EGID blockID, bool input = true)
{
if (signalEngine.IsInGame && GamecraftModdingAPI.Utility.GameState.IsSimulationMode())
{
return signalEngine.GetSignal(blockID, out uint _, input);
}
return 0f;
}
///
/// Get a signal's value.
///
/// The signal's id.
/// Whether to retrieve input IDs (true) or output IDs (false).
/// The signal's value.
public static float GetSignalByID(uint signalID, bool input = true)
{
if (signalEngine.IsInGame && GamecraftModdingAPI.Utility.GameState.IsSimulationMode())
{
return signalEngine.GetSignal(signalID, input);
}
return 0f;
}
///
/// Get the ID of every electric block in the game world.
///
/// The block IDs.
public static EGID[] GetElectricBlocks()
{
return signalEngine.GetElectricBlocks();
}
///
/// Get the unique identifiers for the input wires connected to an electric block.
///
/// The block's id.
/// Whether to retrieve input IDs (true) or output IDs (false).
/// Whether the block is in the owned group (true) or functional group (false)
/// The unique IDs.
public static uint[] GetSignalIDs(uint blockID, bool input = true, bool owned = true)
{
EGID egid = new EGID(blockID, owned ? BlockIdentifiers.OWNED_BLOCKS : BlockIdentifiers.FUNCTIONAL_BLOCK_PARTS);
return signalEngine.GetSignalIDs(egid, input);
}
public static uint[] GetSignalIDs(EGID blockID, bool input = true, bool owned = true)
{
return signalEngine.GetSignalIDs(blockID, input);
}
public static void Init()
{
GameEngineManager.AddGameEngine(signalEngine);
}
}
}