contryConfig.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 contryConfig struct {
  8. maps map[int]*ContryConfigRow
  9. }
  10. type ContryConfigRow struct {
  11. ID int // #物品ID
  12. NameI string // 国家缩写
  13. NameII string // 英文名
  14. Icon_flag string // 道具icon
  15. }
  16. func (p *contryConfig) Name() string {
  17. return "contryConfig"
  18. }
  19. func (p *contryConfig) Init() {
  20. p.maps = make(map[int]*ContryConfigRow)
  21. }
  22. func (p *contryConfig) OnLoad(maps interface{}, _ bool) (int, error) {
  23. list, ok := maps.([]interface{})
  24. if !ok {
  25. return 0, mhayaError.Error("maps convert to []interface{} error.")
  26. }
  27. loadMaps := make(map[int]*ContryConfigRow)
  28. for index, data := range list {
  29. loadConfig := &ContryConfigRow{}
  30. err := DecodeData(data, loadConfig)
  31. if err != nil {
  32. mhayaLogger.Warnf("decode error. [row = %d, %v], err = %s", index+1, loadConfig, err)
  33. continue
  34. }
  35. loadMaps[loadConfig.ID] = loadConfig
  36. }
  37. p.maps = loadMaps
  38. return len(list), nil
  39. }
  40. func (p *contryConfig) OnAfterLoad(_ bool) {
  41. }
  42. func (p *contryConfig) Get(pk int) (*ContryConfigRow, bool) {
  43. i, found := p.maps[pk]
  44. return i, found
  45. }
  46. func (p *contryConfig) GetAll() map[int]*ContryConfigRow {
  47. var ret = make(map[int]*ContryConfigRow)
  48. for _, v := range p.maps {
  49. ret[v.ID] = v
  50. }
  51. return ret
  52. }
  53. func (p *contryConfig) Contain(pk int) bool {
  54. _, found := p.Get(pk)
  55. return found
  56. }