diff --git a/GamecraftModdingAPI/App/GameMenuEngine.cs b/GamecraftModdingAPI/App/GameMenuEngine.cs index fc2c35f..74bc42a 100644 --- a/GamecraftModdingAPI/App/GameMenuEngine.cs +++ b/GamecraftModdingAPI/App/GameMenuEngine.cs @@ -10,6 +10,7 @@ using Svelto.ECS.Experimental; using GamecraftModdingAPI.Engines; using GamecraftModdingAPI.Utility; +using Svelto.DataStructures; namespace GamecraftModdingAPI.App { @@ -114,11 +115,21 @@ namespace GamecraftModdingAPI.App } public ref MyGamesSlotEntityViewStruct GetGameViewInfo(EGID id) - { - return ref GetComponent(new EGID(id.entityID, MyGamesScreenExclusiveGroups.GameSlotGuiEntities)); + { + EntityCollection entities = + entitiesDB.QueryEntities(MyGamesScreenExclusiveGroups.GameSlotGuiEntities); + for (int i = 0; i < entities.count; i++) + { + if (entities[i].ID.entityID == id.entityID) + { + return ref entities[i]; + } + } + MyGamesSlotEntityViewStruct[] defRef = new MyGamesSlotEntityViewStruct[1]; + return ref defRef[0]; } - public ref T GetComponent(EGID id) where T: struct, IEntityComponent + public ref T GetComponent(EGID id) where T: unmanaged, IEntityComponent { return ref entitiesDB.QueryEntity(id); } diff --git a/GamecraftModdingAPI/Block.cs b/GamecraftModdingAPI/Block.cs index 0194bae..c7b5d0d 100644 --- a/GamecraftModdingAPI/Block.cs +++ b/GamecraftModdingAPI/Block.cs @@ -337,10 +337,10 @@ namespace GamecraftModdingAPI /// public string Label { - get => BlockEngine.GetBlockInfo(this, (TextLabelEntityViewStruct st) => st.textLabelComponent?.text); + get => BlockEngine.GetBlockInfoViewStruct(this, (TextLabelEntityViewStruct st) => st.textLabelComponent?.text); set { - BlockEngine.SetBlockInfo(this, (ref TextLabelEntityViewStruct text, string val) => + BlockEngine.SetBlockInfoViewStruct(this, (ref TextLabelEntityViewStruct text, string val) => { if (text.textLabelComponent != null) text.textLabelComponent.text = val; }, value); diff --git a/GamecraftModdingAPI/Blocks/BlockEngine.cs b/GamecraftModdingAPI/Blocks/BlockEngine.cs index f97e405..33c4002 100644 --- a/GamecraftModdingAPI/Blocks/BlockEngine.cs +++ b/GamecraftModdingAPI/Blocks/BlockEngine.cs @@ -59,16 +59,34 @@ namespace GamecraftModdingAPI.Blocks color.paletteColour = paletteEntry.Colour; } - public ref T GetBlockInfo(EGID blockID) where T : struct, IEntityComponent + public ref T GetBlockInfo(EGID blockID) where T : unmanaged, IEntityComponent { if (entitiesDB.Exists(blockID)) return ref entitiesDB.QueryEntity(blockID); T[] structHolder = new T[1]; //Create something that can be referenced return ref structHolder[0]; //Gets a default value automatically } + + public ref T GetBlockInfoViewStruct(EGID blockID) where T : struct, INeedEGID, IEntityComponent + { + if (entitiesDB.Exists(blockID)) + { + // TODO: optimize by using EntitiesDB internal calls instead of iterating over everything + EntityCollection entities = entitiesDB.QueryEntities(blockID.groupID); + for (int i = 0; i < entities.count; i++) + { + if (entities[i].ID == blockID) + { + return ref entities[i]; + } + } + } + T[] structHolder = new T[1]; //Create something that can be referenced + return ref structHolder[0]; //Gets a default value automatically + } public U GetBlockInfo(Block block, Func getter, - U def = default) where T : struct, IEntityComponent + U def = default) where T : unmanaged, IEntityComponent { if (entitiesDB.Exists(block.Id)) return getter(entitiesDB.QueryEntity(block.Id)); @@ -78,10 +96,56 @@ namespace GamecraftModdingAPI.Blocks return getter(initializer.Get()); return def; } + + public U GetBlockInfoViewStruct(Block block, Func getter, + U def = default) where T : struct, INeedEGID, IEntityComponent + { + if (entitiesDB.Exists(block.Id)) + { + // TODO: optimize by using EntitiesDB internal calls instead of iterating over everything + EntityCollection entities = entitiesDB.QueryEntities(block.Id.groupID); + for (int i = 0; i < entities.count; i++) + { + if (entities[i].ID == block.Id) + { + return getter(entities[i]); + } + } + } + if (block.InitData.Group == null) return def; + var initializer = new EntityComponentInitializer(block.Id, block.InitData.Group); + if (initializer.Has()) + return getter(initializer.Get()); + return def; + } public delegate void Setter(ref T component, U value) where T : struct, IEntityComponent; - public void SetBlockInfo(Block block, Setter setter, U value) where T : struct, IEntityComponent + public void SetBlockInfoViewStruct(Block block, Setter setter, U value) where T : struct, INeedEGID, IEntityComponent + { + if (entitiesDB.Exists(block.Id)) + { + EntityCollection entities = entitiesDB.QueryEntities(block.Id.groupID); + for (int i = 0; i < entities.count; i++) + { + if (entities[i].ID == block.Id) + { + setter(ref entities[i], value); + return; + } + } + } + else if (block.InitData.Group != null) + { + var initializer = new EntityComponentInitializer(block.Id, block.InitData.Group); + T component = initializer.Has() ? initializer.Get() : default; + ref T structRef = ref component; + setter(ref structRef, value); + initializer.Init(structRef); + } + } + + public void SetBlockInfo(Block block, Setter setter, U value) where T : unmanaged, IEntityComponent { if (entitiesDB.Exists(block.Id)) setter(ref entitiesDB.QueryEntity(block.Id), value); diff --git a/GamecraftModdingAPI/Blocks/SignalEngine.cs b/GamecraftModdingAPI/Blocks/SignalEngine.cs index e961423..763a1a1 100644 --- a/GamecraftModdingAPI/Blocks/SignalEngine.cs +++ b/GamecraftModdingAPI/Blocks/SignalEngine.cs @@ -96,7 +96,7 @@ namespace GamecraftModdingAPI.Blocks return ref GetPortByOffset(bps, portNumber, input); } - public ref T GetComponent(EGID egid) where T : struct, IEntityComponent + public ref T GetComponent(EGID egid) where T : unmanaged, IEntityComponent { return ref entitiesDB.QueryEntity(egid); } @@ -372,7 +372,7 @@ namespace GamecraftModdingAPI.Blocks return results.ToArray(); } - private ref T GetFromDbOrInitData(Block block, EGID id, out bool exists) where T : struct, IEntityComponent + private ref T GetFromDbOrInitData(Block block, EGID id, out bool exists) where T : unmanaged, IEntityComponent { T[] defRef = new T[1]; if (entitiesDB.Exists(id)) diff --git a/GamecraftModdingAPI/GamecraftModdingAPI.csproj b/GamecraftModdingAPI/GamecraftModdingAPI.csproj index 32c780b..49a3a6a 100644 --- a/GamecraftModdingAPI/GamecraftModdingAPI.csproj +++ b/GamecraftModdingAPI/GamecraftModdingAPI.csproj @@ -22,6 +22,7 @@ +<<<<<<< HEAD @@ -55,6 +56,21 @@ ..\ref\Gamecraft_Data\Managed\Accessibility.dll ..\..\ref\Gamecraft_Data\Managed\Accessibility.dll +======= + + + + + + + + ..\ref\GamecraftPreview_Data\Managed\IllusionInjector.dll + ..\..\ref\GamecraftPreview_Data\Managed\IllusionInjector.dll + + + ..\ref\GamecraftPreview_Data\Managed\IllusionPlugin.dll + ..\..\ref\GamecraftPreview_Data\Managed\IllusionPlugin.dll +>>>>>>> 50ebf4f... Fix build issues for latest Gamecraft preview version ..\ref\Gamecraft_Data\Managed\Analytics.dll @@ -72,10 +88,13 @@ ..\ref\Gamecraft_Data\Managed\Authentication.dll ..\..\ref\Gamecraft_Data\Managed\Authentication.dll +<<<<<<< HEAD ..\ref\Gamecraft_Data\Managed\BlockEntityFactory.dll ..\..\ref\Gamecraft_Data\Managed\BlockEntityFactory.dll +======= +>>>>>>> 50ebf4f... Fix build issues for latest Gamecraft preview version ..\ref\Gamecraft_Data\Managed\Blocks.HUDFeedbackBlocks.dll ..\..\ref\Gamecraft_Data\Managed\Blocks.HUDFeedbackBlocks.dll @@ -84,6 +103,18 @@ ..\ref\Gamecraft_Data\Managed\CommandLine.dll ..\..\ref\Gamecraft_Data\Managed\CommandLine.dll + + ..\ref\GamecraftPreview_Data\Managed\CommandLineCompositionRoot.dll + ..\..\ref\GamecraftPreview_Data\Managed\CommandLineCompositionRoot.dll + + + ..\ref\GamecraftPreview_Data\Managed\ConsoleBlockComposotionRoot.dll + ..\..\ref\GamecraftPreview_Data\Managed\ConsoleBlockComposotionRoot.dll + + + ..\ref\GamecraftPreview_Data\Managed\ConsoleCommand.dll + ..\..\ref\GamecraftPreview_Data\Managed\ConsoleCommand.dll + ..\ref\Gamecraft_Data\Managed\DataLoader.dll ..\..\ref\Gamecraft_Data\Managed\DataLoader.dll @@ -108,6 +139,14 @@ ..\ref\Gamecraft_Data\Managed\Gamecraft.AudioBlocks.dll ..\..\ref\Gamecraft_Data\Managed\Gamecraft.AudioBlocks.dll + + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.BlockCompositionRoot.dll + ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.BlockCompositionRoot.dll + + + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.BlockEntityFactory.dll + ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.BlockEntityFactory.dll + ..\ref\Gamecraft_Data\Managed\Gamecraft.Blocks.ConsoleBlock.dll ..\..\ref\Gamecraft_Data\Managed\Gamecraft.Blocks.ConsoleBlock.dll @@ -116,6 +155,10 @@ ..\ref\Gamecraft_Data\Managed\Gamecraft.Blocks.DamagingSurfaceBlock.dll ..\..\ref\Gamecraft_Data\Managed\Gamecraft.Blocks.DamagingSurfaceBlock.dll + + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.DestructionBlocks.dll + ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.DestructionBlocks.dll + ..\ref\Gamecraft_Data\Managed\Gamecraft.Blocks.GenericPhysicsBlocks.dll ..\..\ref\Gamecraft_Data\Managed\Gamecraft.Blocks.GenericPhysicsBlocks.dll @@ -128,10 +171,18 @@ ..\ref\Gamecraft_Data\Managed\GameCraft.Blocks.ProjectileBlock.dll ..\..\ref\Gamecraft_Data\Managed\GameCraft.Blocks.ProjectileBlock.dll + + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.TextBlock.CompositionRoot.dll + ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.TextBlock.CompositionRoot.dll + ..\ref\Gamecraft_Data\Managed\Gamecraft.Blocks.TimerBlock.dll ..\..\ref\Gamecraft_Data\Managed\Gamecraft.Blocks.TimerBlock.dll + + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.BlocksEntityDescriptors.dll + ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.BlocksEntityDescriptors.dll + ..\ref\Gamecraft_Data\Managed\Gamecraft.CharacterVulnerability.dll ..\..\ref\Gamecraft_Data\Managed\Gamecraft.CharacterVulnerability.dll @@ -140,10 +191,22 @@ ..\ref\Gamecraft_Data\Managed\Gamecraft.CharacterVulnerabilityGui.dll ..\..\ref\Gamecraft_Data\Managed\Gamecraft.CharacterVulnerabilityGui.dll + + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.Damage.dll + ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Damage.dll + ..\ref\Gamecraft_Data\Managed\Gamecraft.Effects.dll ..\..\ref\Gamecraft_Data\Managed\Gamecraft.Effects.dll + + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.ExplosionFragments.dll + ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.ExplosionFragments.dll + + + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.GraphicsSettings.dll + ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.GraphicsSettings.dll + ..\ref\Gamecraft_Data\Managed\Gamecraft.GUI.ConsoleBlock.dll ..\..\ref\Gamecraft_Data\Managed\Gamecraft.GUI.ConsoleBlock.dll @@ -172,6 +235,14 @@ ..\ref\Gamecraft_Data\Managed\Gamecraft.GUI.WorldSpaceGuis.dll ..\..\ref\Gamecraft_Data\Managed\Gamecraft.GUI.WorldSpaceGuis.dll + + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.InventoryTimeRunning.dll + ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.InventoryTimeRunning.dll + + + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.JointBlocks.dll + ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.JointBlocks.dll + ..\ref\Gamecraft_Data\Managed\Gamecraft.Music.dll ..\..\ref\Gamecraft_Data\Managed\Gamecraft.Music.dll @@ -180,6 +251,22 @@ ..\ref\Gamecraft_Data\Managed\Gamecraft.PerformanceWarnings.dll ..\..\ref\Gamecraft_Data\Managed\Gamecraft.PerformanceWarnings.dll + + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.PickupBlck.dll + ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.PickupBlck.dll + + + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.PickupsCommon.dll + ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.PickupsCommon.dll + + + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.PopupMessage.dll + ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.PopupMessage.dll + + + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.Projectiles.dll + ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Projectiles.dll + ..\ref\Gamecraft_Data\Managed\Gamecraft.Tweaks.dll ..\..\ref\Gamecraft_Data\Managed\Gamecraft.Tweaks.dll @@ -188,6 +275,10 @@ ..\ref\Gamecraft_Data\Managed\Gamecraft.Tweaks.Mockup.dll ..\..\ref\Gamecraft_Data\Managed\Gamecraft.Tweaks.Mockup.dll + + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.VisualEffects.Decals.dll + ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.VisualEffects.Decals.dll + ..\ref\Gamecraft_Data\Managed\Gamecraft.VisualEffects.dll ..\..\ref\Gamecraft_Data\Managed\Gamecraft.VisualEffects.dll @@ -196,10 +287,13 @@ ..\ref\Gamecraft_Data\Managed\Gamecraft.Wires.dll ..\..\ref\Gamecraft_Data\Managed\Gamecraft.Wires.dll +<<<<<<< HEAD ..\ref\Gamecraft_Data\Managed\Gamecraft.Wires.Input.dll ..\..\ref\Gamecraft_Data\Managed\Gamecraft.Wires.Input.dll +======= +>>>>>>> 50ebf4f... Fix build issues for latest Gamecraft preview version ..\ref\Gamecraft_Data\Managed\Gamecraft.Wires.Mockup.dll ..\..\ref\Gamecraft_Data\Managed\Gamecraft.Wires.Mockup.dll @@ -424,6 +518,14 @@ ..\ref\Gamecraft_Data\Managed\RobocratX.SimulationCompositionRoot.dll ..\..\ref\Gamecraft_Data\Managed\RobocratX.SimulationCompositionRoot.dll + + ..\ref\GamecraftPreview_Data\Managed\SpawningPointCompositionRoot.dll + ..\..\ref\GamecraftPreview_Data\Managed\SpawningPointCompositionRoot.dll + + + ..\ref\GamecraftPreview_Data\Managed\SpecializedDescriptors.dll + ..\..\ref\GamecraftPreview_Data\Managed\SpecializedDescriptors.dll + ..\ref\Gamecraft_Data\Managed\StringFormatter.dll ..\..\ref\Gamecraft_Data\Managed\StringFormatter.dll @@ -444,6 +546,10 @@ ..\ref\Gamecraft_Data\Managed\Svelto.Tasks.dll ..\..\ref\Gamecraft_Data\Managed\Svelto.Tasks.dll + + ..\ref\GamecraftPreview_Data\Managed\UltimateDecals.dll + ..\..\ref\GamecraftPreview_Data\Managed\UltimateDecals.dll + ..\ref\Gamecraft_Data\Managed\Unity.Addressables.dll ..\..\ref\Gamecraft_Data\Managed\Unity.Addressables.dll @@ -816,6 +922,7 @@ ..\ref\Gamecraft_Data\Managed\UnityEngine.XRModule.dll ..\..\ref\Gamecraft_Data\Managed\UnityEngine.XRModule.dll +<<<<<<< HEAD ..\ref\Gamecraft_Data\Managed\uREPL.dll ..\..\ref\Gamecraft_Data\Managed\uREPL.dll @@ -824,6 +931,8 @@ ..\ref\Gamecraft_Data\Managed\VisualProfiler.dll ..\..\ref\Gamecraft_Data\Managed\VisualProfiler.dll +======= +>>>>>>> 50ebf4f... Fix build issues for latest Gamecraft preview version \ No newline at end of file diff --git a/GamecraftModdingAPI/Players/PlayerEngine.cs b/GamecraftModdingAPI/Players/PlayerEngine.cs index f0aa31d..948c6e9 100644 --- a/GamecraftModdingAPI/Players/PlayerEngine.cs +++ b/GamecraftModdingAPI/Players/PlayerEngine.cs @@ -288,14 +288,7 @@ namespace GamecraftModdingAPI.Players public bool DamagePlayer(uint playerId, float amount) { if (entitiesDB == null) return false; - Factory.BuildEntity( - new EGID(CharacterVulnerabilityExclusiveGroups.NextDamageEntityId, CharacterVulnerabilityExclusiveGroups.CharacterDamageExclusiveGroup) - ).Init(new DamageEntityStruct - { - damage = amount, - targetPlayerEntityId = playerId, - }); - return true; + return SetCurrentHealth(playerId, GetCurrentHealth(playerId) - amount); } public bool GetDamageable(uint playerId)