Add inventory and pickup components with associated resources and presenters
This commit is contained in:
@@ -6,6 +6,7 @@ using GameCore.Attributes;
|
||||
using GameCore.Combat;
|
||||
using GameCore.ECS.Interfaces;
|
||||
using GameCore.Input;
|
||||
using GameCore.Inventory;
|
||||
using GameCore.Movement;
|
||||
using GameCore.Physics;
|
||||
using GameCore.Player;
|
||||
@@ -29,6 +30,8 @@ public class ComponentFactory
|
||||
Register<PlayerComponentResource>(_ => new PlayerComponent());
|
||||
Register<RotationComponentResource>(_ => new RotationComponent());
|
||||
Register<CharacterStateComponentResource>(_ => new CharacterStateComponent());
|
||||
Register<InventoryComponentResource>(_ => new InventoryComponent());
|
||||
Register<PickupComponentResource>(CreatePickupComponent);
|
||||
}
|
||||
|
||||
public IComponent Create(Resource resource)
|
||||
@@ -77,4 +80,14 @@ public class ComponentFactory
|
||||
Lifetime = resource.Lifetime,
|
||||
};
|
||||
}
|
||||
|
||||
private PickupComponent CreatePickupComponent(PickupComponentResource resource)
|
||||
{
|
||||
return new PickupComponent
|
||||
{
|
||||
ItemId = resource.ItemId,
|
||||
Quantity = resource.Quantity,
|
||||
IsInstantUse = resource.IsInstantUse
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ using GameCore.ECS;
|
||||
using GameCore.ECS.Interfaces;
|
||||
using GameCore.Events;
|
||||
using GameCore.Input;
|
||||
using GameCore.Inventory;
|
||||
using GameCore.Movement;
|
||||
using Godot;
|
||||
|
||||
@@ -54,6 +55,8 @@ public partial class GamePresenter : Node
|
||||
_world.RegisterSystem(new JumpSystem());
|
||||
|
||||
_world.RegisterSystem(new AttributeSystem());
|
||||
_world.RegisterSystem(new PickupSystem());
|
||||
_world.RegisterSystem(new InventorySystem(_world));
|
||||
|
||||
_world.RegisterSystem(new WeaponSystem());
|
||||
_world.RegisterSystem(new ProjectileSystem());
|
||||
|
||||
43
Code/Presenters/PickupPresenter.cs
Normal file
43
Code/Presenters/PickupPresenter.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using CryptonymThunder.Code.Autoloads;
|
||||
using GameCore.ECS;
|
||||
using GameCore.ECS.Interfaces;
|
||||
using GameCore.Physics;
|
||||
using Godot;
|
||||
|
||||
namespace CryptonymThunder.Code.Presenters;
|
||||
|
||||
public partial class PickupPresenter : Area3D, IEntityPresenter, IPresenterComponent
|
||||
{
|
||||
private World _world;
|
||||
private PresenterRegistry _presenterRegistry;
|
||||
public Entity CoreEntity { get; set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
BodyEntered += OnBodyEnter;
|
||||
}
|
||||
|
||||
private void OnBodyEnter(Node3D body)
|
||||
{
|
||||
if (_presenterRegistry.TryGetEntity(body.GetInstanceId(), out var hitEntity))
|
||||
{
|
||||
_world.AddComponent(hitEntity, new CollisionEventComponent(CoreEntity));
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize(Entity coreEntity, World world)
|
||||
{
|
||||
CoreEntity = coreEntity;
|
||||
_world = world;
|
||||
_presenterRegistry = GetNode<PresenterRegistry>("/root/PresenterRegistry");
|
||||
BodyEntered += OnBodyEnter;
|
||||
}
|
||||
|
||||
public void SyncToPresentation(float delta)
|
||||
{
|
||||
}
|
||||
|
||||
public void SyncToCore(float delta)
|
||||
{
|
||||
}
|
||||
}
|
||||
9
Code/Resources/InventoryComponentResource.cs
Normal file
9
Code/Resources/InventoryComponentResource.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using Godot;
|
||||
|
||||
namespace CryptonymThunder.Code.Resources;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class InventoryComponentResource : Resource
|
||||
{
|
||||
|
||||
}
|
||||
11
Code/Resources/PickupComponentResource.cs
Normal file
11
Code/Resources/PickupComponentResource.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Godot;
|
||||
|
||||
namespace CryptonymThunder.Code.Resources;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class PickupComponentResource : Resource
|
||||
{
|
||||
[Export] public string ItemId { get; set; }
|
||||
[Export] public int Quantity { get; set; } = 1;
|
||||
[Export] public bool IsInstantUse { get; set; } = false;
|
||||
}
|
||||
Reference in New Issue
Block a user