From 4684b33c6949d84ee1adb8c591cffdafa4395d22 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Mon, 31 Jan 2022 23:20:03 +0100 Subject: [PATCH] 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 --- TechbloxModdingAPI/App/GameBuildSimEventEngine.cs | 2 -- TechbloxModdingAPI/App/GameGameEngine.cs | 3 ++- TechbloxModdingAPI/Block.cs | 10 ++++++++-- TechbloxModdingAPI/Blocks/BlockTests.cs | 7 ------- TechbloxModdingAPI/Blocks/Engines/BlockEngine.cs | 1 + TechbloxModdingAPI/Player.cs | 2 +- TechbloxModdingAPI/Players/PlayerEngine.cs | 4 ++-- TechbloxModdingAPI/Players/PlayerTests.cs | 9 ++++----- 8 files changed, 18 insertions(+), 20 deletions(-) diff --git a/TechbloxModdingAPI/App/GameBuildSimEventEngine.cs b/TechbloxModdingAPI/App/GameBuildSimEventEngine.cs index 1846dd2..67e6769 100644 --- a/TechbloxModdingAPI/App/GameBuildSimEventEngine.cs +++ b/TechbloxModdingAPI/App/GameBuildSimEventEngine.cs @@ -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; } diff --git a/TechbloxModdingAPI/App/GameGameEngine.cs b/TechbloxModdingAPI/App/GameGameEngine.cs index 9856da8..1431eb4 100644 --- a/TechbloxModdingAPI/App/GameGameEngine.cs +++ b/TechbloxModdingAPI/App/GameGameEngine.cs @@ -150,7 +150,8 @@ namespace TechbloxModdingAPI.App dbid = (uint)filter; else dbid = entitiesDB.QueryEntity(buffer[i].ID).DBID; - if (dbid == (ulong)filter) + var ownership = entitiesDB.QueryEntity(buffer[i].ID).BlockOwnership; + if ((ownership & BlockOwnership.User) != 0 && dbid == (ulong)filter) blockEGIDs.Add(buffer[i].ID); } } diff --git a/TechbloxModdingAPI/Block.cs b/TechbloxModdingAPI/Block.cs index 7cead56..391ee62 100644 --- a/TechbloxModdingAPI/Block.cs +++ b/TechbloxModdingAPI/Block.cs @@ -340,9 +340,15 @@ namespace TechbloxModdingAPI [TestValue(null)] public string Label { - get => BlockEngine.GetBlockInfo(this).ToString(); //TODO: Block labels + get + { + var opt = BlockEngine.GetBlockInfoOptional(this); + return opt ? FullGameFields._managers.blockLabelResourceManager.GetText(opt.Get().instanceID) : null; + } set - { //TODO + { + var opt = BlockEngine.GetBlockInfoOptional(this); + if (opt) FullGameFields._managers.blockLabelResourceManager.SetText(opt.Get().instanceID, value); } } diff --git a/TechbloxModdingAPI/Blocks/BlockTests.cs b/TechbloxModdingAPI/Blocks/BlockTests.cs index 4bc29db..e58387e 100644 --- a/TechbloxModdingAPI/Blocks/BlockTests.cs +++ b/TechbloxModdingAPI/Blocks/BlockTests.cs @@ -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)[] diff --git a/TechbloxModdingAPI/Blocks/Engines/BlockEngine.cs b/TechbloxModdingAPI/Blocks/Engines/BlockEngine.cs index 8cbf88d..baea454 100644 --- a/TechbloxModdingAPI/Blocks/Engines/BlockEngine.cs +++ b/TechbloxModdingAPI/Blocks/Engines/BlockEngine.cs @@ -106,6 +106,7 @@ namespace TechbloxModdingAPI.Blocks.Engines var skew = entitiesDB.QueryEntity(id); entitiesDB.QueryEntity(id).matrix = math.mul(float4x4.TRS(pos.position, rot.rotation, scale.scale), skew.skewMatrix); + entitiesDB.PublishEntityChange(id); // Signal a prefab change so it updates the render buffers } internal void UpdatePrefab(Block block, byte material, bool flipped) diff --git a/TechbloxModdingAPI/Player.cs b/TechbloxModdingAPI/Player.cs index e50a29f..635bb74 100644 --- a/TechbloxModdingAPI/Player.cs +++ b/TechbloxModdingAPI/Player.cs @@ -64,7 +64,7 @@ namespace TechbloxModdingAPI } /// - /// Returns the current player belonging to this client. + /// Returns the current player belonging to this client. It will be different after entering/leaving simulation. /// public static Player LocalPlayer { diff --git a/TechbloxModdingAPI/Players/PlayerEngine.cs b/TechbloxModdingAPI/Players/PlayerEngine.cs index b6e38b1..d5feaf5 100644 --- a/TechbloxModdingAPI/Players/PlayerEngine.cs +++ b/TechbloxModdingAPI/Players/PlayerEngine.cs @@ -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(egid); if (!opt) return; opt.Get().instantExit = true; - entitiesDB.PublishEntityChange(egid); + entitiesDB.PublishEntityChange(egid);*/ } public bool SpawnMachine(uint playerId) diff --git a/TechbloxModdingAPI/Players/PlayerTests.cs b/TechbloxModdingAPI/Players/PlayerTests.cs index 9f3de75..32e9c14 100644 --- a/TechbloxModdingAPI/Players/PlayerTests.cs +++ b/TechbloxModdingAPI/Players/PlayerTests.cs @@ -39,15 +39,14 @@ namespace TechbloxModdingAPI.Players [APITestCase(TestType.Game)] public static void SeatEventTestBuild() { - Player.LocalPlayer.SeatEntered += Assert.CallsBack("SeatEntered"); - Player.LocalPlayer.SeatExited += Assert.CallsBack("SeatExited"); Block.PlaceNew(BlockIDs.DriverSeat, Player.LocalPlayer.Position); } [APITestCase(TestType.SimulationMode)] public static IEnumerator SeatEventTestSim() { - yield return new WaitForSecondsEnumerator(1).Continue(); + Player.LocalPlayer.SeatEntered += Assert.CallsBack("SeatEntered"); + Player.LocalPlayer.SeatExited += Assert.CallsBack("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)