From 5ca87c752fa18f0843c0f660106f85a6f0ac8a8e Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sun, 16 Jan 2022 20:20:48 -0800 Subject: [PATCH] Sort level actors deterministically by their (time sensitive) ID --- pkg/uix/canvas_actors.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/uix/canvas_actors.go b/pkg/uix/canvas_actors.go index 87b6a97..e42b39c 100644 --- a/pkg/uix/canvas_actors.go +++ b/pkg/uix/canvas_actors.go @@ -3,6 +3,7 @@ package uix import ( "errors" "fmt" + "sort" "strings" "git.kirsle.net/apps/doodle/pkg/doodads" @@ -17,8 +18,18 @@ import ( func (w *Canvas) InstallActors(actors level.ActorMap) error { var errs []string + // Order the actors deterministically, by their ID string. Actors get + // a time-ordered UUID ID by default so the most recently added actor + // should render on top of the others. + var actorIDs []string + for id := range actors { + actorIDs = append(actorIDs, id) + } + sort.Strings(actorIDs) + w.actors = make([]*Actor, 0) - for id, actor := range actors { + for _, id := range actorIDs { + var actor = actors[id] doodad, err := doodads.LoadFromEmbeddable(actor.Filename, w.level) if err != nil { errs = append(errs, fmt.Sprintf("%s: %s", actor.Filename, err.Error()))