sm64_binds/sm64/
game_state.rs1#[derive(Debug)]
2pub struct GameState {
3 pub num_stars: i32,
4 pub pos: [f32; 3],
5 pub vel: [f32; 3],
6 pub lakitu_pos: [f32; 3],
7 pub lakitu_yaw: i32,
8 pub in_credits: i32,
9 pub course_num: i32,
10 pub act_num: i32,
11 pub area_index: i32,
12}
13
14impl GameState {
15 pub fn new(data: &[u8]) -> GameState {
16 let mut offset = 0;
17
18 let num_stars = i32::from_le_bytes(data[offset..offset + 4].try_into().unwrap());
19 offset += 4;
20
21 let pos = [
22 f32::from_le_bytes(data[offset..offset + 4].try_into().unwrap()),
23 f32::from_le_bytes(data[offset + 4..offset + 8].try_into().unwrap()),
24 f32::from_le_bytes(data[offset + 8..offset + 12].try_into().unwrap()),
25 ];
26 offset += 12;
27
28 let vel = [
29 f32::from_le_bytes(data[offset..offset + 4].try_into().unwrap()),
30 f32::from_le_bytes(data[offset + 4..offset + 8].try_into().unwrap()),
31 f32::from_le_bytes(data[offset + 8..offset + 12].try_into().unwrap()),
32 ];
33 offset += 12;
34
35 let lakitu_pos = [
36 f32::from_le_bytes(data[offset..offset + 4].try_into().unwrap()),
37 f32::from_le_bytes(data[offset + 4..offset + 8].try_into().unwrap()),
38 f32::from_le_bytes(data[offset + 8..offset + 12].try_into().unwrap()),
39 ];
40 offset += 12;
41
42 let lakitu_yaw = i32::from_le_bytes(data[offset..offset+4].try_into().unwrap());
43 offset += 4;
44
45 let in_credits = i32::from_le_bytes(data[offset..offset+4].try_into().unwrap());
46 offset += 4;
47
48 let course_num = i32::from_le_bytes(data[offset..offset+4].try_into().unwrap());
49 offset += 4;
50
51 let act_num = i32::from_le_bytes(data[offset..offset+4].try_into().unwrap());
52 offset += 4;
53
54 let area_index = i32::from_le_bytes(data[offset..offset+4].try_into().unwrap());
55
56 GameState {
58 num_stars,
59 pos,
60 vel,
61 lakitu_pos,
62 lakitu_yaw,
63 in_credits,
64 course_num,
65 act_num,
66 area_index,
67 }
68 }
69
70 pub fn has_won(&self) -> bool {
71 self.num_stars > 0
72 }
73
74 pub fn to_string(&self) -> String {
75 format!(
76 "GameState {{\n\
77 numStars: {},\n\
78 position: ({}, {}, {}),\n\
79 velocity: ({}, {}, {}),\n\
80 lakituPosition: ({}, {}, {}),\n\
81 lakituYaw: {},\n\
82 inCredits: {},\n\
83 courseNum: {},\n\
84 actNum: {},\n\
85 areaIndex: {}\n\
86 }}",
87 self.num_stars,
88 self.pos[0], self.pos[1], self.pos[2],
89 self.vel[0], self.vel[1], self.vel[2],
90 self.lakitu_pos[0], self.lakitu_pos[1], self.lakitu_pos[2],
91 self.lakitu_yaw,
92 self.in_credits,
93 self.course_num,
94 self.act_num,
95 self.area_index,
96 )
97 }
98}