Skip to content

Commit

Permalink
use strings for room teleportation to avoid cycle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Lamby777 committed Jun 14, 2024
1 parent f932fdb commit db39de3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 37 deletions.
2 changes: 1 addition & 1 deletion pets-gd/scenes/char/LYEMBO.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ states/Wade/position = Vector2(433, 247)
transitions = ["Idle", "Run", SubResource("AnimationNodeStateMachineTransition_ji4br"), "Start", "Idle", SubResource("AnimationNodeStateMachineTransition_q0w5r"), "Run", "Idle", SubResource("AnimationNodeStateMachineTransition_hpdl1"), "Idle", "Wade", SubResource("AnimationNodeStateMachineTransition_xnsgn"), "Wade", "Idle", SubResource("AnimationNodeStateMachineTransition_6f020"), "Wade", "Run", SubResource("AnimationNodeStateMachineTransition_gx0ab"), "Run", "Wade", SubResource("AnimationNodeStateMachineTransition_4a04c")]
graph_offset = Vector2(-79, 13)

[node name="DYLAN" instance=ExtResource("1_y7x8p")]
[node name="LYEMBO" instance=ExtResource("1_y7x8p")]

[node name="Sprite2D" parent="." index="0"]
texture = ExtResource("2_wy23g")
Expand Down
1 change: 1 addition & 0 deletions pets-gd/scenes/rooms/cv-houses.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ layer_2/tile_data = PackedInt32Array(6, 65538, 1, 5, 65538, 1, 4, 65538, 1, 3, 6
layer_3/tile_data = PackedInt32Array(131076, 65537, 1, 65540, 65537, 1, 4, 65537, 1, -65532, 65537, 1, -131068, 65537, 1, 131075, 65537, 1, 65539, 65537, 1, 3, 65537, 1, -65533, 65537, 1, -131069, 65537, 1, 131074, 65537, 1, 65538, 65537, 1, 2, 65537, 1, -65534, 65537, 1, -131070, 65537, 1, 131073, 65537, 1, 65537, 65537, 1, 1, 65537, 1, -65535, 65537, 1, -131071, 65537, 1, 131072, 65537, 1, 65536, 65537, 1, 0, 65537, 1, -65536, 65537, 1, -131072, 65537, 1, 196607, 65537, 1, 131071, 65537, 1, 65535, 65537, 1, -1, 65537, 1, -65537, 65537, 1, 196606, 65537, 1, 131070, 65537, 1, 65534, 65537, 1, -2, 65537, 1, -65538, 65537, 1, 196605, 65537, 1, 131069, 65537, 1, 65533, 65537, 1, -3, 65537, 1, -65539, 65537, 1, 196604, 65537, 1, 131068, 65537, 1, 65532, 65537, 1, -4, 65537, 1, -65540, 65537, 1, 196603, 65537, 1, 131067, 65537, 1, 65531, 65537, 1, -5, 65537, 1, -65541, 65537, 1, -65542, 1, 1, -6, 1, 1, 65530, 1, 1, 131066, 1, 1, 196602, 1, 1, 262140, 65537, 2, 262139, 65537, 2, 262138, 1, 2, 262141, 65537, 2, 262142, 65537, 2, 262143, 65537, 2, 196608, 65537, 2, 196609, 65537, 2, 196610, 65537, 2, 196611, 65537, 2, 196612, 65537, 2, -131067, 131073, 1, -65531, 131073, 1, 5, 131073, 1, 65541, 131073, 1, 131077, 131073, 1, 196613, 131073, 2, -131077, 65537, 0, -131076, 65537, 0, -131075, 65537, 0, -131074, 65537, 0, -131073, 65537, 0, -196608, 65537, 0, -196607, 65537, 0, -196606, 65537, 0, -196605, 65537, 0, -196604, 65537, 0, -196603, 131073, 0, -131078, 1, 0)

[node name="Entrance" parent="." index="1" instance=ExtResource("2_flkym")]
beacon_room_name = "cv-outdoors"
beacon_target = "House"
position = Vector2(-416, 32)
scale = Vector2(0.5, 0.5)
5 changes: 2 additions & 3 deletions pets-gd/scenes/rooms/cv-outdoors.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
[gd_scene load_steps=8 format=3 uid="uid://c7x12nyqelw1f"]
[gd_scene load_steps=7 format=3 uid="uid://c7x12nyqelw1f"]

[ext_resource type="PackedScene" uid="uid://pefjtfxt6buk" path="res://scenes/rooms/_Base.tscn" id="1_ls6vf"]
[ext_resource type="PackedScene" uid="uid://dk214wpitbhju" path="res://scenes/walking_enemy.tscn" id="2_2qq46"]
[ext_resource type="PackedScene" uid="uid://xena0e3suwve" path="res://scenes/water_zone.tscn" id="3_bqhqn"]
[ext_resource type="PackedScene" uid="uid://2i16xk27wro6" path="res://scenes/interaction_zone.tscn" id="4_vwc65"]
[ext_resource type="PackedScene" uid="uid://hflql51x7i61" path="res://scenes/rooms/cv-houses.tscn" id="5_oqps0"]
[ext_resource type="PackedScene" uid="uid://q3osyj42bsr4" path="res://scenes/builds/bush_long.tscn" id="5_txn6p"]
[ext_resource type="PackedScene" uid="uid://drxvvfvnc7awr" path="res://scenes/builds/rodrick_sign.tscn" id="6_eminc"]

Expand All @@ -28,7 +27,7 @@ function_name = "debug_skill"
position = Vector2(-192, 64)

[node name="House" parent="." index="4" instance=ExtResource("4_vwc65")]
beacon_target_scene = ExtResource("5_oqps0")
beacon_room_name = "cv-houses"
beacon_target = "Entrance"
position = Vector2(-32, 896)
scale = Vector2(0.5, 0.5)
Expand Down
46 changes: 24 additions & 22 deletions pets-gd/scenes/world.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ _data = {
"crossfade": SubResource("Animation_k4si3")
}

[sub_resource type="ShaderMaterial" id="ShaderMaterial_uyk0u"]
shader = ExtResource("2_6uro0")
shader_parameter/opacity = 0.0

[sub_resource type="ShaderMaterial" id="ShaderMaterial_3xdh0"]
shader = ExtResource("3_a3d4r")
shader_parameter/DEBUG_MODE = false
Expand All @@ -85,6 +81,10 @@ shader_parameter/start_time = 0.0
shader_parameter/current_time = 0.0
shader_parameter/rand_mod = Vector2(1, 1)

[sub_resource type="ShaderMaterial" id="ShaderMaterial_uyk0u"]
shader = ExtResource("2_6uro0")
shader_parameter/opacity = 0.0

[node name="Overworld" type="World"]
battle_scene = ExtResource("1_37bcu")

Expand All @@ -102,24 +102,6 @@ libraries = {
"": SubResource("AnimationLibrary_fv7du")
}

[node name="UILayer" type="CanvasLayer" parent="."]

[node name="BeaconFade" type="ColorRect" parent="UILayer"]
unique_name_in_owner = true
top_level = true
material = SubResource("ShaderMaterial_uyk0u")
offset_right = 1920.0
offset_bottom = 1080.0
color = Color(0, 0, 0, 1)

[node name="Inventory" parent="UILayer" instance=ExtResource("3_jwkdy")]
unique_name_in_owner = true
visible = false

[node name="DialogBox" parent="UILayer" instance=ExtResource("2_lgtmm")]

[node name="WorldMenu" parent="UILayer" instance=ExtResource("2_6orff")]

[node name="InteractionManager" parent="." instance=ExtResource("2_uh12s")]
unique_name_in_owner = true

Expand All @@ -143,6 +125,26 @@ script = ExtResource("4_jple0")

[node name="Room" parent="YSort" instance=ExtResource("10_kug7e")]

[node name="UILayer" type="CanvasLayer" parent="."]

[node name="BeaconFade" type="ColorRect" parent="UILayer"]
unique_name_in_owner = true
top_level = true
material = SubResource("ShaderMaterial_uyk0u")
offset_right = 1920.0
offset_bottom = 1080.0
color = Color(0, 0, 0, 1)

[node name="Inventory" parent="UILayer" instance=ExtResource("3_jwkdy")]
unique_name_in_owner = true
visible = false

[node name="DialogBox" parent="UILayer" instance=ExtResource("2_lgtmm")]
offset_left = -704.0
offset_right = 704.0

[node name="WorldMenu" parent="UILayer" instance=ExtResource("2_6orff")]

[node name="Quests" type="Node" parent="."]
process_mode = 4

Expand Down
26 changes: 15 additions & 11 deletions pets-lib/src/world/interaction/zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct InteractionZone {

#[export]
/// The scene the beacon belongs to
beacon_target_scene: Option<Gd<PackedScene>>,
beacon_room_name: GString,

#[export]
/// The beacon this one sends you to
Expand Down Expand Up @@ -64,7 +64,7 @@ impl InteractionZone {

let target = &self.beacon_target;
if !target.is_empty() {
self.tp_player_to_beacon(target, self.beacon_target_scene.as_ref());
self.tp_player_to_beacon(target, &self.beacon_room_name);
}
}

Expand Down Expand Up @@ -93,14 +93,12 @@ impl InteractionZone {
.unregister_zone(self.to_gd());
}

fn tp_player_to_beacon(
&self,
target: &GString,
target_scene: Option<&Gd<PackedScene>>,
) {
fn tp_player_to_beacon(&self, target: &GString, target_scene: &GString) {
let target = target.to_string();
let black = current_scene().get_node_as::<ColorRect>("%BeaconFade");
let target_scene =
Some(target_scene.to_string()).filter(|s| !s.is_empty());

let black = current_scene().get_node_as::<ColorRect>("%BeaconFade");
fade_black(&black, true, TP_BEACON_BLACK_IN);

{
Expand All @@ -115,8 +113,12 @@ impl InteractionZone {

let black_id = black.instance_id();

let scene_id =
target_scene.map(|s| s.instantiate().unwrap().instance_id());
let scene_id = target_scene.map(|s| {
load::<PackedScene>(format!("res://scenes/rooms/{}.tscn", s))
.instantiate()
.unwrap()
.instance_id()
});

set_timeout(TP_BEACON_BLACK_IN, move || {
// once the screen is black, swap rooms if necessary
Expand All @@ -135,7 +137,9 @@ impl InteractionZone {
let target_pos = target_node.get_global_position();

// after the screen is black, teleport the player
pcb().bind_mut().teleport(target_pos, None, false);
// clear past positions if switching rooms
let switching_rooms = scene_id.is_some();
pcb().bind_mut().teleport(target_pos, None, switching_rooms);

set_timeout(TP_BEACON_BLACK_HOLD, move || {
// when it's time to fade the black away, do it.
Expand Down

0 comments on commit db39de3

Please sign in to comment.