Entitas icon indicating copy to clipboard operation
Entitas copied to clipboard

Is there a way to write my own .Replace[ComponentName] ? or Make some variables do not change by .Replace[ComponentName]?

Open AemaethMonster opened this issue 5 years ago • 5 comments

Some variables in the component should be set by .ReplaceXX. (Like: hp, mp, atk) Some variables in the component store the component's states. (Like: state. state can be "full hp", "healthy", "almost-dead", "dead" ) State can be calculated from hp, in systems.

But after using "Generate", every variables in the component must be re-set in AddXX and ReplaceXX.(this is include the state variables) Is there a way to avoid this ? For example,

  1. write my own .Replace
  2. write specific word as parameter which mean do not change this variable

AemaethMonster avatar Aug 03 '18 06:08 AemaethMonster

 [Game]
    public sealed class HealthComponent : IComponent {
        public float currentValue;
        public float baseMaxValue;
        public float currentMaxValue;
    }

    public static partial class GameEntityExtention {
        public static void AddHealth (this GameEntity entity,float value) {
            entity.AddHealth (value, value, value);
        }

        public static void ReplaceHealth(this GameEntity entity,float value) {
            entity.ReplaceHealth (value, entity.health.baseMaxValue, entity.health.currentMaxValue);
        }
    }

VergilGao avatar Aug 03 '18 08:08 VergilGao

Why not split the components into different ones so you can control which fields you want to replace? In your question I see 7 different components.

ghost avatar Aug 03 '18 08:08 ghost

to VergilGao thank you!

to StormRene I know what you mean. But if a man is "dead", he can't be "full hp","healthy", "almost-dead". If each state is a single component , more code must be write to prevent a full-hp-dead man. That's too Dark Souls XD

Actually I think, if two components share same lifeline (always add, relace and remove together), then they should be one. So that I can remember components as less as possible.

AemaethMonster avatar Aug 03 '18 12:08 AemaethMonster

Sure you don't need to split data if you don't get any advantages from it. You only need to split of you need to react on fields independently.

It's not Dark Souls - it's single responsibility principle. If this is the state of the entity you need then you should write logic that doesn't transform the entity into some full-hp-dead man or vice versa. Maybe it's just me, but I like small components with just 1-2 fields and systems that have only 3-5 lines of code.

ghost avatar Aug 03 '18 13:08 ghost

@StormRene Dark Souls is a game which start with a full-hp-dead man.(:зゝ∠)

Thank you for telling me the single responsibility principle. I will reconsider which style take more advantage:D

AemaethMonster avatar Aug 03 '18 14:08 AemaethMonster