Skip to content

Commit

Permalink
make pcb a singleton again
Browse files Browse the repository at this point in the history
  • Loading branch information
Lamby777 committed Aug 21, 2024
1 parent 25eb3f1 commit 98d85da
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
18 changes: 7 additions & 11 deletions pets-gd/scenes/rooms/cv-outdoors.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,14 @@ prompt_translation_key = "CHECK"
position = Vector2(0, 8)
scale = Vector2(1.02, 0.5)

[node name="PartyCB" type="PartyCB" parent="." index="11"]
y_sort_enabled = true

[node name="Lyembo" parent="PartyCB" index="0" instance=ExtResource("13_2on2m")]
[node name="Lyembo" parent="." index="11" instance=ExtResource("13_2on2m")]
position = Vector2(-264, -536)

[node name="CollisionPolygon2D" type="CollisionShape2D" parent="PartyCB" index="1"]
position = Vector2(-264, -504)
rotation = 1.5708
shape = SubResource("CapsuleShape2D_dljt4")

[node name="InteractionZone" parent="PartyCB" index="2" instance=ExtResource("4_vwc65")]
[node name="InteractionZone" parent="Lyembo" index="4" instance=ExtResource("4_vwc65")]
interaction_script = ExtResource("15_ndq3e")
prompt_translation_key = "TALK"
position = Vector2(-264, -536)

[node name="CollisionPolygon2D" type="CollisionShape2D" parent="Lyembo/InteractionZone" index="1"]
position = Vector2(0, 32)
rotation = 1.5708
shape = SubResource("CapsuleShape2D_dljt4")
1 change: 0 additions & 1 deletion pets-gd/scenes/world.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ libraries = {
y_sort_enabled = true

[node name="PartyCB" parent="YSort" groups=["partycb"] instance=ExtResource("2_r6tgb")]
is_npc = false
unique_name_in_owner = true

[node name="BattleIntroRect" type="ColorRect" parent="YSort/PartyCB"]
Expand Down
23 changes: 10 additions & 13 deletions pets-lib/src/world/partycb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,16 @@ impl Inputs {
/// This scene contains the "player" aka the invisible entity that is
/// moved around with WASD. It also contains party members as scenes,
/// and this script does stuff like running animations on those nodes too.
///
/// This class is not a singleton; many can exist at once. Only one should
/// be controllable by the player. The rest are NPC-controlled.
#[derive(GodotClass)]
#[class(init, base=CharacterBody2D)]
pub struct PartyCB {
base: Base<CharacterBody2D>,

/// Whether or this PCB will apply its movements to all party members' nodes
/// using `past_positions` and `past_rotations`.
#[export]
#[init(val = true)]
pub is_npc: bool,
pub controls_pchar_nodes: bool,

/// Each party member's scene node
#[var]
Expand Down Expand Up @@ -151,16 +150,17 @@ impl PartyCB {

/// Set character positions based on past pos/rot
pub fn move_chars(&mut self, moving: bool) {
if self.past_positions.len() == 0 {
// don't run if disabled or if no previous positions saved
if !self.controls_pchar_nodes || self.past_positions.len() == 0 {
return;
}

for (i, mut ch) in self.party.iter_shared().enumerate() {
// index of past data limqs
for (i, mut ch_node) in self.party.iter_shared().enumerate() {
// index of past data to get from the `LimiQ`s
let nth = i * PERSONAL_SPACE;
ch.set_global_position(*self.past_positions.get_or_last(nth));
ch_node.set_global_position(*self.past_positions.get_or_last(nth));

let mut ch = ch.bind_mut();
let mut ch = ch_node.bind_mut();
ch.anim_move(moving, *self.past_rotations.get_or_last(nth));
}
}
Expand Down Expand Up @@ -277,7 +277,7 @@ impl ICharacterBody2D for PartyCB {
fn physics_process(&mut self, delta: f64) {
let mut moving = false;

if self.can_move() && !self.is_npc {
if self.can_move() {
let inputs = Inputs::from_player_input();
moving = self.calc_movements(inputs, delta);
} else if let Some(target) = self.cutscene_motion {
Expand Down Expand Up @@ -313,9 +313,6 @@ impl ICharacterBody2D for PartyCB {
self.base_mut().emit_signal("motion_done".into(), &[]);
self.base_mut().set_global_position(target);
}

self.move_chars(moving);
return;
}

self.move_chars(moving);
Expand Down

0 comments on commit 98d85da

Please sign in to comment.