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