Skip to content

Large structural changes and addition of `IEntity`

Latest
Compare
Choose a tag to compare
@grofit grofit released this 18 Sep 14:59
· 16 commits to master since this release

Summary

Over the years of working on this library the goal was to try and have an additive and non-breaking way to easily add new responsibilities to core objects, be it via the internal functionality or 3rd party components.

Originally we took the approach of having interfaces that could be extended and composed however needed, which would let the end consumer decide which interfaces to use when composing things, and that has some benefits but it also has some down sides, such as not easily being able to add new responsibilities without inheriting or changing underlying type in some way.

The IStats object originally showed a way to handle this in a nice way, where its just a dictionary under the hood and lets you add keyed information in, so Health could be key 1 and we can add extension methods to the related objects which let us add responsibilities and logic in a more indirect way without needing to alter hierarchies or inheritance models etc.

Now felt like the right time to start solidifying on this idea by bringing a lot of the responsibilities in the OpenRpg.Genres layer into the core, such as ICharacter, which is now what IEntity has become.

IEntity

This is the notion of something that has both Stats, State and Variables under the hood, with the Variables basically becoming out extension point. This lets us expose dynamic ways to extend any entity to contain responsibilities for having an Inventory, or having a Class applied, this in a way is similar to how the ECS pattern works where everything is just a component added to the entity at runtime.

One downside here though is because we allow ANYTHING to be stored against the entities variables it has to be of type object which means ValueTypes will get boxed and everything needs casting on the way out, however this is taken care of in the extension methods that extend the underlying objects, and casting a type is fairly quick to do.

Other Changes

There are some other changes around making IDataTemplate a more official notion and having templates derive from that so we can keep them streamlined, as well as having certain interfaces having generics to support different types of IStatVariables or IStateVariables etc.