diff --git a/TechbloxModdingAPI/Block.cs b/TechbloxModdingAPI/Block.cs index bab3291..a36c2a9 100644 --- a/TechbloxModdingAPI/Block.cs +++ b/TechbloxModdingAPI/Block.cs @@ -86,22 +86,11 @@ namespace TechbloxModdingAPI remove => BlockEventsEngine.Removed -= value; } - private static readonly Dictionary> GroupToConstructor = + internal static readonly Dictionary> GroupToConstructor = new Dictionary> { - {CommonExclusiveGroups.LOGIC_BLOCK_GROUP, id => new LogicGate(id)}, - {CommonExclusiveGroups.MOTOR_BLOCK_GROUP, id => new Motor(id)}, - {CommonExclusiveGroups.MUSIC_BLOCK_GROUP, id => new MusicBlock(id)}, - {CommonExclusiveGroups.OBJID_BLOCK_GROUP, id => new ObjectIdentifier(id)}, - {CommonExclusiveGroups.PISTON_BLOCK_GROUP, id => new Piston(id)}, - {CommonExclusiveGroups.SERVO_BLOCK_GROUP, id => new Servo(id)}, - {CommonExclusiveGroups.SPAWNPOINT_BLOCK_GROUP, id => new SpawnPoint(id)}, - {CommonExclusiveGroups.BUILDINGSPAWN_BLOCK_GROUP, id => new SpawnPoint(id)}, - {CommonExclusiveGroups.SIMPLESFX_BLOCK_GROUP, id => new SfxBlock(id)}, - {CommonExclusiveGroups.LOOPEDSFX_BLOCK_GROUP, id => new SfxBlock(id)}, {CommonExclusiveGroups.DAMPEDSPRING_BLOCK_GROUP, id => new DampedSpring(id)}, - {CommonExclusiveGroups.TEXT_BLOCK_GROUP, id => new TextBlock(id)}, - {CommonExclusiveGroups.TIMER_BLOCK_GROUP, id => new Timer(id)} + {CommonExclusiveGroups.ENGINE_BLOCK_BUILD_GROUP, id => new Engine(id)} }; internal static Block New(EGID egid) diff --git a/TechbloxModdingAPI/Blocks/BlockEngine.cs b/TechbloxModdingAPI/Blocks/BlockEngine.cs index b8eece6..87d7326 100644 --- a/TechbloxModdingAPI/Blocks/BlockEngine.cs +++ b/TechbloxModdingAPI/Blocks/BlockEngine.cs @@ -156,23 +156,6 @@ namespace TechbloxModdingAPI.Blocks return ret.ToArray(); } - public ObjectIdentifier[] GetObjectIDsFromID(byte id, bool sim) - { - var ret = new FasterList(4); - var oide = entitiesDB.QueryEntities(); - foreach (var ((oids, count), _) in oide) - { - for (int i = 0; i < count; i++) - { - ref ObjectIdEntityStruct oid = ref oids[i]; - if (sim ? oid.simObjectId == id : oid.objectId == id) - ret.Add(new ObjectIdentifier(oid.ID)); - } - } - - return ret.ToArray(); - } - public SimBody[] GetConnectedSimBodies(uint id) { var joints = entitiesDB.QueryEntities(MachineSimulationGroups.JOINTS_GROUP).ToBuffer(); diff --git a/TechbloxModdingAPI/Blocks/Engine.cs b/TechbloxModdingAPI/Blocks/Engine.cs new file mode 100644 index 0000000..8396e66 --- /dev/null +++ b/TechbloxModdingAPI/Blocks/Engine.cs @@ -0,0 +1,35 @@ +using RobocraftX.Common; +using Svelto.ECS; +using Techblox.EngineBlock; + +namespace TechbloxModdingAPI.Blocks +{ + public class Engine : SignalingBlock + { + public Engine(EGID id) : base(id) + { + } + + public Engine(uint id) : base(new EGID(id, CommonExclusiveGroups.ENGINE_BLOCK_BUILD_GROUP)) + { + } + + public bool On + { + get => BlockEngine.GetBlockInfo(this).engineOn; + set => BlockEngine.GetBlockInfo(this).engineOn = value; + } + + public int TorqueDirection + { + get => BlockEngine.GetBlockInfo(this).torqueDirection; + set => BlockEngine.GetBlockInfo(this).torqueDirection = value; + } + + public int CurrentGear + { + get => BlockEngine.GetBlockInfo(this).currentGear; + set => BlockEngine.GetBlockInfo(this).currentGear = value; + } + } +} \ No newline at end of file diff --git a/TechbloxModdingAPI/Blocks/LogicGate.cs b/TechbloxModdingAPI/Blocks/LogicGate.cs deleted file mode 100644 index 50a819c..0000000 --- a/TechbloxModdingAPI/Blocks/LogicGate.cs +++ /dev/null @@ -1,16 +0,0 @@ -using RobocraftX.Common; -using Svelto.ECS; - -namespace TechbloxModdingAPI.Blocks -{ - public class LogicGate : SignalingBlock - { - public LogicGate(EGID id) : base(id) - { - } - - public LogicGate(uint id) : base(new EGID(id, CommonExclusiveGroups.LOGIC_BLOCK_GROUP)) - { - } - } -} \ No newline at end of file diff --git a/TechbloxModdingAPI/Blocks/Motor.cs b/TechbloxModdingAPI/Blocks/Motor.cs deleted file mode 100644 index 46ed9e4..0000000 --- a/TechbloxModdingAPI/Blocks/Motor.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System; - -using RobocraftX.Blocks; -using RobocraftX.Common; -using Svelto.ECS; -using Unity.Mathematics; - -using TechbloxModdingAPI.Utility; - -namespace TechbloxModdingAPI.Blocks -{ - public class Motor : SignalingBlock - { - public Motor(EGID id) : base(id) - { - } - - public Motor(uint id): base(new EGID(id, CommonExclusiveGroups.MOTOR_BLOCK_GROUP)) - { - } - - // custom motor properties - - /// - /// The motor's maximum rotational velocity. - /// - public float TopSpeed - { - get - { - return BlockEngine.GetBlockInfo(this).maxVelocity; - } - - set - { - BlockEngine.GetBlockInfo(this).maxVelocity = value; - } - } - - /// - /// The motor's maximum rotational force. - /// - public float Torque - { - get - { - return BlockEngine.GetBlockInfo(this).maxForce; - } - - set - { - BlockEngine.GetBlockInfo(this).maxForce = value; - } - } - - /// - /// The motor's direction. - /// - public bool Reverse - { - get - { - return BlockEngine.GetBlockInfo(this).reverse; - } - - set - { - BlockEngine.GetBlockInfo(this).reverse = value; - } - } - } -} diff --git a/TechbloxModdingAPI/Blocks/MusicBlock.cs b/TechbloxModdingAPI/Blocks/MusicBlock.cs deleted file mode 100644 index 51e96ee..0000000 --- a/TechbloxModdingAPI/Blocks/MusicBlock.cs +++ /dev/null @@ -1,136 +0,0 @@ -using System; - -using FMOD.Studio; -using FMODUnity; -using Gamecraft.Wires; -using RobocraftX.Common; -using RobocraftX.Blocks; -using Svelto.ECS; -using Unity.Mathematics; - -using TechbloxModdingAPI; -using TechbloxModdingAPI.Tests; -using TechbloxModdingAPI.Utility; - -namespace TechbloxModdingAPI.Blocks -{ - public class MusicBlock : SignalingBlock - { - public MusicBlock(EGID id) : base(id) - { - } - - public MusicBlock(uint id) : base(new EGID(id, CommonExclusiveGroups.MUSIC_BLOCK_GROUP)) - { - } - - public byte TrackIndex - { - get - { - return BlockEngine.GetBlockInfo(this).trackIndx; - } - - set - { - BlockEngine.GetBlockInfo(this).trackIndx = value; - } - } - - public Guid Track - { - get - { - var msdes = BlockEngine.GetBlockInfo(this); - return msdes.fmod2DEventPaths.Get(msdes.trackIndx); - } - - set - { - ref var msdes = ref BlockEngine.GetBlockInfo(this); - for (byte i = 0; i < msdes.fmod2DEventPaths.Count(); i++) - { - Guid track = msdes.fmod2DEventPaths.Get(i); - if (track == value) - { - msdes.trackIndx = i; - break; - } - } - } - } - - public Guid[] Tracks - { - get - { - var msdes = BlockEngine.GetBlockInfo(this); - Guid[] tracks = new Guid[msdes.fmod2DEventPaths.Count()]; - for (byte i = 0; i < tracks.Length; i++) - { - tracks[i] = msdes.fmod2DEventPaths.Get(i); - } - return tracks; - } - } - - public float Volume - { - get - { - return BlockEngine.GetBlockInfo(this).tweakableVolume; - } - - set - { - BlockEngine.GetBlockInfo(this).tweakableVolume = value; - } - } - - public ChannelType ChannelType - { - get - { - //Assert.Log("Block exists: " + Exists); - return (ChannelType) BlockEngine.GetBlockInfo(this).channelType; - } - - set - { - BlockEngine.GetBlockInfo(this).channelType = (byte) value; - } - } - - public bool IsPlaying - { - get - { - return BlockEngine.GetBlockInfo(this).isPlaying; - } - - set - { - ref var msdes = ref BlockEngine.GetBlockInfo(this); - if (msdes.isPlaying == value) return; - if (value) - { - // start playing - EventInstance inst = RuntimeManager.CreateInstance(msdes.fmod2DEventPaths.Get(msdes.trackIndx)); - inst.setVolume(msdes.tweakableVolume / 100f); - inst.start(); - msdes.eventHandle = inst.handle; - } - else - { - // stop playing - EventInstance inst = default(EventInstance); - inst.handle = msdes.eventHandle; - inst.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT); - inst.release(); - } - - msdes.isPlaying = value; - } - } - } -} \ No newline at end of file diff --git a/TechbloxModdingAPI/Blocks/ObjectIdentifier.cs b/TechbloxModdingAPI/Blocks/ObjectIdentifier.cs deleted file mode 100644 index 046054b..0000000 --- a/TechbloxModdingAPI/Blocks/ObjectIdentifier.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Gamecraft.Wires; -using RobocraftX.Common; -using Svelto.ECS; - -namespace TechbloxModdingAPI.Blocks -{ - public class ObjectIdentifier : Block - { - public ObjectIdentifier(EGID id) : base(id) - { - } - - public ObjectIdentifier(uint id) : base(new EGID(id, CommonExclusiveGroups.OBJID_BLOCK_GROUP)) - { - } - - public char Identifier - { - get => (char) (BlockEngine.GetBlockInfo(this).objectId + 'A'); - set - { - BlockEngine.GetBlockInfo(this).objectId = (byte) (value - 'A'); - Label = value + ""; //The label isn't updated automatically - } - } - - /// - /// Simulation-time ID. Assigned by the game starting from 0. - /// - public byte SimID - { - get => BlockEngine.GetBlockInfo(this).simObjectId; - } - - /// - /// Finds the identifier blocks with the given ID. - /// - /// The ID to look for - /// An array that may be empty - public static ObjectIdentifier[] GetByID(char id) => BlockEngine.GetObjectIDsFromID((byte) (id - 'A'), false); - - /// - /// Finds the identifier blocks with the given simulation-time ID. This ID is assigned by the game starting from 0. - /// - /// - /// - public static ObjectIdentifier[] GetBySimID(byte id) => BlockEngine.GetObjectIDsFromID(id, true); - } -} \ No newline at end of file diff --git a/TechbloxModdingAPI/Blocks/Piston.cs b/TechbloxModdingAPI/Blocks/Piston.cs deleted file mode 100644 index 9c1b98a..0000000 --- a/TechbloxModdingAPI/Blocks/Piston.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; - -using RobocraftX.Blocks; -using Svelto.ECS; -using Unity.Mathematics; - -using TechbloxModdingAPI.Utility; -using RobocraftX.Common; - -namespace TechbloxModdingAPI.Blocks -{ - public class Piston : SignalingBlock - { - public Piston(EGID id) : base(id) - { - } - - public Piston(uint id) : base(new EGID(id, CommonExclusiveGroups.PISTON_BLOCK_GROUP)) - { - } - - // custom piston properties - - /// - /// The piston's max extension distance. - /// - public float MaximumExtension - { - get => BlockEngine.GetBlockInfo(this).maxDeviation; - - set - { - BlockEngine.GetBlockInfo(this).maxDeviation = value; - } - } - - /// - /// The piston's max extension force. - /// - public float MaximumForce - { - get => BlockEngine.GetBlockInfo(this).pistonVelocity; - - set - { - BlockEngine.GetBlockInfo(this).pistonVelocity = value; - } - } - } -} diff --git a/TechbloxModdingAPI/Blocks/Servo.cs b/TechbloxModdingAPI/Blocks/Servo.cs deleted file mode 100644 index cdbd87b..0000000 --- a/TechbloxModdingAPI/Blocks/Servo.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System; - -using RobocraftX.Blocks; -using RobocraftX.Common; -using Svelto.ECS; -using Unity.Mathematics; - -using TechbloxModdingAPI.Utility; - -namespace TechbloxModdingAPI.Blocks -{ - public class Servo : SignalingBlock - { - public Servo(EGID id) : base(id) - { - } - - public Servo(uint id) : base(new EGID(id, CommonExclusiveGroups.SERVO_BLOCK_GROUP)) - { - } - - // custom servo properties - - /// - /// The servo's minimum angle. - /// - public float MinimumAngle - { - get => BlockEngine.GetBlockInfo(this).minDeviation; - - set - { - BlockEngine.GetBlockInfo(this).minDeviation = value; - } - } - - /// - /// The servo's maximum angle. - /// - public float MaximumAngle - { - get => BlockEngine.GetBlockInfo(this).maxDeviation; - - set - { - BlockEngine.GetBlockInfo(this).maxDeviation = value; - } - } - - /// - /// The servo's maximum force. - /// - public float MaximumForce - { - get => BlockEngine.GetBlockInfo(this).servoVelocity; - - set - { - BlockEngine.GetBlockInfo(this).servoVelocity = value; - } - } - - /// - /// The servo's direction. - /// - public bool Reverse - { - get => BlockEngine.GetBlockInfo(this).reverse; - - set - { - BlockEngine.GetBlockInfo(this).reverse = value; - } - } - } -} diff --git a/TechbloxModdingAPI/Blocks/SfxBlock.cs b/TechbloxModdingAPI/Blocks/SfxBlock.cs deleted file mode 100644 index 6b6ab36..0000000 --- a/TechbloxModdingAPI/Blocks/SfxBlock.cs +++ /dev/null @@ -1,202 +0,0 @@ -using System; -using FMOD.Studio; -using FMODUnity; -using Gamecraft.Wires; -using RobocraftX.Blocks; -using RobocraftX.Common; -using Svelto.ECS; - -namespace TechbloxModdingAPI.Blocks -{ - public class SfxBlock : SignalingBlock - { - public SfxBlock(EGID id) : base(id) - { - } - - public SfxBlock(uint id) : base(new EGID(id, CommonExclusiveGroups.SIMPLESFX_BLOCK_GROUP /* This could also be BUILD_LOOPEDSFX_BLOCK_GROUP */)) - { - } - - public float Volume - { - get - { - return BlockEngine.GetBlockInfo(this).tweakableVolume; - } - - set - { - BlockEngine.GetBlockInfo(this).tweakableVolume = value; - } - } - - public float Pitch - { - get - { - return BlockEngine.GetBlockInfo(this).tweakablePitch; - } - - set - { - BlockEngine.GetBlockInfo(this).tweakablePitch = value; - } - } - - public bool Is3D - { - get - { - return BlockEngine.GetBlockInfo(this).is3D; - } - - set - { - BlockEngine.GetBlockInfo(this).is3D = value; - } - } - - public ChannelType ChannelType - { - get - { - return (ChannelType) BlockEngine.GetBlockInfo(this).channelType; - } - - set - { - BlockEngine.GetBlockInfo(this).channelType = (byte) value; - } - } - - public byte TrackIndex - { - get - { - return BlockEngine.GetBlockInfo(this).soundEffectIndex; - } - - set - { - BlockEngine.GetBlockInfo(this).soundEffectIndex = value; - } - } - - // track - public Guid Track - { - get - { - var obj = BlockEngine.GetBlockInfo(this); - return obj.is3D - ? obj.fmod3DEventPaths.Get(obj.soundEffectIndex) - : obj.fmod2DEventPaths.Get(obj.soundEffectIndex); - } - - set - { - var obj = BlockEngine.GetBlockInfo(this); - for (byte i = 0; i < obj.fmod2DEventPaths.Count(); i++) - { - Guid track = obj.fmod2DEventPaths.Get(i); - if (track == value) - { - obj.soundEffectIndex = i; - obj.is3D = false; - return; - } - } - - for (byte i = 0; i < obj.fmod3DEventPaths.Count(); i++) - { - Guid track = obj.fmod3DEventPaths.Get(i); - if (track == value) - { - obj.soundEffectIndex = i; - obj.is3D = true; - return; - } - } - } - } - - // all tracks - public Guid[] Tracks2D - { - get - { - var obj = BlockEngine.GetBlockInfo(this); - Guid[] tracks = new Guid[obj.fmod2DEventPaths.Count()]; - for (byte i = 0; i < tracks.Length; i++) - { - tracks[i] = obj.fmod2DEventPaths.Get(i); - } - - return tracks; - } - } - - public Guid[] Tracks3D - { - get - { - var obj = BlockEngine.GetBlockInfo(this); - Guid[] tracks = new Guid[obj.fmod3DEventPaths.Count()]; - for (byte i = 0; i < tracks.Length; i++) - { - tracks[i] = obj.fmod2DEventPaths.Get(i); - } - - return tracks; - } - } - - public bool IsLooped - { - get - { - return BlockEngine.GetBlockInfo(this).isLoopedBlock; - } - - set - { - BlockEngine.GetBlockInfo(this).isLoopedBlock = value; - } - } - - public bool IsPlaying - { - get - { - return BlockEngine.GetBlockInfo(this).isPlaying; - } - - set - { - var obj = BlockEngine.GetBlockInfo(this); - if (obj.isPlaying == value) return; - if (value) - { - // start playing - EventInstance inst = RuntimeManager.CreateInstance(obj.is3D - ? obj.fmod3DEventPaths.Get(obj.soundEffectIndex) - : obj.fmod2DEventPaths.Get(obj.soundEffectIndex)); - inst.setVolume(obj.tweakableVolume / 100f); - inst.start(); - obj.eventHandle = inst.handle; - } - else - { - // stop playing - EventInstance inst = default(EventInstance); - inst.handle = obj.eventHandle; - inst.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT); - inst.release(); - } - - obj.isPlaying = value; - } - } - } -} \ No newline at end of file diff --git a/TechbloxModdingAPI/Blocks/SpawnPoint.cs b/TechbloxModdingAPI/Blocks/SpawnPoint.cs deleted file mode 100644 index 0c5c75a..0000000 --- a/TechbloxModdingAPI/Blocks/SpawnPoint.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; - -using RobocraftX.Blocks; -using RobocraftX.Common; -using Gamecraft.CharacterVulnerability; -using Svelto.ECS; -using Unity.Mathematics; - -using TechbloxModdingAPI; -using TechbloxModdingAPI.Utility; - -namespace TechbloxModdingAPI.Blocks -{ - public class SpawnPoint : Block - { - public SpawnPoint(EGID id) : base(id) - { - } - - public SpawnPoint(uint id) : base(new EGID(id, CommonExclusiveGroups.SPAWNPOINT_BLOCK_GROUP)) - { - } - - // custom spawn point properties - - /// - /// The lives the player spawns in with. - /// - public uint Lives - { - get => BlockEngine.GetBlockInfo(this).lives; - - set - { - BlockEngine.GetBlockInfo(this).lives = value; - } - } - - /// - /// Whether the spawned player can take damage. - /// - public bool Damageable - { - get => BlockEngine.GetBlockInfo(this).canTakeDamage; - - set - { - BlockEngine.GetBlockInfo(this).canTakeDamage = value; - } - } - - /// - /// Whether the game over screen will be displayed - /// - public bool GameOverEnabled - { - get => BlockEngine.GetBlockInfo(this).gameOverScreen; - - set - { - BlockEngine.GetBlockInfo(this).gameOverScreen = value; - } - } - - /// - /// The team id for players who spawn here. - /// - public byte Team - { - get => BlockEngine.GetBlockInfo(this).teamId; - - set - { - BlockEngine.GetBlockInfo(this).teamId = value; - } - } - } -} diff --git a/TechbloxModdingAPI/Blocks/TextBlock.cs b/TechbloxModdingAPI/Blocks/TextBlock.cs deleted file mode 100644 index 99c753a..0000000 --- a/TechbloxModdingAPI/Blocks/TextBlock.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; - -using Gamecraft.Blocks.GUI; -using RobocraftX.Common; -using Svelto.ECS; -using Unity.Mathematics; - -using TechbloxModdingAPI; -using TechbloxModdingAPI.Utility; - -namespace TechbloxModdingAPI.Blocks -{ - public class TextBlock : SignalingBlock - { - public TextBlock(EGID id) : base(id) - { - } - - public TextBlock(uint id) : base(new EGID(id, CommonExclusiveGroups.TEXT_BLOCK_GROUP)) - { - } - - // custom text block properties - - /// - /// The text block's current text. - /// - public string Text - { - get => BlockEngine.GetBlockInfo(this).textCurrent; - - set - { - if (value == null) value = ""; - var tbds = BlockEngine.GetBlockInfo(this); - tbds.textCurrent.Set(value); - tbds.textStored.Set(value, true); - } - } - - /// - /// The text block's current text block ID (used in ChangeTextBlockCommand). - /// - public string TextBlockId - { - get => BlockEngine.GetBlockInfo(this).textBlockID; - - set - { - if (value == null) value = ""; - BlockEngine.GetBlockInfo(this).textBlockID.Set(value); - } - } - } -} diff --git a/TechbloxModdingAPI/Blocks/Timer.cs b/TechbloxModdingAPI/Blocks/Timer.cs deleted file mode 100644 index 9803258..0000000 --- a/TechbloxModdingAPI/Blocks/Timer.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; - -using RobocraftX.Blocks; -using RobocraftX.Common; -using Gamecraft.Blocks.TimerBlock; -using Svelto.ECS; -using Unity.Mathematics; - -using TechbloxModdingAPI; -using TechbloxModdingAPI.Utility; - -namespace TechbloxModdingAPI.Blocks -{ - public class Timer : SignalingBlock - { - public Timer(EGID id) : base(id) - { - } - - public Timer(uint id) : base(new EGID(id, CommonExclusiveGroups.TIMER_BLOCK_GROUP)) - { - } - - // custom timer properties - - /// - /// The player-specified start time. - /// - public float Start - { - get => BlockEngine.GetBlockInfo(this).startTime; - - set - { - BlockEngine.GetBlockInfo(this).startTime = value; - } - } - - /// - /// The player-specified end time. - /// - public float End - { - get => BlockEngine.GetBlockInfo(this).endTime; - - set - { - BlockEngine.GetBlockInfo(this).endTime = value; - } - } - - /// - /// Whether to display time with millisecond precision. - /// - public bool DisplayMilliseconds - { - get => BlockEngine.GetBlockInfo(this).outputFormatHasMS; - - set - { - BlockEngine.GetBlockInfo(this).outputFormatHasMS = value; - } - } - - /// - /// Current time (as of the last video frame), in milliseconds. - /// - public int CurrentTime - { - get => BlockEngine.GetBlockInfo(this).timeLastRenderFrameMS; - - set - { - BlockEngine.GetBlockInfo(this).timeLastRenderFrameMS = value; - } - } - } -}