class_name EraseTool extends EditorTool ## Deletes an object, or clears a tile back to id 0 (the reserved empty/air ## id -- world.md ยง3.2 / TileDef doc comment). ## ## `args`: either `{"object_id": ...}` to delete an object, or ## `{"layer", "x", "y", "z"}` to clear a tile (delegates to BrushTool with ## `tile_id = 0` so both paths share one undo/redo implementation). func _init() -> void: tool_id = "erase" func apply(core: EditorCore, args: Dictionary) -> Variant: if args.has("object_id"): return _erase_object(core, args["object_id"]) return _erase_tile(core, args) func _erase_object(core: EditorCore, object_id: String) -> bool: var idx: int = core.model.get_object_index(object_id) if idx == -1: return false var obj: ChunkDataDecoder.WorldObjectData = core.model.payload.objects[idx] core.undo_redo.begin("Delete '%s'" % object_id) core.undo_redo.add_do(core.model.remove_object_raw.bind(object_id)) core.undo_redo.add_undo(core.model.insert_object_raw.bind(obj, idx)) core.undo_redo.commit() if core.selection.get_selected() == object_id: core.selection.clear() return true func _erase_tile(core: EditorCore, args: Dictionary) -> bool: var brush: EditorTool = core.tools.get_tool("brush") var tile_args: Dictionary = args.duplicate() tile_args["tile_id"] = 0 return bool(brush.apply(core, tile_args))