gw2api 0.2.0

A sort-of well-documented and WIP wrapper over the Guild Wars 2 API
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
use crate::client::Client;
use crate::error::ApiError;

use std::collections::BTreeMap;

const ENDPOINT_URL: &str = "/v1/map_floor";

/// Struct containing details about a specified map floor. All coordinates are map coordinates.
#[derive(Debug, Deserialize, PartialEq)]
pub struct Floor {
    /// Tuple describing the dimensions of the texture for the map floor.
    texture_dims: Vec<f32>,
    /// If present, it represents a rectangle of downloadable textures. Every tile coordinate outside this rectangle is not available on the tile server.
    clamped_view: Vec<Vec<f32>>,
    /// A map of the regions of a map, where the region id is the key and the region object is the
    /// value.
    regions: BTreeMap<u32, Region>,
}

/// Struct containing information about a region of a map.
#[derive(Debug, Deserialize, PartialEq)]
pub struct Region {
    /// Region name.
    name: String,
    /// The coordinates of the region label.
    label_coord: Vec<f32>,
    /// Dimensions of the region, given as the coordinates of the lower-left (SW) and upper-right (NE)
    /// corners.
    continent_rect: Vec<Vec<i32>>,
    /// Mapping from the map id to an object.
    maps: BTreeMap<u32, Map>
}

/// Struct containing information about a maps in the game, including information about floor and
/// translation data on how to translate between world coordinates and map coordinates.
#[derive(Debug, Deserialize, PartialEq)]
pub struct Map {
    /// Name of the map.
    name: String,
    /// Minimum level (height) of the map.
    min_level: i32,
    /// Maximum level of the map.
    max_level: i32,
    /// Default floor for the map.
    default_floor: i32,
    /// List of available floors.
    #[serde(default)]
    floors: Vec<i32>,
    /// The coordinates of the map label.
    #[serde(default)]
    label_coord: Vec<f32>,
    /// Dimensions of the map, given as the coordinates of the lower-left (SW) and upper-right (NE)
    /// corners.
    #[serde(default)]
    map_rect: Vec<Vec<i32>>,
    /// Dimensions of the map within the continent coordinate system,
    /// given as the coordinates of the lower-left (SW) and upper-right (NE) corners.
    #[serde(default)]
    continent_rect: Vec<Vec<i32>>,
    /// List of points of interests in the map (landmarks, waypoints and vistas)
    #[serde(default)]
    points_of_interest: Vec<Poi>,
    /// List of god shrines (usually empty with the exception of Orr maps).
    #[serde(default)]
    god_shrines: Vec<GodShrine>,
    /// List of renown hearts.
    #[serde(default)]
    tasks: Vec<Task>,
    /// List of skill challenges.
    #[serde(default)]
    skill_challenges: Vec<SkillChallenge>,
    /// List of sectors/sub-regions in the map.
    #[serde(default)]
    sectors: Vec<Sector>,
    /// List of training points.
    #[serde(default)]
    training_points: Vec<TrainingPoint>,
    /// List of adventures.
    #[serde(default)]
    adventures: Vec<Adventure>,
}

/// Possible types a point of interest can be.
#[derive(Debug, Deserialize, PartialEq, Hash)]
pub enum PoiType {
    /// Actual points of interest (PoI).
    #[serde(rename = "landmark")]
    Landmark,
    /// A waypoint.
    #[serde(rename = "waypoint")]
    Waypoint,
    /// A vista.
    #[serde(rename = "vista")]
    Vista,
    /// An unlock.
    #[serde(rename = "unlock")]
    Unlock,
}

/// Object with information about a particular point of interest.
#[derive(Debug, Deserialize, PartialEq)]
pub struct Poi {
    /// id of the point of interest.
    #[serde(rename = "poi_id")]
    id: u32,
    /// Name of the point of interest.
    name: String,
    /// The kind of point of interest this particular one is.
    #[serde(rename = "type")]
    poi_type: PoiType,
    /// The floor number of this object.
    floor: i32,
    /// The coordinates of this object.
    coord: Vec<f32>,
}

