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/BlockTests.cs b/GamecraftModdingAPI/Blocks/BlockTests.cs index 9013b3d..5447f6c 100644 --- a/GamecraftModdingAPI/Blocks/BlockTests.cs +++ b/GamecraftModdingAPI/Blocks/BlockTests.cs @@ -119,6 +119,6 @@ namespace GamecraftModdingAPI.Blocks if (!Assert.Errorless(() => { newWire = b.Connect(0, target, 0);})) return; if (!Assert.NotNull(newWire, "SignalingBlock.Connect(...) returned null, possible because it failed silently.", "SignalingBlock.Connect(...) returned a non-null value.")) return; } -} + } #endif } 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 7337ebe..7a7fe1d 100644 --- a/GamecraftModdingAPI/GamecraftModdingAPI.csproj +++ b/GamecraftModdingAPI/GamecraftModdingAPI.csproj @@ -25,8 +25,17 @@ + + + ..\ref\GamecraftPreview_Data\Managed\IllusionInjector.dll + ..\..\ref\GamecraftPreview_Data\Managed\IllusionInjector.dll + + + ..\ref\GamecraftPreview_Data\Managed\IllusionPlugin.dll + ..\..\ref\GamecraftPreview_Data\Managed\IllusionPlugin.dll + ..\ref\GamecraftPreview_Data\Managed\Analytics.dll ..\..\ref\GamecraftPreview_Data\Managed\Analytics.dll @@ -43,10 +52,6 @@ ..\ref\GamecraftPreview_Data\Managed\Authentication.dll ..\..\ref\GamecraftPreview_Data\Managed\Authentication.dll - - ..\ref\GamecraftPreview_Data\Managed\BlockEntityFactory.dll - ..\..\ref\GamecraftPreview_Data\Managed\BlockEntityFactory.dll - ..\ref\GamecraftPreview_Data\Managed\Blocks.HUDFeedbackBlocks.dll ..\..\ref\GamecraftPreview_Data\Managed\Blocks.HUDFeedbackBlocks.dll @@ -55,6 +60,18 @@ ..\ref\GamecraftPreview_Data\Managed\CommandLine.dll ..\..\ref\GamecraftPreview_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\GamecraftPreview_Data\Managed\DataLoader.dll ..\..\ref\GamecraftPreview_Data\Managed\DataLoader.dll @@ -75,6 +92,14 @@ ..\ref\GamecraftPreview_Data\Managed\Gamecraft.AudioBlocks.dll ..\..\ref\GamecraftPreview_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\GamecraftPreview_Data\Managed\Gamecraft.Blocks.ConsoleBlock.dll ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.ConsoleBlock.dll @@ -83,6 +108,10 @@ ..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.DamagingSurfaceBlock.dll ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.DamagingSurfaceBlock.dll + + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.DestructionBlocks.dll + ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.DestructionBlocks.dll + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.GenericPhysicsBlocks.dll ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.GenericPhysicsBlocks.dll @@ -95,10 +124,18 @@ ..\ref\GamecraftPreview_Data\Managed\GameCraft.Blocks.ProjectileBlock.dll ..\..\ref\GamecraftPreview_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\GamecraftPreview_Data\Managed\Gamecraft.Blocks.TimerBlock.dll ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Blocks.TimerBlock.dll + + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.BlocksEntityDescriptors.dll + ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.BlocksEntityDescriptors.dll + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.CharacterVulnerability.dll ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.CharacterVulnerability.dll @@ -107,10 +144,22 @@ ..\ref\GamecraftPreview_Data\Managed\Gamecraft.CharacterVulnerabilityGui.dll ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.CharacterVulnerabilityGui.dll + + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.Damage.dll + ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Damage.dll + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.Effects.dll ..\..\ref\GamecraftPreview_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\GamecraftPreview_Data\Managed\Gamecraft.GUI.ConsoleBlock.dll ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.GUI.ConsoleBlock.dll @@ -139,6 +188,14 @@ ..\ref\GamecraftPreview_Data\Managed\Gamecraft.GUI.WorldSpaceGuis.dll ..\..\ref\GamecraftPreview_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\GamecraftPreview_Data\Managed\Gamecraft.Music.dll ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Music.dll @@ -147,6 +204,22 @@ ..\ref\GamecraftPreview_Data\Managed\Gamecraft.PerformanceWarnings.dll ..\..\ref\GamecraftPreview_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\GamecraftPreview_Data\Managed\Gamecraft.Tweaks.dll ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Tweaks.dll @@ -155,6 +228,10 @@ ..\ref\GamecraftPreview_Data\Managed\Gamecraft.Tweaks.Mockup.dll ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Tweaks.Mockup.dll + + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.VisualEffects.Decals.dll + ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.VisualEffects.Decals.dll + ..\ref\GamecraftPreview_Data\Managed\Gamecraft.VisualEffects.dll ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.VisualEffects.dll @@ -163,10 +240,6 @@ ..\ref\GamecraftPreview_Data\Managed\Gamecraft.Wires.dll ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Wires.dll - - ..\ref\GamecraftPreview_Data\Managed\Gamecraft.Wires.Input.dll - ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Wires.Input.dll - ..\ref\GamecraftPreview_Data\Managed\Gamecraft.Wires.Mockup.dll ..\..\ref\GamecraftPreview_Data\Managed\Gamecraft.Wires.Mockup.dll @@ -379,6 +452,14 @@ ..\ref\GamecraftPreview_Data\Managed\RobocratX.SimulationCompositionRoot.dll ..\..\ref\GamecraftPreview_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\GamecraftPreview_Data\Managed\StringFormatter.dll ..\..\ref\GamecraftPreview_Data\Managed\StringFormatter.dll @@ -399,6 +480,10 @@ ..\ref\GamecraftPreview_Data\Managed\Svelto.Tasks.dll ..\..\ref\GamecraftPreview_Data\Managed\Svelto.Tasks.dll + + ..\ref\GamecraftPreview_Data\Managed\UltimateDecals.dll + ..\..\ref\GamecraftPreview_Data\Managed\UltimateDecals.dll + ..\ref\GamecraftPreview_Data\Managed\Unity.Addressables.dll ..\..\ref\GamecraftPreview_Data\Managed\Unity.Addressables.dll @@ -563,6 +648,10 @@ ..\ref\GamecraftPreview_Data\Managed\Unity.Transforms.Hybrid.dll ..\..\ref\GamecraftPreview_Data\Managed\Unity.Transforms.Hybrid.dll + + ..\ref\GamecraftPreview_Data\Managed\Unity.VisualEffectGraph.Runtime.dll + ..\..\ref\GamecraftPreview_Data\Managed\Unity.VisualEffectGraph.Runtime.dll + ..\ref\GamecraftPreview_Data\Managed\UnityEngine.UI.dll ..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.UI.dll @@ -855,14 +944,6 @@ ..\ref\GamecraftPreview_Data\Managed\UnityEngine.XRModule.dll ..\..\ref\GamecraftPreview_Data\Managed\UnityEngine.XRModule.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 - \ No newline at end of file diff --git a/GamecraftModdingAPI/Players/PlayerEngine.cs b/GamecraftModdingAPI/Players/PlayerEngine.cs index 805ae21..ce0b63a 100644 --- a/GamecraftModdingAPI/Players/PlayerEngine.cs +++ b/GamecraftModdingAPI/Players/PlayerEngine.cs @@ -10,8 +10,6 @@ using RobocraftX.Physics; using RobocraftX.Blocks.Ghost; using RobocraftX.Character.Camera; using RobocraftX.Character.Factories; -using Gamecraft.CharacterVulnerability; -using Gamecraft.CharacterVulnerability.Entities; using Svelto.ECS; using Unity.Mathematics; using Unity.Physics; @@ -282,14 +280,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)