47 lines
961 B
Go
47 lines
961 B
Go
![]() |
package data
|
||
|
|
||
|
import json "github.com/json-iterator/go"
|
||
|
|
||
|
type Treasure struct {
|
||
|
Id int `json:"id"`
|
||
|
Quality int `json:"quality"`
|
||
|
Type int `json:"type"`
|
||
|
Levels int `json:"levels"`
|
||
|
SetId int `json:"set_id"`
|
||
|
Holes int `json:"holes"`
|
||
|
OpenedHoles int `json:"opened_holes"`
|
||
|
HoleUnlockType []int `json:"hole_unlock_type"`
|
||
|
HoleUnlockArgs []int `json:"hole_unlock_args"`
|
||
|
}
|
||
|
|
||
|
type TreasureTable struct {
|
||
|
l []*Treasure
|
||
|
m map[int]*Treasure
|
||
|
}
|
||
|
|
||
|
func (this *TreasureTable) load(buf []byte) error {
|
||
|
var err = json.Unmarshal(buf, &this.l)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
this.m = make(map[int]*Treasure)
|
||
|
for i := range this.l {
|
||
|
this.m[this.l[i].Id] = this.l[i]
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (this *TreasureTable) List() []*Treasure {
|
||
|
return this.l
|
||
|
}
|
||
|
|
||
|
func (this *TreasureTable) Get(i int) *Treasure {
|
||
|
return this.l[i]
|
||
|
}
|
||
|
|
||
|
func (this *TreasureTable) Find(id int) *Treasure {
|
||
|
return this.m[id]
|
||
|
}
|