aboutsummaryrefslogtreecommitdiff
path: root/internal/player
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-11 20:41:06 -0400
committerhistoria <[not public]>2026-06-11 20:41:06 -0400
commitd6ab0e93a64525ce34f89e26d5272efbac513c32 (patch)
treed0ec59a72a32a15d0917d9c6c3bfa2f2a424c1f1 /internal/player
parent6b2b4bf470b655f01c5a21c5f558a6102402c214 (diff)
downloadthehouseoficarus-d6ab0e93a64525ce34f89e26d5272efbac513c32.tar.gz
feat: big map and options changes
Diffstat (limited to 'internal/player')
-rw-r--r--internal/player/player.go127
1 files changed, 114 insertions, 13 deletions
diff --git a/internal/player/player.go b/internal/player/player.go
index 56ab06c..97874e3 100644
--- a/internal/player/player.go
+++ b/internal/player/player.go
@@ -86,6 +86,53 @@ type InventorySlot struct {
Quantity int `yaml:"quantity"`
}
+type OptionType int
+
+const (
+ OptBool OptionType = iota
+ OptString
+ OptInt
+)
+
+type OptionDef struct {
+ Name string
+ Type OptionType
+ Default any
+ ValidValues []string
+ Description string
+}
+
+var OptionDefs = []OptionDef{
+ {"description", OptBool, true, nil, "Long room descriptions when moving"},
+ {"tinymap", OptBool, true, nil, "Mini-map display"},
+ {"left-tinymap", OptBool, false, nil, "Mini-map on left side of descriptions"},
+ {"xpdrops", OptBool, true, nil, "XP drop messages"},
+ {"exits", OptBool, true, nil, "Long exit display in look"},
+ {"mobenter", OptBool, true, nil, "Messages when mobs enter the room"},
+ {"mobleave", OptBool, true, nil, "Messages when mobs leave the room"},
+ {"mobspawn", OptBool, true, nil, "Messages when mobs spawn in the area"},
+ {"reserve", OptBool, true, nil, "Show full reserved item details"},
+ {"depletion", OptBool, false, nil, "Show depletion and despawn timers"},
+ {"color", OptString, "none", []string{"none", "ansi", "xterm256"}, "Color output mode"},
+ {"mapwidth", OptInt, 30, nil, "Map width for the map command"},
+ {"mapheight", OptInt, 20, nil, "Map height for the map command"},
+ {"mappadding", OptString, "none", []string{"none", "x", "y", "xy"}, "Map output padding mode"},
+ {"automap", OptBool, false, nil, "Show map automatically after moving"},
+}
+
+var optionByName map[string]*OptionDef
+
+func init() {
+ optionByName = make(map[string]*OptionDef, len(OptionDefs))
+ for i := range OptionDefs {
+ optionByName[OptionDefs[i].Name] = &OptionDefs[i]
+ }
+}
+
+func GetOptionDef(name string) *OptionDef {
+ return optionByName[name]
+}
+
type Player struct {
Name string `yaml:"name"`
Skills map[SkillName]int `yaml:"skills"`
@@ -96,12 +143,73 @@ type Player struct {
Credits int `yaml:"credits"`
Description string `yaml:"description"`
AttackStyle AttackStyle `yaml:"attack_style"`
- Toggles map[string]bool `yaml:"toggles"`
+ Options map[string]any `yaml:"options"`
Flags map[string]any `yaml:"flags"`
RegenerateTick int
Action *action.Action `yaml:"-"`
}
+func (p *Player) OptionBool(name string) bool {
+ def := GetOptionDef(name)
+ if def == nil || def.Type != OptBool {
+ return false
+ }
+ if p.Options == nil {
+ return def.Default.(bool)
+ }
+ val, ok := p.Options[name]
+ if !ok {
+ return def.Default.(bool)
+ }
+ b, ok := val.(bool)
+ if !ok {
+ return def.Default.(bool)
+ }
+ return b
+}
+
+func (p *Player) OptionString(name string) string {
+ def := GetOptionDef(name)
+ if def == nil || def.Type != OptString {
+ return ""
+ }
+ if p.Options == nil {
+ return def.Default.(string)
+ }
+ val, ok := p.Options[name]
+ if !ok {
+ return def.Default.(string)
+ }
+ s, ok := val.(string)
+ if !ok {
+ return def.Default.(string)
+ }
+ return s
+}
+
+func (p *Player) OptionInt(name string) int {
+ def := GetOptionDef(name)
+ if def == nil || def.Type != OptInt {
+ return 0
+ }
+ if p.Options == nil {
+ return def.Default.(int)
+ }
+ val, ok := p.Options[name]
+ if !ok {
+ return def.Default.(int)
+ }
+ switch v := val.(type) {
+ case int:
+ return v
+ case int64:
+ return int(v)
+ case float64:
+ return int(v)
+ }
+ return def.Default.(int)
+}
+
func (p *Player) InvSlot(i int) *InventorySlot {
if p.Inventory == nil {
return nil
@@ -140,18 +248,11 @@ func New(name string) *Player {
Skills: make(map[SkillName]int),
Equipment: make(map[object.EquipSlot]string),
AttackStyle: Accurate,
- Toggles: map[string]bool{
- "description": true,
- "tinymap": true,
- "left-tinymap": false,
- "xpdrops": true,
- "exits": true,
- "mobenter": true,
- "mobleave": true,
- "mobspawn": true,
- "reserve": true,
- },
- RoomID: 0,
+ Options: make(map[string]any),
+ RoomID: 0,
+ }
+ for _, def := range OptionDefs {
+ p.Options[def.Name] = def.Default
}
for _, s := range AllSkills {
p.Skills[s] = 0