- Edited
Update [0.230923]
Summary:
A lot of effort went into cleaning up and reorganizing the code. Several new features, such as an Observer System and State Controller, are now in place. Let's dive in.
What's New:
Here's a rundown of the main updates:
- Code Cleanup: The game reached a point where better organization was essential. So, various pieces of code were either moved, deleted, or updated to make everything more cohesive.
- Observer System: This feature keeps tabs on specific values and notifies other parts of the code when changes occur. It was challenging to implement, but it's doing its job well.
- State Controller: This acts as the game's "brain," governing changes in the game state. Everything else in the game reacts to this centralized system
- UI: The UI used to be tightly bound to game controllers. Now, thanks to the Observer System and State Controller, the game can run without being tied to the UI. This means that removing any UI element won't crash the game.
- Scene Cleanup: Every UI element has been converted into "Packed Scenes" and organized under a main UI component. This not only tidies things up but also allows each component to focus on its own specific function. Overall, it's a big step toward making the project more manageable.
Challenges and Solutions:
Skipping the Code Cleanup, as it's too much to unpack here. However, the Observer System does warrant a detailed look:
- Observer System: This system is vital for cleanly separating various game logic pieces. It's a bit intricate but pays off in spades for extensibility and maintenance. Here's what it entails:
- ObservableProperty: Just as the name suggests, it's a property that triggers an action when its value changes. Setting up a new observable property is fairly straightforward, and you can bind other properties to it just as easily. Whenever a property changes, an event is fired, alerting all the listening objects.
So, anytime the value of any of the properties changes it fires an even to the listening objects. - ObservableAction: Similar in concept, this is essentially a wrapper around existing actions, making them generic. Creating and binding new actions is simple. The generic nature of these actions greatly simplifies a lot of issues, making it easier to keep the code clean and manageable.
- ObservableProperty: Just as the name suggests, it's a property that triggers an action when its value changes. Setting up a new observable property is fairly straightforward, and you can bind other properties to it just as easily. Whenever a property changes, an event is fired, alerting all the listening objects.
- State Controller: This is essentially the game's command center, coordinating all observable properties based on mouse inputs. By doing this, it enables the game to run using just a SINGLE PROCESS METHOD. What happens is the State Controller listens to mouse events, and then toggles the state of the game accordingly. This, in turn, triggers the appropriate observable properties, and thus the necessary game components, to update.
Here's a quick illustration: when you press the left mouse button, the property "IsMouseLeftDown" is set to true. This change then fires off an event to any other component that's listening for changes to this observable value. - Scene Cleanup: The UI has undergone a significant overhaul, moving from a somewhat disorganized structure to a cleaner, more modular setup. All UI components have been encapsulated into their own "PackedScenes." This approach not only tidies up the main UI scene but also localizes the functionality of each UI element.
- Building System: Hey, let's talk about the fun stuff—buildings! I managed to clean up the game behavior, which is already helping me sidestep potential bugs. Here are some of the improvements:
- Show/Hide Buildings: You know that building tab that's always on your screen? Now you can easily toggle it on and off just by tapping the same tab again. Keeps the screen cleaner and lets you focus on your game.
- Display Info: Got a small but neat update here. Now, building info will only pop up when you hover over the button, and it'll go away the moment you move the cursor out of the button's area. A small change, but makes the experience feel a lot smoother.
- Building Placement: So, now when you're dragging a building around the map, you'll actually see it where it could go. If the spot's good, the building stays visible; if not, it disappears. It's still a work-in-progress, but I'm liking where it's headed!
- Show/Hide Buildings: You know that building tab that's always on your screen? Now you can easily toggle it on and off just by tapping the same tab again. Keeps the screen cleaner and lets you focus on your game.
Up Next: Displaying Resources and Selecting Buildings
Alright, the housekeeping is done, the stage is set, and now the real fun begins! Here's what I'm diving into next:
- Displaying Resource: Let's make resources visible on the map, shall we? This way, you won't have to hover over every grid cell to find out what's there.
- Building Selection: Placing buildings is good and all, but how about clicking on them to see what they're up to? Time to add some interactivity to these static structures.
I'm pumped! Finally, I can focus on enriching the gameplay experience without the fear of breaking everything I've built so far. Let's get to it!