Configurable grid + snap-to-grid in the layout system (#45)
Build image / build-and-push (push) Successful in 7s
Build image / build-and-push (push) Successful in 7s
Closes #44. Two independent grids (garden + per-bed), each with a size and a snap toggle; snapping defaults off. See PR #45 for details. Co-authored-by: Steve Dudenhoeffer <[email protected]>
This commit was merged in pull request #45.
This commit is contained in:
@@ -10,9 +10,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
maxObjectNameLen = 200
|
||||
maxObjectNotesLen = 10_000
|
||||
maxObjectPropsLen = 20_000
|
||||
maxObjectNameLen = 200
|
||||
maxObjectNotesLen = 10_000
|
||||
maxObjectPropsLen = 20_000
|
||||
defaultObjectGridCM = 30 // ~1 ft, a practical bed cell for plant snapping
|
||||
)
|
||||
|
||||
// objectKinds maps each valid garden_objects.kind to its traits. plantable is
|
||||
@@ -43,6 +44,8 @@ type ObjectInput struct {
|
||||
Plantable *bool
|
||||
Color *string
|
||||
Props *string
|
||||
GridSizeCM float64
|
||||
SnapToGrid bool
|
||||
Notes string
|
||||
}
|
||||
|
||||
@@ -65,6 +68,8 @@ type ObjectPatch struct {
|
||||
Color *string
|
||||
SetProps bool
|
||||
Props *string
|
||||
GridSizeCM *float64
|
||||
SnapToGrid *bool
|
||||
Notes *string
|
||||
}
|
||||
|
||||
@@ -110,6 +115,8 @@ func (s *Service) CreateObject(ctx context.Context, actorID, gardenID int64, in
|
||||
Plantable: plantable,
|
||||
Color: in.Color,
|
||||
Props: in.Props,
|
||||
GridSizeCM: in.GridSizeCM,
|
||||
SnapToGrid: in.SnapToGrid,
|
||||
Notes: strings.TrimSpace(in.Notes),
|
||||
}
|
||||
if err := finalizeObject(o, g); err != nil {
|
||||
@@ -229,6 +236,12 @@ func applyObjectPatch(o *domain.GardenObject, p ObjectPatch) {
|
||||
if p.SetProps {
|
||||
o.Props = p.Props
|
||||
}
|
||||
if p.GridSizeCM != nil {
|
||||
o.GridSizeCM = *p.GridSizeCM
|
||||
}
|
||||
if p.SnapToGrid != nil {
|
||||
o.SnapToGrid = *p.SnapToGrid
|
||||
}
|
||||
if p.Notes != nil {
|
||||
o.Notes = strings.TrimSpace(*p.Notes)
|
||||
}
|
||||
@@ -251,6 +264,15 @@ func finalizeObject(o *domain.GardenObject, g *domain.Garden) error {
|
||||
if !validDimensionCM(o.WidthCM) || !validDimensionCM(o.HeightCM) {
|
||||
return domain.ErrInvalidInput
|
||||
}
|
||||
// Grid spacing shares the dimension range [1 cm, 100 m]; 0 means "unset" and
|
||||
// is defaulted so a create (or an older client omitting it) still lands a
|
||||
// usable bed grid.
|
||||
if o.GridSizeCM == 0 {
|
||||
o.GridSizeCM = defaultObjectGridCM
|
||||
}
|
||||
if !validDimensionCM(o.GridSizeCM) {
|
||||
return domain.ErrInvalidInput
|
||||
}
|
||||
if !isFinite(o.XCM) || !isFinite(o.YCM) || !isFinite(o.RotationDeg) {
|
||||
return domain.ErrInvalidInput
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user