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.go44
1 files changed, 28 insertions, 16 deletions
diff --git a/internal/admin/server.go b/internal/admin/server.go
index 842f640..ccad6a2 100644
--- a/internal/admin/server.go
+++ b/internal/admin/server.go
@@ -58,9 +58,13 @@ type AdminServer struct {
// configPath is the on-disk config.yaml path, used by the color themer
// to persist edited default_colors back to the file the game loaded.
configPath string
+ // rebuildCraftIndex rebuilds the in-game craft index after item files
+ // change (create/update/delete/rename/move/undo/redo). Wired from the
+ // Game so the web editor's item edits stay consistent with gameplay.
+ rebuildCraftIndex func()
}
-func NewServer(cfg *config.Config, useTLS bool, accountStore *player.AccountStore, w *world.World, is *item.ItemStore, os *object.ObjectStore, ms *world.MobStore, dataDir string, reloadCourses func(), rewriteRoomIDs func(map[int]int), configPath string) (*AdminServer, error) {
+func NewServer(cfg *config.Config, useTLS bool, accountStore *player.AccountStore, w *world.World, is *item.ItemStore, os *object.ObjectStore, ms *world.MobStore, dataDir string, reloadCourses func(), rewriteRoomIDs func(map[int]int), rebuildCraftIndex func(), configPath string) (*AdminServer, error) {
secret := make([]byte, 32)
if _, err := rand.Read(secret); err != nil {
return nil, fmt.Errorf("cookie secret: %w", err)
@@ -92,20 +96,21 @@ func NewServer(cfg *config.Config, useTLS bool, accountStore *player.AccountStor
}
s := &AdminServer{
- cfg: cfg,
- useTLS: useTLS,
- accountStore: accountStore,
- world: w,
- itemStore: is,
- objectStore: os,
- mobStore: ms,
- dataDir: dataDir,
- undoStack: NewUndoStack(dataDir),
- tmpl: tmpl,
- cookieSecret: secret,
- reloadCourses: reloadCourses,
- rewriteRoomIDs: rewriteRoomIDs,
- configPath: configPath,
+ cfg: cfg,
+ useTLS: useTLS,
+ accountStore: accountStore,
+ world: w,
+ itemStore: is,
+ objectStore: os,
+ mobStore: ms,
+ dataDir: dataDir,
+ undoStack: NewUndoStack(dataDir),
+ tmpl: tmpl,
+ cookieSecret: secret,
+ reloadCourses: reloadCourses,
+ rewriteRoomIDs: rewriteRoomIDs,
+ rebuildCraftIndex: rebuildCraftIndex,
+ configPath: configPath,
}
mux := http.NewServeMux()
@@ -657,11 +662,18 @@ func (s *AdminServer) invalidateEntityCaches(entityType string) {
s.mobStore.ReloadDefs(s.dataDir)
case "drops":
behavior.ClearDropIndex()
+ case "items":
+ if s.itemStore != nil {
+ s.itemStore.Reload(s.dataDir)
+ }
+ if s.rebuildCraftIndex != nil {
+ s.rebuildCraftIndex()
+ }
}
}
func (s *AdminServer) invalidateEntityCacheForPath(path string) {
- for _, subdir := range []string{"mobs", "drops"} {
+ for _, subdir := range []string{"mobs", "drops", "items"} {
rel, err := filepath.Rel(filepath.Join(s.dataDir, subdir), path)
if err == nil && !strings.HasPrefix(rel, "..") && rel != "." {
s.invalidateEntityCaches(subdir)