new scene system is kind of working. I haven't tested changing between scenes and Transition effect yet, though.
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -2,6 +2,7 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -189,6 +190,25 @@ func (d *Device) SetState(newState NewDeviceState) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *NewDeviceState) RelativeTo(device Device) NewDeviceState {
|
||||
n := NewDeviceState{}
|
||||
|
||||
if s.Intensity != nil {
|
||||
intensity := device.State.Intensity * *s.Intensity
|
||||
n.Intensity = &intensity
|
||||
}
|
||||
if s.Color != nil {
|
||||
c, err := ParseColorValue(*s.Color)
|
||||
if err == nil {
|
||||
c.Hue = math.Mod(device.State.Color.Hue + c.Hue, 360)
|
||||
c.Saturation *= device.State.Color.Saturation
|
||||
c.Kelvin += device.State.Color.Kelvin
|
||||
}
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
func (s *NewDeviceState) Interpolate(other NewDeviceState, fac float64) NewDeviceState {
|
||||
n := NewDeviceState{}
|
||||
|
||||
|
||||
+10
-3
@@ -69,6 +69,7 @@ type SceneRole struct {
|
||||
TargetKind ReferenceKind `json:"targetKind"`
|
||||
TargetValue string `json:"targetValue"`
|
||||
Interpolate bool `json:"interpolate"`
|
||||
Relative bool `json:"relative"`
|
||||
Order string `json:"order"`
|
||||
States []NewDeviceState `json:"states"`
|
||||
}
|
||||
@@ -81,7 +82,7 @@ type SceneRunContext struct {
|
||||
}
|
||||
|
||||
func (d *SceneRunContext) PositionFacShifted() float64 {
|
||||
shiftFac := float64((int64(d.Index)+d.IntervalNumber)%int64(d.Length)) * (1 / float64(d.Length))
|
||||
shiftFac := float64(d.IntervalNumber%int64(d.Length)) / float64(d.Length)
|
||||
|
||||
return math.Mod(d.PositionFac()+shiftFac, 1)
|
||||
}
|
||||
@@ -179,6 +180,10 @@ func (r *SceneRole) ApplyEffect(device *Device, c SceneRunContext) (newState New
|
||||
newState = r.State(c.IntervalFac())
|
||||
}
|
||||
|
||||
if r.Relative {
|
||||
newState = newState.RelativeTo(*device)
|
||||
}
|
||||
|
||||
switch r.PowerMode {
|
||||
case SPDevice:
|
||||
newState.Power = nil
|
||||
@@ -196,6 +201,8 @@ func (r *SceneRole) State(fac float64) NewDeviceState {
|
||||
return r.States[0]
|
||||
}
|
||||
|
||||
|
||||
|
||||
if r.Interpolate {
|
||||
if len(r.States) == 2 {
|
||||
return r.States[0].Interpolate(r.States[1], fac)
|
||||
@@ -219,8 +226,8 @@ func (r *SceneRole) State(fac float64) NewDeviceState {
|
||||
type ScenePowerMode string
|
||||
|
||||
const (
|
||||
SPDevice ScenePowerMode = "Device" // Device state decides power. Scene state may only power off.
|
||||
SPScene ScenePowerMode = "Scene" // Scene state decide power.
|
||||
SPDevice ScenePowerMode = "Device" // Device state decides power. Scene state may only power off.
|
||||
SPScene ScenePowerMode = "Scene" // Scene state decide power.
|
||||
)
|
||||
|
||||
// DeviceSceneAssignment is an entry on the device stack. StartTime and DurationMS are only respected when the scene
|
||||
|
||||
Reference in New Issue
Block a user