Skip to content

Commit f0f09c9

Browse files
committed
Integrate with loom interaction
1 parent 1bfa329 commit f0f09c9

13 files changed

Lines changed: 543 additions & 261 deletions

File tree

scenes/game_elements/fx/spirograph/components/spirograph.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ func _process(_delta: float) -> void:
5252

5353
func trail(global_pos: Vector2) -> void:
5454
if not line.get_point_count():
55-
line.add_point(global_pos)
55+
line.add_point(line.to_local(global_pos))
5656
else:
5757
var last_p := line.points[-1]
5858
if last_p.distance_squared_to(global_pos) < min_points_distance:
5959
line.remove_point(0)
6060
return
61-
line.add_point(global_pos)
61+
line.add_point(line.to_local(global_pos))
6262
while line.get_point_count() > max_points:
6363
line.remove_point(0)

scenes/game_elements/fx/stitcher/components/stitcher.gd

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ class_name Stitcher
44
extends Node2D
55

66
@export var line: Line2D
7-
@export_range(50, 150, 1.0, "suffix:px") var width: float = 50
7+
@export_range(0, 150, 1.0, "suffix:px") var width: float = 50
88
@export_range(0, 1, 0.01) var stitches_per_second: float = 0.03
99
@export_range(0, 1, 0.01) var direction_update: float = 0.1
10+
@export var on_floor: bool = true
1011
@export var min_points_distance := 40
1112
@export var max_points := 100
1213

@@ -18,27 +19,40 @@ var stitch_sign := 1
1819

1920
func _process(delta: float) -> void:
2021
var diff := Vector2.ZERO if not last_pos else last_pos - global_position
21-
last_pos = global_position
2222
var normal := diff.orthogonal().normalized()
23-
stitch_direction = lerp(stitch_direction, normal * Vector2(1, 0.5), direction_update)
23+
if on_floor:
24+
normal *= Vector2(1, 0.5)
25+
stitch_direction = lerp(stitch_direction, normal, direction_update)
2426

2527
if last_stitch_seconds < stitches_per_second:
2628
last_stitch_seconds += delta
2729
return
2830
last_stitch_seconds = 0
2931

30-
trail(global_position + (stitch_direction * width / 2) * stitch_sign)
31-
stitch_sign *= -1
32+
trail(global_position)
3233

3334

3435
func trail(global_pos: Vector2) -> void:
36+
var new_p := global_position + (stitch_direction * width / 2) * stitch_sign
3537
if not line.get_point_count():
36-
line.add_point(global_pos)
38+
line.add_point(line.to_local(new_p))
39+
stitch_sign *= -1
40+
last_pos = global_position
3741
else:
38-
var last_p := line.points[-1]
39-
if last_p.distance_squared_to(global_pos) < min_points_distance:
42+
if last_pos.distance_squared_to(global_pos) < min_points_distance:
4043
line.remove_point(0)
4144
return
42-
line.add_point(global_pos)
45+
line.add_point(line.to_local(new_p))
46+
stitch_sign *= -1
47+
last_pos = global_position
4348
while line.get_point_count() > max_points:
4449
line.remove_point(0)
50+
51+
52+
func _notification(what: int) -> void:
53+
match what:
54+
NOTIFICATION_ENABLED:
55+
last_pos = Vector2.ZERO
56+
last_stitch_seconds = 0
57+
stitch_direction = Vector2.ZERO
58+
stitch_sign = 1

scenes/game_elements/fx/world_reweaven/components/world_reweaven_test.gd renamed to scenes/game_elements/fx/world_reweaven/components/cutscene.gd

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
# SPDX-FileCopyrightText: The Threadbare Authors
22
# SPDX-License-Identifier: MPL-2.0
3+
class_name Cutscene
34
extends Node2D
45

5-
@onready var animation_player: AnimationPlayer = %AnimationPlayer
6+
signal finished
67

7-
@onready var shaker: Shaker = %Shaker
8+
@onready var animation_player: AnimationPlayer = %AnimationPlayer
89

910

1011
func _ready() -> void:
11-
await get_tree().create_timer(2.).timeout
12-
shaker.shake()
1312
animation_player.play("reweaven")
1413
await animation_player.animation_finished
15-
SceneSwitcher.reload_with_transition(Transition.Effect.FADE, Transition.Effect.FADE)
14+
finished.emit()

scenes/game_elements/fx/world_reweaven/components/world_reweaven_test.gd.uid renamed to scenes/game_elements/fx/world_reweaven/components/cutscene.gd.uid

File renamed without changes.

scenes/game_elements/fx/world_reweaven/components/spirograph_test.tscn

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
[gd_scene format=3 uid="uid://c6mikotrke4mc"]
22

3-
[ext_resource type="Texture2D" uid="uid://756pdnslep0q" path="res://scenes/game_elements/fx/world_reweaven/components/string.png" id="1_k0a1w"]
43
[ext_resource type="PackedScene" uid="uid://bs32ac1yj83ub" path="res://scenes/game_elements/fx/spirograph/spirograph.tscn" id="3_h26y6"]
54
[ext_resource type="Script" uid="uid://c4oww6rkbqfxc" path="res://scenes/game_elements/fx/stitcher/components/stitcher.gd" id="4_5l8d3"]
65

