refactor variable system to be the responsibility of effect enforcer.
This commit is contained in:
@@ -6,14 +6,12 @@ import (
|
||||
"git.aiterp.net/lucifer3/server/events"
|
||||
"git.aiterp.net/lucifer3/server/internal/color"
|
||||
"git.aiterp.net/lucifer3/server/internal/gentools"
|
||||
"git.aiterp.net/lucifer3/server/services/variables"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Data struct {
|
||||
Devices map[string]Device `json:"devices"`
|
||||
Assignments map[uuid.UUID]Assignment `json:"assignments"`
|
||||
Variables variables.Variables `json:"variables"`
|
||||
}
|
||||
|
||||
func (d *Data) WithPatch(patches ...Patch) Data {
|
||||
@@ -81,6 +79,9 @@ func (d *Data) WithPatch(patches ...Patch) Data {
|
||||
}
|
||||
}
|
||||
}
|
||||
if patch.Assignment.Variables != nil {
|
||||
pa.Variables = gentools.CopyMap(patch.Assignment.Variables)
|
||||
}
|
||||
|
||||
if patch.Assignment.Delete {
|
||||
delete(newData.Assignments, pa.ID)
|
||||
@@ -88,10 +89,6 @@ func (d *Data) WithPatch(patches ...Patch) Data {
|
||||
newData.Assignments[pa.ID] = pa
|
||||
}
|
||||
}
|
||||
|
||||
if patch.VariableProperty != nil {
|
||||
newData.Variables = newData.Variables.WithPropertyPatch(*patch.VariableProperty)
|
||||
}
|
||||
}
|
||||
|
||||
return newData
|
||||
@@ -101,7 +98,6 @@ func (d *Data) Copy() Data {
|
||||
return Data{
|
||||
Devices: gentools.CopyMap(d.Devices),
|
||||
Assignments: gentools.CopyMap(d.Assignments),
|
||||
Variables: d.Variables,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,4 +138,5 @@ type Assignment struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
DeviceIDs []string `json:"deviceIds"`
|
||||
Effect *effects.Serializable `json:"effect"`
|
||||
Variables map[string]float64 `json:"variables"`
|
||||
}
|
||||
|
||||
@@ -6,14 +6,12 @@ import (
|
||||
"git.aiterp.net/lucifer3/server/effects"
|
||||
"git.aiterp.net/lucifer3/server/events"
|
||||
"git.aiterp.net/lucifer3/server/internal/color"
|
||||
"git.aiterp.net/lucifer3/server/services/variables"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Patch struct {
|
||||
Assignment *AssignmentPatch `json:"assignment,omitempty"`
|
||||
Device *DevicePatch `json:"device,omitempty"`
|
||||
VariableProperty *variables.PropertyPatch `json:"variableProperty,omitempty"`
|
||||
Assignment *AssignmentPatch `json:"assignment,omitempty"`
|
||||
Device *DevicePatch `json:"device,omitempty"`
|
||||
}
|
||||
|
||||
func (e Patch) VerboseKey() string {
|
||||
@@ -24,7 +22,7 @@ func (e Patch) EventDescription() string {
|
||||
if e.Device != nil {
|
||||
switch {
|
||||
case e.Device.Name != nil:
|
||||
return fmt.Sprintf("uistate.Patch(device=%s, name=%s)", e.Device.ID, e.Device.Name)
|
||||
return fmt.Sprintf("uistate.Patch(device=%s, name=%s)", e.Device.ID, *e.Device.Name)
|
||||
case e.Device.DesiredState != nil:
|
||||
return fmt.Sprintf("uistate.Patch(device=%s, desiredState=%s)", e.Device.ID, e.Device.DesiredState.String())
|
||||
case e.Device.HWState != nil:
|
||||
@@ -43,8 +41,6 @@ func (e Patch) EventDescription() string {
|
||||
}
|
||||
} else if e.Assignment != nil {
|
||||
return fmt.Sprintf("uistate.Patch(assignment=%s)", e.Assignment.ID)
|
||||
} else if e.VariableProperty != nil {
|
||||
return fmt.Sprintf("uistate.Patch(variableProperty=%s)", e.VariableProperty.Key)
|
||||
} else {
|
||||
return "uistate.Patch"
|
||||
}
|
||||
@@ -69,8 +65,9 @@ type DevicePatch struct {
|
||||
|
||||
type AssignmentPatch struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
AddDeviceID *string `json:"addDeviceId"`
|
||||
RemoveDeviceID *string `json:"removeDeviceId"`
|
||||
Effect *effects.Serializable `json:"effect"`
|
||||
Delete bool `json:"delete"`
|
||||
AddDeviceID *string `json:"addDeviceId,omitempty"`
|
||||
RemoveDeviceID *string `json:"removeDeviceId,omitempty"`
|
||||
Effect *effects.Serializable `json:"effect,omitempty"`
|
||||
Variables map[string]float64 `json:"variables,omitempty"`
|
||||
Delete bool `json:"delete,omitempty"`
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"git.aiterp.net/lucifer3/server/effects"
|
||||
"git.aiterp.net/lucifer3/server/events"
|
||||
"git.aiterp.net/lucifer3/server/internal/gentools"
|
||||
"git.aiterp.net/lucifer3/server/services/variables"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@@ -116,8 +115,12 @@ func (s *service) HandleEvent(bus *lucifer3.EventBus, event lucifer3.Event) {
|
||||
Assignment: gentools.ShallowCopy(event.AssignmentID),
|
||||
ClearAssignment: event.AssignmentID == nil,
|
||||
}})
|
||||
case variables.PropertyPatch:
|
||||
patches = append(patches, Patch{VariableProperty: &event})
|
||||
case events.AssignmentVariables:
|
||||
// Always set the assignment
|
||||
patches = append(patches, Patch{Assignment: &AssignmentPatch{
|
||||
ID: event.ID,
|
||||
Variables: event.Map,
|
||||
}})
|
||||
}
|
||||
|
||||
if len(patches) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user