mod ability;
mod action;
mod buff;
mod game;
mod image;
mod player;
mod score;
mod unit;
mod upgrade;
mod map_info;
use na;
use na::geometry;
use sc2_proto::{common, raw, sc2api};
use super::{FromProto, IntoSc2, Result};
pub use self::ability::{Ability, AbilityData};
pub use self::action::{
Action,
ActionTarget,
DebugAabb,
DebugCommand,
DebugLine,
DebugSphere,
DebugText,
DebugTextTarget,
};
pub use self::buff::{Buff, BuffData};
pub use self::game::{GameResult, GameSetup, Map, PlayerResult};
pub use self::image::ImageData;
pub use self::map_info::MapInfo;
pub use self::player::{Difficulty, PlayerSetup, Race};
pub use self::score::Score;
pub use self::unit::{Alliance, DisplayType, Tag, Unit, UnitType, UnitTypeData};
pub use self::upgrade::{Upgrade, UpgradeData};
pub type Color = (u8, u8, u8);
#[derive(Debug, Copy, Clone)]
pub struct Rect<T> {
pub x: T,
pub y: T,
pub w: T,
pub h: T,
}
pub type Vector2 = na::Vector2<f32>;
pub type Vector3 = na::Vector3<f32>;
pub type Point2 = geometry::Point2<f32>;
pub type Point3 = geometry::Point3<f32>;
#[derive(Debug, Copy, Clone)]
pub struct Rect2 {
pub from: Point2,
pub to: Point2,
}
impl Rect2 {
pub fn get_dimensions(&self) -> (f32, f32) {
(self.to.x - self.from.x, self.to.y - self.from.y)
}
}
pub type Point2I = na::Vector2<i32>;
#[derive(Debug, Copy, Clone)]
pub struct Rect2I {
pub from: Point2I,
pub to: Point2I,
}
#[allow(missing_docs)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum Visibility {
Hidden,
Fogged,
Visible,
FullHidden,
}
#[derive(Debug, Clone)]
pub struct EffectData {
effect: Ability,
name: String,
friendly_name: String,
radius: f32,
}
#[derive(Debug, Clone)]
pub struct Effect {
effect: Ability,
positions: Vec<Point2>,
}
#[derive(Debug, Copy, Clone)]
pub struct PowerSource {
tag: Tag,
pos: Point2,
radius: f32,
}
impl From<raw::PowerSource> for PowerSource {
fn from(source: raw::PowerSource) -> Self {
Self {
tag: source.get_tag(),
pos: {
let pos = source.get_pos();
Point2::new(pos.get_x(), pos.get_y())
},
radius: source.get_radius(),
}
}
}
#[derive(Debug, Copy, Clone)]
pub struct ReplayPlayerInfo {
player_id: u32,
mmr: i32,
apm: i32,
race: Race,
race_selected: Option<Race>,
game_result: Option<GameResult>,
}
impl FromProto<sc2api::PlayerInfoExtra> for ReplayPlayerInfo {
fn from_proto(info: sc2api::PlayerInfoExtra) -> Result<Self> {
Ok(Self {
player_id: info.get_player_info().get_player_id(),
race: info.get_player_info().get_race_actual().into_sc2()?,
race_selected: {
if info.get_player_info().has_race_requested() {
let proto_race =
info.get_player_info().get_race_requested();
if proto_race != common::Race::NoRace {
Some(proto_race.into_sc2()?)
} else {
None
}
} else {
None
}
},
mmr: info.get_player_mmr(),
apm: info.get_player_apm(),
game_result: {
if info.has_player_result() {
Some(info.get_player_result().get_result().into_sc2()?)
} else {
None
}
},
})
}
}
#[derive(Debug, Clone)]
pub struct ReplayInfo {
map_name: String,
map_path: String,
game_version: String,
data_version: String,
duration: f32,
duration_steps: u32,
data_build: u32,
base_build: u32,
players: Vec<ReplayPlayerInfo>,
}
impl FromProto<sc2api::ResponseReplayInfo> for ReplayInfo {
fn from_proto(mut info: sc2api::ResponseReplayInfo) -> Result<Self> {
Ok(Self {
map_name: info.take_map_name(),
map_path: info.take_local_map_path(),
game_version: info.take_game_version(),
data_version: info.take_data_version(),
duration: info.get_game_duration_seconds(),
duration_steps: info.get_game_duration_loops(),
data_build: info.get_data_build(),
base_build: info.get_base_build(),
players: {
let mut player_info = vec![];
for p in info.take_player_info().into_iter() {
player_info.push(p.into_sc2()?);
}
player_info
},
})
}
}