From a6cf03a6ae98e4fb675da25046d148e92bcf7206 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Wed, 16 Sep 2026 15:00:46 -0400 Subject: chore: staticcheck and gofmt cleanups --- internal/admin/api_colors.go | 34 +++++-------------- internal/admin/api_colors_test.go | 2 +- internal/admin/api_room_courses.go | 56 ------------------------------- internal/admin/api_rooms.go | 2 +- internal/admin/undo.go | 67 -------------------------------------- internal/admin/xterm_to_css.go | 13 -------- internal/admin/yaml_util.go | 17 ---------- 7 files changed, 10 insertions(+), 181 deletions(-) (limited to 'internal/admin') diff --git a/internal/admin/api_colors.go b/internal/admin/api_colors.go index 876656d..b57ad82 100644 --- a/internal/admin/api_colors.go +++ b/internal/admin/api_colors.go @@ -3,7 +3,6 @@ package admin import ( "net/http" "os" - "sort" "strings" "gopkg.in/yaml.v3" @@ -185,11 +184,6 @@ func knownConstantColor(name string) bool { return false } -// knownColor returns true if name is editable in either section. -func knownColor(name string) bool { - return knownPlayerColor(name) || knownConstantColor(name) -} - // seg is a small constructor helper for the inline preview builder. func seg(t, cat string) colorSegment { return colorSegment{T: t, C: cat} @@ -280,7 +274,6 @@ func buildPreview() []colorSection { ln(seg("Oh dear, you are dead!", "death")), txt(""), txt(""), - }, }) @@ -479,20 +472,20 @@ func (s *AdminServer) getColors(w http.ResponseWriter, _ *http.Request) { } writeJSON(w, map[string]any{ - "colors": live, - "default_colors": def, - "categories": colorCategories, - "constant_colors": liveConst, + "colors": live, + "default_colors": def, + "categories": colorCategories, + "constant_colors": liveConst, "default_constant_colors": defConst, - "constant_categories": constantCategories, - "preview": buildPreview(), + "constant_categories": constantCategories, + "preview": buildPreview(), }) } func (s *AdminServer) saveColors(w http.ResponseWriter, r *http.Request) { var body struct { - Colors map[string]string `json:"colors"` - ConstantColors map[string]string `json:"constant_colors"` + Colors map[string]string `json:"colors"` + ConstantColors map[string]string `json:"constant_colors"` } if err := readJSON(r, &body); err != nil { writeJSONError(w, "invalid request body", http.StatusBadRequest) @@ -593,14 +586,3 @@ func (s *AdminServer) writeConfigFile() error { } return os.WriteFile(s.configPath, out, 0644) } - -// sortedKeys is a small helper retained in case future code wants a stable -// iteration order over the category names. -func sortedKeys(m map[string]string) []string { - keys := make([]string, 0, len(m)) - for k := range m { - keys = append(keys, k) - } - sort.Strings(keys) - return keys -} diff --git a/internal/admin/api_colors_test.go b/internal/admin/api_colors_test.go index 1f5d3eb..53c68b1 100644 --- a/internal/admin/api_colors_test.go +++ b/internal/admin/api_colors_test.go @@ -225,4 +225,4 @@ func TestColorsPreviewExhaustive(t *testing.T) { } } _ = io.Discard -} \ No newline at end of file +} diff --git a/internal/admin/api_room_courses.go b/internal/admin/api_room_courses.go index 47e4d8c..b8f334e 100644 --- a/internal/admin/api_room_courses.go +++ b/internal/admin/api_room_courses.go @@ -105,19 +105,6 @@ func toInt(v any) int { return 0 } -// toFloat64 coerces yaml-decoded numbers to float64. -func toFloat64(v any) float64 { - switch x := v.(type) { - case int: - return float64(x) - case int64: - return float64(x) - case float64: - return x - } - return 0 -} - // indexOfObstacleForRoom returns the index of the obstacle whose room_id // matches roomID, or -1 if none. func indexOfObstacleForRoom(obstacles []map[string]any, roomID int) int { @@ -515,39 +502,6 @@ func (s *AdminServer) loadRoomMapByID(roomID int) (map[string]any, []byte, strin return m, data, path, nil } -// saveRoomMapByID writes a room map back to disk and pushes an undo entry. -func (s *AdminServer) saveRoomMapByID(roomID int, m map[string]any, desc string) error { - path, ok := s.world.GetRoomPath(roomID) - if !ok { - return fmt.Errorf("room %d not found", roomID) - } - oldContent, _ := snapshotFile(path) - newContent, err := writeMapAsYAML(path, m) - if err != nil { - return err - } - s.undoStack.Push(ChangeDesc{ - Description: desc, - FilePath: path, - OldContent: oldContent, - NewContent: newContent, - }) - return nil -} - -// removeExit deletes an exit by direction. Returns true if it existed. -func removeExit(m map[string]any, dir string) bool { - ex, ok := m["exits"].(map[string]any) - if !ok { - return false - } - if _, exists := ex[dir]; exists { - delete(ex, dir) - return true - } - return false -} - // exitTargetRoom returns the target room ID of an exit value (scalar or map). func exitTargetRoom(v any) int { switch x := v.(type) { @@ -563,16 +517,6 @@ func exitTargetRoom(v any) int { return 0 } -// exitIsAlwaysBlocked returns whether an exit value carries always_blocked: true. -func exitIsAlwaysBlocked(v any) bool { - if mm, ok := v.(map[string]any); ok { - if h, ok := mm["always_blocked"]; ok { - return h == true - } - } - return false -} - // isHorizontalDir returns whether d is one of the 8 horizontal directions. func isHorizontalDir(d string) bool { for _, h := range horizontalExitDirs { diff --git a/internal/admin/api_rooms.go b/internal/admin/api_rooms.go index 01b7b9a..8ee16a5 100644 --- a/internal/admin/api_rooms.go +++ b/internal/admin/api_rooms.go @@ -131,7 +131,7 @@ func (s *AdminServer) handleRooms(w http.ResponseWriter, r *http.Request) { conflicts++ }) if conflicts > 0 { - writeJSON(w, map[string]any{"error": fmt.Sprintf("Add Next Step: that grid spot is already occupied — room would cause map overlap")}) + writeJSON(w, map[string]any{"error": "Add Next Step: that grid spot is already occupied — room would cause map overlap"}) return } } else { diff --git a/internal/admin/undo.go b/internal/admin/undo.go index 98d8d9a..51610f8 100644 --- a/internal/admin/undo.go +++ b/internal/admin/undo.go @@ -414,73 +414,6 @@ func (us *UndoStack) save() { } } -func (us *UndoStack) load() { - data, err := os.ReadFile(us.filePath) - if err != nil { - return - } - log.Printf("undo: loaded history from %s", us.filePath) - type extraEntry struct { - FilePath string `json:"file_path"` - NewFilePath string `json:"new_file_path,omitempty"` - OldContent string `json:"old_content"` - NewContent string `json:"new_content"` - IsDelete bool `json:"is_delete,omitempty"` - IsCreate bool `json:"is_create,omitempty"` - } - type entry struct { - Time string `json:"time"` - Description string `json:"description"` - FilePath string `json:"file_path"` - NewFilePath string `json:"new_file_path,omitempty"` - OldContent string `json:"old_content"` - NewContent string `json:"new_content"` - IsDelete bool `json:"is_delete"` - IsCreate bool `json:"is_create"` - ExtraFiles []extraEntry `json:"extra_files,omitempty"` - IDMap map[int]int `json:"id_map,omitempty"` - } - var saveData struct { - History []entry `json:"history"` - Redo []entry `json:"redo"` - } - if err := json.Unmarshal(data, &saveData); err != nil { - log.Printf("undo: failed to unmarshal history: %v", err) - return - } - fromEntries := func(entries []entry) []ChangeDesc { - var changes []ChangeDesc - for _, e := range entries { - var extra []ExtraFile - for _, ef := range e.ExtraFiles { - extra = append(extra, ExtraFile{ - FilePath: ef.FilePath, - NewFilePath: ef.NewFilePath, - OldContent: []byte(ef.OldContent), - NewContent: []byte(ef.NewContent), - IsDelete: ef.IsDelete, - IsCreate: ef.IsCreate, - }) - } - changes = append(changes, ChangeDesc{ - Time: e.Time, - Description: e.Description, - FilePath: e.FilePath, - NewFilePath: e.NewFilePath, - OldContent: []byte(e.OldContent), - NewContent: []byte(e.NewContent), - IsDelete: e.IsDelete, - IsCreate: e.IsCreate, - ExtraFiles: extra, - IDMap: e.IDMap, - }) - } - return changes - } - us.history = fromEntries(saveData.History) - log.Printf("undo: loaded %d history entries", len(us.history)) -} - func (us *UndoStack) Clear() { us.mu.Lock() defer us.mu.Unlock() diff --git a/internal/admin/xterm_to_css.go b/internal/admin/xterm_to_css.go index 098ce62..6c1fda4 100644 --- a/internal/admin/xterm_to_css.go +++ b/internal/admin/xterm_to_css.go @@ -25,16 +25,3 @@ func XtermColorForCSS(idx int) string { r, g, b := color.Xterm256ToRGB(idx) return fmt.Sprintf("#%02x%02x%02x", r, g, b) } - -func xtermColorList() []map[string]any { - var list []map[string]any - for i := 0; i < 256; i++ { - r, g, b := color.Xterm256ToRGB(i) - list = append(list, map[string]any{ - "index": i, - "hex": fmt.Sprintf("%02X%02X%02X", r, g, b), - "color": fmt.Sprintf("#%02x%02x%02x", r, g, b), - }) - } - return list -} diff --git a/internal/admin/yaml_util.go b/internal/admin/yaml_util.go index 9ef8058..6ea6692 100644 --- a/internal/admin/yaml_util.go +++ b/internal/admin/yaml_util.go @@ -142,23 +142,6 @@ func listYAMLTree(dataDir, subdir string) (*YAMLTree, error) { return tree, nil } -func listYAMLFilesDeep(dataDir, subdir string) ([]string, error) { - var ids []string - base := filepath.Join(dataDir, subdir) - err := filepath.WalkDir(base, func(path string, d os.DirEntry, err error) error { - if err != nil { - return err - } - if !d.IsDir() && filepath.Ext(d.Name()) == ".yaml" { - rel, _ := filepath.Rel(base, path) - id := rel[:len(rel)-5] - ids = append(ids, id) - } - return nil - }) - return ids, err -} - func backupFile(path string) []byte { data, err := os.ReadFile(path) if err != nil { -- cgit v1.2.3