-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
289 additions
and
335 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Entities.Factories.Characters; | ||
using Entities.Factories.Items.Rocks; | ||
using LDtk; | ||
using LightInject; | ||
using Scellecs.Morpeh; | ||
|
||
namespace Entities.Factories; | ||
|
||
public class AbstractEntityFactory(IServiceFactory serviceFactory) : IAbstractEntityFactory | ||
{ | ||
private readonly Dictionary<string, IAbstractEntityFactory> _factories = new() | ||
{ | ||
// { "Tree", null }, | ||
{ "Player", serviceFactory.GetInstance<PlayerFactory>() }, | ||
{ "Rock", serviceFactory.GetInstance<AbstractRockFactory>() }, | ||
// { "Default", null } | ||
}; | ||
|
||
public Entity? CreateEntity(EntityInstance entity, World @in) | ||
{ | ||
{ | ||
if (_factories.TryGetValue(entity._Identifier, out var factory)) | ||
{ | ||
return factory.CreateEntity(entity, @in); | ||
} | ||
} | ||
|
||
foreach (var tag in entity._Tags) | ||
{ | ||
if (_factories.TryGetValue(tag, out var factory)) | ||
{ | ||
return factory.CreateEntity(entity, @in); | ||
} | ||
} | ||
|
||
return null; | ||
// throw new ArgumentException( | ||
// $"{entity._Identifier} ({entity.Iid}) has unknown tag(-s): {(string.Join(", ", entity._Tags))}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 0 additions & 63 deletions
63
src/Libs/Entities/Factories/Characters/PlayerEntityFactory.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Components.Data; | ||
using Components.Render.Animation; | ||
using Components.Tags; | ||
using LightInject; | ||
using Scellecs.Morpeh; | ||
using Scellecs.Morpeh.Extended.Extensions; | ||
|
||
namespace Entities.Factories.Characters; | ||
|
||
public class PlayerFactory(IServiceFactory serviceFactory) : ConcreteEntityFactory | ||
{ | ||
protected override void AddTags(Entity e) | ||
{ | ||
e.AddComponent(serviceFactory.GetInstance<CameraComponent>()); | ||
e.AddComponent(serviceFactory.GetInstance<InputMovableComponent>()); | ||
e.AddComponent(serviceFactory.GetInstance<MovableComponent>()); | ||
} | ||
|
||
protected override void AddData(Entity e) | ||
{ | ||
e.AddComponent(serviceFactory.GetInstance<string, NameComponent>("Player")); | ||
e.AddComponent(serviceFactory.GetInstance<TransformComponent>("PlayerEntity")); | ||
e.AddComponent(serviceFactory.GetInstance<RectangleColliderComponent>("PlayerEntity")); | ||
e.AddComponent(serviceFactory.GetInstance<InventoryComponent>()); | ||
} | ||
|
||
protected override void AddRender(Entity e) | ||
{ | ||
e.AddComponent(serviceFactory.GetInstance<MovementAnimationsComponent>("PlayerEntity")); | ||
e.AddComponent(serviceFactory.GetInstance<CharacterAnimatorComponent>("PlayerEntity")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using LDtk; | ||
using Scellecs.Morpeh; | ||
|
||
namespace Entities.Factories; | ||
|
||
public abstract class ConcreteEntityFactory : IConcreteEntityFactory | ||
{ | ||
public Entity CreateEntity(World @in) | ||
{ | ||
Entity e = @in.CreateEntity(); | ||
|
||
AddTags(e); | ||
AddData(e); | ||
AddRender(e); | ||
|
||
return e; | ||
} | ||
|
||
public virtual Entity CreateEntity(EntityInstance entity, World @in) => this.CreateEntity(@in); | ||
|
||
protected abstract void AddTags(Entity e); | ||
|
||
protected abstract void AddData(Entity e); | ||
|
||
protected abstract void AddRender(Entity e); | ||
} |
Oops, something went wrong.