Struct vault::Replay
[−]
[src]
pub struct Replay { pub error: Option<String>, pub version: u16, pub game_type: String, pub date_time: String, pub map: Map, pub players: Vec<Player>, pub commands: HashMap<u8, Vec<Command>>, pub duration: u32, pub rng_seed: u32, pub opponent_type: u32, pub chat: Vec<ChatLine>, // some fields omitted }
The main Replay
type, contains all currently parsed replay data. Can be serialized to JSON
for output using rustc_serialize
.
Fields
error: Option<String>
If parsing failed, this will contain an error string
version: u16
Game engine version
game_type: String
Game type (i.e. Automatch/Annihilate)
date_time: String
Timestamp encoded in replay file
map: Map
Map this game was played on
players: Vec<Player>
Players involved in the game
commands: HashMap<u8, Vec<Command>>
Commands issued per player
duration: u32
Game length in seconds
rng_seed: u32
Internal RNG seed used by game engine
opponent_type: u32
Type of opponent (1 = human, 2 = cpu)
chat: Vec<ChatLine>
List of chat messages sent during replay
Methods
impl Replay
[src]
fn new(path: &Path, config: Config) -> Result<Replay>
Constructs a new Replay
and loads the file specified by path into memory.
Examples
extern crate vault; use vault::Replay; use vault::Config; use std::path::Path; let path = Path::new("/path/to/replay.rec"); let config = Config::default(); let replay = Replay::new(&path, config).unwrap();
fn new_with_error(name: &str, err: Error) -> Replay
Constructs a junk Replay
type with empty data and an error value set. Used to return a
Replay
and its error information out of a thread without panicking if an error was
encountered during creation.
Examples
extern crate vault; use vault::Replay; match Replay::new("/path/to/replay.rec") { Ok(replay) => replay, Err(err) => Replay::with_new_error(err), }
fn from_bytes(name: &str, bytes: Vec<u8>, config: Config) -> Result<Replay>
Constructs a new Replay
and loads the byte vector given as the file data.
Examples
extern crate vault; extern crate zip; use vault::Replay; use vault::Config; use std::ops::Deref; use std::path::Path; use zip::read::{ZipArchive, ZipFile}; let path = Path::new("/path/to/archive.zip"); let config = Config::default(); let name = path.to_string_lossy(); let name = name.deref(); let file = File::open(&path).unwrap(); let archive = ZipArchive::new(file).unwrap(); let mut buff: Vec<u8> = Vec::with_capacity(replay_file.size() as usize); let mut replay_file = archive.by_index(0).unwrap(); replay_file.read_to_end(&mut buff).unwrap(); let mut replay = Replay::from_bytes(&name, buff, config).unwrap(); replay.parse();
fn parse(&mut self)
Parses the loaded replay and populates the Replay
type with the return data.
When the replay has finished being parsed, the vector of byte data loaded into memory from file is dropped. This is done to clean up the resulting type in order to make working with the output easier. The file cursor property remains, however, and is an accurate representation of the size of the replay file in bytes.
Examples
extern crate vault; use vault::Replay; use vault::Config; use std::path::Path; let path = Path::new("/path/to/replay.rec"); let config = Config::default(); let replay = Replay::new(&path, config).unwrap(); replay.parse(); // You can serialize the Replay type to JSON after parsing if you would like to print // replay data to stdout or write it to a file. // let encoded = replay.to_json().unwrap(); println!("{}", encoded);