- Edited
Summary:
Made some good progress this time around. Alongside the Google Sheets integration, I also started laying the groundwork for the UI. It's a work in progress, but it's getting there.
What's New:
This update features two key implementations, one of which is complete and the other is still under development. For more details, read on:
- Google Sheet Integration: A significant milestone. It streamlines the process of managing game data like Units, Buildings, Events, Upgrades, and Territory Settings. The integration allows for real-time online updates which can then be pulled into the game's central Database with a single click. For those interested in a deep dive into the implementation details, you can check out the dedicated thread:
Google Sheet Integration - Buildings and Building UI: This part of the project is engaging and demands a good deal of work before it reaches completion. Below is a snapshot of the current state of this feature:
The design is modular, allowing for the seamless addition, removal, or modification of buildings. Even entire categories of buildings, such as "Resource," can be removed without disrupting the overall system. New types can be introduced just as effortlessly. More details on the challenges and functionalities of this feature will follow.
Challenges and Solutions:
- Item Database: Developing a centralized Data System presented its own set of challenges, but the approach I've taken has streamlined many aspects of the game's data management. The database accepts an item ID, which allows for straightforward retrieval of various kinds of data, each based on a universal "Item" type. This negates the need for multiple arrays or other more complicated structures.
Moreover, structuring the database as a type of Resource permits the storage of items externally, which not only facilitates easier management but also acts as a safeguard against potential future bugs. Here's a glimpse of what the database looks like:
One essential feature is that items are read-only within the game, ensuring that any modification can only occur within the editor, thereby maintaining the integrity of the data. - Buildings: This is another key component of our data management strategy. Buildings are classified as a type of Resource, and they extend the base "Item" data type. This forms a crucial data block that is universally accessible across all game systems. Whenever a system needs information related to any building, it simply queries the Item Database using the building's ID.
Currently, the structure holds a range of data values, with plans for more to be added in the future.
Importantly, all data values are marked as "ReadOnly" (a custom attribute). This setup restricts any in-engine adjustments, thereby eliminating the potential for discrepancies between the online data set and what's downloaded into the game. - Building UI: This is still a work-in-progress but is coming together steadily. The system currently operates in two primary modes:
- Acquiring All Building Item Types: The first step involves fetching all types of Building items from the Item Database. Upon doing so, it instantiates these items on the screen. Initially, these items are hidden. However, when a player clicks on a specific tab (defined as 'TabType' in the Google Sheets), only the buildings corresponding to that tab type are displayed.
- Create Building UI:: During the creation of each UI item, it automatically assigns an Icon and an ID. When the corresponding button is clicked, this ID is returned, and new information is displayed to the player. These UI elements are then neatly arranged in a horizontal box for straightforward display.
- Acquiring All Building Item Types: The first step involves fetching all types of Building items from the Item Database. Upon doing so, it instantiates these items on the screen. Initially, these items are hidden. However, when a player clicks on a specific tab (defined as 'TabType' in the Google Sheets), only the buildings corresponding to that tab type are displayed.
- Building Placement: The system here is also quite straightforward. Upon selecting a desired building and clicking on an available slot on the screen, the building is constructed. If the slot is already occupied or is a resource that doesn't match the building type (e.g., trying to build a harbor on a forest), the game prevents the construction. Once a building is placed, the cell's 'isOccupied' attribute is set to true to prevent additional buildings from being placed there. Here's an example where a 'Harbor' is successfully placed on a 'Fish Resource':
This approach ensures that the placement rules are respected, avoiding duplicate constructions and helping maintain gameplay integrity.
Up Next: A Step Back
By adding so many things I neglected one of the more important systems: FSM. It is really a big requirement of the turn-based strategy games.
- FSM (Finite State Machine): Implementing an FSM is a crucial step forward, as it will act as the centralized control hub or "Brain" of the game. For games with discrete states like turn-based strategy games, an FSM is often more suitable than a Behavior Tree. With an FSM, transitions between various game states such as "Unit Movement," "Building," and "Turns" can be clearly defined and managed. This will improve the gameplay flow and make it easier to debug and extend the game in the future.
- Code decoupling: The current parallel systems for building selection, placement, and raycasting have led to bugs. Implementing an FSM will centralize these processes, resolving existing issues and preventing future bugs.
Up next, the focus will be on integrating the FSM and breaking down the code into more manageable components to fix current issues and set a solid foundation for future work.