itemConfig.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // this file is auto create by program, don't edit manually
  2. package data
  3. import (
  4. mhayaError "github.com/mhaya/error"
  5. mhayaLogger "github.com/mhaya/logger"
  6. )
  7. type itemConfig struct {
  8. maps map[int]*ItemConfigRow
  9. }
  10. type ItemConfigRow struct {
  11. ID int // #物品ID
  12. Type int // 物品类型(1可使用物品2基础物品3wallet4邀请相关)
  13. ItemKey string // 键名
  14. }
  15. func (p *itemConfig) Name() string {
  16. return "itemConfig"
  17. }
  18. func (p *itemConfig) Init() {
  19. p.maps = make(map[int]*ItemConfigRow)
  20. }
  21. func (p *itemConfig) OnLoad(maps interface{}, _ bool) (int, error) {
  22. list, ok := maps.([]interface{})
  23. if !ok {
  24. return 0, mhayaError.Error("maps convert to []interface{} error.")
  25. }
  26. loadMaps := make(map[int]*ItemConfigRow)
  27. for index, data := range list {
  28. loadConfig := &ItemConfigRow{}
  29. err := DecodeData(data, loadConfig)
  30. if err != nil {
  31. mhayaLogger.Warnf("decode error. [row = %d, %v], err = %s", index+1, loadConfig, err)
  32. continue
  33. }
  34. loadMaps[loadConfig.ID] = loadConfig
  35. }
  36. p.maps = loadMaps
  37. return len(list), nil
  38. }
  39. func (p *itemConfig) OnAfterLoad(_ bool) {
  40. }
  41. func (p *itemConfig) Get(pk int) (*ItemConfigRow, bool) {
  42. i, found := p.maps[pk]
  43. return i, found
  44. }
  45. func (p *itemConfig) Contain(pk int) bool {
  46. _, found := p.Get(pk)
  47. return found
  48. }
  49. func (p *itemConfig) GetMap() map[int]*ItemConfigRow {
  50. return p.maps
  51. }