use crate::client::Client;
use crate::error::ApiError;
use std::collections::BTreeMap;
const ENDPOINT_URL: &str = "/v1/map_floor";
#[derive(Debug, Deserialize, PartialEq)]
pub struct Floor {
texture_dims: Vec<f32>,
clamped_view: Vec<Vec<f32>>,
regions: BTreeMap<u32, Region>,
}
#[derive(Debug, Deserialize, PartialEq)]
pub struct Region {
name: String,
label_coord: Vec<f32>,
continent_rect: Vec<Vec<i32>>,
maps: BTreeMap<u32, Map>
}
#[derive(Debug, Deserialize, PartialEq)]
pub struct Map {
name: String,
min_level: i32,
max_level: i32,
default_floor: i32,
#[serde(default)]
floors: Vec<i32>,
#[serde(default)]
label_coord: Vec<f32>,
#[serde(default)]
map_rect: Vec<Vec<i32>>,
#[serde(default)]
continent_rect: Vec<Vec<i32>>,
#[serde(default)]
points_of_interest: Vec<Poi>,
#[serde(default)]
god_shrines: Vec<GodShrine>,
#[serde(default)]
tasks: Vec<Task>,
#[serde(default)]
skill_challenges: Vec<SkillChallenge>,
#[serde(default)]
sectors: Vec<Sector>,
#[serde(default)]
training_points: Vec<TrainingPoint>,
#[serde(default)]
adventures: Vec<Adventure>,
}
#[derive(Debug, Deserialize, PartialEq, Hash)]
pub enum PoiType {
#[serde(rename = "landmark")]
Landmark,
#[serde(rename = "waypoint")]
Waypoint,
#[serde(rename = "vista")]
Vista,
#[serde(rename = "unlock")]
Unlock,
}
#[derive(Debug, Deserialize, PartialEq)]
pub struct Poi {
#[serde(rename = "poi_id")]
id: u32,
name: String,
#[serde(rename = "type")]
poi_type: PoiType,
floor: i32,
coord: Vec<f32>,
}
#[derive(Debug, Deserialize, PartialEq)]
pub struct Icon {
#[serde(rename = "file_id")]
id: u32,
signature: String,
}
#[derive(Debug, Deserialize, PartialEq)]
pub struct GodShrine {
id: u32,
name: String,
name_contested: String,
coord: Vec<f32>,
poi_id: u32,
icon: Icon,
icon_contested: Icon,
}
#[derive(Debug, Deserialize, PartialEq)]
pub struct Task {
#[serde(rename = "task_id")]
id: u32,
objective: String,
level: u16,
coord: Vec<f32>,
bounds: Vec<Vec<f32>>,
}
#[derive(Debug, Deserialize, PartialEq)]
pub struct SkillChallenge {
expac: u32,
#[serde(rename = "idx")]
id: u32,
coord: Vec<f32>,
}
#[derive(Debug, Deserialize, PartialEq)]
pub enum PointType {
Tyria,
Maguuma,
Desert,
Unknown,
}
#[derive(Debug, Deserialize, PartialEq)]
pub struct TrainingPoint {
id: u32,
name: String,
description: String,
coord: Vec<f32>,
#[serde(rename = "type")]
point_type: PointType,
}
#[derive(Debug, Deserialize, PartialEq)]
pub struct Adventure {
#[serde(rename = "guid")]
id: String,
coord: Vec<f32>,
name: String,
leaderboard: Leaderboard,
}
#[derive(Debug, Deserialize, PartialEq)]
pub struct Leaderboard {
#[serde(rename = "guid")]
id: String,
title: String,
description: String,
}
#[derive(Debug, Deserialize, PartialEq)]
pub struct Sector {
#[serde(rename = "sector_id")]
id: u32,
name: String,
level: u32,
coord: Vec<f32>,
bounds: Vec<Vec<f32>>,
}
impl Floor {
pub fn get_map_floor(client: &Client, continent_id: u32, floor: i32) -> Result<Floor, ApiError> {
let url = format!("{}?continent_id={}&floor={}", ENDPOINT_URL, continent_id, floor);
client.request(&url)
}
pub fn texture_dims(&self) -> &Vec<f32> {
&self.texture_dims
}
pub fn clamped_view(&self) -> &Vec<Vec<f32>> {
&self.clamped_view
}
pub fn regions(&self) -> &BTreeMap<u32, Region> {
&self.regions
}
}
impl Region {
pub fn name(&self) -> &str {
&self.name
}
pub fn label_coord(&self) -> &Vec<f32> {
self.label_coord.as_ref()
}
pub fn continent_rect(&self) -> &Vec<Vec<i32>> {
self.continent_rect.as_ref()
}
pub fn maps(&self) -> &BTreeMap<u32, Map> {
&self.maps
}
}
impl Map {
pub fn name(&self) -> &str {
&self.name
}
pub fn min_level(&self) -> i32 {
self.min_level
}
pub fn max_level(&self) -> i32 {
self.max_level
}
pub fn default_floor(&self) -> i32 {
self.default_floor
}
pub fn floors(&self) -> &Vec<i32> {
self.floors.as_ref()
}
pub fn map_rect(&self) -> &Vec<Vec<i32>> {
&self.map_rect
}
pub fn continent_rect(&self) -> &Vec<Vec<i32>> {
self.continent_rect.as_ref()
}
pub fn points_of_interest(&self) -> &Vec<Poi> {
&self.points_of_interest
}
pub fn god_shrines(&self) -> &Vec<Task> {
&self.tasks
}
pub fn tasks(&self) -> &Vec<Task> {
&self.tasks
}
pub fn skill_challenges(&self) -> &Vec<SkillChallenge> {
&self.skill_challenges
}
pub fn sectors(&self) -> &Vec<Sector> {
&self.sectors
}
pub fn training_points(&self) -> &Vec<TrainingPoint> {
&self.training_points
}
pub fn adventures(&self) -> &Vec<Adventure> {
&self.adventures
}
}
impl Poi {
pub fn id(&self) -> u32 {
self.id
}
pub fn name(&self) -> &str {
&self.name
}
pub fn poi_type(&self) -> &PoiType {
&self.poi_type
}
pub fn floor(&self) -> i32 {
self.floor
}
pub fn coord(&self) -> &Vec<f32> {
&self.coord
}
}
impl Icon {
pub fn id(&self) -> u32 {
self.id
}
pub fn signature(&self) -> &str {
&self.signature
}
}
impl GodShrine {
pub fn id(&self) -> u32 {
self.id
}
pub fn name(&self) -> &str {
&self.name
}
pub fn name_contested(&self) -> &str {
&self.name_contested
}
pub fn coord(&self) -> &Vec<f32> {
&self.coord
}
pub fn poi_id(&self) -> u32 {
self.poi_id
}
pub fn icon(&self) -> &Icon {
&self.icon
}
pub fn icon_contested(&self) -> &Icon {
&self.icon_contested
}
}
impl Task {
pub fn id(&self) -> u32 {
self.id
}
pub fn objective(&self) -> &str {
&self.objective
}
pub fn level(&self) -> u16 {
self.level
}
pub fn coord(&self) -> &Vec<f32> {
&self.coord
}
pub fn bounds(&self) -> &Vec<Vec<f32>> {
&self.bounds
}
}
impl SkillChallenge {
pub fn expac(&self) -> u32 {
self.expac
}
pub fn id(&self) -> u32 {
self.id
}
pub fn coord(&self) -> &Vec<f32> {
&self.coord
}
}
impl TrainingPoint {
pub fn id(&self) -> u32 {
self.id
}
pub fn name(&self) -> &str {
&self.name
}
pub fn description(&self) -> &str {
&self.description
}
pub fn coord(&self) -> &Vec<f32> {
&self.coord
}
pub fn point_type(&self) -> &PointType {
&self.point_type
}
}
impl Adventure {
pub fn id(&self) -> &str {
&self.id
}
pub fn coord(&self) -> &Vec<f32> {
&self.coord
}
pub fn name(&self) -> &str {
&self.name
}
pub fn leaderboard(&self) -> &Leaderboard {
&self.leaderboard
}
}
impl Leaderboard {
pub fn id(&self) -> &str {
&self.id
}
pub fn title(&self) -> &str {
&self.title
}
pub fn description(&self) -> &str {
&self.description
}
}
impl Sector {
pub fn id(&self) -> u32 {
self.id
}
pub fn name(&self) -> &str {
&self.name
}
pub fn level(&self) -> u32 {
self.level
}
pub fn coord(&self) -> &Vec<f32> {
&self.coord
}
pub fn bounds(&self) -> &Vec<Vec<f32>> {
&self.bounds
}
}
#[cfg(test)]
mod tests {
use crate::v1::map_floor::*;
use crate::client::Client;
const JSON_FLOOR: &str = r#"
{
"texture_dims": [
49152,
49152
],
"clamped_view": [
[
0,
0
],
[
38000,
48000
]
],
"regions": {
"3": {
"name": "Ruins of Orr",
"label_coord": [
13600,
25728
],
"continent_rect": [
[
10112,
22400
],
[
17792,
29312
]
],
"maps": {
"51": {
"name": "Straits of Devastation",
"min_level": 70,
"max_level": 75,
"default_floor": 1,
"label_coord": [
15920,
23808
],
"map_rect": [
[
-39936,
-33792
],
[
39936,
33792
]
],
"continent_rect": [
[
14464,
22400
],
[
17792,
25216
]
],
"points_of_interest": [
{
"poi_id": 736,
"name": "Plaza of Lost Wisdom",
"type": "landmark",
"floor": 1,
"coord": [
15529.3,
22720.4
]
},
{
"poi_id": 760,
"name": "Waywarde Waypoint",
"type": "waypoint",
"floor": 1,
"coord": [
15764.5,
24931.8
]
},
{
"poi_id": 1723,
"name": "",
"type": "vista",
"floor": 1,
"coord": [
16934.3,
23610.7
]
}
],
"god_shrines": [
{
"id": 5,
"name": "Temple of Balthazar <c=#a9a9a9>[Uncontested]</c><br>• All Balthazar statues in Orr are disabled.</c>",
"name_contested": "Temple of Balthazar <c=#ff8c00>[Contested]</c><br>• All Balthazar statues in Orr are active.",
"coord": [
15071.2,
24623.8
],
"poi_id": 762,
"icon": {
"file_id": 347219,
"signature": "61EB4505770BBC22013E4EBD60D2B878456C9712"
},
"icon_contested": {
"file_id": 347220,
"signature": "4B937E3ECA980ACD29655EA1D767DD5E0E23462F"
}
}
],
"tasks": [],
"skill_challenges": [
{
"expac": 0,
"idx": 157,
"coord": [
14611.5,
23328.9
]
}
],
"sectors": [
{
"sector_id": 692,
"name": "Shark's Teeth Archipelago",
"level": 73,
"coord": [
16620.6,
24486.7
],
"bounds": [
[
16929.7,
24499.7
],
[
16684.7,
24778.7
],
[
16476.7,
24941.7
],
[
16338.4,
24892.1
],
[
16294.6,
24586.3
],
[
16329.3,
24470.4
],
[
16166,
24305.3
],
[
16664.4,
23936.9
],
[
17100.9,
24094.1
],
[
17221.3,
24362.1
],
[
16929.7,
24499.7
]
]
}
],
"training_points": [
{
"id": 112,
"name": "",
"description": "",
"coord": [
3701.83,
18299.5
],
"type": "Maguuma"
}
],
"adventures": [
{
"guid": "8D00FA87-28CD-4402-AAEF-501A610E0447",
"coord": [
4548.5,
17730.2
],
"name": "Beetle Feast",
"leaderboard": {
"guid": "31AC0BFC-C14E-4708-91C5-EAC226D8DE7C",
"title": "Beetle Feast",
"description": "Eat yellow mushrooms to score points and blue mushrooms to gain abilities that help you in your hunt. Beware of the poisonous mushrooms with green spores, and use your burrow ability to bypass closed gates!"
}
}
]
}
}
}
}
}"#;
#[test]
fn create_floor() {
match serde_json::from_str::<Floor>(JSON_FLOOR) {
Ok(_) => assert!(true),
Err(e) => panic!(e.to_string()),
}
}
#[test]
fn get_map_floor() {
let client = Client::new();
assert!(Floor::get_map_floor(&client, 1, 1).unwrap().regions().len() > 0)
}
}