Skip to content

Commit

Permalink
Add new functons to WorldPosition and WorldPosition2
Browse files Browse the repository at this point in the history
  • Loading branch information
vE5li committed May 20, 2024
1 parent 24bee0d commit c0c3a9b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ragnarok_packets/src/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ pub struct WorldPosition {
pub y: usize,
}

impl WorldPosition {
pub fn new(x: usize, y: usize) -> Self {
Self { x, y }
}
}

impl FromBytes for WorldPosition {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
let coordinates: Vec<usize> = byte_stream.slice::<Self>(3)?.iter().map(|byte| *byte as usize).collect();
Expand Down Expand Up @@ -41,6 +47,10 @@ pub struct WorldPosition2 {
}

impl WorldPosition2 {
pub fn new(x1: usize, y1: usize, x2: usize, y2: usize) -> Self {
Self { x1, y1, x2, y2 }
}

pub fn to_origin_destination(self) -> (WorldPosition, WorldPosition) {
(WorldPosition { x: self.x1, y: self.y1 }, WorldPosition {
x: self.x2,
Expand Down

0 comments on commit c0c3a9b

Please sign in to comment.