76
[sub_resource type="GDScript" id="GDScript_0e48y"]
87
script/source = "extends Node2D
98

9+
@onready var mouse_tracker: Node2D = %MouseTracker
1010
@onready var spirograph_mouse: Spirograph = %SpirographMouse
11+
@onready var stitcher_mouse: Stitcher = %StitcherMouse
1112

1213
func _process(_delta: float) -> void:
1314
var mouse_pos := get_global_mouse_position()
14-
spirograph_mouse.global_position = lerp(spirograph_mouse.global_position, mouse_pos, 0.1)
15-
#var new_pos := spirograph_mouse.global_position.move_toward(mouse_pos, 5.0)
16-
#new_pos = lerp(new_pos, mouse_pos, 0.1)
17-
#spirograph_mouse.global_position = new_pos
15+
mouse_tracker.global_position = lerp(mouse_tracker.global_position, mouse_pos, 0.1)
16+
17+
func _unhandled_input(event: InputEvent) -> void:
18+
if event is not InputEventMouseButton:
19+
return
20+
if event.pressed:
21+
spirograph_mouse.process_mode = Node.PROCESS_MODE_DISABLED
22+
spirograph_mouse.visible = false
23+
stitcher_mouse.process_mode = Node.PROCESS_MODE_INHERIT
24+
stitcher_mouse.visible = true
25+
else:
26+
spirograph_mouse.process_mode = Node.PROCESS_MODE_INHERIT
27+
spirograph_mouse.visible = true
28+
stitcher_mouse.process_mode = Node.PROCESS_MODE_DISABLED
29+
stitcher_mouse.visible = false
1830
"
1931

2032
[sub_resource type="Animation" id="Animation_0hol4"]
@@ -43,17 +55,16 @@ tracks/1/keys = {
4355
"update": 0,
4456
"values": [0.0]
4557
}
46-
tracks/2/type = "value"
58+
tracks/2/type = "bezier"
4759
tracks/2/imported = false
4860
tracks/2/enabled = true
49-
tracks/2/path = NodePath("StitchTest/Path2D/PathFollow2D:progress_ratio")
61+
tracks/2/path = NodePath("StitchTest/Path2D/PathFollow2D:progress")
5062
tracks/2/interp = 1
5163
tracks/2/loop_wrap = true
5264
tracks/2/keys = {
53-
"times": PackedFloat32Array(0),
54-
"transitions": PackedFloat32Array(1),
55-
"update": 0,
56-
"values": [0.0]
65+
"handle_modes": PackedInt32Array(0),
66+
"points": PackedFloat32Array(0, -0.25, 0, 0.25, 0),
67+
"times": PackedFloat32Array(0)
5768
}
5869

5970
[sub_resource type="Animation" id="Animation_epypp"]
@@ -85,17 +96,16 @@ tracks/1/keys = {
8596
"update": 0,
8697
"values": [0.0, 1.0]
8798
}
88-
tracks/2/type = "value"
99+
tracks/2/type = "bezier"
89100
tracks/2/imported = false
90101
tracks/2/enabled = true
91-
tracks/2/path = NodePath("StitchTest/Path2D/PathFollow2D:progress_ratio")
102+
tracks/2/path = NodePath("StitchTest/Path2D/PathFollow2D:progress")
92103
tracks/2/interp = 1
93104
tracks/2/loop_wrap = true
94105
tracks/2/keys = {
95-
"times": PackedFloat32Array(0, 0.5, 1.6, 2.1, 3.2, 3.7, 4.6, 5.1, 6),
96-
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1, 1),
97-
"update": 0,
98-
"values": [0.0, 0.26666668, 0.26666668, 0.53333336, 0.53333336, 0.76666665, 0.76666665, 1.0, 1.0]
106+
"handle_modes": PackedInt32Array(0, 0, 0, 0, 0, 0, 0, 0, 0),
107+
"points": PackedFloat32Array(0, -0.25, 0, 0.25, 0, 338.0688, -0.25, 0, 0.25, 0, 338.0688, -0.25, 0, 0.25, 0, 702.7635, -0.25, 0, 0.25, 0, 702.7635, -0.25, 0, 0.25, 0, 1070.8698, -0.25, 0, 0.25, 0, 1070.8698, -0.25, 0, 0.25, 0, 1441.0135, -0.25, 0, 0.25, 0, 1441.0135, -0.25, 0, 0.25, 0),
108+
"times": PackedFloat32Array(0, 1.1261708, 1.3764602, 2.6011987, 2.851488, 4.152527, 4.402816, 5.7497106, 6)
99109
}
100110

101111
[sub_resource type="AnimationLibrary" id="AnimationLibrary_0hol4"]
@@ -111,7 +121,7 @@ point_count = 3
111121

