blob: 5b6902c30ce77f35f6d087ffe7eb98ca0e2dc042 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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)
}
|