/// Struct containing information about an icon (used for the shrines of the gods).
#[derive(Debug, Deserialize, PartialEq)]
pub struct Icon {
    /// File id of the icon.
    #[serde(rename = "file_id")]
    id: u32,
    /// File signature of the icon.
    signature: String,
}

/// Struct containing information about a god shrine (found in Straits of Devestation)
#[derive(Debug, Deserialize, PartialEq)]
pub struct GodShrine {
    /// id of the god shrine.
    id: u32,
    /// Uncontested name of the god shrine.
    name: String,
    /// Contested name of the god shrine.
    name_contested: String,
    /// Coordinates where the god shrine is.
    coord: Vec<f32>,
    /// id of the point of interest for the shrine.
    poi_id: u32,
    /// Icon for the uncontested shrine.
    icon: Icon,
    /// Icon for the contested version of the shrine.
    icon_contested: Icon,
}

/// Struct containing information about a task (renown heart).
#[derive(Debug, Deserialize, PartialEq)]
pub struct Task {
    /// id of the renown heart.
    #[serde(rename = "task_id")]
    id: u32,
    /// Objective or name of the heart.
    objective: String,
    /// The level of the the heart.
    level: u16,
    /// Coordinates where the task takes place.
    coord: Vec<f32>,
    /// Boundaries of the task.
    bounds: Vec<Vec<f32>>,
}

/// Struct containing information about a skill challenge.
#[derive(Debug, Deserialize, PartialEq)]
pub struct SkillChallenge {
    // TODO: Check if these fields are accurate
    /// The expansion required for the skill challenge.
    expac: u32,
    /// id of the skill challenge
    #[serde(rename = "idx")]
    id: u32,
    /// Coordinates where the skill challenge is.
    coord: Vec<f32>,
}

/// Possible types of a training point, Tyrian ones give less hero points than Maguuman or ones
/// found in the Crystal Desert.
#[derive(Debug, Deserialize, PartialEq)]
pub enum PointType {
    Tyria,
    Maguuma,
    Desert,
    Unknown,
}

/// Struct containing information about a training point.
#[derive(Debug, Deserialize, PartialEq)]
pub struct TrainingPoint {
    /// id of the training point.
    id: u32,
    /// Name of the training point.
    name: String,
    /// Description of the training point.
    description: String,
    /// Coordinates where the training point is.
    coord: Vec<f32>,
    /// Type of training point (either Maguuma or Tyria)
    #[serde(rename = "type")]
    point_type: PointType,
}

/// Struct containing information about an adventure. Seemingly only used in a few maps in the
/// Heart of Maguuma.
#[derive(Debug, Deserialize, PartialEq)]
pub struct Adventure {
    /// id of the adventure.
    #[serde(rename = "guid")]
    id: String,
    /// Coordinates where the adventure is.
    coord: Vec<f32>,
    /// Name of the adventure.
    name: String,
    /// Further information about the leaderboard and description of the adventure.
    leaderboard: Leaderboard,
}

/// Struct containing information about a leaderboard for an adventure.
#[derive(Debug, Deserialize, PartialEq)]
pub struct Leaderboard {
    /// id of the leaderboard.
    #[serde(rename = "guid")]
    id: String,
    /// Name of the adventure the leaderboard belongs to.
    title: String,
    /// Description of the adventure.
    description: String,
}

/// Struct containing information about a sector (area) of a map.
#[derive(Debug, Deserialize, PartialEq)]
pub struct Sector {
    /// id of the area.
    #[serde(rename = "sector_id")]
    id: u32,
    /// Name of the area.
    name: String,
    /// Level of the area.
    level: u32,
    /// Coordinates of this area.
    coord: Vec<f32>,
    /// Bounds of the area.
    bounds: Vec<Vec<f32>>,
}

impl Floor {
    /// Retrieve a map floor by its continent id and floor number.
    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)
    }

    /// Returns a tuple describing the dimension of the texture for the map floor.
    pub fn texture_dims(&self) -> &Vec<f32> {
        &self.texture_dims
    }

    /// If present, it represents a rectangle of downloadable textures. Every tile coordinate outside this rectangle is not available on the tile server.
    /// Returns the name of the map.
    pub fn clamped_view(&self) -> &Vec<Vec<f32>> {
        &self.clamped_view
    }

    /// Returns a map of the regions of a map, where the region id is key and the region object is the
    /// value.
    pub fn regions(&self) -> &BTreeMap<u32, Region> {
        &self.regions
    }
}

