|
@ -17,10 +17,25 @@ type Scene struct { |
|
|
due bool |
|
|
due bool |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// UpdateScene updates the scene data and re-seats all devices.
|
|
|
func (s *Scene) UpdateScene(data models.Scene) { |
|
|
func (s *Scene) UpdateScene(data models.Scene) { |
|
|
|
|
|
devices := make([]models.Device, 0, 16) |
|
|
|
|
|
|
|
|
|
|
|
for ri, list := range s.roleList { |
|
|
|
|
|
for _, device := range list { |
|
|
|
|
|
devices = append(devices, device) |
|
|
|
|
|
s.roleMap[device.ID] = -1 |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
s.roleList = map[int][]models.Device {-1: devices} |
|
|
|
|
|
|
|
|
|
|
|
for _, device := range append(devices[:0:0], devices...) { |
|
|
|
|
|
s.UpsertDevice(device) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// UpsertDevice moves the device if neccesary and updates its state.
|
|
|
func (s *Scene) UpsertDevice(device models.Device) { |
|
|
func (s *Scene) UpsertDevice(device models.Device) { |
|
|
if s.data == nil { |
|
|
if s.data == nil { |
|
|
s.roleMap[device.ID] = -1 |
|
|
s.roleMap[device.ID] = -1 |
|
@ -56,6 +71,7 @@ func (s *Scene) UpsertDevice(device models.Device) { |
|
|
s.data.Roles[newIndex].ApplyOrder(s.roleList[newIndex]) |
|
|
s.data.Roles[newIndex].ApplyOrder(s.roleList[newIndex]) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// RemoveDevice finds and remove a device. It's a noop if the device does not exist in this scene.
|
|
|
func (s *Scene) RemoveDevice(device models.Device) { |
|
|
func (s *Scene) RemoveDevice(device models.Device) { |
|
|
roleIndex, hasRoleIndex := s.roleMap[device.ID] |
|
|
roleIndex, hasRoleIndex := s.roleMap[device.ID] |
|
|
if !hasRoleIndex { |
|
|
if !hasRoleIndex { |
|
@ -68,8 +84,11 @@ func (s *Scene) RemoveDevice(device models.Device) { |
|
|
break |
|
|
break |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
delete(s.roleMap, device.ID) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Run runs the scene
|
|
|
func (s *Scene) Run() []models.Device { |
|
|
func (s *Scene) Run() []models.Device { |
|
|
if s.data == nil { |
|
|
if s.data == nil { |
|
|
return []models.Device{} |
|
|
return []models.Device{} |
|
|