SchemeRole.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package scheme
  2. import (
  3. "Server-Core/Server/Base"
  4. "errors"
  5. "reflect"
  6. "strconv"
  7. )
  8. type RoleItem struct {
  9. Id int32
  10. }
  11. type Role struct {
  12. dataList map[int32]*RoleItem
  13. }
  14. func (scp *Role) Load() {
  15. scp.dataList = make(map[int32]*RoleItem)
  16. //records := base.LoadCsvCfg("../Scp/Role.csv").Records
  17. var path string = ""
  18. if ip == "192.168.1.122" {
  19. path = "E://ChatGameService2/Bin/Scp/Role.csv"
  20. } else {
  21. // records := base.LoadCsvCfg("E://ChatGameService2/Bin/Scp/Level.csv").Records
  22. path = "../Scp/Role.csv"
  23. }
  24. records := base.LoadCsvCfg(path).Records
  25. //records := base.LoadCsvCfg("E://ChatGameService2/Bin/Scp/Role.csv").Records
  26. for i := 4; i < len(records); i++ {
  27. item := new(RoleItem)
  28. cr := reflect.ValueOf(item).Elem()
  29. for k, v := range records[i].Record {
  30. k = base.StrFirstToUpper(k)
  31. a := cr.FieldByName(k)
  32. switch a.Type().String() {
  33. case "string":
  34. a.Set(reflect.ValueOf(v))
  35. case "int32":
  36. i, _ := strconv.Atoi(v)
  37. a.Set(reflect.ValueOf(int32(i)))
  38. case "float64":
  39. f, _ := strconv.ParseFloat(v, 64)
  40. a.Set(reflect.ValueOf(f))
  41. }
  42. }
  43. scp.dataList[item.Id] = item
  44. }
  45. }
  46. func (scp *Role) Get(key int32) (interface{}, error) {
  47. data, ok := scp.dataList[key]
  48. if ok {
  49. return data, nil
  50. } else {
  51. return nil, errors.New("not find")
  52. }
  53. }