Hope some of you have ideas for this. first I will describe the Task ahead and then go on with the my thoughts about solving it and what kind of problems I see.
1) I have a number of buildings. Their data is stored in a json file and contains stuff like name, price, maxHP, etc... all those static infos - This file can be changed or extended by additional types of buildings and my system should take them all, as long as there are no invalid data (negative health for example)
2) I need some kind of list of all buildings, that I can use to iterate over (for example to display all buildings in a build-menu)
3) I need to be able to place them somewhere and therefore create concrete instances of them in my gameworld
basically buildings can do different stuff in my game. they can create units, generate income, attack and other stuff.
my thoughts about solving it:
1) On loading my building.json, first the allowedActions of this building are looked at and the various components are added (e.g weapon component for shooting stuff) and then the actual data (like hp, damage, etc) is set and validated.
2) Currently to get a list of all my buildings and being able to place them somewhere, I do the following. on loading buildings, I actually create an instance of each of them in order to get a List of prototypes - this prototype list is then used everywhere, where I need to be able to iterate over them, e.g. buildmenu.
3) When I then want to build it, I kind of just clone this building and update the data specific to the new clone (e.g. its actual position) and add it to my game world
So basically I'm using some kind of prototype pattern, if I understood it correct. However I don't really feel comfortable to have a list of instances of my buildings that in reality don't exist in my gameworld and for which I always have to care, that they don't ever influence the actual game (like accidently they are iterated through in a list, when I want to do something to all currently constructed buildings in my game but this will also influence the prototypes, which i clone my buildings from but are not actually constructed)
Do you have other Ideas to solve this, or is using prototypes here the right thing to do?
Thanks for any advice Kind Regards