Skip to content

Commit

Permalink
Fix old style of backgrounds.yaml not being supported with this PR
Browse files Browse the repository at this point in the history
Fix formatting issues with /bgs changes
  • Loading branch information
Crystalwarrior committed Apr 10, 2024
1 parent f9a7278 commit 20d75fc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 4 additions & 4 deletions server/commands/areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ def ooc_cmd_bgs(client, arg):
Usage: /bgs category
"""
if arg == "":
msg = "Available backgrounds:\n"
msg = "Available Categories:"
for category in client.area.server.backgrounds_categories:
msg += f"\n{category};"
msg += f"\n{category}"
client.send_ooc(msg)
elif arg in client.server.backgrounds_categories:
msg = f"Available {arg} backgrounds:\n"
msg = f"Backgrounds in Category '{arg}':"
for bg in client.server.backgrounds_categories[arg]:
msg += f"\n{bg};"
msg += f"\n{bg}"
client.send_ooc(msg)
else:
client.send_ooc("There is no category with this name in server background list.")
Expand Down
11 changes: 9 additions & 2 deletions server/tsuserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,15 @@ def load_music(self):
def load_backgrounds(self):
"""Load the backgrounds list from a YAML file."""
with open("config/backgrounds.yaml", "r", encoding="utf-8") as bgs:
self.backgrounds_categories = yaml.safe_load(bgs)
self.backgrounds = list(self.backgrounds_categories.values())
bg_yaml = yaml.safe_load(bgs)
# old style of backgrounds.yaml
if type(bg_yaml) is list:
self.backgrounds_categories = {"backgrounds": bg_yaml}
self.backgrounds = bg_yaml
# new style of categorized backgrounds.yaml
else:
self.backgrounds_categories = bg_yaml
self.backgrounds = list(self.backgrounds_categories.values())

def load_server_links(self):
"""Load the server links list from a YAML file."""
Expand Down

0 comments on commit 20d75fc

Please sign in to comment.