add variable system + fix bugs here and there.
This commit is contained in:
@@ -6,12 +6,14 @@ 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 {
|
||||
@@ -86,6 +88,10 @@ 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
|
||||
@@ -95,6 +101,7 @@ func (d *Data) Copy() Data {
|
||||
return Data{
|
||||
Devices: gentools.CopyMap(d.Devices),
|
||||
Assignments: gentools.CopyMap(d.Assignments),
|
||||
Variables: d.Variables,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,12 +6,14 @@ 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"`
|
||||
Assignment *AssignmentPatch `json:"assignment,omitempty"`
|
||||
Device *DevicePatch `json:"device,omitempty"`
|
||||
VariableProperty *variables.PropertyPatch `json:"variableProperty,omitempty"`
|
||||
}
|
||||
|
||||
func (e Patch) VerboseKey() string {
|
||||
@@ -41,6 +43,8 @@ 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"
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ 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"
|
||||
)
|
||||
|
||||
@@ -31,7 +32,9 @@ func (s *service) HandleCommand(bus *lucifer3.EventBus, command lucifer3.Command
|
||||
patches = []Patch{{Device: &DevicePatch{ID: command.ID, DesiredState: &command.State}}}
|
||||
case commands.SetStateBatch:
|
||||
for id, state := range command {
|
||||
patches = []Patch{{Device: &DevicePatch{ID: id, DesiredState: gentools.ShallowCopy(&state)}}}
|
||||
patches = append(patches, Patch{
|
||||
Device: &DevicePatch{ID: id, DesiredState: gentools.ShallowCopy(&state)},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,6 +116,8 @@ 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})
|
||||
}
|
||||
|
||||
if len(patches) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user