Add start of Engine class, removed nonexistent blocks

Not all engine properties are added (yet)
The old block types can be brought back when/if they come back, potentially with different properties
This commit is contained in:
Norbi Peti 2021-05-20 23:26:22 +02:00
parent e9df67f462
commit b3f7dcd36d
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
13 changed files with 37 additions and 842 deletions

View file

@ -86,22 +86,11 @@ namespace TechbloxModdingAPI
remove => BlockEventsEngine.Removed -= value;
}
private static readonly Dictionary<ExclusiveBuildGroup, Func<EGID, Block>> GroupToConstructor =
internal static readonly Dictionary<ExclusiveBuildGroup, Func<EGID, Block>> GroupToConstructor =
new Dictionary<ExclusiveBuildGroup, Func<EGID, Block>>
{
{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)

View file

@ -156,23 +156,6 @@ namespace TechbloxModdingAPI.Blocks
return ret.ToArray();
}
public ObjectIdentifier[] GetObjectIDsFromID(byte id, bool sim)
{
var ret = new FasterList<ObjectIdentifier>(4);
var oide = entitiesDB.QueryEntities<ObjectIdEntityStruct>();
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<JointEntityStruct>(MachineSimulationGroups.JOINTS_GROUP).ToBuffer();

View file

@ -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<EngineBlockComponent>(this).engineOn;
set => BlockEngine.GetBlockInfo<EngineBlockComponent>(this).engineOn = value;
}
public int TorqueDirection
{
get => BlockEngine.GetBlockInfo<EngineBlockComponent>(this).torqueDirection;
set => BlockEngine.GetBlockInfo<EngineBlockComponent>(this).torqueDirection = value;
}
public int CurrentGear
{
get => BlockEngine.GetBlockInfo<EngineBlockComponent>(this).currentGear;
set => BlockEngine.GetBlockInfo<EngineBlockComponent>(this).currentGear = value;
}
}
}

View file

@ -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))
{
}
}
}

View file

@ -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
/// <summary>
/// The motor's maximum rotational velocity.
/// </summary>
public float TopSpeed
{
get
{
return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(this).maxVelocity;
}
set
{
BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(this).maxVelocity = value;
}
}
/// <summary>
/// The motor's maximum rotational force.
/// </summary>
public float Torque
{
get
{
return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(this).maxForce;
}
set
{
BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(this).maxForce = value;
}
}
/// <summary>
/// The motor's direction.
/// </summary>
public bool Reverse
{
get
{
return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(this).reverse;
}
set
{
BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(this).reverse = value;
}
}
}
}

View file

@ -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<MusicBlockDataEntityStruct>(this).trackIndx;
}
set
{
BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this).trackIndx = value;
}
}
public Guid Track
{
get
{
var msdes = BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this);
return msdes.fmod2DEventPaths.Get<Guid>(msdes.trackIndx);
}
set
{
ref var msdes = ref BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this);
for (byte i = 0; i < msdes.fmod2DEventPaths.Count<Guid>(); i++)
{
Guid track = msdes.fmod2DEventPaths.Get<Guid>(i);
if (track == value)
{
msdes.trackIndx = i;
break;
}
}
}
}
public Guid[] Tracks
{
get
{
var msdes = BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this);
Guid[] tracks = new Guid[msdes.fmod2DEventPaths.Count<Guid>()];
for (byte i = 0; i < tracks.Length; i++)
{
tracks[i] = msdes.fmod2DEventPaths.Get<Guid>(i);
}
return tracks;
}
}
public float Volume
{
get
{
return BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this).tweakableVolume;
}
set
{
BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this).tweakableVolume = value;
}
}
public ChannelType ChannelType
{
get
{
//Assert.Log("Block exists: " + Exists);
return (ChannelType) BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this).channelType;
}
set
{
BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this).channelType = (byte) value;
}
}
public bool IsPlaying
{
get
{
return BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this).isPlaying;
}
set
{
ref var msdes = ref BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this);
if (msdes.isPlaying == value) return;
if (value)
{
// start playing
EventInstance inst = RuntimeManager.CreateInstance(msdes.fmod2DEventPaths.Get<Guid>(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;
}
}
}
}

