generated from krampus/template-godot4
37 lines
869 B
GDScript3
37 lines
869 B
GDScript3
|
class_name ToolMount extends Node3D
|
||
|
## Access controller for the player's active & available tools
|
||
|
|
||
|
@export var initial_tool: Tool
|
||
|
|
||
|
var _active: Tool
|
||
|
|
||
|
|
||
|
func _ready() -> void:
|
||
|
set_active(initial_tool)
|
||
|
|
||
|
|
||
|
## Returns the currently-active tool.
|
||
|
func get_active() -> Tool:
|
||
|
return _active
|
||
|
|
||
|
|
||
|
## Sets the given tool as active.
|
||
|
##
|
||
|
## The tool should be a child of this mount.
|
||
|
func set_active(tool: Tool) -> void:
|
||
|
for c: Node3D in get_children():
|
||
|
c.visible = false
|
||
|
# TODO unequip animation?
|
||
|
_active = tool
|
||
|
_active.visible = true
|
||
|
# TODO equip animation?
|
||
|
|
||
|
|
||
|
## Sets the active tool by index relative to the currently-active tool.
|
||
|
##
|
||
|
## Use this for "select next/prev tool" functions.
|
||
|
func set_active_relative(delta: int) -> void:
|
||
|
var active_idx := _active.get_index()
|
||
|
var new_idx := wrapi(active_idx + delta, 0, get_child_count())
|
||
|
set_active(get_child(new_idx) as Tool)
|