From 3351993936877391a61fab47f1ad7bdf3c3e0b9e Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 29 Jul 2021 01:04:27 +0200 Subject: [PATCH] Automatically generate properties, fixes, engine class --- CodeGenerator/BlockClassGenerator.cs | 35 ++++- TechbloxModdingAPI/Blocks/Engine.cs | 217 ++++++++++++++++++++++++--- 2 files changed, 231 insertions(+), 21 deletions(-) diff --git a/CodeGenerator/BlockClassGenerator.cs b/CodeGenerator/BlockClassGenerator.cs index 82c3206..5a2e748 100644 --- a/CodeGenerator/BlockClassGenerator.cs +++ b/CodeGenerator/BlockClassGenerator.cs @@ -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(cl); ns.Types.Add(cl); codeUnit.Namespaces.Add(ns); @@ -64,5 +69,33 @@ namespace CodeGenerator return ret; } + + private void GenerateProperties(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) + }); + } + } } } \ No newline at end of file diff --git a/TechbloxModdingAPI/Blocks/Engine.cs b/TechbloxModdingAPI/Blocks/Engine.cs index 08a8f33..05c09e6 100644 --- a/TechbloxModdingAPI/Blocks/Engine.cs +++ b/TechbloxModdingAPI/Blocks/Engine.cs @@ -1,35 +1,212 @@ -using RobocraftX.Common; -using Svelto.ECS; -using Techblox.EngineBlock; +//------------------------------------------------------------------------------ +// +// 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. +// +//------------------------------------------------------------------------------ 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(this).engineOn; - set => BlockEngine.GetBlockInfo(this).engineOn = value; + get + { + return BlockEngine.GetBlockInfo(this).engineOn; + } + set + { + BlockEngine.GetBlockInfo(this).engineOn = value; + } } - - public float CurrentTorque + + private int CurrentGear { - get => BlockEngine.GetBlockInfo(this).currentTorque; - set => BlockEngine.GetBlockInfo(this).currentTorque = value; + get + { + return BlockEngine.GetBlockInfo(this).currentGear; + } + set + { + BlockEngine.GetBlockInfo(this).currentGear = value; + } } - - public int CurrentGear + + private float GearChangeCountdown + { + get + { + return BlockEngine.GetBlockInfo(this).gearChangeCountdown; + } + set + { + BlockEngine.GetBlockInfo(this).gearChangeCountdown = value; + } + } + + private float CurrentRpmAV + { + get + { + return BlockEngine.GetBlockInfo(this).currentRpmAV; + } + set + { + BlockEngine.GetBlockInfo(this).currentRpmAV = value; + } + } + + private float CurrentRpmLV + { + get + { + return BlockEngine.GetBlockInfo(this).currentRpmLV; + } + set + { + BlockEngine.GetBlockInfo(this).currentRpmLV = value; + } + } + + private float TargetRpmAV + { + get + { + return BlockEngine.GetBlockInfo(this).targetRpmAV; + } + set + { + BlockEngine.GetBlockInfo(this).targetRpmAV = value; + } + } + + private float TargetRpmLV + { + get + { + return BlockEngine.GetBlockInfo(this).targetRpmLV; + } + set + { + BlockEngine.GetBlockInfo(this).targetRpmLV = value; + } + } + + private float CurrentTorque + { + get + { + return BlockEngine.GetBlockInfo(this).currentTorque; + } + set + { + BlockEngine.GetBlockInfo(this).currentTorque = value; + } + } + + private float TotalWheelVelocityAV + { + get + { + return BlockEngine.GetBlockInfo(this).totalWheelVelocityAV; + } + set + { + BlockEngine.GetBlockInfo(this).totalWheelVelocityAV = value; + } + } + + private float TotalWheelVelocityLV + { + get + { + return BlockEngine.GetBlockInfo(this).totalWheelVelocityLV; + } + set + { + BlockEngine.GetBlockInfo(this).totalWheelVelocityLV = value; + } + } + + private int TotalWheelCount + { + get + { + return BlockEngine.GetBlockInfo(this).totalWheelCount; + } + set + { + BlockEngine.GetBlockInfo(this).totalWheelCount = value; + } + } + + private bool LastGearUpInput + { + get + { + return BlockEngine.GetBlockInfo(this).lastGearUpInput; + } + set + { + BlockEngine.GetBlockInfo(this).lastGearUpInput = value; + } + } + + private bool LastGearDownInput + { + get + { + return BlockEngine.GetBlockInfo(this).lastGearDownInput; + } + set + { + BlockEngine.GetBlockInfo(this).lastGearDownInput = value; + } + } + + private float ManualToAutoGearCoolOffCounter + { + get + { + return BlockEngine.GetBlockInfo(this).manualToAutoGearCoolOffCounter; + } + set + { + BlockEngine.GetBlockInfo(this).manualToAutoGearCoolOffCounter = value; + } + } + + private float Load { - get => BlockEngine.GetBlockInfo(this).currentGear; - set => BlockEngine.GetBlockInfo(this).currentGear = value; + get + { + return BlockEngine.GetBlockInfo(this).load; + } + set + { + BlockEngine.GetBlockInfo(this).load = value; + } } } -} \ No newline at end of file +}