Posted October 18, 2023 by Chris' Tutorials
#patch notes #Devlog #Grid Building System #Godot 4
The main focus on this update was overhauling the generation of indicators from a single template set on the building system based on the rules that are set in the placement validator (Resource defined on building system) and Placeable specific rules optionally defined in each Placeable resource file. No longer do each rule that deals with collisions have to have their own indicator template. You simply define a mask to find the collision objects for indicator generation and then a mask to evaluate the rules using the indicators. Where rules overlap positions, tile indicators are shared but each rule is evaluated seperately (for instance, an indicator can check for collisions and also that it is above a valid tilemap tile as seperate rules but for the same indicator space. In such a case, the indicator would check both rules to determine if it is valid when all rules set are valid first)
To have extra fail textures to represent different rules having a failing result, you can define IndicatorVisualSettings in each rule and set a priority to determine which settings show in case of multiple failures (Highest failing priority number shows). This means there is no real need for multiple indicator templates and hopefully simplifies setting up rules for now and the future.
RuleCheckIndicator - Direct replacement to TileCollisionIndicator. A shape cast 2D that evaluates it's "valid" property based on evaluating the assigned rules. These rules are assigned automatically when the system creates indicators for rules when selecting a new placeable & preview instance (test object before the placement). In the template scene or your own RuleCheckIndicator scene, you will want to define success and fail IndicatorVisualSettings to set corresponding textures and modulate colors (By default this would be a green square for success and a red square for failure).
TileCheckRule - For any rule that needs to access collision shapes and RuleCheckIndicators to test the placement location against the tilemap and game world, a tile check rule lets you do that by defining a Match Collision Objects Mask. When the building system creates a preview instance, rules will be assigned to each collision object (Physics Objects, Area 2Ds, etc) based on matching their physics layers.
RuleValidationParameters - The details to test placement rules against for validating whether a Placeable object can place into the scene at the target location. Currently used to pass placer, preview_instance, placeable, and building_signal_bus into the placement validator and any rules setup in that validator (Base Rules of the validation + placeable specific rules you define on each Placeable resource). If you define a BuildingRule, you can use these fields in setup(params) to have more information in evaluating your rule logic at validate_condition() time.
When the rule evaluates (either for individual indicators or all of the found and assigned indicators for the build, it will do so using the rule mask. For instance, if you have a CollisionCheckRule that has the Rule Mask on layer 1, then the rule will check collisions against layer 1 for each RuleCheckIndicator, then it will be able to evaluate the rule true or false for the indicators depending on if pass_on_collision is set true or false (With this property, you can use a CollisionCheckRule to expect there to be collisions or not to be collisions for the final RuleResult to be successful.
Did a fair bit of unit testing against the system to knock out some bugs and improve the code. There could be more to find so if you happen to run into any problems. Let me know and I'll be happy to add futher tests to find them.
Now that I have the plugin again in a good state I'm happy with, I can turn to tutorials for Grid Builder, World Time, Item Drops plugins and general Godot GameDev tutorials again.