Skip to content

Commit 2f0e833

Browse files
authored
Better format and static type Fade (#785)
1 parent 7d58ac8 commit 2f0e833

File tree

2 files changed

+36
-36
lines changed

2 files changed

+36
-36
lines changed

addons/godot-xr-tools/effects/fade.gd

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,52 @@
22
class_name XRToolsFade
33
extends Node3D
44

5-
65
## XR Tools Fade Script
76
##
87
## This script manages fading the view.
98

10-
@export_flags_3d_render var layers = 2:
9+
@export_flags_3d_render var layers: int = 2:
1110
set(value):
1211
layers = value
1312
if _mesh:
1413
_mesh.layers = layers
1514

15+
1616
# Dictionary of fade requests
17-
var _faders : Dictionary = {}
17+
var _faders: Dictionary[Variant, Color] = {}
1818

1919
# Fade update flag
20-
var _update : bool = false
20+
var _update: bool = false
2121

2222
# Fade mesh
23-
var _mesh : MeshInstance3D
23+
var _mesh: MeshInstance3D
2424

2525
# Fade shader material
26-
var _material : ShaderMaterial
26+
var _material: ShaderMaterial
2727

2828

29-
# Add support for is_xr_class on XRTools classes
30-
func is_xr_class(xr_name: String) -> bool:
31-
return xr_name == "XRToolsFade"
29+
## Returns our first current fade node
30+
static func get_fade_node() -> XRToolsFade:
31+
# In the future this use of groups should be replaced by static instances.
32+
var tree := Engine.get_main_loop() as SceneTree
33+
for node in tree.get_nodes_in_group("fade_mesh"):
34+
var fade := node as XRToolsFade
35+
if fade:
36+
return fade
37+
38+
return null
39+
40+
41+
## Set the fade level on the fade instance
42+
static func set_fade(p_whom: Variant, p_color: Color) -> void:
43+
# In the future this use of groups should be replaced by static instances.
44+
var tree := Engine.get_main_loop() as SceneTree
45+
for node in tree.get_nodes_in_group("fade_mesh"):
46+
var fade := node as XRToolsFade
47+
if fade:
48+
fade.set_fade_level(p_whom, p_color)
3249

3350

34-
# Called when the fade node is ready
3551
func _ready() -> void:
3652
# Add to the fade_mesh group - in the future this should be replaced with
3753
# static instances.
@@ -44,15 +60,15 @@ func _ready() -> void:
4460
_material = _mesh.get_surface_override_material(0)
4561

4662

47-
# Called every frame. 'delta' is the elapsed time since the previous frame.
48-
func _process(_delta : float) -> void:
63+
func _process(_delta: float) -> void:
4964
# Skip if nothing to update
5065
if not _update:
5166
return
5267

5368
# Calculate the cumulative shade color
5469
var fade := Color(1, 1, 1, 0)
5570
var show := false
71+
5672
for whom in _faders:
5773
var color := _faders[whom] as Color
5874
fade = fade.blend(color)
@@ -64,8 +80,13 @@ func _process(_delta : float) -> void:
6480
_update = false
6581

6682

67-
# Set the fade level
68-
func set_fade_level(p_whom : Variant, p_color : Color) -> void:
83+
## Add support for is_xr_class on XRTools classes
84+
func is_xr_class(xr_name: String) -> bool:
85+
return xr_name == "XRToolsFade"
86+
87+
88+
## Set the fade level
89+
func set_fade_level(p_whom: Variant, p_color: Color) -> void:
6990
# Test if fading is needed
7091
if p_color.a > 0:
7192
# Set the fade level
@@ -74,24 +95,3 @@ func set_fade_level(p_whom : Variant, p_color : Color) -> void:
7495
elif _faders.erase(p_whom):
7596
# Fade erased
7697
_update = true
77-
78-
79-
## Returns our first current fade node
80-
static func get_fade_node() -> XRToolsFade:
81-
# In the future this use of groups should be replaced by static instances.
82-
var tree := Engine.get_main_loop() as SceneTree
83-
for node in tree.get_nodes_in_group("fade_mesh"):
84-
var fade := node as XRToolsFade
85-
if fade:
86-
return fade
87-
88-
return null
89-
90-
## Set the fade level on the fade instance
91-
static func set_fade(p_whom : Variant, p_color : Color) -> void:
92-
# In the future this use of groups should be replaced by static instances.
93-
var tree := Engine.get_main_loop() as SceneTree
94-
for node in tree.get_nodes_in_group("fade_mesh"):
95-
var fade := node as XRToolsFade
96-
if fade:
97-
fade.set_fade_level(p_whom, p_color)

addons/godot-xr-tools/effects/fade.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ shader_parameter/albedo = Color(0, 0, 0, 1)
1414

1515
[node name="Fade" type="Node3D"]
1616
script = ExtResource("1_6667f")
17-
cull_mask = 1
1817

1918
[node name="FadeMesh" type="MeshInstance3D" parent="."]
2019
visible = false
20+
layers = 2
2121
mesh = SubResource("QuadMesh_aqp6r")
2222
surface_material_override/0 = SubResource("ShaderMaterial_xjgy8")

0 commit comments

Comments
 (0)