@@ -1,4 +1,5 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using RobocraftX.GUI.CommandLine; | |||
using RobocraftX.Multiplayer; | |||
using RobocraftX.StateSync; | |||
@@ -8,11 +9,14 @@ using Unity.Entities; | |||
using UnityEngine; | |||
using uREPL; | |||
using Svelto.Context; | |||
using Svelto.Tasks; | |||
using Svelto.Tasks.ExtraLean; | |||
using RobocraftX; | |||
using RobocraftX.Schedulers; | |||
namespace ExtraCommands.Basics | |||
{ | |||
[CustomCommand] | |||
[CustomCommand("Chain")] | |||
class ChainCommandEngine : CustomCommandEngine | |||
{ | |||
public ChainCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) | |||
@@ -22,75 +26,38 @@ namespace ExtraCommands.Basics | |||
public override void Ready() | |||
{ | |||
CustomCommandUtility.Register<string, string>("Chain", ChainCommand, "Run two commands, one after the other"); | |||
CustomCommandUtility.Register<string, string>("ChainNoFail", ChainNoFailCommand, "Run two commands, one after the other even if the first one is invalid"); | |||
CustomCommandUtility.Register<string, string>("ChainQuiet", ChainQuietCommand, "Run two commands, one after the other quietly"); | |||
} | |||
private void ChainCommand(string command1, string command2) | |||
{ | |||
string command1a = decomma(command1); | |||
string command2a = decomma(command2); | |||
bool success1 = uREPL.Evaluator.Evaluate(command1a).type == CompileResult.Type.Success; | |||
if (!success1) { | |||
uREPL.Log.Error("First command was not executed successfully"); | |||
return; | |||
} | |||
bool success2 = uREPL.Evaluator.Evaluate(command2a).type == CompileResult.Type.Success; | |||
if (!success2) { | |||
uREPL.Log.Error("Second command was not executed successfully"); | |||
} | |||
ScheduleCommands(command1a, command2a).RunOn(ExtraLean.CharacterUpdateScheduler); | |||
} | |||
private void ChainNoFailCommand(string command1, string command2) | |||
private IEnumerator<TaskContract> ScheduleCommands(string c1, string c2) | |||
{ | |||
string command1a = decomma(command1); | |||
string command2a = decomma(command2); | |||
bool success1 = uREPL.Evaluator.Evaluate(command1a).type == CompileResult.Type.Success; | |||
if (!success1) { | |||
yield return Yield.It; | |||
bool success1 = uREPL.Evaluator.Evaluate(c1).type == CompileResult.Type.Success; | |||
if (!success1) | |||
{ | |||
uREPL.Log.Error("First command was not executed successfully"); | |||
} | |||
bool success2 = uREPL.Evaluator.Evaluate(command2a).type == CompileResult.Type.Success; | |||
if (!success2) { | |||
bool success2 = uREPL.Evaluator.Evaluate(c2).type == CompileResult.Type.Success; | |||
if (!success2) | |||
{ | |||
uREPL.Log.Error("Second command was not executed successfully"); | |||
} | |||
} | |||
private void ChainQuietCommand(string command1, string command2) | |||
{ | |||
string command1a = decomma(command1); | |||
string command2a = decomma(command2); | |||
uREPL.Evaluator.Evaluate(command1a); | |||
uREPL.Evaluator.Evaluate(command2a); | |||
} | |||
private string decomma(string strIn) | |||
{ | |||
string strOut = ""; | |||
bool wasCommaLast = false; | |||
foreach (char c in strIn) | |||
{ | |||
if (wasCommaLast) | |||
{ | |||
wasCommaLast = false; | |||
if (c == ' ') | |||
{ | |||
strOut = strOut.Substring(0, strOut.Length - 1); | |||
} | |||
} | |||
if (c == ',') | |||
{ | |||
wasCommaLast = true; | |||
} | |||
strOut += c; | |||
} | |||
return strOut; | |||
return strIn.Replace(", ", " "); | |||
} | |||
public override void Dispose() | |||
{ | |||
CustomCommandUtility.Unregister("Chain"); | |||
CustomCommandUtility.Unregister("ChainNoFail"); | |||
CustomCommandUtility.Unregister("ChainQuiet"); | |||
} | |||
} | |||
} |
@@ -49,6 +49,9 @@ | |||
<Reference Include="RobocraftX.MultiplayerInput"> | |||
<HintPath>..\ref\RobocraftX.MultiplayerInput.dll</HintPath> | |||
</Reference> | |||
<Reference Include="RobocraftX.Physics"> | |||
<HintPath>..\ref\RobocraftX.Physics.dll</HintPath> | |||
</Reference> | |||
<Reference Include="RobocraftX.StateSync"> | |||
<HintPath>..\ref\RobocraftX.StateSync.dll</HintPath> | |||
</Reference> | |||
@@ -14,7 +14,7 @@ namespace ExtraCommands | |||
public string Name { get; } = "ExtraCommands"; | |||
public string Version { get; } = "v0.0.1"; | |||
public string Version { get; } = "v0.0.3"; | |||
public string HarmonyID { get; } = "org.git.exmods.extracommands.extracommands"; | |||
@@ -104,7 +104,7 @@ namespace ExtraCommands.Building | |||
uint connectedBlockID = cubeStack.Pop(); | |||
processedCubes.Add(connectedBlockID); | |||
ScalingEntityStruct scale = entitiesDB.QueryEntity<ScalingEntityStruct>(connectedBlockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); | |||
uREPL.Log.Output($"Catching {connectedBlockID} with scale {scale.scale}"); | |||
//uREPL.Log.Output($"Catching {connectedBlockID} with scale {scale.scale}"); | |||
blockConnections = entitiesDB.QueryEntity<GridConnectionsEntityStruct>(connectedBlockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); | |||
connections = entitiesDB.QueryEntities<MachineGraphConnectionEntityStruct>(blockConnections.connectionGroup, out count); | |||
@@ -115,7 +115,7 @@ namespace ExtraCommands.Building | |||
&& (conn.oppositeConnectionEgid.entityID != 0u | |||
|| conn.oppositeConnectionEgid.entityID != conn.connectedBlock.entityID)) | |||
{ | |||
uREPL.Log.Output($"Block {connectedBlockID} connects to {conn.connectedBlock.entityID} (opposite {conn.oppositeConnectionEgid.entityID})"); | |||
//uREPL.Log.Output($"Block {connectedBlockID} connects to {conn.connectedBlock.entityID} (opposite {conn.oppositeConnectionEgid.entityID})"); | |||
cubeStack.Push(conn.connectedBlock.entityID); | |||
} | |||
} | |||
@@ -124,59 +124,10 @@ namespace ExtraCommands.Building | |||
{ | |||
TranslateSingleBlock(id, translationVector); | |||
} | |||
uREPL.Log.Output($"Found {processedCubes.Count} connected blocks"); | |||
//uREPL.Log.Output($"Found {processedCubes.Count} connected blocks"); | |||
return this.entitiesDB.QueryEntity<PositionEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP).position; | |||
} | |||
// unused; for future reference | |||
private void ToggleMode() | |||
{ | |||
ref SimulationModeStateEntityStruct ptr = ref this.entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP); | |||
ref SimulationFrameEntityStruct ptr2 = ref this.entitiesDB.QueryUniqueEntity<SimulationFrameEntityStruct>(SimulationFrame.SimulationFrameGroup); | |||
switch (ptr.simulationMode) | |||
{ | |||
case SimulationMode.Build: | |||
ptr.simulationMode = SimulationMode.SwitchToSim; | |||
ptr.simulationModeChangeFrame = ptr2.simFrame; | |||
return; | |||
case SimulationMode.SwitchToSim: | |||
case SimulationMode.SwitchToBuild: | |||
return; | |||
case SimulationMode.Simulation: | |||
ptr.simulationMode = SimulationMode.SwitchToBuild; | |||
ptr.simulationModeChangeFrame = ptr2.simFrame; | |||
ptr.rigidBodiesCreated = false; | |||
return; | |||
default: | |||
throw new ArgumentOutOfRangeException(); | |||
} | |||
} | |||
// unused; for future reference | |||
private IEnumerator<TaskContract> TriggerSwitchToSimTask() | |||
{ | |||
this.ToggleMode(); | |||
yield break; | |||
} | |||
// unused; for future reference | |||
private IEnumerator<TaskContract> WaitThenTriggerSwitchToBuildTask() | |||
{ | |||
while (true) | |||
{ | |||
SimulationModeStateEntityStruct modeStruct = this.entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP); | |||
if (modeStruct.simulationMode == SimulationMode.Simulation) | |||
{ | |||
this.ToggleMode(); | |||
break; | |||
} else | |||
{ | |||
yield return Yield.It; | |||
} | |||
} | |||
yield break; | |||
} | |||
public override void Dispose() | |||
{ | |||
CustomCommandUtility.Unregister("MoveBlocks"); | |||
@@ -102,15 +102,13 @@ namespace ExtraCommands.Building | |||
switch (ptr.simulationMode) | |||
{ | |||
case SimulationMode.Build: | |||
ptr.simulationMode = SimulationMode.SwitchToSim; | |||
ptr.simulationModeChangeFrame = ptr2.simFrame; | |||
ptr.nextSimulationMode = SimulationMode.SwitchToSim; | |||
return; | |||
case SimulationMode.SwitchToSim: | |||
case SimulationMode.SwitchToBuild: | |||
return; | |||
case SimulationMode.Simulation: | |||
ptr.simulationMode = SimulationMode.SwitchToBuild; | |||
ptr.simulationModeChangeFrame = ptr2.simFrame; | |||
ptr.nextSimulationMode = SimulationMode.SwitchToBuild; | |||
ptr.rigidBodiesCreated = false; | |||
return; | |||
default: | |||
@@ -9,6 +9,7 @@ using Unity.Entities; | |||
using uREPL; | |||
using Svelto.Context; | |||
using RobocraftX; | |||
using RobocraftX.Physics; | |||
namespace ExtraCommands.Waypoints | |||
{ | |||