Dev Log: Save System Updated
The save system has been expanded to capture all farm data, including plants! I was able to accomplish this by leveraging the logic used in the environment and inventory save processes. This made the update relatively easy, even though the requirements were more complex than the other save elements.
The main components of the farm data are the build nodes and the grid system. The build nodes include structures like light towers, plant containers, and active plants. The grid stores data used to determine if a space is available to build and if a plant container is getting enough light.
Loaded plants
I started with just the build nodes, which behave similar to the environment nodes within the save system. The light towers were fairly straightforward and only required a single dictionary to capture the build type, global position, and light variables. The plant containers needed a similar dictionary, as well as an array of dictionaries for the plants. This turned out to be very similar to capturing active mobs and resources in the environment save process, although each plant dictionary required more data in order to preserve the growth cycle.
To make the system flexible, I added a dictionary and an array to each build, regardless of the type. The dictionary holds the basic build data and the array is either null, or contains plant data dictionaries. This allows me to aggregate all the farm data into an array of arrays and process each subarray with the same function upon loading. If the plant array is not null, the load function proceeds with loading the plants. If it is null, it skips that step and moves to the next build.
Saving the grid was actually very easy. I used the same logic applied to the inventory system and pulled a copy of the occupied tile and light tile arrays (farm grids). These were added to the beginning of the aggregate farm array, with occupied tiles always being at index 0 and light tiles always being at index 1. The aggregate farm array is then saved to the data file.
To load the farm, I again was able to leverage the existing environment and inventory load logic. First, I pull the occupied tile and light tile arrays out of the aggregate farm array and use them to set the global values (same as the inventory process). This leaves me with an array of subarrays that represent each of the builds. I can then use the environment load logic to instantiate each build, including any plant subscenes.
Even though this save system update was fairly simple, I struggled with the plants due to having several unnecessary @onready calls in the plant scenes, which would override the data I set while loading each plant. Now that those have been corrected, I believe this system can be scaled to include many different types of plants.
That concludes my update on the save system, and I don’t anticipate any further changes until I run into errors. After making those changes, I was also able to add a simple pause menu to the game (not worth a separate dev log).
The upcoming development tasks are to finish building out the quick slot/inventory functionality (set quick slots, move items, delete items), add dash, revisit control bindings, then finally start playtesting the controls.
Pause Menu