impl Region {
    /// Returns the region name.
    pub fn name(&self) -> &str {
        &self.name
    }

    /// Returns the coordinates of the region label.
    pub fn label_coord(&self) -> &Vec<f32> {
        self.label_coord.as_ref()
    }

    /// Returns a reference to a Vec object that contains the dimensions of the region, using the
    /// continent coordinate system.
    pub fn continent_rect(&self) -> &Vec<Vec<i32>> {
        self.continent_rect.as_ref()
    }

    /// Returns a reference to a map of maps.
    pub fn maps(&self) -> &BTreeMap<u32, Map> {
        &self.maps
    }
}

impl Map {
    /// Returns the name of the map.
    pub fn name(&self) -> &str {
        &self.name
    }

    /// Returns the minimum level (height) of the map.
    pub fn min_level(&self) -> i32 {
        self.min_level
    }

    /// Returns the maximum level (height) of the map.
    pub fn max_level(&self) -> i32 {
        self.max_level
    }

    /// Returns the default floor.
    pub fn default_floor(&self) -> i32 {
        self.default_floor
    }

    /// Returns a reference to a list of floors for the map.
    pub fn floors(&self) -> &Vec<i32> {
        self.floors.as_ref()
    }

    /// Returns a reference to a list of lists that contains the dimensions of the map, using the
    /// maps local coordinates.
    pub fn map_rect(&self) -> &Vec<Vec<i32>> {
        &self.map_rect
    }

    /// Returns a reference to a list of lists that contains the dimensions of the map, using the
    /// continent coordinate system.
    pub fn continent_rect(&self) -> &Vec<Vec<i32>> {
        self.continent_rect.as_ref()
    }

    /// Returns a reference to a list of points of interests in the map.
    pub fn points_of_interest(&self) -> &Vec<Poi> {
        &self.points_of_interest
    }

    /// Returns a reference to a list of god shrines in the map. Only relevant in Orr, should
    /// otherwise be empty.
    pub fn god_shrines(&self) -> &Vec<Task> {
        &self.tasks
    }

    /// Returns a reference to a list of tasks (renown hearts) in the map.
    pub fn tasks(&self) -> &Vec<Task> {
        &self.tasks
    }

    /// Returns a reference to a list of skill challenges in the map.
    pub fn skill_challenges(&self) -> &Vec<SkillChallenge> {
        &self.skill_challenges
    }

    /// Returns a reference to a list of sectors/sub-regions in the map.
    pub fn sectors(&self) -> &Vec<Sector> {
        &self.sectors
    }

    // TODO: Check if this is accurate.
    /// Returns a reference to a list of training points (probably meaning channelable hero points) in the map.
    pub fn training_points(&self) -> &Vec<TrainingPoint> {
        &self.training_points
    }

    /// Returns a reference to a list of adventures in the map. Only used in Verdant Brink & Tangled Depths.
    pub fn adventures(&self) -> &Vec<Adventure> {
        &self.adventures
    }
}

impl Poi {
    /// Returns the id of the point of interest.
    pub fn id(&self) -> u32 {
        self.id
    }

    /// Returns the name of the point of interest.
    pub fn name(&self) -> &str {
        &self.name
    }

    /// Returns what type of point of interest this is. Possible types are: Landmark, Waypoint,
    /// Vista and Unlock.
    pub fn poi_type(&self) -> &PoiType {
        &self.poi_type
    }

    /// Returns the floor number of the point of interest.
    pub fn floor(&self) -> i32 {
        self.floor
    }

    /// Returns the coordinates for the point of interest.
    pub fn coord(&self) -> &Vec<f32> {
        &self.coord
    }
}

impl Icon {
    /// Returns the file id of the icon.
    pub fn id(&self) -> u32 {
        self.id
    }

    /// Returns the file signature of the icon.
    pub fn signature(&self) -> &str {
        &self.signature
    }
}

impl GodShrine {
    /// Returns the id of the god shrine.
    pub fn id(&self) -> u32 {
        self.id
    }

