wolfrpg_map_parser/command/
show_text_command.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use crate::byte_utils::parse_string;
#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(PartialEq)]
pub struct ShowTextCommand {
    text: String
}

impl ShowTextCommand {
    pub(crate) fn parse(bytes: &[u8]) -> (usize, Self) {
        let mut offset: usize = 0;
        offset += 2; // Unknown, probably padding

        let (bytes_read, text): (usize, String) = parse_string(&bytes[offset..]);
        offset += bytes_read;

        offset += 1; // command end byte, should be 0x00

        (offset, Self {
            text
        })
    }

    pub fn text(&self) -> &str {
        &self.text
    }

    pub fn text_mut(&mut self) -> &mut String {
        &mut self.text
    }
}