-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhook_game.go
51 lines (46 loc) · 1.27 KB
/
hook_game.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
package itchio
import (
"reflect"
)
// GameHookFunc is used to transform API results from
// what they currently are to what we expect them to be.
func GameHookFunc(
f reflect.Type,
t reflect.Type,
data interface{}) (interface{}, error) {
if t != reflect.TypeOf(Game{}) {
return data, nil
}
if gameMap, ok := data.(map[string]interface{}); ok {
// API v2 briefly returned traits, which were 100%
// amos's terrible idea - they're going away, but
// in the meantime let's convert them to something saner.
if traitsAny, ok := gameMap["traits"]; ok {
platforms := make(map[string]interface{})
if traits, ok := traitsAny.([]interface{}); ok {
for _, traitAny := range traits {
if trait, ok := traitAny.(string); ok {
switch trait {
case "p_osx":
platforms["osx"] = ArchitecturesAll
case "p_windows":
platforms["windows"] = ArchitecturesAll
case "p_linux":
platforms["linux"] = ArchitecturesAll
case "can_be_bought":
gameMap["canBeBought"] = true
case "has_demo":
gameMap["hasDemo"] = true
case "in_press_system":
gameMap["inPressSystem"] = true
}
}
}
}
gameMap["platforms"] = platforms
delete(gameMap, "traits")
return gameMap, nil
}
}
return data, nil
}