Browse Source

Get wire looked at, block class generation

tags/v2.1.0
NorbiPeti 2 years ago
parent
commit
49c3b60963
11 changed files with 1471 additions and 3 deletions
  1. +68
    -0
      CodeGenerator/BlockClassGenerator.cs
  2. +1176
    -0
      CodeGenerator/CodeGenerator.csproj
  3. +16
    -0
      CodeGenerator/Program.cs
  4. +35
    -0
      CodeGenerator/Properties/AssemblyInfo.cs
  5. +8
    -0
      TechbloxModdingAPI.sln
  6. +0
    -2
      TechbloxModdingAPI/App/GameGameEngine.cs
  7. +16
    -0
      TechbloxModdingAPI/Blocks/LogicGate.cs
  8. +50
    -0
      TechbloxModdingAPI/Blocks/Piston.cs
  9. +71
    -0
      TechbloxModdingAPI/Blocks/Servo.cs
  10. +16
    -1
      TechbloxModdingAPI/Player.cs
  11. +15
    -0
      TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs

+ 68
- 0
CodeGenerator/BlockClassGenerator.cs View File

@@ -0,0 +1,68 @@
using System.CodeDom;
using System.CodeDom.Compiler;
using System.IO;
using System.Linq;
using RobocraftX.Common;

namespace CodeGenerator
{
public class BlockClassGenerator
{
public void Generate(string name, string group)
{
if (group is null)
{
group = GetGroup(name) + "_BLOCK_GROUP";
if (typeof(CommonExclusiveGroups).GetFields().All(field => field.Name != group))
group = GetGroup(name) + "_BLOCK_BUILD_GROUP";
}

var codeUnit = new CodeCompileUnit();
var ns = new CodeNamespace("TechbloxModdingAPI.Blocks");
ns.Imports.Add(new CodeNamespaceImport("RobocraftX.Common"));
ns.Imports.Add(new CodeNamespaceImport("Svelto.ECS"));
var cl = new CodeTypeDeclaration(name);
cl.Members.Add(new CodeConstructor
{
Parameters = {new CodeParameterDeclarationExpression("EGID", "egid")},
Comments = { new CodeCommentStatement($"{name} constructor", true)}
});
cl.Members.Add(new CodeConstructor
{
Parameters =
{
new CodeParameterDeclarationExpression(typeof(uint), "id")
},
Comments = {new CodeCommentStatement($"{name} constructor", true)},
BaseConstructorArgs =
{
new CodeObjectCreateExpression("EGID", new CodeVariableReferenceExpression("id"),
new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("CommonExclusiveGroups"),
group))
}
});
ns.Types.Add(cl);
codeUnit.Namespaces.Add(ns);

var provider = CodeDomProvider.CreateProvider("CSharp");
using (var sw = new StreamWriter($"{name}.cs"))
{
provider.GenerateCodeFromCompileUnit(codeUnit, sw, new CodeGeneratorOptions {BracingStyle = "C"});
}
}

private static string GetGroup(string name)
{
var ret = "";
foreach (var ch in name)
{
if (char.IsUpper(ch) && ret.Length > 0)
ret += "_" + ch;
else
ret += char.ToUpper(ch);
}

return ret;
}
}
}

+ 1176
- 0
CodeGenerator/CodeGenerator.csproj
File diff suppressed because it is too large
View File


+ 16
- 0
CodeGenerator/Program.cs View File

@@ -0,0 +1,16 @@
using System.CodeDom;
using System.CodeDom.Compiler;
using System.IO;

namespace CodeGenerator
{
internal class Program
{
public static void Main(string[] args)
{
var bcg = new BlockClassGenerator();
bcg.Generate("TestBlock", "TEST_BLOCK");
bcg.Generate("Engine", null);
}
}
}

+ 35
- 0
CodeGenerator/Properties/AssemblyInfo.cs View File

