Hey forum : )
I have an entity-component-system running here that I made but I'm still struggling with a few things.
Entities are being used for the following cases:
1. Entities as play-objects within a grid-based level.
2. Used as GUI-widgets.
Entities are being loaded in two ways:
1. From a file, which is pretty much a Lua-evel-file, representing the grid's objects.
2. Automatically generated (e.g. scanning for play-objects in a file-path).
I have two loader-classes, one for the GUI and one for grid-levels. One component-store and a Lua-table-deserialiser.
I gave my graphics-component coordinates-variables, as every visible component will also be at some spot on the screen. The issue is how to apply such to the component, when they have to be generated. They also contain a string as file-path (and reference to the actual loaded texture within a texture-store) and a scaling-value.
The issue is the following, I heard one shall keep constant values out of the level-file. I saw that some games, using XML, have one index-table with IDs to object-files containing constant characteristics (images, mesh-paths, ...). Now, where would I save coordinates? While file-paths will stay constantly the same, coordinates might change, especially of the player-entity. Putting them into the graphics-component seems not a wise-choice.
Should I go with a position-component?
Another problem is, that level-grids use coordinates-variables differently compared to the overall GUI.
x = 1 and y = 1 within the grid mean, column 1 and row 1, while as GUI-widget, they mean x-coordinate 1 and y-coordinate 1. Also, some of these values are not known upon creation - e.g. coordinates. E.g. GUI-loader asks the component-store to create one component and obtains the specific component-object. Then, depending on the type, the loader calls the Lua-deserialiser and obtains values such as image-file-path. But what about coordinates - for automatically generated GUIs, they are pretty much based on available files within a folder. Who shall provide them? Let the GUI-Loader count and add the position-component? It feels weird to change a components values after it has been created and obtained deserialised information.
Having a position-component feels a bit cleaner, either it exists or it does not. If it exists, nothing else has to be done, but if it does not, the GUI-loader will provide one based on counting.
And what class shall require the texture-reference for the graphics-component? And what class adds the graphics-component to the scene-graph? At the moment, whenever my level-loader gets a graphics-component from the component-store returned, it simply adds that component to the scene-graph.
When should this graphics-component acquire its reference from the texture-store? Should the scene-graph do this when a new component gets added to its structure? This seems to be the most reasonable.
In the end, I'm not sure if a position-component is common-practice, I bet people prefer to use a physics-component, that also adds a hit-box-field.
I assume, differentiating between constant components, as a base characteristic of one special enemy/unit/tile/... is common? And using a list of references to files that contain them too?
I hope my post is somewhat understandable, thanks a lot for your time, though : )