some more work.
continuous-integration/drone/push Build is failing

This commit is contained in:
2021-09-28 21:57:28 +02:00
parent ffa757f742
commit a3695a3ddd
3 changed files with 23 additions and 1 deletions
+19
View File
@@ -17,10 +17,25 @@ type Scene struct {
due bool
}
// UpdateScene updates the scene data and re-seats all devices.
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) {
if s.data == nil {
s.roleMap[device.ID] = -1
@@ -56,6 +71,7 @@ func (s *Scene) UpsertDevice(device models.Device) {
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) {
roleIndex, hasRoleIndex := s.roleMap[device.ID]
if !hasRoleIndex {
@@ -68,8 +84,11 @@ func (s *Scene) RemoveDevice(device models.Device) {
break
}
}
delete(s.roleMap, device.ID)
}
// Run runs the scene
func (s *Scene) Run() []models.Device {
if s.data == nil {
return []models.Device{}