@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CodeGenerator")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CodeGenerator")]
[assembly: AssemblyCopyright("Copyright © ExMods 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("0EBB6400-95A7-4A3D-B2ED-BF31E364CC10")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

+ 8
- 0
TechbloxModdingAPI.sln View File

@@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.29411.108
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechbloxModdingAPI", "TechbloxModdingAPI\TechbloxModdingAPI.csproj", "{7FD5A7D8-4F3E-426A-B07D-7DC70442A4DF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeGenerator", "CodeGenerator\CodeGenerator.csproj", "{0EBB6400-95A7-4A3D-B2ED-BF31E364CC10}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -18,6 +20,12 @@ Global
{7FD5A7D8-4F3E-426A-B07D-7DC70442A4DF}.Release|Any CPU.Build.0 = Release|Any CPU
{7FD5A7D8-4F3E-426A-B07D-7DC70442A4DF}.Test|Any CPU.ActiveCfg = Test|Any CPU
{7FD5A7D8-4F3E-426A-B07D-7DC70442A4DF}.Test|Any CPU.Build.0 = Test|Any CPU
{0EBB6400-95A7-4A3D-B2ED-BF31E364CC10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0EBB6400-95A7-4A3D-B2ED-BF31E364CC10}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0EBB6400-95A7-4A3D-B2ED-BF31E364CC10}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0EBB6400-95A7-4A3D-B2ED-BF31E364CC10}.Release|Any CPU.Build.0 = Release|Any CPU
{0EBB6400-95A7-4A3D-B2ED-BF31E364CC10}.Test|Any CPU.ActiveCfg = Debug|Any CPU
{0EBB6400-95A7-4A3D-B2ED-BF31E364CC10}.Test|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE


+ 0
- 2
TechbloxModdingAPI/App/GameGameEngine.cs View File

@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using HarmonyLib;

using RobocraftX;
using RobocraftX.Common;
using RobocraftX.Schedulers;
using RobocraftX.SimulationModeState;


+ 16
- 0
TechbloxModdingAPI/Blocks/LogicGate.cs View File

@@ -0,0 +1,16 @@
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))
{
}
}
}

+ 50
- 0
TechbloxModdingAPI/Blocks/Piston.cs View File

@@ -0,0 +1,50 @@
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;
}
}
}
}

+ 71
- 0
TechbloxModdingAPI/Blocks/Servo.cs View File

@@ -0,0 +1,71 @@
using RobocraftX.Blocks;
using RobocraftX.Common;
using Svelto.ECS;

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;
}
}
}
}

+ 16
- 1
TechbloxModdingAPI/Player.cs View File

@@ -4,6 +4,7 @@ using RobocraftX.Character.Movement;
using Unity.Mathematics;
using RobocraftX.Common;
using RobocraftX.Common.Players;
using RobocraftX.GUI.Wires;
using RobocraftX.Physics;
using Svelto.ECS;
using Techblox.BuildingDrone;
@@ -432,8 +433,9 @@ namespace TechbloxModdingAPI
{
var egid = playerEngine.GetThingLookedAt(Id, maxDistance);
return egid != EGID.Empty && egid.groupID != CommonExclusiveGroups.SIMULATION_BODIES_GROUP
&& egid.groupID != WiresGUIExclusiveGroups.WireGroup
? Block.New(egid)
: null;
: null;
}
/// <summary>
@@ -449,6 +451,19 @@ namespace TechbloxModdingAPI
: null;
}

/// <summary>
/// Returns the wire the player is currently looking at in build mode.
/// </summary>
/// <param name="maxDistance">The maximum distance from the player (default is the player's building reach)</param>
/// <returns>The wire or null if not found</returns>
public Wire GetWireLookedAt(float maxDistance = -1f)
{
var egid = playerEngine.GetThingLookedAt(Id, maxDistance);
return egid != EGID.Empty && egid.groupID == WiresGUIExclusiveGroups.WireGroup
? new Wire(egid)
: null;
}

/// <summary>
/// Returns the blocks that are in the player's current selection.
/// </summary>


+ 15
- 0
TechbloxModdingAPI/Tests/TechbloxModdingAPIPluginTest.cs View File

@@ -312,6 +312,21 @@ namespace TechbloxModdingAPI.Tests

Loop().RunOn(Scheduler.leanRunner);
}).Build();

CommandBuilder.Builder("importAssetBundle")
.Action(() =>
{
Logging.CommandLog("Importing asset bundle...");
var ab = AssetBundle.LoadFromFile(
@"filepath");
Logging.CommandLog("Imported asset bundle: " + ab);
var assets = ab.LoadAllAssets();
Logging.CommandLog("Loaded " + assets.Length + " assets");
foreach (var asset in assets)
{
Logging.CommandLog(asset);
}
}).Build();
#if TEST
TestRoot.RunTests();
#endif


Loading…
Cancel
Save