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 the electric block's channel to a value /// /// 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 an electric block's channel signal /// /// 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 electric block's channel's signal value /// /// The block's id /// The channel (1 to 99) /// The signal value public static float GetSignalBlock(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; } /// /// Get the ID of every electricity consumer in the game world /// /// The block IDs public static uint[] GetElectricBlocks() { return signalEngine.GetElectricBlocks(); } /// /// Get the conductive cluster's unique identifier for an electric block /// /// The block's id /// /// The unique ID public static EGID GetClusterID(uint id, uint channel) { return signalEngine.GetClusterEGID(id, channel); } public static void Init() { GameEngineManager.AddGameEngine(signalEngine); } } }