Skip to content

Commit 2656c28

Browse files
committed
Fixed gmcp-individual-nodes to use UserInterface instead of TextFormats
Updated all references from GetTextFormatsConfig() to GetUserInterfaceConfig().Formats to maintain compatibility with the UserInterface configuration structure introduced in mob-equipment-templates. Changed: - Config struct to use UserInterface instead of TextFormats - gmcp.Game.go to use c.UserInterface.Formats.Time - All usercommands and mobcommands to use GetUserInterfaceConfig().Formats - inbox.go DateString() to use UserInterface.Formats.Time - userrecord.prompt.go to use GetUserInterfaceConfig().Formats.Prompt
1 parent b300210 commit 2656c28

File tree

10 files changed

+95
-23
lines changed

10 files changed

+95
-23
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
}

internal/configs/configs.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ var (
3535

3636
type Config struct {
3737
// Start config subsections
38-
Server Server `yaml:"Server"`
39-
Memory Memory `yaml:"Memory"`
40-
LootGoblin LootGoblin `yaml:"LootGoblin"`
41-
Timing Timing `yaml:"Timing"`
42-
FilePaths FilePaths `yaml:"FilePaths"`
43-
GamePlay GamePlay `yaml:"GamePlay"`
44-
Integrations Integrations `yaml:"Integrations"`
45-
TextFormats TextFormats `yaml:"TextFormats"`
46-
Translation Translation `yaml:"Translation"`
47-
Network Network `yaml:"Network"`
48-
Scripting Scripting `yaml:"Scripting"`
49-
SpecialRooms SpecialRooms `yaml:"SpecialRooms"`
50-
Validation Validation `yaml:"Validation"`
51-
Roles Roles `yaml:"Roles"`
38+
Server Server `yaml:"Server"`
39+
Memory Memory `yaml:"Memory"`
40+
LootGoblin LootGoblin `yaml:"LootGoblin"`
41+
Timing Timing `yaml:"Timing"`
42+
FilePaths FilePaths `yaml:"FilePaths"`
43+
GamePlay GamePlay `yaml:"GamePlay"`
44+
UserInterface UserInterface `yaml:"UserInterface"`
45+
Integrations Integrations `yaml:"Integrations"`
46+
Translation Translation `yaml:"Translation"`
47+
Network Network `yaml:"Network"`
48+
Scripting Scripting `yaml:"Scripting"`
49+
SpecialRooms SpecialRooms `yaml:"SpecialRooms"`
50+
Validation Validation `yaml:"Validation"`
51+
Roles Roles `yaml:"Roles"`
5252
// Plugins is a special case
5353
Modules Modules `yaml:"Modules"`
5454

internal/mobcommands/go.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func Go(rest string, mob *mobs.Mob, room *rooms.Room) (bool, error) {
3030
}
3131

3232
if !foundRoomExit {
33-
c := configs.GetTextFormatsConfig()
33+
c := configs.GetUserInterfaceConfig().Formats
3434

3535
if forceRoomId == room.RoomId {
3636
return true, nil
@@ -112,7 +112,7 @@ func Go(rest string, mob *mobs.Mob, room *rooms.Room) (bool, error) {
112112
room.RemoveMob(mob.InstanceId)
113113
destRoom.AddMob(mob.InstanceId)
114114

115-
c := configs.GetTextFormatsConfig()
115+
c := configs.GetUserInterfaceConfig().Formats
116116

117117
// Tell the old room they are leaving
118118
room.SendText(

internal/usercommands/go.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func Go(rest string, user *users.UserRecord, room *rooms.Room, flags events.Even
2929
return true, nil
3030
}
3131

32-
c := configs.GetTextFormatsConfig()
32+
c := configs.GetUserInterfaceConfig().Formats
3333

3434
isSneaking := user.Character.HasBuffFlag(buffs.Hidden)
3535

internal/usercommands/history.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func History(rest string, user *users.UserRecord, room *rooms.Room, flags events
2121
`<ansi fg="white-bold">%s</ansi>`,
2222
}
2323

24-
tFormat := string(configs.GetTextFormatsConfig().TimeShort)
24+
tFormat := string(configs.GetUserInterfaceConfig().Formats.TimeShort)
2525

2626
for itm := range user.EventLog.Items {
2727

internal/usercommands/set.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
func Set(rest string, user *users.UserRecord, room *rooms.Room, flags events.EventFlag) (bool, error) {
1616

1717
args := util.SplitButRespectQuotes(strings.ToLower(rest))
18-
c := configs.GetTextFormatsConfig()
18+
c := configs.GetUserInterfaceConfig().Formats
1919

2020
if len(args) == 0 {
2121

internal/usercommands/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func Start(rest string, user *users.UserRecord, room *rooms.Room, flags events.E
211211
// Tell the new room they have arrived
212212

213213
destRoom.SendText(
214-
fmt.Sprintf(configs.GetTextFormatsConfig().EnterRoomMessageWrapper.String(),
214+
fmt.Sprintf(configs.GetUserInterfaceConfig().Formats.EnterRoomMessageWrapper.String(),
215215
fmt.Sprintf(`<ansi fg="username">%s</ansi> enters from <ansi fg="exit">somewhere</ansi>.`, user.Character.Name),
216216
),
217217
user.UserId,

internal/users/inbox.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ func (i *Inbox) Empty() {
5757
}
5858

5959
func (m Message) DateString() string {
60-
tFormat := string(configs.GetConfig().TextFormats.Time)
60+
tFormat := string(configs.GetConfig().UserInterface.Formats.Time)
6161
return m.DateSent.Format(tFormat)
6262
}

internal/users/userrecord.prompt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (u *UserRecord) GetCommandPrompt() string {
4848
if len(promptOut) == 0 {
4949

5050
if promptDefaultCompiled == `` {
51-
promptDefaultCompiled = util.ConvertColorShortTags(configs.GetTextFormatsConfig().Prompt.String())
51+
promptDefaultCompiled = util.ConvertColorShortTags(configs.GetUserInterfaceConfig().Formats.Prompt.String())
5252
}
5353

5454
var customPrompt any = nil

modules/gmcp/gmcp.Game.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (g *GMCPGameModule) sendAllGameNodes(userId int) {
124124
}
125125

126126
c := configs.GetConfig()
127-
tFormat := string(c.TextFormats.Time)
127+
tFormat := string(c.UserInterface.Formats.Time)
128128

129129
// Send Game.Info
130130
infoPayload := map[string]interface{}{

0 commit comments

Comments
 (0)