From 0d13222ed71377b85b49ed6e84de4d53a8700675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Caras?= Date: Thu, 2 Dec 2021 11:20:39 +0100 Subject: [PATCH 1/2] coolors --- example.yml | 2 +- game.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example.yml b/example.yml index d3163ef..3180d7e 100644 --- a/example.yml +++ b/example.yml @@ -10,7 +10,7 @@ game: # here goes all the game logic - sit wave: description: "Wave" # this appears in the selection box, if no description is supplied - text: "You wave at the customers to signal your arrival. They all ignore you and look away." + text: "&bYou wave at the customers to signal your arrival. &rThey all ignore you and look away." sit: # if no `actions` are supplied, the game exits description: "Sit down" text: "You quietly sit down and check the menu." diff --git a/game.py b/game.py index 9902603..119221b 100644 --- a/game.py +++ b/game.py @@ -42,7 +42,7 @@ class Game: ''' Used to convert color codes in string to colors from the colorama lib ''' - newText = text.replace("&b",Fore.CYAN).replace("\n",Fore.RESET + "\n") # replace color codes and newlines with colorama + newText = text.replace("&b",Fore.CYAN).replace("&c",Fore.RED).replace("&e", Fore.YELLOW).replace("&a",Fore.GREEN).replace("&9",Fore.BLUE).replace("&r",Fore.RESET).replace("&f",Fore.WHITE).replace("&5",Fore.MAGENTA).replace("\n",Fore.RESET + "\n") # replace color codes and newlines with colorama newText += Fore.RESET # reset color at the end of the text return newText From 8955263a6223b4b6e70f22848d5e2752ff49a1a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Caras?= Date: Thu, 16 Dec 2021 10:12:00 +0100 Subject: [PATCH 2/2] Actually parse the colors --- game.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/game.py b/game.py index 119221b..6025a05 100644 --- a/game.py +++ b/game.py @@ -24,7 +24,7 @@ class Game: ''' Used to print out the current prompt with the options ''' - print(self.nodes[self.current]["text"]) + print(self.parse_colors(self.nodes[self.current]["text"])) print("") ostring = "" if("actions" in self.nodes[self.current].keys()): @@ -55,6 +55,6 @@ def load(file_path): g = Game(data) return g except Exception as e: - print("An exception has occured while loading the game from the YAML file:") + print(f"{Back.RED}{Fore.WHITE}An exception has occured while loading the game from the YAML file:{Fore.RESET}{Back.RESET}") print(e) - return None \ No newline at end of file + return None