112122
[sub_resource type="Curve2D" id="Curve2D_5l8d3"]
113123
_data = {
114-
"points": PackedVector2Array(0, 0, 0, 0, 505, 108, 0, 0, 0, 0, 856, 407, 0, 0, 0, 0, 492, 693, 0, 0, 0, 0, 210, 398, 0, 0, 0, 0, 505, 108)
124+
"points": PackedVector2Array(0, 0, 0, 0, 555, 253, 0, 0, 0, 0, 856, 407, 0, 0, 0, 0, 532, 571, 0, 0, 0, 0, 210, 398, 0, 0, 0, 0, 555, 253)
115125
}
116126
point_count = 5
117127

@@ -132,29 +142,34 @@ autoplay = &"default"
132142

133143
[node name="Line2D" type="Line2D" parent="MouseTest" unique_id=1593087933]
134144
texture_repeat = 2
135-
position = Vector2(3, -1)
145+
width = 3.0
136146
width_curve = SubResource("Curve_k0a1w")
137-
texture = ExtResource("1_k0a1w")
138-
texture_mode = 2
139147
joint_mode = 2
140148

141-
[node name="SpirographMouse" parent="MouseTest" unique_id=812965254 node_paths=PackedStringArray("line") instance=ExtResource("3_h26y6")]
149+
[node name="MouseTracker" type="Node2D" parent="MouseTest" unique_id=1967144198]
142150
unique_name_in_owner = true
143-
position = Vector2(742, 340)
144-
line = NodePath("../Line2D")
151+
152+
[node name="SpirographMouse" parent="MouseTest/MouseTracker" unique_id=812965254 node_paths=PackedStringArray("line") instance=ExtResource("3_h26y6")]
153+
unique_name_in_owner = true
154+
line = NodePath("../../Line2D")
145155
radius = 44.0
146156
max_vel = 100.0
147-
radius_update = 0.03
148157
debug = true
149158

159+
[node name="StitcherMouse" type="Node2D" parent="MouseTest/MouseTracker" unique_id=782158258 node_paths=PackedStringArray("line")]
160+
unique_name_in_owner = true
161+
process_mode = 4
162+
script = ExtResource("4_5l8d3")
163+
line = NodePath("../../Line2D")
164+
stitches_per_second = 0.01
165+
metadata/_custom_type_script = "uid://c4oww6rkbqfxc"
166+
150167
[node name="SimpleTest" type="Node2D" parent="." unique_id=1650676841]
151168

152169
[node name="Line2D" type="Line2D" parent="SimpleTest" unique_id=625975575]
153170
texture_repeat = 2
154-
position = Vector2(3, -1)
171+
width = 3.0
155172
width_curve = SubResource("Curve_k0a1w")
156-
texture = ExtResource("1_k0a1w")
157-
texture_mode = 1
158173
joint_mode = 2
159174

160175
[node name="Spirograph" parent="SimpleTest" unique_id=1097706612 node_paths=PackedStringArray("line") instance=ExtResource("3_h26y6")]
@@ -167,32 +182,34 @@ debug = true
167182

168183
[node name="Line2D" type="Line2D" parent="StitchTest" unique_id=214318953]
169184
texture_repeat = 2
170-
position = Vector2(3, -1)
171-
texture = ExtResource("1_k0a1w")
172-
texture_mode = 1
185+
width = 3.0
186+
width_curve = SubResource("Curve_k0a1w")
173187
joint_mode = 2
174188

175189
[node name="Path2D" type="Path2D" parent="StitchTest" unique_id=1459786898]
190+
position = Vector2(393, 118)
176191
curve = SubResource("Curve2D_5l8d3")
177192

178193
[node name="PathFollow2D" type="PathFollow2D" parent="StitchTest/Path2D" unique_id=1080902156]
179-
position = Vector2(505, 108)
194+
position = Vector2(555, 253)
180195
rotation = 0.70556813
181196
rotates = false
182197

183198
[node name="Stitcher" type="Node2D" parent="StitchTest/Path2D/PathFollow2D" unique_id=1460959262 node_paths=PackedStringArray("line")]
184199
script = ExtResource("4_5l8d3")
185200
line = NodePath("../../../Line2D")
201+
stitches_per_second = 0.0
202+
direction_update = 0.09
203+
min_points_distance = 20
204+
max_points = 40
186205
metadata/_custom_type_script = "uid://c4oww6rkbqfxc"
187206

188207
[node name="PathTest" type="Node2D" parent="." unique_id=1542033045]
189208

190209
[node name="Line2D" type="Line2D" parent="PathTest" unique_id=479563041]
191210
texture_repeat = 2
192-
position = Vector2(3, -1)
211+
width = 3.0
193212
width_curve = SubResource("Curve_k0a1w")
194-
texture = ExtResource("1_k0a1w")
195-
texture_mode = 1
196213
joint_mode = 2
197214

198215
[node name="Path2D" type="Path2D" parent="PathTest" unique_id=452573456]

scenes/game_elements/fx/world_reweaven/components/string.png

Lines changed: 0 additions & 3 deletions
This file was deleted.

scenes/game_elements/fx/world_reweaven/components/string.png.import

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)