From d238c97906eb56dbd3aa0561bdfa2f3d6363289d Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Mon, 10 May 2021 23:08:15 +0200 Subject: [PATCH] Remove block info getters and setters Regex is great GetBlockInfo\(this, \((\w+) (\w+)\) ?=> ?\2(.+)\); GetBlockInfo<$1>(this)$3; SetBlockInfo\(this, \(ref (\w+) (\w+), \w+ (\w+)\) ?=> \2(.*) = \3,\s*value\); GetBlockInfo<$1>(this)$4 = value; --- TechbloxModdingAPI/Block.cs | 13 ++++++------ TechbloxModdingAPI/Blocks/BlockEngine.cs | 7 ++++++- TechbloxModdingAPI/Blocks/DampedSpring.cs | 6 +++--- TechbloxModdingAPI/Blocks/Motor.cs | 12 +++++------ TechbloxModdingAPI/Blocks/MusicBlock.cs | 4 ++-- TechbloxModdingAPI/Blocks/ObjectIdentifier.cs | 4 ++-- TechbloxModdingAPI/Blocks/Piston.cs | 9 ++++----- TechbloxModdingAPI/Blocks/Servo.cs | 16 +++++++-------- TechbloxModdingAPI/Blocks/SfxBlock.cs | 10 +++++----- TechbloxModdingAPI/Blocks/SignalingBlock.cs | 4 ++-- TechbloxModdingAPI/Blocks/SpawnPoint.cs | 16 +++++++-------- TechbloxModdingAPI/Blocks/TextBlock.cs | 6 +++--- TechbloxModdingAPI/Blocks/Timer.cs | 20 ++++++++----------- 13 files changed, 63 insertions(+), 64 deletions(-) diff --git a/TechbloxModdingAPI/Block.cs b/TechbloxModdingAPI/Block.cs index 0e97a03..b2d400d 100644 --- a/TechbloxModdingAPI/Block.cs +++ b/TechbloxModdingAPI/Block.cs @@ -285,14 +285,14 @@ namespace TechbloxModdingAPI /// public float3 Scale { - get => BlockEngine.GetBlockInfo(this, (ScalingEntityStruct st) => st.scale); + get => BlockEngine.GetBlockInfo(this).scale; set { int uscale = UniformScale; if (value.x < 4e-5) value.x = uscale; if (value.y < 4e-5) value.y = uscale; if (value.z < 4e-5) value.z = uscale; - BlockEngine.SetBlockInfo(this, (ref ScalingEntityStruct st, float3 val) => st.scale = val, value); + BlockEngine.GetBlockInfo(this).scale = value; if (!Exists) return; //UpdateCollision needs the block to exist ScalingEngine.UpdateCollision(Id); BlockEngine.UpdateDisplayedBlock(Id); @@ -305,12 +305,11 @@ namespace TechbloxModdingAPI /// public int UniformScale { - get => BlockEngine.GetBlockInfo(this, (UniformBlockScaleEntityStruct st) => st.scaleFactor); + get => BlockEngine.GetBlockInfo(this).scaleFactor; set { if (value < 1) value = 1; - BlockEngine.SetBlockInfo(this, (ref UniformBlockScaleEntityStruct st, int val) => st.scaleFactor = val, - value); + BlockEngine.GetBlockInfo(this).scaleFactor = value; Scale = new float3(value, value, value); } } @@ -320,7 +319,7 @@ namespace TechbloxModdingAPI */ public bool Flipped { - get => BlockEngine.GetBlockInfo(this, (ScalingEntityStruct st) => st.scale.x < 0); + get => BlockEngine.GetBlockInfo(this).scale.x < 0; set { BlockEngine.SetBlockInfo(this, (ref ScalingEntityStruct st, bool val) => @@ -371,7 +370,7 @@ namespace TechbloxModdingAPI /// public float4 CustomColor { - get => BlockEngine.GetBlockInfo(this, (ColourParameterEntityStruct st) => st.paletteColour); + get => BlockEngine.GetBlockInfo(this).paletteColour; set { BlockEngine.SetBlockInfo(this, (ref ColourParameterEntityStruct color, float4 val) => diff --git a/TechbloxModdingAPI/Blocks/BlockEngine.cs b/TechbloxModdingAPI/Blocks/BlockEngine.cs index 935e3a1..80e14f3 100644 --- a/TechbloxModdingAPI/Blocks/BlockEngine.cs +++ b/TechbloxModdingAPI/Blocks/BlockEngine.cs @@ -70,11 +70,16 @@ namespace TechbloxModdingAPI.Blocks : entitiesDB.QueryEntity(index, CommonExclusiveGroups.COLOUR_PALETTE_GROUP).Colour; - public OptionalRef GetBlockInfo(Block block) where T : unmanaged, IEntityComponent + public OptionalRef GetBlockInfoOptional(Block block) where T : unmanaged, IEntityComponent { return entitiesDB.QueryEntityOptional(block); } + public ref T GetBlockInfo(Block block) where T : unmanaged, IEntityComponent + { + return ref entitiesDB.QueryEntityOrDefault(block); + } + public void UpdateDisplayedBlock(EGID id) { if (!BlockExists(id)) return; diff --git a/TechbloxModdingAPI/Blocks/DampedSpring.cs b/TechbloxModdingAPI/Blocks/DampedSpring.cs index 34c7543..3c92f72 100644 --- a/TechbloxModdingAPI/Blocks/DampedSpring.cs +++ b/TechbloxModdingAPI/Blocks/DampedSpring.cs @@ -19,7 +19,7 @@ namespace TechbloxModdingAPI.Blocks /// public float MaxForce { - get => BlockEngine.GetBlockInfo(this, (DampedSpringReadOnlyStruct dsrs) => dsrs.springFrequency); + get => BlockEngine.GetBlockInfo(this).springFrequency; set => BlockEngine.SetBlockInfo(this, (ref DampedSpringReadOnlyStruct dsrs, float val) => dsrs.springFrequency = val, value); @@ -39,7 +39,7 @@ namespace TechbloxModdingAPI.Blocks /// public float Damping { - get => BlockEngine.GetBlockInfo(this, (DampedSpringReadOnlyStruct ljf) => ljf.springDamping); + get => BlockEngine.GetBlockInfo(this).springDamping; set => BlockEngine.SetBlockInfo(this, (ref DampedSpringReadOnlyStruct ljf, float val) => ljf.springDamping = val, value); @@ -50,7 +50,7 @@ namespace TechbloxModdingAPI.Blocks /// public float MaxExtension { - get => BlockEngine.GetBlockInfo(this, (DampedSpringReadOnlyStruct ljf) => ljf.maxExtent); + get => BlockEngine.GetBlockInfo(this).maxExtent; set => BlockEngine.SetBlockInfo(this, (ref DampedSpringReadOnlyStruct ljf, float val) => ljf.maxExtent = val, value); diff --git a/TechbloxModdingAPI/Blocks/Motor.cs b/TechbloxModdingAPI/Blocks/Motor.cs index 6b1e500..46ed9e4 100644 --- a/TechbloxModdingAPI/Blocks/Motor.cs +++ b/TechbloxModdingAPI/Blocks/Motor.cs @@ -28,12 +28,12 @@ namespace TechbloxModdingAPI.Blocks { get { - return BlockEngine.GetBlockInfo(this, (MotorReadOnlyStruct st) => st.maxVelocity); + return BlockEngine.GetBlockInfo(this).maxVelocity; } set { - BlockEngine.SetBlockInfo(this, (ref MotorReadOnlyStruct st, float val) => st.maxVelocity = val, value); + BlockEngine.GetBlockInfo(this).maxVelocity = value; } } @@ -44,12 +44,12 @@ namespace TechbloxModdingAPI.Blocks { get { - return BlockEngine.GetBlockInfo(this, (MotorReadOnlyStruct st) => st.maxForce); + return BlockEngine.GetBlockInfo(this).maxForce; } set { - BlockEngine.SetBlockInfo(this, (ref MotorReadOnlyStruct st, float val) => st.maxForce = val, value); + BlockEngine.GetBlockInfo(this).maxForce = value; } } @@ -60,12 +60,12 @@ namespace TechbloxModdingAPI.Blocks { get { - return BlockEngine.GetBlockInfo(this, (MotorReadOnlyStruct st) => st.reverse); + return BlockEngine.GetBlockInfo(this).reverse; } set { - BlockEngine.SetBlockInfo(this, (ref MotorReadOnlyStruct st, bool val) => st.reverse = val, value); + BlockEngine.GetBlockInfo(this).reverse = value; } } } diff --git a/TechbloxModdingAPI/Blocks/MusicBlock.cs b/TechbloxModdingAPI/Blocks/MusicBlock.cs index 30ca5ab..ea4aeca 100644 --- a/TechbloxModdingAPI/Blocks/MusicBlock.cs +++ b/TechbloxModdingAPI/Blocks/MusicBlock.cs @@ -28,7 +28,7 @@ namespace TechbloxModdingAPI.Blocks { get { - return BlockEngine.GetBlockInfo(this, (MusicBlockDataEntityStruct st) => st.trackIndx); + return BlockEngine.GetBlockInfo(this).trackIndx; } set @@ -83,7 +83,7 @@ namespace TechbloxModdingAPI.Blocks { get { - return BlockEngine.GetBlockInfo(this, (MusicBlockDataEntityStruct msdes) => msdes.tweakableVolume); + return BlockEngine.GetBlockInfo(this).tweakableVolume; } set diff --git a/TechbloxModdingAPI/Blocks/ObjectIdentifier.cs b/TechbloxModdingAPI/Blocks/ObjectIdentifier.cs index 67e250e..fe2d657 100644 --- a/TechbloxModdingAPI/Blocks/ObjectIdentifier.cs +++ b/TechbloxModdingAPI/Blocks/ObjectIdentifier.cs @@ -16,7 +16,7 @@ namespace TechbloxModdingAPI.Blocks public char Identifier { - get => (char) BlockEngine.GetBlockInfo(this, (ObjectIdEntityStruct st) => st.objectId + 'A'); + get => (char) BlockEngine.GetBlockInfo(this).objectId + 'A'; set { BlockEngine.SetBlockInfo(this, (ref ObjectIdEntityStruct st, char val) => @@ -32,7 +32,7 @@ namespace TechbloxModdingAPI.Blocks /// public byte SimID { - get => BlockEngine.GetBlockInfo(this, (ObjectIdEntityStruct st) => st.simObjectId); + get => BlockEngine.GetBlockInfo(this).simObjectId; } /// diff --git a/TechbloxModdingAPI/Blocks/Piston.cs b/TechbloxModdingAPI/Blocks/Piston.cs index b5953ee..9c1b98a 100644 --- a/TechbloxModdingAPI/Blocks/Piston.cs +++ b/TechbloxModdingAPI/Blocks/Piston.cs @@ -26,12 +26,11 @@ namespace TechbloxModdingAPI.Blocks /// public float MaximumExtension { - get => BlockEngine.GetBlockInfo(this, (PistonReadOnlyStruct st) => st.maxDeviation); + get => BlockEngine.GetBlockInfo(this).maxDeviation; set { - BlockEngine.SetBlockInfo(this, (ref PistonReadOnlyStruct st, float val) => st.maxDeviation = val, - value); + BlockEngine.GetBlockInfo(this).maxDeviation = value; } } @@ -40,11 +39,11 @@ namespace TechbloxModdingAPI.Blocks /// public float MaximumForce { - get => BlockEngine.GetBlockInfo(this, (PistonReadOnlyStruct st) => st.pistonVelocity); + get => BlockEngine.GetBlockInfo(this).pistonVelocity; set { - BlockEngine.SetBlockInfo(this, (ref PistonReadOnlyStruct st, float val) => st.pistonVelocity = val, value); + BlockEngine.GetBlockInfo(this).pistonVelocity = value; } } } diff --git a/TechbloxModdingAPI/Blocks/Servo.cs b/TechbloxModdingAPI/Blocks/Servo.cs index 12232de..cdbd87b 100644 --- a/TechbloxModdingAPI/Blocks/Servo.cs +++ b/TechbloxModdingAPI/Blocks/Servo.cs @@ -26,11 +26,11 @@ namespace TechbloxModdingAPI.Blocks /// public float MinimumAngle { - get => BlockEngine.GetBlockInfo(this, (ServoReadOnlyStruct st) => st.minDeviation); + get => BlockEngine.GetBlockInfo(this).minDeviation; set { - BlockEngine.SetBlockInfo(this, (ref ServoReadOnlyStruct st, float val) => st.minDeviation = val, value); + BlockEngine.GetBlockInfo(this).minDeviation = value; } } @@ -39,11 +39,11 @@ namespace TechbloxModdingAPI.Blocks /// public float MaximumAngle { - get => BlockEngine.GetBlockInfo(this, (ServoReadOnlyStruct st) => st.maxDeviation); + get => BlockEngine.GetBlockInfo(this).maxDeviation; set { - BlockEngine.SetBlockInfo(this, (ref ServoReadOnlyStruct st, float val) => st.maxDeviation = val, value); + BlockEngine.GetBlockInfo(this).maxDeviation = value; } } @@ -52,11 +52,11 @@ namespace TechbloxModdingAPI.Blocks /// public float MaximumForce { - get => BlockEngine.GetBlockInfo(this, (ServoReadOnlyStruct st) => st.servoVelocity); + get => BlockEngine.GetBlockInfo(this).servoVelocity; set { - BlockEngine.SetBlockInfo(this, (ref ServoReadOnlyStruct st, float val) => st.servoVelocity = val, value); + BlockEngine.GetBlockInfo(this).servoVelocity = value; } } @@ -65,11 +65,11 @@ namespace TechbloxModdingAPI.Blocks /// public bool Reverse { - get => BlockEngine.GetBlockInfo(this, (ServoReadOnlyStruct st) => st.reverse); + get => BlockEngine.GetBlockInfo(this).reverse; set { - BlockEngine.SetBlockInfo(this, (ref ServoReadOnlyStruct st, bool val) => st.reverse = val, value); + BlockEngine.GetBlockInfo(this).reverse = value; } } } diff --git a/TechbloxModdingAPI/Blocks/SfxBlock.cs b/TechbloxModdingAPI/Blocks/SfxBlock.cs index c72d37a..45453fb 100644 --- a/TechbloxModdingAPI/Blocks/SfxBlock.cs +++ b/TechbloxModdingAPI/Blocks/SfxBlock.cs @@ -22,7 +22,7 @@ namespace TechbloxModdingAPI.Blocks { get { - return BlockEngine.GetBlockInfo(this, (SoundSfxBlockDataEntityStruct obj) => obj.tweakableVolume); + return BlockEngine.GetBlockInfo(this).tweakableVolume; } set @@ -36,7 +36,7 @@ namespace TechbloxModdingAPI.Blocks { get { - return BlockEngine.GetBlockInfo(this, (SoundSfxBlockDataEntityStruct obj) => obj.tweakablePitch); + return BlockEngine.GetBlockInfo(this).tweakablePitch; } set @@ -50,7 +50,7 @@ namespace TechbloxModdingAPI.Blocks { get { - return BlockEngine.GetBlockInfo(this, (SoundSfxBlockDataEntityStruct obj) => obj.is3D); + return BlockEngine.GetBlockInfo(this).is3D; } set @@ -78,7 +78,7 @@ namespace TechbloxModdingAPI.Blocks { get { - return BlockEngine.GetBlockInfo(this, (SoundSfxBlockDataEntityStruct obj) => obj.soundEffectIndex); + return BlockEngine.GetBlockInfo(this).soundEffectIndex; } set @@ -162,7 +162,7 @@ namespace TechbloxModdingAPI.Blocks { get { - return BlockEngine.GetBlockInfo(this, (SoundSfxBlockDataEntityStruct obj) => obj.isLoopedBlock); + return BlockEngine.GetBlockInfo(this).isLoopedBlock; } set diff --git a/TechbloxModdingAPI/Blocks/SignalingBlock.cs b/TechbloxModdingAPI/Blocks/SignalingBlock.cs index b18521a..293e00d 100644 --- a/TechbloxModdingAPI/Blocks/SignalingBlock.cs +++ b/TechbloxModdingAPI/Blocks/SignalingBlock.cs @@ -67,7 +67,7 @@ namespace TechbloxModdingAPI.Blocks /// public uint InputCount { - get => BlockEngine.GetBlockInfo(this, (BlockPortsStruct st) => st.inputCount); + get => BlockEngine.GetBlockInfo(this).inputCount; } /// @@ -75,7 +75,7 @@ namespace TechbloxModdingAPI.Blocks /// public uint OutputCount { - get => BlockEngine.GetBlockInfo(this, (BlockPortsStruct st) => st.outputCount); + get => BlockEngine.GetBlockInfo(this).outputCount; } /// diff --git a/TechbloxModdingAPI/Blocks/SpawnPoint.cs b/TechbloxModdingAPI/Blocks/SpawnPoint.cs index ac6c014..0c5c75a 100644 --- a/TechbloxModdingAPI/Blocks/SpawnPoint.cs +++ b/TechbloxModdingAPI/Blocks/SpawnPoint.cs @@ -28,11 +28,11 @@ namespace TechbloxModdingAPI.Blocks /// public uint Lives { - get => BlockEngine.GetBlockInfo(this, (SpawnPointStatsEntityStruct st) => st.lives); + get => BlockEngine.GetBlockInfo(this).lives; set { - BlockEngine.SetBlockInfo(this, (ref SpawnPointStatsEntityStruct st, uint val) => st.lives = val, value); + BlockEngine.GetBlockInfo(this).lives = value; } } @@ -41,11 +41,11 @@ namespace TechbloxModdingAPI.Blocks /// public bool Damageable { - get => BlockEngine.GetBlockInfo(this, (SpawnPointStatsEntityStruct st) => st.canTakeDamage); + get => BlockEngine.GetBlockInfo(this).canTakeDamage; set { - BlockEngine.SetBlockInfo(this, (ref SpawnPointStatsEntityStruct st, bool val) => st.canTakeDamage = val, value); + BlockEngine.GetBlockInfo(this).canTakeDamage = value; } } @@ -54,11 +54,11 @@ namespace TechbloxModdingAPI.Blocks /// public bool GameOverEnabled { - get => BlockEngine.GetBlockInfo(this, (SpawnPointStatsEntityStruct st) => st.gameOverScreen); + get => BlockEngine.GetBlockInfo(this).gameOverScreen; set { - BlockEngine.SetBlockInfo(this, (ref SpawnPointStatsEntityStruct st, bool val) => st.gameOverScreen = val, value); + BlockEngine.GetBlockInfo(this).gameOverScreen = value; } } @@ -67,11 +67,11 @@ namespace TechbloxModdingAPI.Blocks /// public byte Team { - get => BlockEngine.GetBlockInfo(this, (SpawnPointIdsEntityStruct st) => st.teamId); + get => BlockEngine.GetBlockInfo(this).teamId; set { - BlockEngine.SetBlockInfo(this, (ref SpawnPointIdsEntityStruct st, byte val) => st.teamId = val, value); + BlockEngine.GetBlockInfo(this).teamId = value; } } } diff --git a/TechbloxModdingAPI/Blocks/TextBlock.cs b/TechbloxModdingAPI/Blocks/TextBlock.cs index 0e33b75..c3ee1b0 100644 --- a/TechbloxModdingAPI/Blocks/TextBlock.cs +++ b/TechbloxModdingAPI/Blocks/TextBlock.cs @@ -26,8 +26,8 @@ namespace TechbloxModdingAPI.Blocks /// The text block's current text. /// public string Text - { - get => BlockEngine.GetBlockInfo(this, (TextBlockDataStruct st) => st.textCurrent); + { + get => BlockEngine.GetBlockInfo(this).textCurrent; set { @@ -45,7 +45,7 @@ namespace TechbloxModdingAPI.Blocks /// public string TextBlockId { - get => BlockEngine.GetBlockInfo(this, (TextBlockDataStruct st) => st.textBlockID); + get => BlockEngine.GetBlockInfo(this).textBlockID; set { diff --git a/TechbloxModdingAPI/Blocks/Timer.cs b/TechbloxModdingAPI/Blocks/Timer.cs index 6337864..9803258 100644 --- a/TechbloxModdingAPI/Blocks/Timer.cs +++ b/TechbloxModdingAPI/Blocks/Timer.cs @@ -28,12 +28,11 @@ namespace TechbloxModdingAPI.Blocks /// public float Start { - get => BlockEngine.GetBlockInfo(this, (TimerBlockDataStruct st) => st.startTime); + get => BlockEngine.GetBlockInfo(this).startTime; set { - BlockEngine.SetBlockInfo(this, (ref TimerBlockDataStruct tbds, float val) => tbds.startTime = val, - value); + BlockEngine.GetBlockInfo(this).startTime = value; } } @@ -42,12 +41,11 @@ namespace TechbloxModdingAPI.Blocks /// public float End { - get => BlockEngine.GetBlockInfo(this, (TimerBlockDataStruct st) => st.endTime); + get => BlockEngine.GetBlockInfo(this).endTime; set { - BlockEngine.SetBlockInfo(this, (ref TimerBlockDataStruct tbds, float val) => tbds.endTime = val, - value); + BlockEngine.GetBlockInfo(this).endTime = value; } } @@ -56,12 +54,11 @@ namespace TechbloxModdingAPI.Blocks /// public bool DisplayMilliseconds { - get => BlockEngine.GetBlockInfo(this, (TimerBlockDataStruct st) => st.outputFormatHasMS); + get => BlockEngine.GetBlockInfo(this).outputFormatHasMS; set { - BlockEngine.SetBlockInfo(this, (ref TimerBlockDataStruct tbds, bool val) => tbds.outputFormatHasMS = val, - value); + BlockEngine.GetBlockInfo(this).outputFormatHasMS = value; } } @@ -70,12 +67,11 @@ namespace TechbloxModdingAPI.Blocks /// public int CurrentTime { - get => BlockEngine.GetBlockInfo(this, (TimerBlockLabelCacheEntityStruct st) => st.timeLastRenderFrameMS); + get => BlockEngine.GetBlockInfo(this).timeLastRenderFrameMS; set { - BlockEngine.SetBlockInfo(this, (ref TimerBlockLabelCacheEntityStruct tbds, int val) => tbds.timeLastRenderFrameMS = val, - value); + BlockEngine.GetBlockInfo(this).timeLastRenderFrameMS = value; } } }