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
This commit is contained in:
Norbi Peti 2022-01-31 23:20:03 +01:00
parent d27bcee8d5
commit 4684b33c69
8 changed files with 18 additions and 20 deletions

View file

@ -27,14 +27,12 @@ namespace TechbloxModdingAPI.App
public JobHandle OnInitializeTimeRunningMode(JobHandle inputDeps) public JobHandle OnInitializeTimeRunningMode(JobHandle inputDeps)
{ {
Console.WriteLine("Init time running mode");
SimulationMode.Invoke(this, new GameEventArgs { GameName = "", GamePath = "" }); // TODO SimulationMode.Invoke(this, new GameEventArgs { GameName = "", GamePath = "" }); // TODO
return inputDeps; return inputDeps;
} }
public JobHandle OnInitializeTimeStoppedMode(JobHandle inputDeps) public JobHandle OnInitializeTimeStoppedMode(JobHandle inputDeps)
{ {
Console.WriteLine("Init time stopped mode");
BuildMode.Invoke(this, new GameEventArgs { GameName = "", GamePath = "" }); BuildMode.Invoke(this, new GameEventArgs { GameName = "", GamePath = "" });
return inputDeps; return inputDeps;
} }

View file

@ -150,7 +150,8 @@ namespace TechbloxModdingAPI.App
dbid = (uint)filter; dbid = (uint)filter;
else else
dbid = entitiesDB.QueryEntity<DBEntityStruct>(buffer[i].ID).DBID; 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); blockEGIDs.Add(buffer[i].ID);
} }
} }

View file

@ -340,9 +340,15 @@ namespace TechbloxModdingAPI
[TestValue(null)] [TestValue(null)]
public string Label 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 set
{ //TODO {
var opt = BlockEngine.GetBlockInfoOptional<LabelResourceIDComponent>(this);
if (opt) FullGameFields._managers.blockLabelResourceManager.SetText(opt.Get().instanceID, value);
} }
} }

View file

@ -87,13 +87,6 @@ namespace TechbloxModdingAPI.Blocks
if (!block.Exists) continue; if (!block.Exists) continue;
foreach (var property in block.GetType().GetProperties()) 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 //Includes specialised block properties
if (property.SetMethod == null) continue; if (property.SetMethod == null) continue;
var testValues = new (Type, object, Predicate<object>)[] var testValues = new (Type, object, Predicate<object>)[]

View file

@ -106,6 +106,7 @@ namespace TechbloxModdingAPI.Blocks.Engines
var skew = entitiesDB.QueryEntity<SkewComponent>(id); var skew = entitiesDB.QueryEntity<SkewComponent>(id);
entitiesDB.QueryEntity<RenderingDataStruct>(id).matrix = entitiesDB.QueryEntity<RenderingDataStruct>(id).matrix =
math.mul(float4x4.TRS(pos.position, rot.rotation, scale.scale), skew.skewMatrix); 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) internal void UpdatePrefab(Block block, byte material, bool flipped)

View file

@ -64,7 +64,7 @@ namespace TechbloxModdingAPI
} }
/// <summary> /// <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> /// </summary>
public static Player LocalPlayer public static Player LocalPlayer
{ {

View file

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

View file

@ -39,15 +39,14 @@ namespace TechbloxModdingAPI.Players
[APITestCase(TestType.Game)] [APITestCase(TestType.Game)]
public static void SeatEventTestBuild() 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); Block.PlaceNew(BlockIDs.DriverSeat, Player.LocalPlayer.Position);
} }
[APITestCase(TestType.SimulationMode)] [APITestCase(TestType.SimulationMode)]
public static IEnumerator<TaskContract> SeatEventTestSim() 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."); 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(); yield return new WaitForSecondsEnumerator(1).Continue();
var seats = Game.CurrentGame().GetBlocksInGame(BlockIDs.DriverSeat); var seats = Game.CurrentGame().GetBlocksInGame(BlockIDs.DriverSeat);
@ -56,7 +55,7 @@ namespace TechbloxModdingAPI.Players
{ {
Logging.MetaLog("Waiting for a seat to be spawned..."); Logging.MetaLog("Waiting for a seat to be spawned...");
yield return new WaitForSecondsEnumerator(1).Continue(); 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); seats = Game.CurrentGame().GetBlocksInGame(BlockIDs.DriverSeat);
c++; c++;
} }
@ -68,7 +67,7 @@ namespace TechbloxModdingAPI.Players
} }
if (seats[0] is Seat seat) 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.", Assert.Errorless(() => Player.LocalPlayer.EnterSeat(seat), "Failed to enter seat.",
"Entered seat successfully."); "Entered seat successfully.");
while (Player.LocalPlayer.State != PlayerState.InSeat) while (Player.LocalPlayer.State != PlayerState.InSeat)