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;
This commit is contained in:
Norbi Peti 2021-05-10 23:08:15 +02:00
parent 61184145a9
commit d238c97906
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
13 changed files with 63 additions and 64 deletions

View file

@ -285,14 +285,14 @@ namespace TechbloxModdingAPI
/// </summary>
public float3 Scale
{
get => BlockEngine.GetBlockInfo(this, (ScalingEntityStruct st) => st.scale);
get => BlockEngine.GetBlockInfo<ScalingEntityStruct>(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<ScalingEntityStruct>(this).scale = value;
if (!Exists) return; //UpdateCollision needs the block to exist
ScalingEngine.UpdateCollision(Id);
BlockEngine.UpdateDisplayedBlock(Id);
@ -305,12 +305,11 @@ namespace TechbloxModdingAPI
/// </summary>
public int UniformScale
{
get => BlockEngine.GetBlockInfo(this, (UniformBlockScaleEntityStruct st) => st.scaleFactor);
get => BlockEngine.GetBlockInfo<UniformBlockScaleEntityStruct>(this).scaleFactor;
set
{
if (value < 1) value = 1;
BlockEngine.SetBlockInfo(this, (ref UniformBlockScaleEntityStruct st, int val) => st.scaleFactor = val,
value);
BlockEngine.GetBlockInfo<UniformBlockScaleEntityStruct>(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<ScalingEntityStruct>(this).scale.x < 0;
set
{
BlockEngine.SetBlockInfo(this, (ref ScalingEntityStruct st, bool val) =>
@ -371,7 +370,7 @@ namespace TechbloxModdingAPI
/// </summary>
public float4 CustomColor
{
get => BlockEngine.GetBlockInfo(this, (ColourParameterEntityStruct st) => st.paletteColour);
get => BlockEngine.GetBlockInfo<ColourParameterEntityStruct>(this).paletteColour;
set
{
BlockEngine.SetBlockInfo(this, (ref ColourParameterEntityStruct color, float4 val) =>

View file

@ -70,11 +70,16 @@ namespace TechbloxModdingAPI.Blocks
: entitiesDB.QueryEntity<PaletteEntryEntityStruct>(index,
CommonExclusiveGroups.COLOUR_PALETTE_GROUP).Colour;
public OptionalRef<T> GetBlockInfo<T>(Block block) where T : unmanaged, IEntityComponent
public OptionalRef<T> GetBlockInfoOptional<T>(Block block) where T : unmanaged, IEntityComponent
{
return entitiesDB.QueryEntityOptional<T>(block);
}
public ref T GetBlockInfo<T>(Block block) where T : unmanaged, IEntityComponent
{
return ref entitiesDB.QueryEntityOrDefault<T>(block);
}
public void UpdateDisplayedBlock(EGID id)
{
if (!BlockExists(id)) return;

View file

@ -19,7 +19,7 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public float MaxForce
{
get => BlockEngine.GetBlockInfo(this, (DampedSpringReadOnlyStruct dsrs) => dsrs.springFrequency);
get => BlockEngine.GetBlockInfo<DampedSpringReadOnlyStruct>(this).springFrequency;
set => BlockEngine.SetBlockInfo(this,
(ref DampedSpringReadOnlyStruct dsrs, float val) => dsrs.springFrequency = val, value);
@ -39,7 +39,7 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public float Damping
{
get => BlockEngine.GetBlockInfo(this, (DampedSpringReadOnlyStruct ljf) => ljf.springDamping);
get => BlockEngine.GetBlockInfo<DampedSpringReadOnlyStruct>(this).springDamping;
set => BlockEngine.SetBlockInfo(this,
(ref DampedSpringReadOnlyStruct ljf, float val) => ljf.springDamping = val, value);
@ -50,7 +50,7 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public float MaxExtension
{
get => BlockEngine.GetBlockInfo(this, (DampedSpringReadOnlyStruct ljf) => ljf.maxExtent);
get => BlockEngine.GetBlockInfo<DampedSpringReadOnlyStruct>(this).maxExtent;
set => BlockEngine.SetBlockInfo(this,
(ref DampedSpringReadOnlyStruct ljf, float val) => ljf.maxExtent = val, value);

View file

@ -28,12 +28,12 @@ namespace TechbloxModdingAPI.Blocks
{
get
{
return BlockEngine.GetBlockInfo(this, (MotorReadOnlyStruct st) => st.maxVelocity);
return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(this).maxVelocity;
}
set
{
BlockEngine.SetBlockInfo(this, (ref MotorReadOnlyStruct st, float val) => st.maxVelocity = val, value);
BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(this).maxVelocity = value;
}
}
@ -44,12 +44,12 @@ namespace TechbloxModdingAPI.Blocks
{
get
{
return BlockEngine.GetBlockInfo(this, (MotorReadOnlyStruct st) => st.maxForce);
return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(this).maxForce;
}
set
{
BlockEngine.SetBlockInfo(this, (ref MotorReadOnlyStruct st, float val) => st.maxForce = val, value);
BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(this).maxForce = value;
}
}
@ -60,12 +60,12 @@ namespace TechbloxModdingAPI.Blocks
{
get
{
return BlockEngine.GetBlockInfo(this, (MotorReadOnlyStruct st) => st.reverse);
return BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(this).reverse;
}
set
{
BlockEngine.SetBlockInfo(this, (ref MotorReadOnlyStruct st, bool val) => st.reverse = val, value);
BlockEngine.GetBlockInfo<MotorReadOnlyStruct>(this).reverse = value;
}
}
}

View file

@ -28,7 +28,7 @@ namespace TechbloxModdingAPI.Blocks
{
get
{
return BlockEngine.GetBlockInfo(this, (MusicBlockDataEntityStruct st) => st.trackIndx);
return BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this).trackIndx;
}
set
@ -83,7 +83,7 @@ namespace TechbloxModdingAPI.Blocks
{
get
{
return BlockEngine.GetBlockInfo(this, (MusicBlockDataEntityStruct msdes) => msdes.tweakableVolume);
return BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this).tweakableVolume;
}
set

View file

@ -16,7 +16,7 @@ namespace TechbloxModdingAPI.Blocks
public char Identifier
{
get => (char) BlockEngine.GetBlockInfo(this, (ObjectIdEntityStruct st) => st.objectId + 'A');
get => (char) BlockEngine.GetBlockInfo<ObjectIdEntityStruct>(this).objectId + 'A';
set
{
BlockEngine.SetBlockInfo(this, (ref ObjectIdEntityStruct st, char val) =>
@ -32,7 +32,7 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public byte SimID
{
get => BlockEngine.GetBlockInfo(this, (ObjectIdEntityStruct st) => st.simObjectId);
get => BlockEngine.GetBlockInfo<ObjectIdEntityStruct>(this).simObjectId;
}
/// <summary>

View file

@ -26,12 +26,11 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public float MaximumExtension
{
get => BlockEngine.GetBlockInfo(this, (PistonReadOnlyStruct st) => st.maxDeviation);
get => BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(this).maxDeviation;
set
{
BlockEngine.SetBlockInfo(this, (ref PistonReadOnlyStruct st, float val) => st.maxDeviation = val,
value);
BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(this).maxDeviation = value;
}
}
@ -40,11 +39,11 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public float MaximumForce
{
get => BlockEngine.GetBlockInfo(this, (PistonReadOnlyStruct st) => st.pistonVelocity);
get => BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(this).pistonVelocity;
set
{
BlockEngine.SetBlockInfo(this, (ref PistonReadOnlyStruct st, float val) => st.pistonVelocity = val, value);
BlockEngine.GetBlockInfo<PistonReadOnlyStruct>(this).pistonVelocity = value;
}
}
}

View file

@ -26,11 +26,11 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public float MinimumAngle
{
get => BlockEngine.GetBlockInfo(this, (ServoReadOnlyStruct st) => st.minDeviation);
get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(this).minDeviation;
set
{
BlockEngine.SetBlockInfo(this, (ref ServoReadOnlyStruct st, float val) => st.minDeviation = val, value);
BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(this).minDeviation = value;
}
}
@ -39,11 +39,11 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public float MaximumAngle
{
get => BlockEngine.GetBlockInfo(this, (ServoReadOnlyStruct st) => st.maxDeviation);
get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(this).maxDeviation;
set
{
BlockEngine.SetBlockInfo(this, (ref ServoReadOnlyStruct st, float val) => st.maxDeviation = val, value);
BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(this).maxDeviation = value;
}
}
@ -52,11 +52,11 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public float MaximumForce
{
get => BlockEngine.GetBlockInfo(this, (ServoReadOnlyStruct st) => st.servoVelocity);
get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(this).servoVelocity;
set
{
BlockEngine.SetBlockInfo(this, (ref ServoReadOnlyStruct st, float val) => st.servoVelocity = val, value);
BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(this).servoVelocity = value;
}
}
@ -65,11 +65,11 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public bool Reverse
{
get => BlockEngine.GetBlockInfo(this, (ServoReadOnlyStruct st) => st.reverse);
get => BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(this).reverse;
set
{
BlockEngine.SetBlockInfo(this, (ref ServoReadOnlyStruct st, bool val) => st.reverse = val, value);
BlockEngine.GetBlockInfo<ServoReadOnlyStruct>(this).reverse = value;
}
}
}

View file

@ -22,7 +22,7 @@ namespace TechbloxModdingAPI.Blocks
{
get
{
return BlockEngine.GetBlockInfo(this, (SoundSfxBlockDataEntityStruct obj) => obj.tweakableVolume);
return BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).tweakableVolume;
}
set
@ -36,7 +36,7 @@ namespace TechbloxModdingAPI.Blocks
{
get
{
return BlockEngine.GetBlockInfo(this, (SoundSfxBlockDataEntityStruct obj) => obj.tweakablePitch);
return BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).tweakablePitch;
}
set
@ -50,7 +50,7 @@ namespace TechbloxModdingAPI.Blocks
{
get
{
return BlockEngine.GetBlockInfo(this, (SoundSfxBlockDataEntityStruct obj) => obj.is3D);
return BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).is3D;
}
set
@ -78,7 +78,7 @@ namespace TechbloxModdingAPI.Blocks
{
get
{
return BlockEngine.GetBlockInfo(this, (SoundSfxBlockDataEntityStruct obj) => obj.soundEffectIndex);
return BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).soundEffectIndex;
}
set
@ -162,7 +162,7 @@ namespace TechbloxModdingAPI.Blocks
{
get
{
return BlockEngine.GetBlockInfo(this, (SoundSfxBlockDataEntityStruct obj) => obj.isLoopedBlock);
return BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).isLoopedBlock;
}
set

View file

@ -67,7 +67,7 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public uint InputCount
{
get => BlockEngine.GetBlockInfo(this, (BlockPortsStruct st) => st.inputCount);
get => BlockEngine.GetBlockInfo<BlockPortsStruct>(this).inputCount;
}
/// <summary>
@ -75,7 +75,7 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public uint OutputCount
{
get => BlockEngine.GetBlockInfo(this, (BlockPortsStruct st) => st.outputCount);
get => BlockEngine.GetBlockInfo<BlockPortsStruct>(this).outputCount;
}
/// <summary>

View file

@ -28,11 +28,11 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public uint Lives
{
get => BlockEngine.GetBlockInfo(this, (SpawnPointStatsEntityStruct st) => st.lives);
get => BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(this).lives;
set
{
BlockEngine.SetBlockInfo(this, (ref SpawnPointStatsEntityStruct st, uint val) => st.lives = val, value);
BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(this).lives = value;
}
}
@ -41,11 +41,11 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public bool Damageable
{
get => BlockEngine.GetBlockInfo(this, (SpawnPointStatsEntityStruct st) => st.canTakeDamage);
get => BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(this).canTakeDamage;
set
{
BlockEngine.SetBlockInfo(this, (ref SpawnPointStatsEntityStruct st, bool val) => st.canTakeDamage = val, value);
BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(this).canTakeDamage = value;
}
}
@ -54,11 +54,11 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public bool GameOverEnabled
{
get => BlockEngine.GetBlockInfo(this, (SpawnPointStatsEntityStruct st) => st.gameOverScreen);
get => BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(this).gameOverScreen;
set
{
BlockEngine.SetBlockInfo(this, (ref SpawnPointStatsEntityStruct st, bool val) => st.gameOverScreen = val, value);
BlockEngine.GetBlockInfo<SpawnPointStatsEntityStruct>(this).gameOverScreen = value;
}
}
@ -67,11 +67,11 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public byte Team
{
get => BlockEngine.GetBlockInfo(this, (SpawnPointIdsEntityStruct st) => st.teamId);
get => BlockEngine.GetBlockInfo<SpawnPointIdsEntityStruct>(this).teamId;
set
{
BlockEngine.SetBlockInfo(this, (ref SpawnPointIdsEntityStruct st, byte val) => st.teamId = val, value);
BlockEngine.GetBlockInfo<SpawnPointIdsEntityStruct>(this).teamId = value;
}
}
}

View file

@ -26,8 +26,8 @@ namespace TechbloxModdingAPI.Blocks
/// The text block's current text.
/// </summary>
public string Text
{
get => BlockEngine.GetBlockInfo(this, (TextBlockDataStruct st) => st.textCurrent);
{
get => BlockEngine.GetBlockInfo<TextBlockDataStruct>(this).textCurrent;
set
{
@ -45,7 +45,7 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public string TextBlockId
{
get => BlockEngine.GetBlockInfo(this, (TextBlockDataStruct st) => st.textBlockID);
get => BlockEngine.GetBlockInfo<TextBlockDataStruct>(this).textBlockID;
set
{

View file

@ -28,12 +28,11 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public float Start
{
get => BlockEngine.GetBlockInfo(this, (TimerBlockDataStruct st) => st.startTime);
get => BlockEngine.GetBlockInfo<TimerBlockDataStruct>(this).startTime;
set
{
BlockEngine.SetBlockInfo(this, (ref TimerBlockDataStruct tbds, float val) => tbds.startTime = val,
value);
BlockEngine.GetBlockInfo<TimerBlockDataStruct>(this).startTime = value;
}
}
@ -42,12 +41,11 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public float End
{
get => BlockEngine.GetBlockInfo(this, (TimerBlockDataStruct st) => st.endTime);
get => BlockEngine.GetBlockInfo<TimerBlockDataStruct>(this).endTime;
set
{
BlockEngine.SetBlockInfo(this, (ref TimerBlockDataStruct tbds, float val) => tbds.endTime = val,
value);
BlockEngine.GetBlockInfo<TimerBlockDataStruct>(this).endTime = value;
}
}
@ -56,12 +54,11 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public bool DisplayMilliseconds
{
get => BlockEngine.GetBlockInfo(this, (TimerBlockDataStruct st) => st.outputFormatHasMS);
get => BlockEngine.GetBlockInfo<TimerBlockDataStruct>(this).outputFormatHasMS;
set
{
BlockEngine.SetBlockInfo(this, (ref TimerBlockDataStruct tbds, bool val) => tbds.outputFormatHasMS = val,
value);
BlockEngine.GetBlockInfo<TimerBlockDataStruct>(this).outputFormatHasMS = value;
}
}
@ -70,12 +67,11 @@ namespace TechbloxModdingAPI.Blocks
/// </summary>
public int CurrentTime
{
get => BlockEngine.GetBlockInfo(this, (TimerBlockLabelCacheEntityStruct st) => st.timeLastRenderFrameMS);
get => BlockEngine.GetBlockInfo<TimerBlockLabelCacheEntityStruct>(this).timeLastRenderFrameMS;
set
{
BlockEngine.SetBlockInfo(this, (ref TimerBlockLabelCacheEntityStruct tbds, int val) => tbds.timeLastRenderFrameMS = val,
value);
BlockEngine.GetBlockInfo<TimerBlockLabelCacheEntityStruct>(this).timeLastRenderFrameMS = value;
}
}
}