diff options
Diffstat (limited to 'internal/admin/casino_validate.go')
| -rw-r--r-- | internal/admin/casino_validate.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/internal/admin/casino_validate.go b/internal/admin/casino_validate.go new file mode 100644 index 0000000..5b6902c --- /dev/null +++ b/internal/admin/casino_validate.go @@ -0,0 +1,33 @@ +package admin + +import ( + "bytes" + + "gopkg.in/yaml.v3" + "thehouseoficarus/internal/casino" +) + +// Validate before any room/link writes. Only casino fields are decoded here; +// the room editor's unrelated fields retain their existing representation. +func validateRoomCasinoMap(m map[string]any) error { + fields := map[string]any{} + for _, key := range []string{"casino_tables", "casino_machines"} { + if value, ok := m[key]; ok { + fields[key] = value + } + } + data, err := yaml.Marshal(fields) + if err != nil { + return err + } + var cfg struct { + Tables []casino.TableConfig `yaml:"casino_tables"` + Machines []casino.MachineConfig `yaml:"casino_machines"` + } + decoder := yaml.NewDecoder(bytes.NewReader(data)) + decoder.KnownFields(true) + if err := decoder.Decode(&cfg); err != nil { + return err + } + return casino.ValidateRoomConfigs(cfg.Tables, cfg.Machines) +} |
