Skip to content

Commit

Permalink
Rename player_idx (index) to player_id
Browse files Browse the repository at this point in the history
  • Loading branch information
Yarwin committed Oct 2, 2024
1 parent d24ad70 commit 042b0a1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
18 changes: 8 additions & 10 deletions examples/multiplayer-bomber/rust/src/bomb_spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use godot::prelude::*;
#[derive(Debug)]
pub struct BombArgs {
position: Vector2,
player_idx: i64,
player_id: i64,
}

impl BombArgs {
pub fn new(position: Vector2, player_idx: i64) -> Self {
pub fn new(position: Vector2, player_id: i64) -> Self {
Self {
position,
player_idx,
player_id,
}
}
}
Expand All @@ -28,15 +28,13 @@ impl FromGodot for BombArgs {
.get(0)
.ok_or(ConvertError::new("couldn't find position for bomb spawn!"))?
.try_to::<Vector2>()?;
let player_idx = via
let player_id = via
.get(1)
.ok_or(ConvertError::new(
"couldn't find player idx for bomb spawn!",
))?
.ok_or(ConvertError::new("couldn't find player id for bomb spawn!"))?
.try_to::<i64>()?;
Ok(Self {
position,
player_idx,
player_id,
})
}
}
Expand All @@ -45,7 +43,7 @@ impl ToGodot for BombArgs {
type ToVia<'v> = VariantArray where Self: 'v;

fn to_godot(&self) -> Self::ToVia<'_> {
varray![self.position.to_variant(), self.player_idx.to_variant()]
varray![self.position.to_variant(), self.player_id.to_variant()]
}
}

Expand Down Expand Up @@ -79,7 +77,7 @@ impl BombSpawner {
panic!("couldn't instantiate bomb scene!")
};
bomb.set_position(args.position);
bomb.bind_mut().from_player = args.player_idx;
bomb.bind_mut().from_player = args.player_id;
bomb
}
}
10 changes: 5 additions & 5 deletions examples/multiplayer-bomber/rust/src/game_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl GameState {
let Some(world) = self.game_board.as_mut() else {
panic!("no game board!")
};
for (i, (player_idx, player_name)) in self.players.iter().enumerate() {
for (i, (player_id, player_name)) in self.players.iter().enumerate() {
let spawn_marker = world
.bind_mut()
.spawn_points
Expand All @@ -197,8 +197,8 @@ impl GameState {
panic!("Couldn't instantiate player scene!")
};
player.bind_mut().synced_position = spawn_marker.get_position();
player.bind_mut().player_idx = *player_idx;
player.set_name(GString::from(player_idx.to_string()));
player.bind_mut().player_id = *player_id;
player.set_name(GString::from(player_id.to_string()));
world.bind_mut().players.add_child(&player);
player.bind_mut().label.set_text(player_name.clone());
}
Expand All @@ -221,12 +221,12 @@ impl GameState {
.unwrap()
.add_child(&world);

for (player_idx, player_name) in self.players.iter() {
for (player_id, player_name) in self.players.iter() {
world
.bind_mut()
.score
.bind_mut()
.add_player(*player_idx, player_name.clone());
.add_player(*player_id, player_name.clone());
}
self.game_board = Some(world);
self.base().get_tree().unwrap().set_pause(false);
Expand Down
8 changes: 4 additions & 4 deletions examples/multiplayer-bomber/rust/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct Player {
#[export]
pub synced_position: Vector2,
#[export]
pub player_idx: i32,
pub player_id: i32,
last_bomb_time: f64,
#[init(val = OnReady::manual())]
multiplayer: OnReady<Gd<MultiplayerApi>>,
Expand All @@ -39,12 +39,12 @@ impl ICharacterBody2D for Player {
self.base_mut().set_position(pos);
self.multiplayer
.init(self.base().get_multiplayer().unwrap());
self.inputs_sync.set_multiplayer_authority(self.player_idx);
self.inputs_sync.set_multiplayer_authority(self.player_id);
}

fn physics_process(&mut self, delta: f64) {
if self.multiplayer.get_multiplayer_peer().is_none()
|| self.multiplayer.get_unique_id() == self.player_idx
|| self.multiplayer.get_unique_id() == self.player_id
{
self.inputs.bind_mut().update();
}
Expand All @@ -61,7 +61,7 @@ impl ICharacterBody2D for Player {
{
self.last_bomb_time = 0.0;
let bomb_args =
BombArgs::new(self.base().get_position(), self.player_idx as i64).to_variant();
BombArgs::new(self.base().get_position(), self.player_id as i64).to_variant();
GameState::singleton().emit_signal("spawn_bomb".into(), &[bomb_args]);
}
} else {
Expand Down

0 comments on commit 042b0a1

Please sign in to comment.