This repository has been archived by the owner on Nov 16, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
location.go
105 lines (97 loc) · 3.62 KB
/
location.go
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
package golem
import "github.com/mitchellh/mapstructure"
// GetLocation returns a Location object
// Acceptable search queries:
// ID, String
func GetLocation(query string) Location {
searchType := idOrString(query)
location := Location{}
if checkCache("location", query, searchType) {
mapstructure.Decode(getDataCache("location", query, searchType, location), &location)
} else {
dataInterface = getDataAPI("location", query, location)
if dataInterface != nil {
mapstructure.Decode(dataInterface, &location)
storeData(false, location, "location", location.ID, location.Name)
}
}
location.GetRegion = getRegion(location.Region.Name)
for _, area := range location.Areas {
location.GetAreas = append(location.GetAreas, getLocationArea(area.Name))
}
return location
}
// GetLocationArea returns a LocationArea object
// Acceptable search queries:
// ID, String
func GetLocationArea(query string) LocationArea {
searchType := idOrString(query)
locationArea := LocationArea{}
if checkCache("location-area", query, searchType) {
mapstructure.Decode(getDataCache("location-area", query, searchType, locationArea), &locationArea)
} else {
dataInterface = getDataAPI("location-area", query, locationArea)
if dataInterface != nil {
mapstructure.Decode(dataInterface, &locationArea)
storeData(false, locationArea, "location-area", locationArea.ID, locationArea.Name)
}
}
locationArea.GetLocation = getLocation(locationArea.Location.Name)
for i, emr := range locationArea.EncounterMethodRates {
locationArea.EncounterMethodRates[i].GetEncounterMethod = getEncounterMethod(emr.EncounterMethod.Name)
for ii, vd := range emr.VersionDetails {
locationArea.EncounterMethodRates[i].VersionDetails[ii].GetVersion = getVersion(vd.Version.Name)
}
}
for i, pe := range locationArea.PokemonEncounters {
locationArea.PokemonEncounters[i].GetPokemon = getPokemon(pe.Pokemon.Name)
}
return locationArea
}
// GetPalParkArea returns a PalParkArea object
// Acceptable search queries:
// ID, String
func GetPalParkArea(query string) PalParkArea {
searchType := idOrString(query)
palParkArea := PalParkArea{}
if checkCache("pal-park-area", query, searchType) {
mapstructure.Decode(getDataCache("pal-park-area", query, searchType, palParkArea), &palParkArea)
} else {
dataInterface = getDataAPI("pal-park-area", query, palParkArea)
if dataInterface != nil {
mapstructure.Decode(dataInterface, &palParkArea)
storeData(false, palParkArea, "pal-park-area", palParkArea.ID, palParkArea.Name)
}
}
for i, pe := range palParkArea.PokemonEncounters {
palParkArea.PokemonEncounters[i].GetPokemonSpecies = getPokemonSpecies(pe.PokemonSpecies.Name)
}
return palParkArea
}
// GetRegion returns a Region object
// Acceptable search queries:
// ID, String
func GetRegion(query string) Region {
searchType := idOrString(query)
region := Region{}
if checkCache("region", query, searchType) {
mapstructure.Decode(getDataCache("region", query, searchType, region), ®ion)
} else {
dataInterface = getDataAPI("region", query, region)
if dataInterface != nil {
mapstructure.Decode(dataInterface, ®ion)
storeData(false, region, "region", region.ID, region.Name)
}
}
for _, location := range region.Locations {
region.GetLocations = append(region.GetLocations, getLocation(location.Name))
}
region.GetMainGeneration = getGeneration(region.MainGeneration.Name)
for _, pokedex := range region.Pokedexes {
region.GetPokedexes = append(region.GetPokedexes, getPokedex(pokedex.Name))
}
for _, vg := range region.VersionGroups {
region.GetVersionGroups = append(region.GetVersionGroups, getVersionGroup(vg.Name))
}
return region
}