    /// Returns the regular name of the god shrine.
    pub fn name(&self) -> &str {
        &self.name
    }

    /// Returns the contested name of the god shrine.
    pub fn name_contested(&self) -> &str {
        &self.name_contested
    }

    /// Returns the coordinates for the god shrine.
    pub fn coord(&self) -> &Vec<f32> {
        &self.coord
    }

    /// Returns the id of point of interest of the shrine.
    pub fn poi_id(&self) -> u32 {
        self.poi_id
    }

    /// Returns the icon information for the regular shrine.
    pub fn icon(&self) -> &Icon {
        &self.icon
    }

    /// Returns the icon information for the contested shrine.
    pub fn icon_contested(&self) -> &Icon {
        &self.icon_contested
    }
}

impl Task {
    /// Returns the id of the renown heart.
    pub fn id(&self) -> u32 {
        self.id
    }

    /// Returns the objective or the name of the heart.
    pub fn objective(&self) -> &str {
        &self.objective
    }

    /// Returns the recommended character level of the heart.
    pub fn level(&self) -> u16 {
        self.level
    }

    /// Returns the coordinates where the task takes place.
    pub fn coord(&self) -> &Vec<f32> {
        &self.coord
    }

    /// Returns the boundaries of the task's area.
    pub fn bounds(&self) -> &Vec<Vec<f32>> {
        &self.bounds
    }
}

impl SkillChallenge {
    /// Returns the expansion required for the skill challenge.
    pub fn expac(&self) -> u32 {
        self.expac
    }

    /// Returns the id of the skill challenge.
    pub fn id(&self) -> u32 {
        self.id
    }

    /// Returns the coordinates where the skill challenge is.
    pub fn coord(&self) -> &Vec<f32> {
        &self.coord
    }
}

impl TrainingPoint {
    /// Returns the id of the training point.
    pub fn id(&self) -> u32 {
        self.id
    }

    /// Returns the name of the training point.
    pub fn name(&self) -> &str {
        &self.name
    }

    /// Returns the description of the training point.
    pub fn description(&self) -> &str {
        &self.description
    }

    /// Returns the coordinates of where the training point is.
    pub fn coord(&self) -> &Vec<f32> {
        &self.coord
    }

    /// Returns the type of training point it is (either Tyria, Maguuma, Desert or Unknown).
    pub fn point_type(&self) -> &PointType {
        &self.point_type
    }
}

impl Adventure {
    /// Returns the id of the adventure.
    pub fn id(&self) -> &str {
        &self.id
    }

    /// Returns the coordinates where the adventure is.
    pub fn coord(&self) -> &Vec<f32> {
        &self.coord
    }

    /// Returns the name of the adventure.
    pub fn name(&self) -> &str {
        &self.name
    }

    /// Returns a Leaderboard object containing further information and description about an
    /// adventure.
    pub fn leaderboard(&self) -> &Leaderboard {
        &self.leaderboard
    }
}

impl Leaderboard {
    /// Returns the id of the leaderboard.
    pub fn id(&self) -> &str {
        &self.id
    }

    /// Returns the title of the adventure the leaderboard belongs to.
    pub fn title(&self) -> &str {
        &self.title
    }

    /// Returns the description of the adventure the leaderboard belongs to.
    pub fn description(&self) -> &str {
        &self.description
    }

}

impl Sector {
    /// Returns the id of the area.
    pub fn id(&self) -> u32 {
        self.id
    }

    /// Returns the name of the area.
    pub fn name(&self) -> &str {
        &self.name
    }

    /// Returns the level of the area.
    pub fn level(&self) -> u32 {
        self.level
    }

    /// Returns the coordinates of the area.
    pub fn coord(&self) -> &Vec<f32> {
        &self.coord
    }

    /// Returns the boundaries of the task's area.
    pub fn bounds(&self) -> &Vec<Vec<f32>> {
        &self.bounds
    }
}

#[cfg(test)]
mod tests {
    use crate::v1::map_floor::*;
    use crate::client::Client;

    // A mix of Ruins of Orr for god shrines and Tangled Depths for adventures. This endpoint is
    // such a mess.
    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)
    }
}