71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package reg
|
|
|
|
import (
|
|
"mongo.games.com/game/gamesrv/slotspkg/internal/generic/errors"
|
|
"mongo.games.com/game/gamesrv/slotspkg/slots/intf"
|
|
"reflect"
|
|
)
|
|
|
|
// Register register multiple plugins to global map
|
|
func Register(s ...interface{}) {
|
|
for _, v := range s {
|
|
plugin := getValidPlugin(v)
|
|
RegisterPlugin(plugin)
|
|
|
|
for _, custom := range plugin.Customs() {
|
|
RegisterCustom(custom)
|
|
}
|
|
}
|
|
}
|
|
|
|
// RegisterCustoms register customs to global map
|
|
func RegisterCustoms(s ...interface{}) {
|
|
for _, v := range s {
|
|
plugin := getValidPlugin(v)
|
|
for _, custom := range plugin.Customs() {
|
|
RegisterCustom(custom)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Deregister deregisters multiple plugins from global map
|
|
func Deregister(s ...interface{}) {
|
|
for _, v := range s {
|
|
plugin := getValidPlugin(v)
|
|
DeregisterPlugin(plugin)
|
|
for _, custom := range plugin.Customs() {
|
|
DeregisterCustom(custom)
|
|
}
|
|
}
|
|
}
|
|
|
|
// DeregisterCustoms deregisters customs to global map
|
|
func DeregisterCustoms(s ...interface{}) {
|
|
for _, v := range s {
|
|
plugin := getValidPlugin(v)
|
|
for _, custom := range plugin.Customs() {
|
|
DeregisterCustom(custom)
|
|
}
|
|
}
|
|
}
|
|
|
|
// getValidPlugin gets valid plugin or panic an error
|
|
func getValidPlugin(v interface{}) intf.Plugin {
|
|
plugin, ok := v.(intf.Plugin)
|
|
if !ok {
|
|
panic(errors.Errorf("plugin is not derived from Plugin: %s", reflect.TypeOf(v)))
|
|
}
|
|
|
|
theme := plugin.Theme()
|
|
if theme == "" {
|
|
panic(errors.Errorf("theme can't be empty when register theme: %s", reflect.TypeOf(v)))
|
|
}
|
|
|
|
customs := plugin.Customs()
|
|
if customs == nil {
|
|
panic(errors.Errorf("customs can't be nil"))
|
|
}
|
|
|
|
return plugin
|
|
}
|