Skip to content

Commit

Permalink
rework load_backgrounds (#132)
Browse files Browse the repository at this point in the history
* rework backgrounds

* rework load_backgrounds

* rework /bgs command

* Fix old style of backgrounds.yaml not being supported with this PR
Fix formatting issues with /bgs changes

* Edit the backgrounds.yaml sample to show off bg categories better

---------

Co-authored-by: Alex Noir <[email protected]>
  • Loading branch information
EstatoDeviato and Crystalwarrior authored Apr 10, 2024
1 parent ca7da40 commit de72d1d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 27 deletions.
46 changes: 24 additions & 22 deletions config_sample/backgrounds.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
- Anime
- birthday
- Christmas
- CountyCourt
- CruiseCourt
- default
- DGSEnglishCourt
- DGSJapanCourt
- DualDestinies
- EnglishCourt
- gs4
- GS4Night
- HD
- Khura'in
- NewCourt
- RuinedCourt
- Sky
- SpaceCourt
- Themis
- TouhouCourt
- WitchTrialCourt
- Zetta
Courtrooms:
- default
- DGSEnglishCourt
- DGSJapanCourt
- DualDestinies
- EnglishCourt
- gs4
- HD
- Khura'in
- NewCourt
- RuinedCourt
- Themis
- WitchTrialCourt
Custom Courts:
- Anime
- birthday
- Christmas
- CountyCourt
- CruiseCourt
- GS4Night
- Sky
- SpaceCourt
- TouhouCourt
- Zetta
17 changes: 13 additions & 4 deletions server/commands/areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,20 @@ def ooc_cmd_bg(client, arg):
def ooc_cmd_bgs(client, arg):
"""
Display the server's available backgrounds.
Usage: /bgs
Usage: /bgs category
"""
msg = "Available backgrounds:"
msg += "\n" + "; ".join(client.server.backgrounds)
client.send_ooc(msg)
if arg == "":
msg = "Available Categories:"
for category in client.area.server.backgrounds_categories:
msg += f"\n{category}"
client.send_ooc(msg)
elif arg in client.server.backgrounds_categories:
msg = f"Backgrounds in Category '{arg}':"
for bg in client.server.backgrounds_categories[arg]:
msg += f"\n{bg}"
client.send_ooc(msg)
else:
client.send_ooc("There is no category with this name in server background list.")


def ooc_cmd_status(client, arg):
Expand Down
11 changes: 10 additions & 1 deletion server/tsuserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(self):
self.music_list = []
self.music_whitelist = []
self.backgrounds = None
self.backgrounds_categories = None
self.server_links = None
self.zalgo_tolerance = None
self.ipRange_bans = []
Expand Down Expand Up @@ -319,7 +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 = yaml.safe_load(bgs)
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 de72d1d

Please sign in to comment.