Browse Source

Fix tests, getting machine blocks, block labels and visuals

- Checking the material property again, it seems to work now
- Fixed the Seat events not triggering during tests (the player in build and in sim is different)
- Fixed Game.GetAllBlocksInGame() returning environment blocks (since a Game refers to a machine save)
- Fixed the Block.Label property
- Fixed the block visuals not being updated after applying changes
tags/v2.2.0
NorbiPeti 2 years ago
parent
commit
4684b33c69
8 changed files with 18 additions and 20 deletions
  1. +0
    -2
      TechbloxModdingAPI/App/GameBuildSimEventEngine.cs
  2. +2
    -1
      TechbloxModdingAPI/App/GameGameEngine.cs
  3. +8
    -2
      TechbloxModdingAPI/Block.cs
  4. +0
    -7
      TechbloxModdingAPI/Blocks/BlockTests.cs
  5. +1
    -0
      TechbloxModdingAPI/Blocks/Engines/BlockEngine.cs
  6. +1
    -1
      TechbloxModdingAPI/Player.cs
  7. +2
    -2
      TechbloxModdingAPI/Players/PlayerEngine.cs
  8. +4
    -5
      TechbloxModdingAPI/Players/PlayerTests.cs

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

@@ -27,14 +27,12 @@ namespace TechbloxModdingAPI.App

public JobHandle OnInitializeTimeRunningMode(JobHandle inputDeps)
{
Console.WriteLine("Init time running mode");
SimulationMode.Invoke(this, new GameEventArgs { GameName = "", GamePath = "" }); // TODO
return inputDeps;
}

public JobHandle OnInitializeTimeStoppedMode(JobHandle inputDeps)
{
Console.WriteLine("Init time stopped mode");
BuildMode.Invoke(this, new GameEventArgs { GameName = "", GamePath = "" });
return inputDeps;
}


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

@@ -150,7 +150,8 @@ namespace TechbloxModdingAPI.App
dbid = (uint)filter;
else
dbid = entitiesDB.QueryEntity<DBEntityStruct>(buffer[i].ID).DBID;
if (dbid == (ulong)filter)
var ownership = entitiesDB.QueryEntity<BlockOwnershipComponent>(buffer[i].ID).BlockOwnership;
if ((ownership & BlockOwnership.User) != 0 && dbid == (ulong)filter)
blockEGIDs.Add(buffer[i].ID);
}
}


+ 8
- 2
TechbloxModdingAPI/Block.cs View File

@@ -340,9 +340,15 @@ namespace TechbloxModdingAPI
[TestValue(null)]
public string Label
{
get => BlockEngine.GetBlockInfo<LabelResourceIDComponent>(this).ToString(); //TODO: Block labels
get
{
var opt = BlockEngine.GetBlockInfoOptional<LabelResourceIDComponent>(this);
return opt ? FullGameFields._managers.blockLabelResourceManager.GetText(opt.Get().instanceID) : null;
}
set
{ //TODO
{
var opt = BlockEngine.GetBlockInfoOptional<LabelResourceIDComponent>(this);
if (opt) FullGameFields._managers.blockLabelResourceManager.SetText(opt.Get().instanceID, value);
}
}



+ 0
- 7
TechbloxModdingAPI/Blocks/BlockTests.cs View File

@@ -87,13 +87,6 @@ namespace TechbloxModdingAPI.Blocks
if (!block.Exists) continue;
foreach (var property in block.GetType().GetProperties())
{
if (property.Name == "Material" || property.Name == "Flipped") continue; // TODO: Crashes in game
if (property.Name == "Material" || property.Name == "Flipped")
{
Console.WriteLine("Block type: "+block.Type);
Console.WriteLine("Will set " + property.Name);
yield return new WaitForSecondsEnumerator(1).Continue();
}
//Includes specialised block properties
if (property.SetMethod == null) continue;
var testValues = new (Type, object, Predicate<object>)[]


+ 1
- 0
TechbloxModdingAPI/Blocks/Engines/BlockEngine.cs View File

@@ -106,6 +106,7 @@ namespace TechbloxModdingAPI.Blocks.Engines
var skew = entitiesDB.QueryEntity<SkewComponent>(id);
entitiesDB.QueryEntity<RenderingDataStruct>(id).matrix =
math.mul(float4x4.TRS(pos.position, rot.rotation, scale.scale), skew.skewMatrix);
entitiesDB.PublishEntityChange<GFXPrefabEntityStructGPUI>(id); // Signal a prefab change so it updates the render buffers
}

internal void UpdatePrefab(Block block, byte material, bool flipped)


+ 1
- 1
TechbloxModdingAPI/Player.cs View File

@@ -64,7 +64,7 @@ namespace TechbloxModdingAPI
}

