Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # GridBuilding Plugin for Godot 4.3+
- A building and targeting system for 2D Godot games using **TileMapLayer** nodes.
- ## Requirements
- - Godot 4.3 or newer
- ## Resources
- - **Tutorials:** [YouTube Playlist](https://www.youtube.com/playlist?list=PLyH-qXFkNSxl5bQkTYzMXyRwVr8Vc4Sib)
- - **Devlog Updates:** [Itch.io Devlog](https://itch.io/dashboard/game/2117450/devlog)
- - **Support:** Join the discord (link provided on purchase & in the plugin README files)
- ---
- ## Important Usage Tips
- - Use the `templates` folder to quickly add systems and the **GridPositioner** stack to your scene. Customize systems or states as needed later.
- - Add **UserAssigner** to your player and **GridNodeAssigner** to your level/world to assign runtime nodes to system states.
- - For scene design, enable grid snapping with an offset (e.g., 8x8 for 16x16 tiles) to preview collision lines.
- - Check the demo project for examples of integrating systems and resources.
- ---
- ## How the System Works
- ### Core Components
- - **BuildingSystem:** Shows previews without collision and places objects if placement is valid.
- - **PlacementValidator:** Tests defined rules to ensure placement validity across all tiles under an object.
- - **RuleCheckIndicatorManager:** Creates indicators for each tile under an object based on **TileCheckRules**, showing validity.
- - **ManipulationSystem:** Manages rotating, flipping, moving, and demolishing objects in the scene.
- - **GridTargetingSystem:** Aligns object targeting with the grid, moving indicators accordingly.
- - **GridTargetingState:** Updates the **GridPositioner** for tile-snapped positioning based on mouse movement.
- - **ManipulationParent:** Applies transforms (e.g., rotation, flipping) to selected objects and indicators.
- ### Integration
- State resources connect these systems with node references and signals. Use **UserAssigner** (on the player) and **GridStateAssigner** (on the level/world) to set references at runtime. See the demo for examples (Top-Down 2D, Platformer, Isometric).
- ---
- ## Quick Start Guide
- 1. **Backup Your Project:** Disable any old plugin in *Project Settings > Plugins*, remove the旧 `grid_builder` folder, and unzip the new plugin into `addons/grid_building`.
- 2. **Enable Plugin:** Activate it in *Project Settings > Plugins*.
- 3. **Add Templates:** Import `templates/systems.tscn` into your main scene (make it local to edit).
- 4. **Add Grid Stack:** Include `grid_positioner_stack.tscn` and set its collision mask to your target layer.
- 5. **Isometric Setup:** For isometric games, adjust the **RuleCheckIndicatorManager**’s template to `rule_check_indicator_isometric` and resize as needed.
- 6. **Set Runtime Nodes:** Add **UserAssigner** to your player and **GridStateAssigner** to your level, then assign nodes in the Inspector.
- 7. **Enable Build Mode:** Create a **Placeable** resource and use `set_buildable_preview()` on **BuildingSystem**. Or, add `placeable_selection_ui.tscn` to your UI, setting **BuildingState** and **ModeState**.
- 8. **Create Placeable:** In a new folder, make a **Placeable** resource, set its `scene_path` to a **PackedScene**, and add a tag/name/icon.
- 9. **Link UI:** Create a **CategoricalTag**, assign it to the **Placeable** and **PlaceableSelectionUI**, and add the **Placeable** to the UI’s array.
- 10. **Test UI:** Enable "Show at Start" on **PlaceableSelectionUI** or set an "Open Action" (e.g., "B") in *Project Settings > Input Map*.
- 11. **Design Scene:** Assign a 2D `.tscn` file (e.g., a building) to the **Placeable**’s `packed_scene`.
- 12. **Run Scene:** Launch with **BuildingSystem**, **GridTargetingSystem**, and **ManipulationSystem**. Use the UI to select and place objects (default build key: Enter).
- 13. **Make Manipulatable:** Add a **Manipulatable** node to an object’s scene, set its root, and configure **ManipulatableSettings** for move/rotate/flip/demolish options.
- ---
- ## Building Rules
- Rules restrict placement and are set in two places:
- - **BuildingSystem > PlacementValidator > Base Rules** (global rules).
- - **Placeable > Placement Rules** (per-object rules).
- All rules must pass for placement. Use `build_log.tscn` in your UI (with **BuildingState**) to debug rule results (`RuleResult.new(success, reason)`).
- ### Included Rules
- - **CollisionCheckRule:** Passes/fails based on collisions and `pass_on_collision`.
- - **SpendMaterialsRuleGeneric:** Spends resources from any inventory (inherit **VirtualItemContainer** for compatibility).
- - **WithinTilemapBoundsRule:** Ensures indicators cover valid **TileMap** tiles.
- - **ValidPlacementTileRule:** Verifies tile data (e.g., "buildable" custom field).
- ### Custom Rules
- Inherit **PlacementRule** or **TileCheckRule**, then override `setup()`, `validate_condition()`, and `tear_down()`. See `building_rule.gd` for method details.
- ---
- ## Manipulating Objects
- Add a **Manipulatable** node to an object’s scene, set its root, and configure **ManipulatableSettings** for move, rotate, flip, or demolish options.
- ### Overlapping Source Objects
- To move an object over its original position:
- - In **ManipulationSystem > ManipulationSettings**, enable "Disable Layer in Manipulation" and set "Disabled Physics Layer" to the source’s layer.
- - Example: See `demo_top_down.tscn`.
- ---
- ## Key Classes
- - **Placeable:** Resource defining an object for placement, including its **PackedScene** and optional rules.
- - **BuildingSystem:** Manages previews and placement, relying on **GridTargetingSystem** and **RuleCheckIndicator**.
- - **GridTargetingSystem:** Converts mouse position to tile coordinates.
- - **PlacementRule:** Base for rules blocking placement if conditions fail.
- ---
- ## Inventory (Optional Addon)
- Install at `addons/grid_building_inventory/`:
- - **ItemContainer:** Stores **BaseItemStacks** with tag filtering.
- - **BaseItemStack:** Holds a **BaseItem** and count.
- - **BaseItem:** Base resource for items (inherit for **SpendMaterialsRule**).
- - **SpendMaterialsRule:** Checks **ItemContainer** for required items.
- ---
- ## Categorical Tags
- - **CategoricalTag:** Resource with `display_name` and `icon` for categorizing **Placeable** or **BaseItem**. Store in separate folders (e.g., `placeable_tags/`).
- ---
- ## Optional Components
- Add these under your main systems (see demo):
- - **TileMapBuildingOverlay:** Overlays a tile during build mode (set via **TileSet** Atlas ID). [More Info](https://chris-tutorials.itch.io/grid-building-godot/devlog/630838/320-isometric-tilemap-support)
- - **TargetHighlighter:** Tints targets (green for valid, red for invalid).
- - **CursorChanger:** Updates cursor based on mode.
- ---
- ## Asset Credits
- See credits: [Pastebin](https://pastebin.com/HYznA3F8)
- ---
- ## FAQ
- **Q: Why do targeting/preview disappear when hovering over UI?**
- **A:** Set UI nodes’ *Mouse > Filter* to "Pass" or "Ignore." Or, uncheck "Hide On Handled" in **TargetingSettings** to always show the preview.
- ---
Advertisement
Add Comment
Please, Sign In to add comment