diff options
| author | historia <[not public]> | 2026-06-30 19:27:37 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-30 19:27:37 -0400 |
| commit | fee376102192dc6f24297a7b11324636ace3a07d (patch) | |
| tree | 6c777cc71208b429eebdbdc5864b353d4af34a09 /internal/admin/server.go | |
| parent | 98bdef072c843fdd8ccdf85a9b54ab9d32d34187 (diff) | |
| download | thehouseoficarus-fee376102192dc6f24297a7b11324636ace3a07d.tar.gz | |
feat: admin gui object CRUD is much nicer
Diffstat (limited to 'internal/admin/server.go')
| -rw-r--r-- | internal/admin/server.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/internal/admin/server.go b/internal/admin/server.go index 823d7ba..df6d5d9 100644 --- a/internal/admin/server.go +++ b/internal/admin/server.go @@ -19,6 +19,8 @@ import ( "math/big" "net" "net/http" + "path/filepath" + "strconv" "strings" "time" @@ -400,6 +402,7 @@ func (s *AdminServer) doUndo(w http.ResponseWriter, r *http.Request) { writeJSON(w, map[string]any{"message": "Nothing to undo"}) return } + s.rebuildAfterUndo(change) writeJSON(w, map[string]any{"message": "Undid: " + change.Description}) } @@ -413,5 +416,38 @@ func (s *AdminServer) doRedo(w http.ResponseWriter, r *http.Request) { writeJSON(w, map[string]any{"message": "Nothing to redo"}) return } + s.rebuildAfterUndo(change) writeJSON(w, map[string]any{"message": "Redid: " + change.Description}) } + +func (s *AdminServer) rebuildAfterUndo(change *ChangeDesc) { + s.world.RebuildRoomIndex(s.dataDir) + s.world.ClearHazardCache() + + for _, p := range changeFiles(change) { + rel, err := filepath.Rel(filepath.Join(s.dataDir, "rooms"), p) + if err != nil { + continue + } + if rel == "." || rel == ".." || strings.HasPrefix(rel, "..") { + continue + } + name := filepath.Base(p) + if idStr := strings.TrimSuffix(name, ".yaml"); idStr != name { + if id, err := strconv.Atoi(idStr); err == nil && id > 0 { + s.world.ClearRoomState(id) + } + } + } +} + +func changeFiles(change *ChangeDesc) []string { + files := []string{change.FilePath} + if change.NewFilePath != "" { + files = append(files, change.NewFilePath) + } + for _, ef := range change.ExtraFiles { + files = append(files, ef.FilePath) + } + return files +} |
