Skip to content

Commit 603a066

Browse files
committed
spaghettification (both pcb and pcharnode have cutscene motions)
1 parent d1df9b0 commit 603a066

File tree

3 files changed

+51
-16
lines changed

3 files changed

+51
-16
lines changed

pets-gd/quests/intro1.gd

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ func _ready():
77
for pchar in ["Ethan", "Siva", "Terra", "Mira"]:
88
pcb().push_pchar_gd(pchar)
99

10+
# pcb().in_cutscene = true
11+
# pcb().party[0].move_to_relative(0.0, -200.0)
12+
# await pcb().party[0].motion_done
13+
# pcb().in_cutscene = false
1014
pcb().move_to_relative(0.0, -200.0)
1115
await pcb().motion_done
1216

pets-lib/src/world/partycb.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ pub struct PartyCB {
7171
/// Whether or this PCB will apply its movements to all party members' nodes
7272
/// using `past_positions` and `past_rotations`.
7373
#[export]
74-
#[init(val = true)]
75-
pub controls_pchar_nodes: bool,
74+
#[init(val = false)]
75+
pub in_cutscene: bool,
7676

7777
/// Each party member's scene node
7878
#[var]
@@ -90,27 +90,25 @@ pub struct PartyCB {
9090
pub tpbeacon_debounce: bool,
9191
pub in_water: bool,
9292

93-
/// if the player is currently being controlled by a script,
94-
/// this is the location the player is being moved to
95-
pub cutscene_motion: Option<Vector2>,
96-
9793
#[init(val = 1.0)]
9894
pub water_speed_mod: real,
95+
96+
pub cutscene_motion: Option<Vector2>,
9997
}
10098

10199
#[godot_api]
102100
impl PartyCB {
103101
#[signal]
104102
fn teleported(&self, target: Gd<Node2D>);
105103

104+
#[signal]
105+
fn motion_done(&self);
106+
106107
#[func]
107108
pub fn singleton() -> Gd<Self> {
108109
World::singleton().get_node_as("%PartyCB")
109110
}
110111

111-
#[signal]
112-
fn motion_done(&self);
113-
114112
#[func]
115113
pub fn move_to_absolute(&mut self, x: real, y: real) {
116114
let end = Vector2::new(x, y);
@@ -159,7 +157,8 @@ impl PartyCB {
159157
|| InventoryNode::singleton().bind().is_open()
160158
|| self.is_in_battle()
161159
|| self.tpbeacon_debounce
162-
|| self.cutscene_motion.is_some();
160+
|| self.cutscene_motion.is_some()
161+
|| self.in_cutscene;
163162

164163
!cant_move
165164
}
@@ -171,7 +170,7 @@ impl PartyCB {
171170
/// Set character positions based on past pos/rot
172171
pub fn move_chars(&mut self, moving: bool) {
173172
// don't run if disabled or if no previous positions saved
174-
if !self.controls_pchar_nodes || self.past_positions.len() == 0 {
173+
if self.in_cutscene || self.past_positions.len() == 0 {
175174
return;
176175
}
177176

pets-lib/src/world/pchar_node.rs

+37-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ use godot::classes::{
55
use godot::prelude::*;
66

77
use crate::common::*;
8+
use crate::consts::partycb::MAX_SPEED;
9+
10+
use super::partycb::{Inputs, CUTSCENE_MOTION_CLOSE_ENOUGH};
811

912
#[derive(GodotClass)]
1013
#[class(init, base=Node2D)]
@@ -30,13 +33,14 @@ pub struct PCharNode {
3033
#[init(val = OnReady::manual())]
3134
anim_state: OnReady<Gd<AnimationNodeStateMachinePlayback>>,
3235

33-
/// if the player is currently being controlled by a script,
34-
/// this is the location the player is being moved to
3536
pub cutscene_motion: Option<Vector2>,
3637
}
3738

3839
#[godot_api]
3940
impl PCharNode {
41+
#[signal]
42+
fn motion_done(&self);
43+
4044
#[func]
4145
pub fn anim_move(&mut self, moving: bool, inputs: Vector2) {
4246
// change the animationtree state machine to the correct mode
@@ -63,6 +67,19 @@ impl PCharNode {
6367
.iter_shared()
6468
.any(|area| area.is_in_group("water".into()))
6569
}
70+
71+
#[func]
72+
pub fn move_to_absolute(&mut self, x: real, y: real) {
73+
self.cutscene_motion = Some(Vector2::new(x, y));
74+
}
75+
76+
#[func]
77+
pub fn move_to_relative(&mut self, x: real, y: real) {
78+
let end = Vector2::new(x, y);
79+
let start = self.base().get_global_position();
80+
let total = start + end;
81+
self.cutscene_motion = Some(total);
82+
}
6683
}
6784

6885
#[godot_api]
@@ -73,7 +90,22 @@ impl INode2D for PCharNode {
7390
self.anim_state.init(anim_state);
7491
}
7592

76-
// fn physics_process(&mut self, delta: f64) {
77-
// if let Some(target) = self.cutscene_motion {}
78-
// }
93+
fn physics_process(&mut self, delta: f64) {
94+
if let Some(target) = self.cutscene_motion {
95+
let own_pos = self.base().get_global_position();
96+
let input_vector = Inputs::iv_from_to(own_pos, target);
97+
98+
self.base_mut().set_global_position(
99+
own_pos + input_vector * MAX_SPEED * delta as real,
100+
);
101+
102+
self.anim_move(true, input_vector);
103+
104+
if (target - own_pos).length() < CUTSCENE_MOTION_CLOSE_ENOUGH {
105+
self.cutscene_motion = None;
106+
self.base_mut().emit_signal("motion_done".into(), &[]);
107+
self.base_mut().set_global_position(target);
108+
}
109+
}
110+
}
79111
}

0 commit comments

Comments
 (0)