Automatically generate properties, fixes, engine class

This commit is contained in:
Norbi Peti 2021-07-29 01:04:27 +02:00
parent 49c3b60963
commit 3351993936
2 changed files with 231 additions and 21 deletions

View file

@ -3,6 +3,8 @@ using System.CodeDom.Compiler;
using System.IO;
using System.Linq;
using RobocraftX.Common;
using Svelto.ECS;
using Techblox.EngineBlock;
namespace CodeGenerator
{
@ -22,10 +24,12 @@ namespace CodeGenerator
ns.Imports.Add(new CodeNamespaceImport("RobocraftX.Common"));
ns.Imports.Add(new CodeNamespaceImport("Svelto.ECS"));
var cl = new CodeTypeDeclaration(name);
cl.BaseTypes.Add(new CodeTypeReference("Block"));
cl.Members.Add(new CodeConstructor
{
Parameters = {new CodeParameterDeclarationExpression("EGID", "egid")},
Comments = { new CodeCommentStatement($"{name} constructor", true)}
Comments = {new CodeCommentStatement($"{name} constructor", true)},
BaseConstructorArgs = {new CodeVariableReferenceExpression("egid")}
});
cl.Members.Add(new CodeConstructor
{
@ -41,6 +45,7 @@ namespace CodeGenerator
group))
}
});
GenerateProperties<EngineBlockComponent>(cl);
ns.Types.Add(cl);
codeUnit.Namespaces.Add(ns);
@ -64,5 +69,33 @@ namespace CodeGenerator
return ret;
}
private void GenerateProperties<T>(CodeTypeDeclaration cl) where T : IEntityComponent
{
var type = typeof(T);
foreach (var field in type.GetFields())
{
var propName = char.ToUpper(field.Name[0]) + field.Name.Substring(1);
var structFieldReference = new CodeFieldReferenceExpression(new CodeMethodInvokeExpression(
new CodeMethodReferenceExpression(new CodeSnippetExpression("BlockEngine"),
"GetBlockInfo", new CodeTypeReference(type)),
new CodeThisReferenceExpression()), field.Name);
cl.Members.Add(new CodeMemberProperty
{
Name = propName,
HasGet = true,
HasSet = true,
GetStatements =
{
new CodeMethodReturnStatement(structFieldReference)
},
SetStatements =
{
new CodeAssignStatement(structFieldReference, new CodePropertySetValueReferenceExpression())
},
Type = new CodeTypeReference(field.FieldType)
});
}
}
}
}

View file

@ -1,35 +1,212 @@
using RobocraftX.Common;
using Svelto.ECS;
using Techblox.EngineBlock;
//------------------------------------------------------------------------------
// <auto-generated>
// Ezt a kódot eszköz generálta.
// Futásidejű verzió:4.0.30319.42000
//
// Ennek a fájlnak a módosítása helytelen viselkedést eredményezhet, és elvész, ha
// a kódot újragenerálják.
// </auto-generated>
//------------------------------------------------------------------------------
namespace TechbloxModdingAPI.Blocks
{
public class Engine : SignalingBlock
using RobocraftX.Common;
using Svelto.ECS;
public class Engine : Block
{
public Engine(EGID id) : base(id)
/// Engine constructor
private Engine(EGID egid) :
base(egid)
{
}
public Engine(uint id) : base(new EGID(id, CommonExclusiveGroups.ENGINE_BLOCK_BUILD_GROUP))
/// Engine constructor
private Engine(uint id) :
base(new EGID(id, CommonExclusiveGroups.ENGINE_BLOCK_BUILD_GROUP))
{
}
public bool On
private bool EngineOn
{
get => BlockEngine.GetBlockInfo<EngineBlockComponent>(this).engineOn;
set => BlockEngine.GetBlockInfo<EngineBlockComponent>(this).engineOn = value;
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).engineOn;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).engineOn = value;
}
}
public float CurrentTorque
private int CurrentGear
{
get => BlockEngine.GetBlockInfo<EngineBlockComponent>(this).currentTorque;
set => BlockEngine.GetBlockInfo<EngineBlockComponent>(this).currentTorque = value;
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).currentGear;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).currentGear = value;
}
}
public int CurrentGear
private float GearChangeCountdown
{
get => BlockEngine.GetBlockInfo<EngineBlockComponent>(this).currentGear;
set => BlockEngine.GetBlockInfo<EngineBlockComponent>(this).currentGear = value;
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).gearChangeCountdown;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).gearChangeCountdown = value;
}
}
private float CurrentRpmAV
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).currentRpmAV;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).currentRpmAV = value;
}
}
private float CurrentRpmLV
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).currentRpmLV;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).currentRpmLV = value;
}
}
private float TargetRpmAV
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).targetRpmAV;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).targetRpmAV = value;
}
}
private float TargetRpmLV
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).targetRpmLV;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).targetRpmLV = value;
}
}
private float CurrentTorque
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).currentTorque;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).currentTorque = value;
}
}
private float TotalWheelVelocityAV
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).totalWheelVelocityAV;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).totalWheelVelocityAV = value;
}
}
private float TotalWheelVelocityLV
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).totalWheelVelocityLV;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).totalWheelVelocityLV = value;
}
}
private int TotalWheelCount
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).totalWheelCount;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).totalWheelCount = value;
}
}
private bool LastGearUpInput
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).lastGearUpInput;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).lastGearUpInput = value;
}
}
private bool LastGearDownInput
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).lastGearDownInput;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).lastGearDownInput = value;
}
}
private float ManualToAutoGearCoolOffCounter
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).manualToAutoGearCoolOffCounter;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).manualToAutoGearCoolOffCounter = value;
}
}
private float Load
{
get
{
return BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).load;
}
set
{
BlockEngine.GetBlockInfo<Techblox.EngineBlock.EngineBlockComponent>(this).load = value;
}
}
}
}