|
| 1 | +package configs |
| 2 | + |
| 3 | +import ( |
| 4 | + "strings" |
| 5 | +) |
| 6 | + |
| 7 | +type UserInterface struct { |
| 8 | + Formats UserInterfaceFormats `yaml:"Formats"` |
| 9 | + Display UserInterfaceDisplay `yaml:"Display"` |
| 10 | +} |
| 11 | + |
| 12 | +type UserInterfaceFormats struct { |
| 13 | + Prompt ConfigString `yaml:"Prompt"` // The in-game status prompt style |
| 14 | + EnterRoomMessageWrapper ConfigString `yaml:"EnterRoomMessageWrapper"` // Special enter messages |
| 15 | + ExitRoomMessageWrapper ConfigString `yaml:"ExitRoomMessageWrapper"` // Special exit messages |
| 16 | + Time ConfigString `yaml:"Time"` // How to format time when displaying real time |
| 17 | + TimeShort ConfigString `yaml:"TimeShort"` // How to format time when displaying real time (shortform) |
| 18 | +} |
| 19 | + |
| 20 | +type UserInterfaceDisplay struct { |
| 21 | + ShowEmptyEquipmentSlots ConfigBool `yaml:"ShowEmptyEquipmentSlots"` // Whether to show empty equipment slots when looking at characters/mobs |
| 22 | +} |
| 23 | + |
| 24 | +func (u *UserInterface) Validate() { |
| 25 | + u.Formats.Validate() |
| 26 | + u.Display.Validate() |
| 27 | +} |
| 28 | + |
| 29 | +func (f *UserInterfaceFormats) Validate() { |
| 30 | + if f.Prompt == `` { |
| 31 | + f.Prompt = `{8}[{t} {T} {255}HP:{hp}{8}/{HP} {255}MP:{13}{mp}{8}/{13}{MP}{8}]{239}{h}{8}:` |
| 32 | + } |
| 33 | + |
| 34 | + // Must have a message wrapper... |
| 35 | + if f.EnterRoomMessageWrapper == `` { |
| 36 | + f.EnterRoomMessageWrapper = `%s` // default |
| 37 | + } |
| 38 | + if strings.LastIndex(string(f.EnterRoomMessageWrapper), `%s`) < 0 { |
| 39 | + f.EnterRoomMessageWrapper += `%s` // append if missing |
| 40 | + } |
| 41 | + |
| 42 | + // Must have a message wrapper... |
| 43 | + if f.ExitRoomMessageWrapper == `` { |
| 44 | + f.ExitRoomMessageWrapper = `%s` // default |
| 45 | + } |
| 46 | + if strings.LastIndex(string(f.ExitRoomMessageWrapper), `%s`) < 0 { |
| 47 | + f.ExitRoomMessageWrapper += `%s` // append if missing |
| 48 | + } |
| 49 | + |
| 50 | + if f.Time == `` { |
| 51 | + f.Time = `Monday, 02-Jan-2006 03:04:05PM` |
| 52 | + } |
| 53 | + |
| 54 | + if f.TimeShort == `` { |
| 55 | + f.TimeShort = `Jan 2 '06 3:04PM` |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +func (d *UserInterfaceDisplay) Validate() { |
| 60 | + // ShowEmptyEquipmentSlots defaults to true (show all slots) |
| 61 | + // The ConfigBool type handles the default value |
| 62 | +} |
| 63 | + |
| 64 | +// Convenience method to check if empty equipment slots should be shown |
| 65 | +func (c Config) ShouldShowEmptyEquipmentSlots() bool { |
| 66 | + return bool(c.UserInterface.Display.ShowEmptyEquipmentSlots) |
| 67 | +} |
| 68 | + |
| 69 | +// GetUserInterfaceConfig returns the UserInterface configuration |
| 70 | +func GetUserInterfaceConfig() UserInterface { |
| 71 | + return GetConfig().UserInterface |
| 72 | +} |
0 commit comments