itemConfig.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. }