moar stuff.

This commit is contained in:
2023-09-23 14:04:13 +02:00
parent c7d3a3200e
commit 2188d489ea
48 changed files with 1684 additions and 91 deletions
+43
View File
@@ -0,0 +1,43 @@
package effects
import (
"fmt"
"git.aiterp.net/lucifer3/server/device"
"time"
)
type Solid struct {
States []device.State `json:"states,omitempty"`
AnimationMS int64 `json:"animationMs,omitempty"`
Interleave int `json:"interleave,omitempty"`
}
func (e Solid) State(_, length, round int) device.State {
if len(e.States) == 0 {
return device.State{}
}
if len(e.States) == 1 {
return e.States[0]
}
interleave := e.Interleave + 1
if interleave < 1 {
interleave = 1
}
if interleave > 1 {
calcIndex := round % (len(e.States) * interleave)
return gradientState(append(e.States, e.States[0]), e.Interleave != 0, calcIndex, len(e.States)*interleave+1)
} else {
calcIndex := round % len(e.States)
return gradientState(e.States, e.Interleave != 0, calcIndex, len(e.States)*interleave)
}
}
func (e Solid) Frequency() time.Duration {
return time.Duration(e.AnimationMS) * time.Millisecond
}
func (e Solid) EffectDescription() string {
return fmt.Sprintf("Solid(states:%s, anim:%dms, interleave:%d)", statesDescription(e.States), e.AnimationMS, e.Interleave)
}
+2 -2
View File
@@ -8,8 +8,8 @@ import (
type Gradient struct {
States []device.State `json:"states,omitempty"`
AnimationMS int64 `json:"AnimationMs,omitempty"`
Reverse bool `json:"backward,omitempty"`
AnimationMS int64 `json:"animationMs,omitempty"`
Reverse bool `json:"reverse,omitempty"`
Interpolate bool `json:"interpolate,omitempty"`
}
+5
View File
@@ -8,6 +8,7 @@ import (
type serializedEffect struct {
Manual *Manual `json:"manual,omitempty"`
Solid *Solid `json:"solid,omitempty"`
Gradient *Gradient `json:"gradient,omitempty"`
Pattern *Pattern `json:"pattern,omitempty"`
Random *Random `json:"random,omitempty"`
@@ -28,6 +29,8 @@ func (s *Serializable) UnmarshalJSON(raw []byte) error {
switch {
case value.Manual != nil:
s.Effect = *value.Manual
case value.Solid != nil:
s.Effect = *value.Solid
case value.Gradient != nil:
s.Effect = *value.Gradient
case value.Pattern != nil:
@@ -47,6 +50,8 @@ func (s *Serializable) MarshalJSON() ([]byte, error) {
switch effect := s.Effect.(type) {
case Manual:
return json.Marshal(serializedEffect{Manual: &effect})
case Solid:
return json.Marshal(serializedEffect{Solid: &effect})
case Gradient:
return json.Marshal(serializedEffect{Gradient: &effect})
case Pattern:
+6 -5
View File
@@ -7,10 +7,11 @@ import (
)
type VRange struct {
States []device.State `json:"states,omitempty"`
Variable string `json:"variable"`
Min float64 `json:"min"`
Max float64 `json:"max"`
States []device.State `json:"states,omitempty"`
Variable string `json:"variable"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Interpolate bool `json:"interpolate"`
}
func (e VRange) VariableName() string {
@@ -24,7 +25,7 @@ func (e VRange) VariableState(_, _ int, value float64) device.State {
return e.States[len(e.States)-1]
}
return gradientStateFactor(e.States, true, (value-e.Min)/(e.Max-e.Min))
return gradientStateFactor(e.States, e.Interpolate, (value-e.Min)/(e.Max-e.Min))
}
func (e VRange) State(_, _, _ int) device.State {