View file

@ -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<ObjectIdEntityStruct>(this).objectId + 'A');
set
{
BlockEngine.GetBlockInfo<ObjectIdEntityStruct>(this).objectId = (byte) (value - 'A');
Label = value + ""; //The label isn't updated automatically
}
}
/// <summary>
/// Simulation-time ID. Assigned by the game starting from 0.
/// </summary>
public byte SimID
{
get => BlockEngine.GetBlockInfo<ObjectIdEntityStruct>(this).simObjectId;
}
/// <summary>
/// Finds the identifier blocks with the given ID.
/// </summary>
/// <param name="id">The ID to look for</param>
/// <returns>An array that may be empty</returns>
public static ObjectIdentifier[] GetByID(char id) => BlockEngine.GetObjectIDsFromID((byte) (id - 'A'), false);
/// <summary>
/// Finds the identifier blocks with the given simulation-time ID. This ID is assigned by the game starting from 0.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public static ObjectIdentifier[] GetBySimID(byte id) => BlockEngine.GetObjectIDsFromID(id, true);
}
}

View file

@ -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
/// <summary>
/// The piston's max extension distance.
/// </summary>
public float MaximumExtension
{
get => BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(this).maxDeviation;
set
{
BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(this).maxDeviation = value;
}
}
/// <summary>
/// The piston's max extension force.
/// </summary>
public float MaximumForce
{
get => BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(this).pistonVelocity;
set
{
BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(this).pistonVelocity = value;
}
}
}
}

View file

@ -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
/// <summary>
/// The servo's minimum angle.
/// </summary>
public float MinimumAngle
{
get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(this).minDeviation;
set
{
BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(this).minDeviation = value;
}
}
/// <summary>
/// The servo's maximum angle.
/// </summary>
public float MaximumAngle
{
get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(this).maxDeviation;
set
{
BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(this).maxDeviation = value;
}
}
/// <summary>
/// The servo's maximum force.
/// </summary>
public float MaximumForce
{
get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(this).servoVelocity;
set
{
BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(this).servoVelocity = value;
}
}
/// <summary>
/// The servo's direction.
/// </summary>
public bool Reverse
{
get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(this).reverse;
set
{
BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(this).reverse = value;
}
}
}
}

View file

@ -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<SoundSfxBlockDataEntityStruct>(this).tweakableVolume;
}
set
{
BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).tweakableVolume = value;
}
}
public float Pitch
{
get
{
return BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).tweakablePitch;
}
set
{
BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).tweakablePitch = value;
}
}
public bool Is3D
{
get
{
return BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).is3D;
}
set
{
BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).is3D = value;
}
}
public ChannelType ChannelType
{
get
{
return (ChannelType) BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).channelType;
}
set
{
BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).channelType = (byte) value;
}
}
public byte TrackIndex
{
get
{
return BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).soundEffectIndex;
}
set
{
BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).soundEffectIndex = value;
}
}
// track
public Guid Track
{
get
{
var obj = BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this);
return obj.is3D
? obj.fmod3DEventPaths.Get<Guid>(obj.soundEffectIndex)
: obj.fmod2DEventPaths.Get<Guid>(obj.soundEffectIndex);
}
set
{
var obj = BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this);
for (byte i = 0; i < obj.fmod2DEventPaths.Count<Guid>(); i++)
{
Guid track = obj.fmod2DEventPaths.Get<Guid>(i);
if (track == value)
{
obj.soundEffectIndex = i;
obj.is3D = false;
return;
}
}
for (byte i = 0; i < obj.fmod3DEventPaths.Count<Guid>(); i++)
{
Guid track = obj.fmod3DEventPaths.Get<Guid>(i);
if (track == value)
{
obj.soundEffectIndex = i;
obj.is3D = true;
return;
}
}
}
}
// all tracks
public Guid[] Tracks2D
{
get
{
var obj = BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this);
Guid[] tracks = new Guid[obj.fmod2DEventPaths.Count<Guid>()];
for (byte i = 0; i < tracks.Length; i++)
{
tracks[i] = obj.fmod2DEventPaths.Get<Guid>(i);
}
return tracks;
}
}
public Guid[] Tracks3D
{
get
{
var obj = BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this);
Guid[] tracks = new Guid[obj.fmod3DEventPaths.Count<Guid>()];
for (byte i = 0; i < tracks.Length; i++)
{
tracks[i] = obj.fmod2DEventPaths.Get<Guid>(i);
}
return tracks;
}
}
public bool IsLooped
{
get
{
return BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).isLoopedBlock;
}
set
{
BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).isLoopedBlock = value;
}
}
public bool IsPlaying
{
get
{
return BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).isPlaying;
}
set
{
var obj = BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this);
if (obj.isPlaying == value) return;
if (value)
{
// start playing
EventInstance inst = RuntimeManager.CreateInstance(obj.is3D
? obj.fmod3DEventPaths.Get<Guid>(obj.soundEffectIndex)
: obj.fmod2DEventPaths.Get<Guid>(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;
}
}
}
}

