Buildings Functionality - UQdeco2800/2022-studio-3 GitHub Wiki
What is a Building?
Building Entity
Buildings are spawned as an Entity() using the BuildingFactory that creates a new entity and adds necessary components to it. See Entity Component System for how this component system works.
Why use a factory? The game engine already uses the Abstract Factory Pattern, a great way of creating similar objects without specifying a concrete class, so it made sense to conform. he
Spawning and Adding Components in the BuildingFactory
- A base building is created first by calling createBaseBuilding()which returns an entity with a PhysicsComponent and ColliderCompenet.
This is where to put non unique components (components that every building will possess)
- The specific components are then added for that specific building
e.g. the
TextureRenderComponentwhich requires the path of the image asset to be constructed which differs for different buildings
- Some of these components are also configured using a configuration file
e.g.
townHall.addComponent(new CombatStatsComponent(config.health, config.baseAttack));
Building configs
The rationale for using configs - Configuring Entities
The current Config Classes extend from the BaseEntityConfig and adds support for a building level up system. 
Visualisation of the BuildingFactory using BuildingConfigs in a class diagram:

The Building factory loads the configs and uses the fields in them to create and add components to the newly created building entity. 
private static final BuildingConfigs configs = FileLoader.readClass(BuildingConfigs.class, "configs/buildings.json");