You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
package services
import ( lucifer3 "git.aiterp.net/lucifer3/server" "git.aiterp.net/lucifer3/server/commands" "git.aiterp.net/lucifer3/server/device" "sync" )
func NewSceneMap(resolver device.Resolver) *SceneMap { return &SceneMap{ resolver: resolver, sceneMap: make(map[string]string, 64), } }
type SceneMap struct { resolver device.Resolver
mu sync.Mutex sceneMap map[string]string }
func (s *SceneMap) SceneID(id string) *string { s.mu.Lock() defer s.mu.Unlock()
sceneID, ok := s.sceneMap[id] if !ok { return nil }
return &sceneID }
func (s *SceneMap) Active() bool { return true }
func (s *SceneMap) HandleEvent(*lucifer3.EventBus, lucifer3.Event) {}
func (s *SceneMap) HandleCommand(_ *lucifer3.EventBus, command lucifer3.Command) { switch command := command.(type) { case commands.ReplaceScene: matched := s.resolver.Resolve(command.Match)
if len(matched) > 0 { s.mu.Lock() for _, ptr := range matched { s.sceneMap[ptr.ID] = command.SceneName } s.mu.Unlock() } case commands.ClearScene: matched := s.resolver.Resolve(command.Match)
if len(matched) > 0 { s.mu.Lock() for _, ptr := range matched { delete(s.sceneMap, ptr.ID) } s.mu.Unlock() } } }
|