Add check_reference helper

This commit is contained in:
JonShard
2026-08-20 11:46:00 +02:00
parent 6432dca31a
commit a79096eb1d
14 changed files with 45 additions and 54 deletions
+2 -4
View File
@@ -23,10 +23,8 @@ var _pending_absorb: Array[Node3D] = []
func _ready() -> void: func _ready() -> void:
area_3d.body_entered.connect(_on_body_entered) area_3d.body_entered.connect(_on_body_entered)
if not area_3d: Helper.check_reference(self, area_3d, Area3D)
SweetLogger.warning("{0} missing area_3d reference", [name]) Helper.check_reference(self, xr_pickable, XRToolsPickable)
if not xr_pickable:
SweetLogger.warning("{0} missing xr_pickable reference", [name])
# Absorbing items is a server decision (the container's holder is server- # Absorbing items is a server decision (the container's holder is server-
+1 -2
View File
@@ -29,5 +29,4 @@ func get_food_items() -> Array[FoodItem]:
return container.contained_items return container.contained_items
func _ready() -> void: func _ready() -> void:
if not dirty_node: Helper.check_reference(self, dirty_node, Node3D)
SweetLogger.warning("{0} missing dirty_node reference", [name])
+1 -4
View File
@@ -14,14 +14,11 @@ var _food_item: FoodItem
func _ready() -> void: func _ready() -> void:
SweetLogger.debug("{0} ready", [_pickable.name]) SweetLogger.debug("{0} ready", [_pickable.name])
_food_item = get_parent().get_node_or_null("FoodItem") as FoodItem _food_item = get_parent().get_node_or_null("FoodItem") as FoodItem
if not _food_item:
SweetLogger.warning("{0} missing FoodItem reference, must be a sibling of a FoodItem", [get_parent().name])
if not _pickable: if not _pickable:
SweetLogger.error("{0} must be a grandchild of an XRToolsPickable", [get_parent().name]) SweetLogger.error("{0} must be a grandchild of an XRToolsPickable", [get_parent().name])
return return
if not _food_item: if not Helper.check_reference(get_parent(), _food_item, FoodItem):
SweetLogger.warning("{0} requires a FoodItem sibling", [_pickable.name])
return return
if not enabled: if not enabled:
return return
+1 -2
View File
@@ -5,5 +5,4 @@ extends Node
@export var turns_into: PackedScene @export var turns_into: PackedScene
func _ready() -> void: func _ready() -> void:
if not turns_into: Helper.check_reference(self, turns_into, PackedScene)
SweetLogger.warning("{0} missing turns_into reference", [name])
+1 -3
View File
@@ -5,9 +5,7 @@ extends Node3D
func _ready() -> void: func _ready() -> void:
Helper.check_reference(self, kitchen_scene, PackedScene)
if not kitchen_scene:
SweetLogger.warning("{0} missing kitchen_scene reference", [name])
SweetLogger.debug("->[]") SweetLogger.debug("->[]")
+3 -6
View File
@@ -12,12 +12,9 @@ extends WorkStation
func _ready() -> void: func _ready() -> void:
super.ready() super.ready()
SweetLogger.debug("Counter {0} _ready", [name]) SweetLogger.debug("Counter {0} _ready", [name])
if not audio: Helper.check_reference(self, audio, AudioStreamPlayer3D)
SweetLogger.warning("{0} missing audio reference", [name]) Helper.check_reference(self, chop_audio, AudioStream)
if not chop_audio: Helper.check_reference(self, knife, XRToolsPickable)
SweetLogger.warning("{0} missing chop_audio reference", [name])
if not knife:
SweetLogger.warning("{0} missing knife reference", [name])
_disable_all_tools() _disable_all_tools()
+1 -2
View File
@@ -9,8 +9,7 @@ extends WorkStation
func _ready() -> void: func _ready() -> void:
super.ready() super.ready()
SweetLogger.debug("Hob {0} _ready", [name]) SweetLogger.debug("Hob {0} _ready", [name])
if not animation_player: Helper.check_reference(self, animation_player, AnimationPlayer)
SweetLogger.warning("{0} missing animation_player reference", [name])
func _start_cooking(id: String, work: float) -> void: func _start_cooking(id: String, work: float) -> void:
animation_player.play("hob") animation_player.play("hob")
+1 -2
View File
@@ -7,8 +7,7 @@ extends Station
func _ready() -> void: func _ready() -> void:
super.ready() super.ready()
SweetLogger.debug("ItemDispenser {0} _ready", [name]) SweetLogger.debug("ItemDispenser {0} _ready", [name])
if not item_scene: Helper.check_reference(self, item_scene, PackedScene)
SweetLogger.warning("{0} missing item_scene reference", [name])
func _process(delta: float) -> void: func _process(delta: float) -> void:
+3 -6
View File
@@ -38,12 +38,9 @@ func _on_station_bought(_instance: Node3D):
func _ready() -> void: func _ready() -> void:
SweetLogger.debug("->[]") SweetLogger.debug("->[]")
if not station: Helper.check_reference(self, station, StaticBody3D)
SweetLogger.warning("{0} missing station reference", [name]) Helper.check_reference(self, move_handle, XRToolsPickable)
if not move_handle: Helper.check_reference(self, move_ghost, Area3D)
SweetLogger.warning("{0} missing move_handle reference", [name])
if not move_ghost:
SweetLogger.warning("{0} missing move_ghost reference", [name])
move_handle_rigid = move_handle as RigidBody3D move_handle_rigid = move_handle as RigidBody3D
original_collision_layer = station.collision_layer original_collision_layer = station.collision_layer
+8 -10
View File
@@ -152,19 +152,15 @@ func _enter_tree() -> void:
func _ready() -> void: func _ready() -> void:
super.ready() super.ready()
if not label_3d: Helper.check_reference(self, label_3d, Label3D)
SweetLogger.warning("{0} missing label_3d reference", [name]) Helper.check_reference(self, label_3d_time, Label3D)
if not label_3d_time: Helper.check_reference(self, progress_bar, ProgressBar3D)
SweetLogger.warning("{0} missing label_3d_time reference", [name])
if not progress_bar or progress_bar is not ProgressBar3D:
SweetLogger.warning("{0} missing progress_bar reference", [name])
progress_bar.y_billboard = true progress_bar.y_billboard = true
progress_bar.exponential = true progress_bar.exponential = true
# Render whatever state already arrived from the server before we were in # Render whatever state already arrived from the server before we were in
# the tree (see the guard in _refresh_display). # the tree (see the guard in _refresh_display).
_refresh_display.call_deferred() _refresh_display.call_deferred()
if not audio_player: Helper.check_reference(self, audio_player, AudioStreamPlayer3D)
SweetLogger.warning("{0} missing audio_player reference", [name])
# Get snap_zones for plates, store in array snap_zones # Get snap_zones for plates, store in array snap_zones
for child in get_children(): for child in get_children():
@@ -371,8 +367,10 @@ func _refresh_display() -> void:
# tree — so these setters fire while the @onready children below are still # tree — so these setters fire while the @onready children below are still
# null. Bail out until _ready() has resolved them; _ready() calls back in # null. Bail out until _ready() has resolved them; _ready() calls back in
# once it has, so nothing that arrived early is lost. # once it has, so nothing that arrived early is lost.
if not progress_bar or not label_3d or not label_3d_time: var a := Helper.check_reference(self, progress_bar, ProgressBar3D)
SweetLogger.warning("{0} missing progress_bar or label reference", [name]) var b := Helper.check_reference(self, label_3d, Label3D)
var c := Helper.check_reference(self, label_3d_time, Label3D)
if not (a and b and c):
return return
match _state: match _state:
TableState.IDLE: TableState.IDLE:
+1 -2
View File
@@ -9,8 +9,7 @@ class_name ProgressBar3D
func _ready() -> void: func _ready() -> void:
if not progress_bar: Helper.check_reference(self, progress_bar, ProgressBar)
SweetLogger.warning("{0} missing progress_bar reference", [name])
if y_billboard: if y_billboard:
$Sprite3D.billboard = BaseMaterial3D.BillboardMode.BILLBOARD_FIXED_Y $Sprite3D.billboard = BaseMaterial3D.BillboardMode.BILLBOARD_FIXED_Y
+4 -8
View File
@@ -39,14 +39,10 @@ func _enter_tree() -> void:
# The child station has to call super.ready() for this to be called # The child station has to call super.ready() for this to be called
func ready() -> void: func ready() -> void:
SweetLogger.debug("Station {0} ready", [name]) SweetLogger.debug("Station {0} ready", [name])
if not notification_audio: Helper.check_reference(self, notification_audio, AudioStreamPlayer3D)
SweetLogger.warning("{0} missing notification_audio reference", [name]) Helper.check_reference(self, ambient_audio, AudioStreamPlayer3D)
if not ambient_audio: Helper.check_reference(self, snap_zone, XRToolsSnapZone)
SweetLogger.warning("{0} missing ambient_audio reference", [name]) Helper.check_reference(self, synchronizer, MultiplayerSynchronizer)
if not snap_zone:
SweetLogger.warning("{0} missing snap_zone reference", [name])
if not synchronizer:
SweetLogger.warning("{0} missing synchronizer reference", [name])
# Disable if we're not the server. # Disable if we're not the server.
if not NetworkManager.owns_world(): if not NetworkManager.owns_world():
enabled = false enabled = false
+1 -2
View File
@@ -32,8 +32,7 @@ func _enter_tree() -> void:
# The child station has to call super.ready() for this to be called # The child station has to call super.ready() for this to be called
func ready() -> void: func ready() -> void:
super.ready() super.ready()
if not progress_bar: Helper.check_reference(self, progress_bar, ProgressBar3D)
SweetLogger.warning("{0} missing progress_bar reference", [name])
# The child station has to call super.process(delta) for this to be called # The child station has to call super.process(delta) for this to be called
+16
View File
@@ -72,6 +72,22 @@ static func get_node_from_path(from: Node, node_path: NodePath) -> Node3D:
static func check_reference(node: Node, ref: Variant, type: Variant) -> bool:
if is_instance_valid(ref) and is_instance_of(ref, type):
return true
var type_name: String
if type is Script:
type_name = type.get_global_name()
else:
var probe: Object = type.new()
type_name = probe.get_class()
if not (probe is RefCounted):
probe.free()
SweetLogger.warning("{0} missing reference {1} ({2})", [node.name, type_name, _get_caller_label()])
return false
static func play_sound(player: AudioStreamPlayer3D, stream: AudioStream, pitch_scale: float = 1): static func play_sound(player: AudioStreamPlayer3D, stream: AudioStream, pitch_scale: float = 1):
if not player: if not player:
SweetLogger.warning("{0}: AudioStreamPlayer3D is null, can not play sound", [_get_caller_label()]) SweetLogger.warning("{0}: AudioStreamPlayer3D is null, can not play sound", [_get_caller_label()])