extend.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package data
  2. import (
  3. "f1-game/internal/types"
  4. cmapStructure "github.com/cherry-game/cherry/extend/mapstructure"
  5. cdataConfig "github.com/cherry-game/components/data-config"
  6. )
  7. // 策划配表
  8. // 所有策划配表映射的golang文件都可以小写开头命名struct
  9. // 通过下面的var() 暴露struct给外部调用
  10. // 禁止!!!外部引用任何配置的地址,以防热刷数据时没及时生效
  11. type baseConfig struct {
  12. denyLoad bool
  13. }
  14. func (baseConfig) OnAfterLoad(_ bool) {
  15. }
  16. var (
  17. _allList []cdataConfig.IConfig
  18. )
  19. // 手工创建的表初始化放这里
  20. var (
  21. ProtoRoute = &protoRouteConfig{}
  22. SDK = &sdkConfig{}
  23. Lua = &luaConfig{}
  24. )
  25. func init() {
  26. _allList = append(_allList,
  27. ProtoRoute,
  28. SDK,
  29. Lua,
  30. )
  31. }
  32. func NewConfigs(configs ...cdataConfig.IConfig) *cdataConfig.Component {
  33. dataConfig := cdataConfig.New()
  34. dataConfig.Register(configs...)
  35. return dataConfig
  36. }
  37. func New() *cdataConfig.Component {
  38. return NewConfigs(_allList...)
  39. }
  40. func DecodeData(input any, output any) error {
  41. return cmapStructure.HookDecode(
  42. input,
  43. output,
  44. "json",
  45. types.GetDecodeHooks(),
  46. )
  47. }
  48. func I32Min(v int32, minValue int32) int32 {
  49. if v < minValue {
  50. return minValue
  51. }
  52. return v
  53. }