package privilege import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "sync" ) var moduleName = "privilege" const ( game_privilegecard = "game_privilegecard.json" game_privilege = "game_privilege.json" ) // /背包配置管理组件 type configureComp struct { modules.MCompConfigure module *Privilege hlock sync.RWMutex _privilegeMap map[int32]map[int32]int32 } // 组件初始化接口 func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { this.MCompConfigure.Init(service, module, comp, options) this.module = module.(*Privilege) this.LoadConfigure(game_privilegecard, cfg.NewGamePrivilegeCard) this.LoadConfigure(game_privilege, cfg.NewGamePrivilege) this._privilegeMap = make(map[int32]map[int32]int32, 0) configure.RegisterConfigure(game_privilege, cfg.NewGamePrivilege, func() { if v, err := this.GetConfigure(game_privilege); err == nil { if configure, ok := v.(*cfg.GamePrivilege); ok { this.hlock.Lock() defer this.hlock.Unlock() for k, v := range configure.GetDataMap() { if v1, ok := this._privilegeMap[v.PrivilegeType]; ok { v1[k] = v.PrivilegeParameter } else { this._privilegeMap[v.PrivilegeType] = make(map[int32]int32) } } return } } log.Errorf("get game_pagoda conf err:%v", err) return }) return } func (this *configureComp) GetPrivilegeCard(id string) (data *cfg.GamePrivilegeCardData, err error) { var ( v interface{} ) if v, err = this.GetConfigure(game_privilegecard); err == nil { if configure, ok := v.(*cfg.GamePrivilegeCard); ok { if data = configure.Get(id); data != nil { return } } } err = comm.NewNotFoundConfErr(moduleName, game_privilegecard, id) return } // 获取指定特权配置 func (this *configureComp) GetPrivilegeData(id int32) (result *cfg.GamePrivilegeData) { if v, err := this.GetConfigure(game_privilege); err == nil { if c, ok := v.(*cfg.GamePrivilege); ok { result = c.Get(id) return } } this.module.Errorf("GetPrivilegeData err, id:%d", id) return nil } func (this *configureComp) GetPrivilegeByType(iType int32) (result map[int32]int32) { result = make(map[int32]int32) if v, ok := this._privilegeMap[iType]; ok { result = v } return result }