-
-
Save Yardanico/ce7202ee0de5c512ce9c0cd9c895ae0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ReplayAction = struct { | |
time_since_previous: i64 = undefined, | |
x: f32 = undefined, | |
y: f32 = undefined, | |
key_mouse_set: i32 = undefined, | |
fn init(data: []const u8) !ReplayAction { | |
var res = ReplayAction{}; | |
// w | x | y | z | |
var i: usize = 0; | |
var current_var: usize = 0; | |
while (i < data.len) { | |
const start = i; | |
while (i < data.len and isDigit(data[i])) : (i += 1) {} | |
// Parse the neccesary field | |
if (start != i) { | |
switch (current_var) { | |
0 => res.time_since_previous = try fmt.parseInt(i64, data[start..i], 10), | |
1 => res.x = try fmt.parseFloat(f32, data[start..i]), | |
2 => res.y = try fmt.parseFloat(f32, data[start..i]), | |
3 => res.key_mouse_set = try fmt.parseInt(i32, data[start..i], 10), | |
else => return error.InvalidReplayFile, | |
} | |
current_var += 1; | |
} | |
i += 1; | |
} | |
return res; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment