-
Notifications
You must be signed in to change notification settings - Fork 43
/
birthplace.go
62 lines (48 loc) · 982 Bytes
/
birthplace.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
package excel
import (
"encoding/json"
"io/ioutil"
"sync"
log "github.com/cihub/seelog"
)
type BirthplaceData struct {
Id uint64
X int
Z int
Length int
Width int
}
var birthplace map[uint64]BirthplaceData
var birthplaceLock sync.RWMutex
func LoadBirthplace(){
birthplaceLock.Lock()
defer birthplaceLock.Unlock()
data,err := ioutil.ReadFile("../res/excel/birthplace.json")
if err != nil {
log.Error("ReadFile err: ", err)
return
}
err = json.Unmarshal(data, &birthplace)
if err != nil {
log.Error("Unmarshal err: ", err)
return
}
}
func GetBirthplaceMap() map[uint64]BirthplaceData {
birthplaceLock.RLock()
defer birthplaceLock.RUnlock()
birthplace2 := make(map[uint64]BirthplaceData)
for k, v := range birthplace{
birthplace2[k] = v
}
return birthplace2
}
func GetBirthplace(key uint64) (BirthplaceData, bool) {
birthplaceLock.RLock()
defer birthplaceLock.RUnlock()
val, ok := birthplace[key]
return val, ok
}
func GetBirthplaceMapLen() int {
return len(birthplace)
}