View file

@ -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
/// <summary>
/// The lives the player spawns in with.
/// </summary>
public uint Lives
{
get => BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(this).lives;
set
{
BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(this).lives = value;
}
}
/// <summary>
/// Whether the spawned player can take damage.
/// </summary>
public bool Damageable
{
get => BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(this).canTakeDamage;
set
{
BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(this).canTakeDamage = value;
}
}
/// <summary>
/// Whether the game over screen will be displayed
/// </summary>
public bool GameOverEnabled
{
get => BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(this).gameOverScreen;
set
{
BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(this).gameOverScreen = value;
}
}
/// <summary>
/// The team id for players who spawn here.
/// </summary>
public byte Team
{
get => BlockEngine.GetBlockInfo<SpawnPointIdsEntityStruct>(this).teamId;
set
{
BlockEngine.GetBlockInfo<SpawnPointIdsEntityStruct>(this).teamId = value;
}
}
}
}

View file

@ -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
/// <summary>
/// The text block's current text.
/// </summary>
public string Text
{
get => BlockEngine.GetBlockInfo<TextBlockDataStruct>(this).textCurrent;
set
{
if (value == null) value = "";
var tbds = BlockEngine.GetBlockInfo<TextBlockDataStruct>(this);
tbds.textCurrent.Set(value);
tbds.textStored.Set(value, true);
}
}
/// <summary>
/// The text block's current text block ID (used in ChangeTextBlockCommand).
/// </summary>
public string TextBlockId
{
get => BlockEngine.GetBlockInfo<TextBlockDataStruct>(this).textBlockID;
set
{
if (value == null) value = "";
BlockEngine.GetBlockInfo<TextBlockDataStruct>(this).textBlockID.Set(value);
}
}
}
}

View file

@ -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
/// <summary>
/// The player-specified start time.
/// </summary>
public float Start
{
get => BlockEngine.GetBlockInfo<TimerBlockDataStruct>(this).startTime;
set
{
BlockEngine.GetBlockInfo<TimerBlockDataStruct>(this).startTime = value;
}
}
/// <summary>
/// The player-specified end time.
/// </summary>
public float End
{
get => BlockEngine.GetBlockInfo<TimerBlockDataStruct>(this).endTime;
set
{
BlockEngine.GetBlockInfo<TimerBlockDataStruct>(this).endTime = value;
}
}
/// <summary>
/// Whether to display time with millisecond precision.
/// </summary>
public bool DisplayMilliseconds
{
get => BlockEngine.GetBlockInfo<TimerBlockDataStruct>(this).outputFormatHasMS;
set
{
BlockEngine.GetBlockInfo<TimerBlockDataStruct>(this).outputFormatHasMS = value;
}
}
/// <summary>
/// Current time (as of the last video frame), in milliseconds.
/// </summary>
public int CurrentTime
{
get => BlockEngine.GetBlockInfo<TimerBlockLabelCacheEntityStruct>(this).timeLastRenderFrameMS;
set
{
BlockEngine.GetBlockInfo<TimerBlockLabelCacheEntityStruct>(this).timeLastRenderFrameMS = value;
}
}
}
}