Sort level actors deterministically by their (time sensitive) ID
This commit is contained in:
parent
4d08bf1d85
commit
5ca87c752f
|
@ -3,6 +3,7 @@ package uix
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.kirsle.net/apps/doodle/pkg/doodads"
|
"git.kirsle.net/apps/doodle/pkg/doodads"
|
||||||
|
@ -17,8 +18,18 @@ import (
|
||||||
func (w *Canvas) InstallActors(actors level.ActorMap) error {
|
func (w *Canvas) InstallActors(actors level.ActorMap) error {
|
||||||
var errs []string
|
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)
|
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)
|
doodad, err := doodads.LoadFromEmbeddable(actor.Filename, w.level)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = append(errs, fmt.Sprintf("%s: %s", actor.Filename, err.Error()))
|
errs = append(errs, fmt.Sprintf("%s: %s", actor.Filename, err.Error()))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user