describe_garden: list each plop's position, so a move can keep the layout #128

Merged
steve merged 2 commits from fix/describe-plop-coordinates into main 2026-08-23 04:43:48 +00:00
2 changed files with 14 additions and 9 deletions
Showing only changes of commit 85b7dbbe3a - Show all commits
+5 -6
View File
@@ -605,17 +605,16 @@ type DescribeGroup struct {
// DaysToMaturity is the plant's, when the catalog knows it — with PlantedAt, // DaysToMaturity is the plant's, when the catalog knows it — with PlantedAt,
// enough to say when the harvest is due. // enough to say when the harvest is due.
DaysToMaturity *int `json:"daysToMaturity,omitempty"` DaysToMaturity *int `json:"daysToMaturity,omitempty"`
// Each lists the plops individually (id, version, location) only when the // Each lists the plops individually (id, version, position, location) only
// group has at most maxListedPlops of them. // when the group has at most maxListedPlops of them.
Each []DescribePlanting `json:"each,omitempty"` Each []DescribePlanting `json:"each,omitempty"`
} }
// DescribePlanting is one plop with its position and a rough compass location. // DescribePlanting is one plop with its position and a rough compass location.
// ID + Version let an agent address a single plop — remove it or move it — the // ID + Version let an agent address a single plop — remove it or move it — the
// same way DescribeObject.Version lets it edit an object; XCM/YCM (the object's // same way DescribeObject.Version lets it edit an object. XCM/YCM are in the
// local frame) let a move keep the layout the plops had, which "north, south" // object's local frame: they are what lets a move keep the layout the plops
// alone cannot: asked to move four tomatoes in a column "keeping the same // had, which the compass word alone ("north", "south") cannot.
// spacing", the live assistant re-laid them as two pairs for want of these.
type DescribePlanting struct { type DescribePlanting struct {
ID int64 `json:"id"` ID int64 `json:"id"`
Version int64 `json:"version"` Version int64 `json:"version"`
+9 -3
View File
@@ -628,14 +628,20 @@ func TestDescribeGardenGroupsByPlant(t *testing.T) {
if want := 2*derivedCount(20, 25) + 3; ba.Plants != want { if want := 2*derivedCount(20, 25) + 3; ba.Plants != want {
t.Errorf("basil plants = %d, want %d", ba.Plants, want) t.Errorf("basil plants = %d, want %d", ba.Plants, want)
} }
// The position is what lets a move keep the layout; "south" alone can't. The
// three basil plops were placed at exactly these local points.
placedAt := map[[2]float64]bool{{-100, 100}: true, {0, 150}: true, {100, 100}: true}
for _, e := range ba.Each { for _, e := range ba.Each {
if e.PlantedAt == "" || e.Version == 0 || e.ID == 0 { if e.PlantedAt == "" || e.Version == 0 || e.ID == 0 {
t.Errorf("listed plop %+v is missing id, version or date", e) t.Errorf("listed plop %+v is missing id, version or date", e)
} }
// The position is what lets a move keep the layout; "south" alone can't. if !placedAt[[2]float64{e.XCM, e.YCM}] {
if e.YCM < 100 || (e.XCM != -100 && e.XCM != 0 && e.XCM != 100) { t.Errorf("listed plop %+v is not at a position a basil was placed at", e)
t.Errorf("listed plop %+v doesn't carry the position it was placed at", e)
} }
delete(placedAt, [2]float64{e.XCM, e.YCM})
}
if len(placedAt) != 0 {
t.Errorf("positions never listed: %v", placedAt)
} }
// The big group's ids are a call away, narrowed to one plant. // The big group's ids are a call away, narrowed to one plant.