/// <summary>
/// Returns the current player belonging to this client.
/// Returns the current player belonging to this client. It will be different after entering/leaving simulation.
/// </summary>
public static Player LocalPlayer
{


+ 2
- 2
TechbloxModdingAPI/Players/PlayerEngine.cs View File

@@ -226,11 +226,11 @@ namespace TechbloxModdingAPI.Players
{
if (!TimeRunningModeUtil.IsTimeRunningMode(entitiesDB))
return;
EGID egid = new EGID(playerId, CharacterExclusiveGroups.InPilotSeatGroup);
/*EGID egid = new EGID(playerId, CharacterExclusiveGroups.InPilotSeatGroup);
var opt = entitiesDB.QueryEntityOptional<CharacterPilotSeatEntityStruct>(egid);
if (!opt) return;
opt.Get().instantExit = true;
entitiesDB.PublishEntityChange<CharacterPilotSeatEntityStruct>(egid);
entitiesDB.PublishEntityChange<CharacterPilotSeatEntityStruct>(egid);*/
}

public bool SpawnMachine(uint playerId)


+ 4
- 5
TechbloxModdingAPI/Players/PlayerTests.cs View File

@@ -39,15 +39,14 @@ namespace TechbloxModdingAPI.Players
[APITestCase(TestType.Game)]
public static void SeatEventTestBuild()
{
Player.LocalPlayer.SeatEntered += Assert.CallsBack<PlayerSeatEventArgs>("SeatEntered");
Player.LocalPlayer.SeatExited += Assert.CallsBack<PlayerSeatEventArgs>("SeatExited");
Block.PlaceNew(BlockIDs.DriverSeat, Player.LocalPlayer.Position);
}

[APITestCase(TestType.SimulationMode)]
public static IEnumerator<TaskContract> SeatEventTestSim()
{
yield return new WaitForSecondsEnumerator(1).Continue();
Player.LocalPlayer.SeatEntered += Assert.CallsBack<PlayerSeatEventArgs>("SeatEntered");
Player.LocalPlayer.SeatExited += Assert.CallsBack<PlayerSeatEventArgs>("SeatExited");
Assert.Equal(Player.LocalPlayer.SpawnMachine(), true, "Failed to spawn the player's machine.", "Successfully spawned the player's machine.");
yield return new WaitForSecondsEnumerator(1).Continue();
var seats = Game.CurrentGame().GetBlocksInGame(BlockIDs.DriverSeat);
@@ -56,7 +55,7 @@ namespace TechbloxModdingAPI.Players
{
Logging.MetaLog("Waiting for a seat to be spawned...");
yield return new WaitForSecondsEnumerator(1).Continue();
Console.WriteLine("Spawn machine: " + Player.LocalPlayer.SpawnMachine());
Logging.MetaLog("Spawn machine: " + Player.LocalPlayer.SpawnMachine());
seats = Game.CurrentGame().GetBlocksInGame(BlockIDs.DriverSeat);
c++;
}
@@ -68,7 +67,7 @@ namespace TechbloxModdingAPI.Players
}

if (seats[0] is Seat seat)
{ //TODO: Actually, the problem is likely that the player ID is different in build and sim
{
Assert.Errorless(() => Player.LocalPlayer.EnterSeat(seat), "Failed to enter seat.",
"Entered seat successfully.");
while (Player.LocalPlayer.State != PlayerState.InSeat)


Loading…
Cancel
Save