aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/server.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/admin/server.go')
-rw-r--r--internal/admin/server.go43
1 files changed, 41 insertions, 2 deletions
diff --git a/internal/admin/server.go b/internal/admin/server.go
index ef95e73..b1f641a 100644
--- a/internal/admin/server.go
+++ b/internal/admin/server.go
@@ -117,20 +117,25 @@ func NewServer(cfg *config.Config, useTLS bool, accountStore *player.AccountStor
apiMux.HandleFunc("/api/rooms", s.handleRooms)
apiMux.HandleFunc("/api/rooms/new-empty", s.handleCreateEmptyRoom)
apiMux.HandleFunc("/api/rooms/", s.handleRoomByID)
+ apiMux.HandleFunc("/api/objects/move", s.handleEntityMove("objects"))
apiMux.HandleFunc("/api/objects", s.handleObjects)
apiMux.HandleFunc("/api/objects/", s.handleObjectByID)
+ apiMux.HandleFunc("/api/items/move", s.handleEntityMove("items"))
apiMux.HandleFunc("/api/items", s.handleItems)
apiMux.HandleFunc("/api/items/", s.handleItemByID)
+ apiMux.HandleFunc("/api/mobs/move", s.handleEntityMove("mobs"))
apiMux.HandleFunc("/api/mobs", s.handleMobs)
apiMux.HandleFunc("/api/mobs/", s.handleMobByID)
+ apiMux.HandleFunc("/api/drops/move", s.handleEntityMove("drops"))
apiMux.HandleFunc("/api/drops", s.handleDrops)
apiMux.HandleFunc("/api/drops/", s.handleDropByID)
+ apiMux.HandleFunc("/api/hazards/move", s.handleEntityMove("hazards"))
apiMux.HandleFunc("/api/hazards", s.handleHazards)
apiMux.HandleFunc("/api/hazards/", s.handleHazardByID)
+ apiMux.HandleFunc("/api/techs/move", s.handleEntityMove("techs"))
apiMux.HandleFunc("/api/techs", s.handleTechs)
apiMux.HandleFunc("/api/techs/", s.handleTechByID)
- apiMux.HandleFunc("/api/courses", s.handleCourses)
- apiMux.HandleFunc("/api/courses/", s.handleCourseByID)
+ apiMux.HandleFunc("/api/modules/move", s.handleEntityMove("modules"))
apiMux.HandleFunc("/api/modules", s.handleModules)
apiMux.HandleFunc("/api/modules/", s.handleModuleByID)
apiMux.HandleFunc("/api/players", s.handlePlayers)
@@ -461,6 +466,40 @@ func (s *AdminServer) doRedo(w http.ResponseWriter, r *http.Request) {
writeJSON(w, resp)
}
+func (s *AdminServer) handleEntityMove(entityType string) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ if r.Method != http.MethodPost {
+ http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
+ return
+ }
+ var body struct {
+ ID string `json:"id"`
+ Dir string `json:"dir"`
+ }
+ if err := readJSON(r, &body); err != nil || body.ID == "" {
+ writeJSON(w, map[string]any{"error": "invalid"})
+ return
+ }
+ oldPath, newPath, data, err := moveEntityFile(s.dataDir, entityType, body.ID, body.Dir)
+ if err != nil {
+ writeJSON(w, map[string]any{"error": err.Error()})
+ return
+ }
+ desc := fmt.Sprintf("move %s %s to %s/", entityType, body.ID, body.Dir)
+ if body.Dir == "" {
+ desc = fmt.Sprintf("move %s %s to root", entityType, body.ID)
+ }
+ s.undoStack.Push(ChangeDesc{
+ Description: desc,
+ FilePath: oldPath,
+ NewFilePath: newPath,
+ OldContent: data,
+ NewContent: data,
+ })
+ writeJSON(w, map[string]any{"ok": true})
+ }
+}
+
func (s *AdminServer) rebuildAfterUndo(change *ChangeDesc) {
s.world.RebuildRoomIndex(s.dataDir)
s.world.ClearHazardCache()