From 52d4f5bbfe4c8370257583806d9702c7305c6a4f Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 16 Feb 2021 18:18:34 -0500 Subject: [PATCH 01/29] Nearing a sort-of-functional alpha --- Adventure Game/.gitignore | 1 + Adventure Game/adventure_game/curses_test.py | 92 ---------------- Adventure Game/adventure_game/example.py | 46 +++++--- Adventure Game/adventure_game/main.py | 109 +++++++------------ Adventure Game/requirements.txt | 3 +- 5 files changed, 71 insertions(+), 180 deletions(-) delete mode 100644 Adventure Game/adventure_game/curses_test.py diff --git a/Adventure Game/.gitignore b/Adventure Game/.gitignore index 5ceb386..29e5705 100644 --- a/Adventure Game/.gitignore +++ b/Adventure Game/.gitignore @@ -1 +1,2 @@ venv +inspectionProfiles diff --git a/Adventure Game/adventure_game/curses_test.py b/Adventure Game/adventure_game/curses_test.py deleted file mode 100644 index d316fcd..0000000 --- a/Adventure Game/adventure_game/curses_test.py +++ /dev/null @@ -1,92 +0,0 @@ -import sys,os -import curses - -def draw_menu(stdscr): - k = 0 - cursor_x = 0 - cursor_y = 0 - - # Clear and refresh the screen for a blank canvas - stdscr.clear() - stdscr.refresh() - - # Start colors in curses - curses.start_color() - curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) - curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) - curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) - - # Loop where k is the last character pressed - while (k != ord('q')): - - # Initialization - stdscr.clear() - height, width = stdscr.getmaxyx() - - if k == curses.KEY_DOWN: - cursor_y = cursor_y + 1 - elif k == curses.KEY_UP: - cursor_y = cursor_y - 1 - elif k == curses.KEY_RIGHT: - cursor_x = cursor_x + 1 - elif k == curses.KEY_LEFT: - cursor_x = cursor_x - 1 - - cursor_x = max(0, cursor_x) - cursor_x = min(width-1, cursor_x) - - cursor_y = max(0, cursor_y) - cursor_y = min(height-1, cursor_y) - - # Declaration of strings - title = "Curses example"[:width-1] - subtitle = "Written by Clay McLeod"[:width-1] - keystr = "Last key pressed: {}".format(k)[:width-1] - statusbarstr = "Press 'q' to exit | STATUS BAR | Pos: {}, {}".format(cursor_x, cursor_y) - if k == 0: - keystr = "No key press detected..."[:width-1] - - # Centering calculations - start_x_title = int((width // 2) - (len(title) // 2) - len(title) % 2) - start_x_subtitle = int((width // 2) - (len(subtitle) // 2) - len(subtitle) % 2) - start_x_keystr = int((width // 2) - (len(keystr) // 2) - len(keystr) % 2) - start_y = int((height // 2) - 2) - - # Rendering some text - whstr = "Width: {}, Height: {}".format(width, height) - stdscr.addstr(0, 0, whstr, curses.color_pair(1)) - - # Render status bar - stdscr.attron(curses.color_pair(3)) - stdscr.addstr(height-1, 0, statusbarstr) - stdscr.addstr(height-1, len(statusbarstr), " " * (width - len(statusbarstr) - 1)) - stdscr.attroff(curses.color_pair(3)) - - # Turning on attributes for title - stdscr.attron(curses.color_pair(2)) - stdscr.attron(curses.A_BOLD) - - # Rendering title - stdscr.addstr(start_y, start_x_title, title) - - # Turning off attributes for title - stdscr.attroff(curses.color_pair(2)) - stdscr.attroff(curses.A_BOLD) - - # Print rest of text - stdscr.addstr(start_y + 1, start_x_subtitle, subtitle) - stdscr.addstr(start_y + 3, (width // 2) - 2, '-' * 4) - stdscr.addstr(start_y + 5, start_x_keystr, keystr) - stdscr.move(cursor_y, cursor_x) - - # Refresh the screen - stdscr.refresh() - - # Wait for next input - k = stdscr.getch() - -def main(): - curses.wrapper(draw_menu) - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/Adventure Game/adventure_game/example.py b/Adventure Game/adventure_game/example.py index 4913d5d..6cf4ea8 100644 --- a/Adventure Game/adventure_game/example.py +++ b/Adventure Game/adventure_game/example.py @@ -1,18 +1,32 @@ -import curses, curses.textpad -def setup_input(): - inp = curses.newwin(8,55, 0,0) - inp.addstr(1,1, "Please enter your username:") - sub = inp.subwin(2,1) - sub.border() - sub2 = sub.subwin(3,2) - global tb - tb = curses.textpad.Textbox(sub2) - inp.refresh() - tb.edit(enter_is_terminate) +# encoding: utf-8 -def enter_is_terminate(x): - if x == 10: - tb.do_command(7) - tb.do_command(x) +import npyscreen -setup_input() \ No newline at end of file + +class TestApp(npyscreen.NPSApp): + def main(self): + # These lines create the form and populate it with widgets. + # A fairly complex screen in only 8 or so lines of code - a line for each control. + F = npyscreen.Form(name="Welcome to Npyscreen", ) + t = F.add(npyscreen.TitleText, name="Text:", ) + fn = F.add(npyscreen.TitleFilename, name="Filename:") + fn2 = F.add(npyscreen.TitleFilenameCombo, name="Filename2:") + dt = F.add(npyscreen.TitleDateCombo, name="Date:") + s = F.add(npyscreen.TitleSlider, out_of=12, name="Slider") + ml = F.add(npyscreen.MultiLineEdit, + value="""try typing here!\nMutiline text, press ^R to reformat.\n""", + max_height=5, rely=9) + ms = F.add(npyscreen.TitleSelectOne, max_height=4, value=[1, ], name="Pick One", + values=["Option1", "Option2", "Option3"], scroll_exit=True) + ms2 = F.add(npyscreen.TitleMultiSelect, max_height=-2, value=[1, ], name="Pick Several", + values=["Option1", "Option2", "Option3"], scroll_exit=True) + + # This lets the user interact with the Form. + F.edit() + + print(ms.get_selected_objects()) + + +if __name__ == "__main__": + App = TestApp() + App.run() diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index d30f79d..940dd35 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,87 +1,56 @@ -import curses -from curses.textpad import Textbox +import npyscreen -class AdventureGame: - def __init__(self, stdscr): - # Self.stdrscr is our parent standard screen - self.stdscr = stdscr +class GameNavigator(npyscreen.Form): + def afterEditing(self): + # TODO: the game needs to happen after this inital main menu + self.parentApp.setNextForm(None) - # This is just done once at startup to get inital windows sizes - # TODO: handle live window resize! - self.height, self.width = self.stdscr.getmaxyx() + def create(self): + self.myName = self.add(npyscreen.TitleText, name='Name') + self.myDepartment = self.add(npyscreen.TitleSelectOne, scroll_exit=True, max_height=3, name='Department', + values=['Department 1', 'Department 2', 'Department 3']) + self.myDate = self.add(npyscreen.TitleDateCombo, name='Date Employed') - self.command = 0 - # Clear and refresh the screen - self.stdscr.clear() - self.stdscr.refresh() +class MainMenu(npyscreen.Form): + def afterEditing(self): + # TODO: the game needs to happen after this inital main menu + self.parentApp.setNextForm('GAME') - # Setup some colors! - # Start some curses colors - curses.start_color() - curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) - curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) - curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) + def create(self): + self.add(npyscreen.MultiLineEdit, value='Test', editable=False) + self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Filename:") - # Setup art_win - art_win_width = int((self.width / 3) * 2) - art_win_begin_x = int(self.width - art_win_width) - art_win_begin_y = 1 # Must be at least 1 (to allow header) - art_win_height = int(self.height / 2) - art_win = curses.newwin(art_win_height, art_win_width, art_win_begin_y, art_win_begin_x) +class AlphaWarning(npyscreen.Popup): + def afterEditing(self): + self.parentApp.setNextForm('MENU') - # Setup dialogue_win - dialogue_win_width = self.width - dialogue_win_begin_x = 0 - dialogue_win_begin_y = art_win_height + 1 # Fits 1 underneath the art box above. - dialogue_win_height = self.height - art_win_height - 2 # Fits 2 underneath the bottom box, + def create(self): + self.add(npyscreen.Pager, values=['Welcome to Unnamed Adventure game!', + 'Please enjoy your stay and report any bugs at', + 'kitsunehosting.net'], editable=False) - dialogue_win = curses.newwin(dialogue_win_height, dialogue_win_width, dialogue_win_begin_y, - dialogue_win_begin_x) - while self.command != ord('q'): - # Get the height of everything - self.height, self.width = self.stdscr.getmaxyx() - self.title = 'Untitled Adventure Game PRE ALPHA'[:self.width - 1] - self.statusbarstr = "Press 'q' to exit " +class AdventureGame(npyscreen.NPSAppManaged): + # Do on creation + def onStart(self): + # Intalize a game renderer for most game windows + self.addForm('GAME', GameNavigator, name='Unnamed Adventure Game') - # Render status bar - self.stdscr.attron(curses.color_pair(3)) - self.stdscr.addstr(self.height - 1, 0, self.statusbarstr) - self.stdscr.addstr(self.height - 1, len(self.statusbarstr), ' ' * (self.width - len(self.statusbarstr) - 1)) - self.stdscr.attroff(curses.color_pair(3)) + # Initalize a savegameSelector that allows a user to choose a savegame + self.addForm('MENU', MainMenu, name='Welcome to the main menu') - # Render major game windows - self.draw_art_window(art_win) - self.command = self.draw_dialogue_box(dialogue_win) - - # Refresh the screen - self.stdscr.refresh() - - # Wait for next input - # self.command = self.stdscr.getch() - curses.echo() - #self.command = self.stdscr.getstr(0, 0) - - def draw_main_menu(self): - pass - - def draw_art_window(self, window): - window.addstr("Wip") - window.addstr("Morewip lol") - window.box() - window.refresh() - - def draw_dialogue_box(self, window): - window.box() - window.refresh() - - textbox = Textbox(window) - return textbox.edit() + # Initalize a savegameSelector that allows a user to choose a savegame + self.addForm('MAIN', AlphaWarning, name='Welcome to the alpha!') + #TODO: Create a 'splash screen' or, traditional "main menu" if __name__ == '__main__': - curses.wrapper(AdventureGame) + # Make a new adventure game if not imported + adventure_game = AdventureGame() + + # Run the game! + adventure_game.run() diff --git a/Adventure Game/requirements.txt b/Adventure Game/requirements.txt index 6493b8a..52c0eb3 100644 --- a/Adventure Game/requirements.txt +++ b/Adventure Game/requirements.txt @@ -1,2 +1 @@ -# Blessed handles our terminal "graphics" -blessed==1.17.12 \ No newline at end of file +npyscreen~=4.10.5 \ No newline at end of file -- 2.43.0 From db78cca216e85a571ab0d0898a78ddc90956257a Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 16 Feb 2021 20:17:37 -0500 Subject: [PATCH 02/29] If we add the multiline edit above playersavelocation then it crashes, fix? --- Adventure Game/adventure_game/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 940dd35..0005530 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -19,8 +19,8 @@ class MainMenu(npyscreen.Form): self.parentApp.setNextForm('GAME') def create(self): - self.add(npyscreen.MultiLineEdit, value='Test', editable=False) self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Filename:") + self.add(npyscreen.MultiLineEdit, value='Test', editable=False) class AlphaWarning(npyscreen.Popup): -- 2.43.0 From 1999e8b8ecc69e5e61ff5718aaacf54ce2ea6cef Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 16 Feb 2021 20:23:26 -0500 Subject: [PATCH 03/29] Added in yaml This works, but has a few minor bugs. it lays the foundation though for more stuff to be added --- Adventure Game/adventure_game/gamedata/gamelib.yaml | 13 +++++++++++++ Adventure Game/adventure_game/main.py | 5 ++++- Adventure Game/adventure_game/yaml_parser.py | 12 ++++++++++++ Adventure Game/requirements.txt | 3 ++- 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 Adventure Game/adventure_game/gamedata/gamelib.yaml create mode 100644 Adventure Game/adventure_game/yaml_parser.py diff --git a/Adventure Game/adventure_game/gamedata/gamelib.yaml b/Adventure Game/adventure_game/gamedata/gamelib.yaml new file mode 100644 index 0000000..223c904 --- /dev/null +++ b/Adventure Game/adventure_game/gamedata/gamelib.yaml @@ -0,0 +1,13 @@ +menu: + graphics: + logo: | + __ __ __ ___ __ __ + / / / /___ ____ ____ _____ ___ ___ ____/ / / | ____/ / _____ ____ / /___ __________ + / / / / __ \/ __ \/ __ `/ __ `__ \/ _ \/ __ / / /| |/ __ / | / / _ \/ __ \/ __/ / / / ___/ _ \ + / /_/ / / / / / / / /_/ / / / / / / __/ /_/ / / ___ / /_/ /| |/ / __/ / / / /_/ /_/ / / / __/ + \____/_/ /_/_/ /_/\__,_/_/ /_/ /_/\___/\__,_/ /_/ |_\__,_/ |___/\___/_/ /_/\__/\__,_/_/ \___/ + _________ __ _________ + / ____/ | / |/ / ____/ + / / __/ /| | / /|_/ / __/ + / /_/ / ___ |/ / / / /___ + \____/_/ |_/_/ /_/_____/ \ No newline at end of file diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 0005530..91a55c7 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,4 +1,5 @@ import npyscreen +from yaml_parser import parse_datafile as parse class GameNavigator(npyscreen.Form): @@ -20,7 +21,7 @@ class MainMenu(npyscreen.Form): def create(self): self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Filename:") - self.add(npyscreen.MultiLineEdit, value='Test', editable=False) + self.add(npyscreen.MultiLineEdit, value=self.parentApp.gamelib['menu']['graphics']['logo'], editable=False) class AlphaWarning(npyscreen.Popup): @@ -37,6 +38,8 @@ class AlphaWarning(npyscreen.Popup): class AdventureGame(npyscreen.NPSAppManaged): # Do on creation def onStart(self): + self.gamelib = parse('gamedata/gamelib.yaml') + # Intalize a game renderer for most game windows self.addForm('GAME', GameNavigator, name='Unnamed Adventure Game') diff --git a/Adventure Game/adventure_game/yaml_parser.py b/Adventure Game/adventure_game/yaml_parser.py new file mode 100644 index 0000000..0d41be6 --- /dev/null +++ b/Adventure Game/adventure_game/yaml_parser.py @@ -0,0 +1,12 @@ +import yaml + + +def parse_datafile(file): + # With the file open + with open(file, 'r') as stream: + # Try to read it and return it + try: + content = yaml.safe_load(stream) + return content + except yaml.YAMLError as exc: + return exc diff --git a/Adventure Game/requirements.txt b/Adventure Game/requirements.txt index 52c0eb3..ba33800 100644 --- a/Adventure Game/requirements.txt +++ b/Adventure Game/requirements.txt @@ -1 +1,2 @@ -npyscreen~=4.10.5 \ No newline at end of file +npyscreen~=4.10.5 +PyYAML~=5.1.2 \ No newline at end of file -- 2.43.0 From 45801c53b05bc06980fda43291f772b17fdb002a Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 16 Feb 2021 20:25:36 -0500 Subject: [PATCH 04/29] TODO Weird bug where this crashes the game if the first char is not something other than space --- Adventure Game/adventure_game/gamedata/gamelib.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/gamedata/gamelib.yaml b/Adventure Game/adventure_game/gamedata/gamelib.yaml index 223c904..c1b0624 100644 --- a/Adventure Game/adventure_game/gamedata/gamelib.yaml +++ b/Adventure Game/adventure_game/gamedata/gamelib.yaml @@ -1,7 +1,7 @@ menu: graphics: logo: | - __ __ __ ___ __ __ + . __ __ __ ___ __ __ / / / /___ ____ ____ _____ ___ ___ ____/ / / | ____/ / _____ ____ / /___ __________ / / / / __ \/ __ \/ __ `/ __ `__ \/ _ \/ __ / / /| |/ __ / | / / _ \/ __ \/ __/ / / / ___/ _ \ / /_/ / / / / / / / /_/ / / / / / / __/ /_/ / / ___ / /_/ /| |/ / __/ / / / /_/ /_/ / / / __/ -- 2.43.0 From e79fda1bb9ae9d5b03984949b05bd4f071b3fc04 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 16 Feb 2021 22:53:12 -0500 Subject: [PATCH 05/29] Add a lot of quality of life stuff including exception to handle small screens --- .../adventure_game/gamedata/gamelib.yaml | 7 ++- Adventure Game/adventure_game/main.py | 44 ++++++++++++------- Adventure Game/adventure_game/text.py | 35 +++++++++++++++ 3 files changed, 68 insertions(+), 18 deletions(-) create mode 100644 Adventure Game/adventure_game/text.py diff --git a/Adventure Game/adventure_game/gamedata/gamelib.yaml b/Adventure Game/adventure_game/gamedata/gamelib.yaml index c1b0624..3ed6da6 100644 --- a/Adventure Game/adventure_game/gamedata/gamelib.yaml +++ b/Adventure Game/adventure_game/gamedata/gamelib.yaml @@ -10,4 +10,9 @@ menu: / ____/ | / |/ / ____/ / / __/ /| | / /|_/ / __/ / /_/ / ___ |/ / / / /___ - \____/_/ |_/_/ /_/_____/ \ No newline at end of file + \____/_/ |_/_/ /_/_____/ + + not_found: | + . / \ + / ! \ + / \ \ No newline at end of file diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 91a55c7..cb4e615 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,17 +1,24 @@ import npyscreen +from npyscreen import NotEnoughSpaceForWidget + from yaml_parser import parse_datafile as parse class GameNavigator(npyscreen.Form): def afterEditing(self): - # TODO: the game needs to happen after this inital main menu - self.parentApp.setNextForm(None) + self.parentApp.setNextForm(None) # Nothing to do after this but exit the game. def create(self): - self.myName = self.add(npyscreen.TitleText, name='Name') - self.myDepartment = self.add(npyscreen.TitleSelectOne, scroll_exit=True, max_height=3, name='Department', - values=['Department 1', 'Department 2', 'Department 3']) - self.myDate = self.add(npyscreen.TitleDateCombo, name='Date Employed') + self.artBox = self.add(npyscreen.BoxBasic, name='ArtBox', max_width=100, max_height=20, relx=2,) + self.artBox.footer = 'Unknown Location' + + self.artBox = self.add(npyscreen.BoxBasic, name='ArtBox', max_width=100, max_height=20, relx=32, rely=2) + self.artBox.footer = 'Unknown Location' + + #self.myName = self.add(npyscreen.TitleText, name='Name') + #self.myDepartment = self.add(npyscreen.TitleSelectOne, scroll_exit=True, max_height=3, name='Department', + # values=['Department 1', 'Department 2', 'Department 3']) + #self.myDate = self.add(npyscreen.TitleDateCombo, name='Date Employed') class MainMenu(npyscreen.Form): @@ -34,26 +41,29 @@ class AlphaWarning(npyscreen.Popup): 'kitsunehosting.net'], editable=False) - class AdventureGame(npyscreen.NPSAppManaged): # Do on creation def onStart(self): - self.gamelib = parse('gamedata/gamelib.yaml') + # Setup some important 'globa' values we'll need later + self.gamelib = parse( + 'gamedata/gamelib.yaml') # parse this data first (since it includes graphics for the main menu + self.playerSaveLocation = None # We'll load the save location after the player gets to the save select screen - # Intalize a game renderer for most game windows - self.addForm('GAME', GameNavigator, name='Unnamed Adventure Game') + # Draw game windows + self.addForm('GAME', GameNavigator, name='Unnamed Adventure Game') # This window should draw the actual game + self.addForm('MENU', MainMenu, name='Welcome to the main menu') # This window should draw the main menu + self.addForm('MAIN', AlphaWarning, name='Welcome to the alpha!') # This window is only needed for the ALPHA - # Initalize a savegameSelector that allows a user to choose a savegame - self.addForm('MENU', MainMenu, name='Welcome to the main menu') + # TODO: Create a 'splash screen' or, traditional "main menu" - # Initalize a savegameSelector that allows a user to choose a savegame - self.addForm('MAIN', AlphaWarning, name='Welcome to the alpha!') - - #TODO: Create a 'splash screen' or, traditional "main menu" if __name__ == '__main__': # Make a new adventure game if not imported adventure_game = AdventureGame() # Run the game! - adventure_game.run() + try: + adventure_game.run() + except NotEnoughSpaceForWidget: + # This exception should catch if a player tries to play in a screen that is too small. + print('Your screen is too small!\nOr, Joe has not fixed https://kitsunehosting.net/gitea/Kenwood/SNHU-IT-140/issues/7') diff --git a/Adventure Game/adventure_game/text.py b/Adventure Game/adventure_game/text.py new file mode 100644 index 0000000..53df858 --- /dev/null +++ b/Adventure Game/adventure_game/text.py @@ -0,0 +1,35 @@ +import npyscreen + + +# npyscreen.disableColor() +class TestApp(npyscreen.NPSApp): + def main(self): + F = npyscreen.Form(name="Welcome to Npyscreen", ) + t = F.add(npyscreen.BoxBasic, name="Basic Box:", max_width=30, relx=2, max_height=3) + t.footer = "This is a footer" + + t1 = F.add(npyscreen.BoxBasic, name="Basic Box:", rely=2, relx=32, max_width=30, max_height=3) + + t2 = F.add(npyscreen.BoxTitle, name="Box Title:", max_height=6) + t3 = F.add(npyscreen.BoxTitle, name="Box Title2:", max_height=6, + scroll_exit=True, + contained_widget_arguments={ + 'color': "WARNING", + 'widgets_inherit_color': True, } + ) + + t2.entry_widget.scroll_exit = True + t2.values = ["Hello", + "This is a Test", + "This is another test", + "And here is another line", + "And here is another line, which is really very long. abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", + "And one more."] + t3.values = t2.values + + F.edit() + + +if __name__ == "__main__": + App = TestApp() + App.run() \ No newline at end of file -- 2.43.0 From cc620fda20e0479fd527be8f6fae71f58b7fd807 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 17 Feb 2021 14:35:19 -0500 Subject: [PATCH 06/29] Fix yaml arangement --- Adventure Game/adventure_game/gamedata/gamelib.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/gamedata/gamelib.yaml b/Adventure Game/adventure_game/gamedata/gamelib.yaml index 3ed6da6..5ecc905 100644 --- a/Adventure Game/adventure_game/gamedata/gamelib.yaml +++ b/Adventure Game/adventure_game/gamedata/gamelib.yaml @@ -15,4 +15,4 @@ menu: not_found: | . / \ / ! \ - / \ \ No newline at end of file + / \ -- 2.43.0 From 0867fe6d5fbafa2d82a4b2bd3b67f795101cdc10 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 17 Feb 2021 14:35:36 -0500 Subject: [PATCH 07/29] Order artbox and inventory list together --- Adventure Game/adventure_game/main.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index cb4e615..0a9c462 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -9,11 +9,10 @@ class GameNavigator(npyscreen.Form): self.parentApp.setNextForm(None) # Nothing to do after this but exit the game. def create(self): - self.artBox = self.add(npyscreen.BoxBasic, name='ArtBox', max_width=100, max_height=20, relx=2,) + self.artBox = self.add(npyscreen.BoxBasic, name='ArtBox', max_width=100, max_height=20, relx=21) self.artBox.footer = 'Unknown Location' - self.artBox = self.add(npyscreen.BoxBasic, name='ArtBox', max_width=100, max_height=20, relx=32, rely=2) - self.artBox.footer = 'Unknown Location' + self.artBox = self.add(npyscreen.BoxBasic, name='Inventory', max_width=20, max_height=20, relx=1, rely=2) #self.myName = self.add(npyscreen.TitleText, name='Name') #self.myDepartment = self.add(npyscreen.TitleSelectOne, scroll_exit=True, max_height=3, name='Department', @@ -44,7 +43,7 @@ class AlphaWarning(npyscreen.Popup): class AdventureGame(npyscreen.NPSAppManaged): # Do on creation def onStart(self): - # Setup some important 'globa' values we'll need later + # Setup some important 'global' values we'll need later self.gamelib = parse( 'gamedata/gamelib.yaml') # parse this data first (since it includes graphics for the main menu self.playerSaveLocation = None # We'll load the save location after the player gets to the save select screen -- 2.43.0 From adf7383c9fae365a124044caa64ff6c7e0b33da3 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 17 Feb 2021 16:23:43 -0500 Subject: [PATCH 08/29] Update main.py --- Adventure Game/adventure_game/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 0a9c462..57e3c0e 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -14,6 +14,8 @@ class GameNavigator(npyscreen.Form): self.artBox = self.add(npyscreen.BoxBasic, name='Inventory', max_width=20, max_height=20, relx=1, rely=2) + self.DialogueBox = self.add(npyscreen.BoxBasic, name='Type Here', max_width=20, max_height=20, relx=1, rely=2) + #self.myName = self.add(npyscreen.TitleText, name='Name') #self.myDepartment = self.add(npyscreen.TitleSelectOne, scroll_exit=True, max_height=3, name='Department', # values=['Department 1', 'Department 2', 'Department 3']) @@ -26,7 +28,8 @@ class MainMenu(npyscreen.Form): self.parentApp.setNextForm('GAME') def create(self): - self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Filename:") + self.add(npyscreen.FixedText, value='You cannot select a file yet! Just hit OK', editable=False) + self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Your save file:") self.add(npyscreen.MultiLineEdit, value=self.parentApp.gamelib['menu']['graphics']['logo'], editable=False) -- 2.43.0 From 6743be8a6c4cdecae42ec84f5face1eedbe2a43d Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 17 Feb 2021 22:07:19 -0500 Subject: [PATCH 09/29] Update art rendering and prepare for input handling --- .../adventure_game/gamedata/gamelib.yaml | 21 +++++++-- .../adventure_game/gamedata/world/office.yaml | 12 ++++++ Adventure Game/adventure_game/main.py | 43 ++++++++++++++++--- 3 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 Adventure Game/adventure_game/gamedata/world/office.yaml diff --git a/Adventure Game/adventure_game/gamedata/gamelib.yaml b/Adventure Game/adventure_game/gamedata/gamelib.yaml index 5ecc905..dc5deff 100644 --- a/Adventure Game/adventure_game/gamedata/gamelib.yaml +++ b/Adventure Game/adventure_game/gamedata/gamelib.yaml @@ -13,6 +13,21 @@ menu: \____/_/ |_/_/ /_/_____/ not_found: | - . / \ - / ! \ - / \ + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- + -----------------------------------------------/ \----------------------------------------------- + ----------------------------------------------/ !! \---------------------------------------------- + ---------------------------------------------/ \--------------------------------------------- + --------------------------------------No Art for this location------------------------------------ + ----------------------------------Consider making a pull request?--------------------------------- + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- diff --git a/Adventure Game/adventure_game/gamedata/world/office.yaml b/Adventure Game/adventure_game/gamedata/world/office.yaml new file mode 100644 index 0000000..3d88078 --- /dev/null +++ b/Adventure Game/adventure_game/gamedata/world/office.yaml @@ -0,0 +1,12 @@ +office: + grid: [0, 0] + upon_enter: "You are standing behind your desk, you see a |NAMEPLATE|, a |TAPE RECORDER| and your trusty |LOG VIEWER|" + look_around: "You look around the room, you see a |DESK|, a |BOOKSHELF| and the |DOOR|" + pick_up_logviewer: "You pick the *LOG VIEWER* up." + desk: + look_at: "You move to stand behind your desk. You see a |NAMEPLATE|, a |TAPE RECORDER| and your trusty |LOG VIEWER|" + inspect: "Desk, ornate, stuff" + log_viewer: + look_at: "logviewer looks like garbo" + inspect: "beep boop" + pick_up: "You pick up the *LOG VIEWER*." \ No newline at end of file diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 57e3c0e..e85176c 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -9,17 +9,46 @@ class GameNavigator(npyscreen.Form): self.parentApp.setNextForm(None) # Nothing to do after this but exit the game. def create(self): - self.artBox = self.add(npyscreen.BoxBasic, name='ArtBox', max_width=100, max_height=20, relx=21) + top_division_height = 20 + inventory_width = 20 + art_width = 100 + + self.artBox = self.add(npyscreen.BoxBasic, + name='ArtBox', + max_width=art_width, + max_height=top_division_height, + rely=2, + relx=inventory_width + 1, + editable=False) + self.artContent = self.add(npyscreen.MultiLineEdit, + rely=3, + relx=inventory_width + 2, + max_width=art_width - 2, + max_height=top_division_height - 2, + value=self.parentApp.gamelib['menu']['graphics']['not_found'], + editable=False) self.artBox.footer = 'Unknown Location' - self.artBox = self.add(npyscreen.BoxBasic, name='Inventory', max_width=20, max_height=20, relx=1, rely=2) + self.artBox = self.add(npyscreen.BoxBasic, + name='Inventory', + max_width=inventory_width, + max_height=top_division_height, + relx=1, + rely=2, + editable=False) - self.DialogueBox = self.add(npyscreen.BoxBasic, name='Type Here', max_width=20, max_height=20, relx=1, rely=2) + self.dialogueBoxOutline = self.add(npyscreen.BoxBasic, + max_width=inventory_width + art_width, + max_height=3, + relx=1, + rely=top_division_height + 2) - #self.myName = self.add(npyscreen.TitleText, name='Name') - #self.myDepartment = self.add(npyscreen.TitleSelectOne, scroll_exit=True, max_height=3, name='Department', - # values=['Department 1', 'Department 2', 'Department 3']) - #self.myDate = self.add(npyscreen.TitleDateCombo, name='Date Employed') + self.dialogueBox = self.add(npyscreen.Textfield, + name='Type Here', + max_width=inventory_width + art_width - 2, + max_height=1, + relx=2, + rely=top_division_height + 3) class MainMenu(npyscreen.Form): -- 2.43.0 From 04669d0f8f51761b15fc70f49fd659222b58de93 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 17 Feb 2021 22:46:21 -0500 Subject: [PATCH 10/29] Send button functions but needs implementation --- Adventure Game/adventure_game/main.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index e85176c..90e3fef 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,8 +1,12 @@ -import npyscreen +import npyscreen, sys from npyscreen import NotEnoughSpaceForWidget from yaml_parser import parse_datafile as parse +class ExitButton(npyscreen.ButtonPress): + def whenPressed(self): + sys.exit(0) + class GameNavigator(npyscreen.Form): def afterEditing(self): @@ -45,11 +49,13 @@ class GameNavigator(npyscreen.Form): self.dialogueBox = self.add(npyscreen.Textfield, name='Type Here', - max_width=inventory_width + art_width - 2, + max_width=inventory_width + art_width - 7, max_height=1, relx=2, rely=top_division_height + 3) + self.tryAction = self.add(ExitButton, name="Send", relx=inventory_width + art_width - 7, rely=top_division_height + 3) + class MainMenu(npyscreen.Form): def afterEditing(self): -- 2.43.0 From b2466257ceb48e98015a99fcf4f532150d97ae87 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 19 Feb 2021 17:13:02 -0500 Subject: [PATCH 11/29] Refactor Game navigator location also cleanup some unused files --- .../adventure_game/GameNavigator.py | 53 ++++++++++++++++ Adventure Game/adventure_game/example.py | 32 ---------- .../adventure_game/gamedata/gamelib.yaml | 9 +++ Adventure Game/adventure_game/main.py | 61 +++---------------- Adventure Game/adventure_game/text.py | 35 ----------- 5 files changed, 70 insertions(+), 120 deletions(-) create mode 100644 Adventure Game/adventure_game/GameNavigator.py delete mode 100644 Adventure Game/adventure_game/example.py delete mode 100644 Adventure Game/adventure_game/text.py diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py new file mode 100644 index 0000000..a342861 --- /dev/null +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -0,0 +1,53 @@ +import npyscreen, sys + +class ExitButton(npyscreen.ButtonPress): + def whenPressed(self): + sys.exit(0) + +class GameNavigator(npyscreen.Form): + def afterEditing(self): + self.parentApp.setNextForm(None) # Nothing to do after this but exit the game. + + def create(self): + top_division_height = 20 + inventory_width = 20 + art_width = 100 + + self.artBox = self.add(npyscreen.BoxBasic, + name='ArtBox', + max_width=art_width, + max_height=top_division_height, + rely=2, + relx=inventory_width + 1, + editable=False) + self.artContent = self.add(npyscreen.MultiLineEdit, + rely=3, + relx=inventory_width + 2, + max_width=art_width - 2, + max_height=top_division_height - 2, + value=self.parentApp.gamelib['menu']['graphics']['not_found'], + editable=False) + self.artBox.footer = 'Unknown Location' + + self.artBox = self.add(npyscreen.BoxBasic, + name='Inventory', + max_width=inventory_width, + max_height=top_division_height, + relx=1, + rely=2, + editable=False) + + self.dialogueBoxOutline = self.add(npyscreen.BoxBasic, + max_width=inventory_width + art_width, + max_height=3, + relx=1, + rely=top_division_height + 2) + + self.dialogueBox = self.add(npyscreen.Textfield, + name='Type Here', + max_width=inventory_width + art_width - 7, + max_height=1, + relx=2, + rely=top_division_height + 3) + + self.tryAction = self.add(ExitButton, name="Send", relx=inventory_width + art_width - 7, rely=top_division_height + 3) \ No newline at end of file diff --git a/Adventure Game/adventure_game/example.py b/Adventure Game/adventure_game/example.py deleted file mode 100644 index 6cf4ea8..0000000 --- a/Adventure Game/adventure_game/example.py +++ /dev/null @@ -1,32 +0,0 @@ -# encoding: utf-8 - -import npyscreen - - -class TestApp(npyscreen.NPSApp): - def main(self): - # These lines create the form and populate it with widgets. - # A fairly complex screen in only 8 or so lines of code - a line for each control. - F = npyscreen.Form(name="Welcome to Npyscreen", ) - t = F.add(npyscreen.TitleText, name="Text:", ) - fn = F.add(npyscreen.TitleFilename, name="Filename:") - fn2 = F.add(npyscreen.TitleFilenameCombo, name="Filename2:") - dt = F.add(npyscreen.TitleDateCombo, name="Date:") - s = F.add(npyscreen.TitleSlider, out_of=12, name="Slider") - ml = F.add(npyscreen.MultiLineEdit, - value="""try typing here!\nMutiline text, press ^R to reformat.\n""", - max_height=5, rely=9) - ms = F.add(npyscreen.TitleSelectOne, max_height=4, value=[1, ], name="Pick One", - values=["Option1", "Option2", "Option3"], scroll_exit=True) - ms2 = F.add(npyscreen.TitleMultiSelect, max_height=-2, value=[1, ], name="Pick Several", - values=["Option1", "Option2", "Option3"], scroll_exit=True) - - # This lets the user interact with the Form. - F.edit() - - print(ms.get_selected_objects()) - - -if __name__ == "__main__": - App = TestApp() - App.run() diff --git a/Adventure Game/adventure_game/gamedata/gamelib.yaml b/Adventure Game/adventure_game/gamedata/gamelib.yaml index dc5deff..d817750 100644 --- a/Adventure Game/adventure_game/gamedata/gamelib.yaml +++ b/Adventure Game/adventure_game/gamedata/gamelib.yaml @@ -31,3 +31,12 @@ menu: -------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------- + dimensions: + inventory_width: 23 + inventory_height: 20 + art_width: 101 + art_height: 20 + dialogue_width: 122 + dialogue_height: 20 + entry_box_width: 122 + entry_box_height: 3 diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 90e3fef..e99b86b 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,60 +1,9 @@ import npyscreen, sys from npyscreen import NotEnoughSpaceForWidget +from os import system from yaml_parser import parse_datafile as parse - -class ExitButton(npyscreen.ButtonPress): - def whenPressed(self): - sys.exit(0) - - -class GameNavigator(npyscreen.Form): - def afterEditing(self): - self.parentApp.setNextForm(None) # Nothing to do after this but exit the game. - - def create(self): - top_division_height = 20 - inventory_width = 20 - art_width = 100 - - self.artBox = self.add(npyscreen.BoxBasic, - name='ArtBox', - max_width=art_width, - max_height=top_division_height, - rely=2, - relx=inventory_width + 1, - editable=False) - self.artContent = self.add(npyscreen.MultiLineEdit, - rely=3, - relx=inventory_width + 2, - max_width=art_width - 2, - max_height=top_division_height - 2, - value=self.parentApp.gamelib['menu']['graphics']['not_found'], - editable=False) - self.artBox.footer = 'Unknown Location' - - self.artBox = self.add(npyscreen.BoxBasic, - name='Inventory', - max_width=inventory_width, - max_height=top_division_height, - relx=1, - rely=2, - editable=False) - - self.dialogueBoxOutline = self.add(npyscreen.BoxBasic, - max_width=inventory_width + art_width, - max_height=3, - relx=1, - rely=top_division_height + 2) - - self.dialogueBox = self.add(npyscreen.Textfield, - name='Type Here', - max_width=inventory_width + art_width - 7, - max_height=1, - relx=2, - rely=top_division_height + 3) - - self.tryAction = self.add(ExitButton, name="Send", relx=inventory_width + art_width - 7, rely=top_division_height + 3) +from GameNavigator import GameNavigator class MainMenu(npyscreen.Form): @@ -86,6 +35,12 @@ class AdventureGame(npyscreen.NPSAppManaged): 'gamedata/gamelib.yaml') # parse this data first (since it includes graphics for the main menu self.playerSaveLocation = None # We'll load the save location after the player gets to the save select screen + # Set screen size before drawing windows + dimensions = self.gamelib['menu']['graphics']['dimensions'] + system('mode con: cols={0} lines={1}'.format( + dimensions['inventory_width']+dimensions['art_width'], + 30)) # TODO: Finish setting this up. + # Draw game windows self.addForm('GAME', GameNavigator, name='Unnamed Adventure Game') # This window should draw the actual game self.addForm('MENU', MainMenu, name='Welcome to the main menu') # This window should draw the main menu diff --git a/Adventure Game/adventure_game/text.py b/Adventure Game/adventure_game/text.py deleted file mode 100644 index 53df858..0000000 --- a/Adventure Game/adventure_game/text.py +++ /dev/null @@ -1,35 +0,0 @@ -import npyscreen - - -# npyscreen.disableColor() -class TestApp(npyscreen.NPSApp): - def main(self): - F = npyscreen.Form(name="Welcome to Npyscreen", ) - t = F.add(npyscreen.BoxBasic, name="Basic Box:", max_width=30, relx=2, max_height=3) - t.footer = "This is a footer" - - t1 = F.add(npyscreen.BoxBasic, name="Basic Box:", rely=2, relx=32, max_width=30, max_height=3) - - t2 = F.add(npyscreen.BoxTitle, name="Box Title:", max_height=6) - t3 = F.add(npyscreen.BoxTitle, name="Box Title2:", max_height=6, - scroll_exit=True, - contained_widget_arguments={ - 'color': "WARNING", - 'widgets_inherit_color': True, } - ) - - t2.entry_widget.scroll_exit = True - t2.values = ["Hello", - "This is a Test", - "This is another test", - "And here is another line", - "And here is another line, which is really very long. abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", - "And one more."] - t3.values = t2.values - - F.edit() - - -if __name__ == "__main__": - App = TestApp() - App.run() \ No newline at end of file -- 2.43.0 From 5437129a768c36f0fddf2978865e7379feee27bc Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 19 Feb 2021 17:21:05 -0500 Subject: [PATCH 12/29] Eyy! fix bug 14, send button and ok button not working together --- Adventure Game/adventure_game/GameNavigator.py | 4 ++-- Adventure Game/adventure_game/player.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 Adventure Game/adventure_game/player.py diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index a342861..143430c 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -4,9 +4,9 @@ class ExitButton(npyscreen.ButtonPress): def whenPressed(self): sys.exit(0) -class GameNavigator(npyscreen.Form): +class GameNavigator(npyscreen.FormBaseNew): def afterEditing(self): - self.parentApp.setNextForm(None) # Nothing to do after this but exit the game. + self.parentApp.setNextForm('GAME') def create(self): top_division_height = 20 diff --git a/Adventure Game/adventure_game/player.py b/Adventure Game/adventure_game/player.py new file mode 100644 index 0000000..81620ec --- /dev/null +++ b/Adventure Game/adventure_game/player.py @@ -0,0 +1,7 @@ +from yaml_parser import parse_datafile as parse + +class Player: + def __init__(self, save_location): + self.save_location = save_location + + self.playerData = parse(save_location) \ No newline at end of file -- 2.43.0 From 7eb8dfde07460ee9b6618bd2fb85a645754b123e Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sat, 20 Feb 2021 18:53:44 -0500 Subject: [PATCH 13/29] Basic UI should work fine now! TODO: slight bug with send button not 'clearing' screen? --- .../adventure_game/GameNavigator.py | 26 ++++++++++++++----- Adventure Game/adventure_game/MainMenu.py | 11 ++++++++ Adventure Game/adventure_game/Player.py | 11 ++++++++ Adventure Game/adventure_game/main.py | 22 +++++++--------- Adventure Game/adventure_game/player.py | 7 ----- .../playerdata/defaults/default_player.yaml | 4 +++ 6 files changed, 55 insertions(+), 26 deletions(-) create mode 100644 Adventure Game/adventure_game/MainMenu.py create mode 100644 Adventure Game/adventure_game/Player.py delete mode 100644 Adventure Game/adventure_game/player.py create mode 100644 Adventure Game/adventure_game/playerdata/defaults/default_player.yaml diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index 143430c..81fd744 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -1,12 +1,18 @@ -import npyscreen, sys +import npyscreen +import sys -class ExitButton(npyscreen.ButtonPress): + +class QuitButton(npyscreen.ButtonPress): def whenPressed(self): sys.exit(0) +class SendButton(npyscreen.ButtonPress): + def whenPressed(self): + self.parent.parentApp.switchForm('GAME') + class GameNavigator(npyscreen.FormBaseNew): - def afterEditing(self): - self.parentApp.setNextForm('GAME') +# def afterEditing(self): +#it self.parentApp.setNextForm('GAME') def create(self): top_division_height = 20 @@ -41,7 +47,8 @@ class GameNavigator(npyscreen.FormBaseNew): max_width=inventory_width + art_width, max_height=3, relx=1, - rely=top_division_height + 2) + rely=top_division_height + 2, + editable=False) self.dialogueBox = self.add(npyscreen.Textfield, name='Type Here', @@ -50,4 +57,11 @@ class GameNavigator(npyscreen.FormBaseNew): relx=2, rely=top_division_height + 3) - self.tryAction = self.add(ExitButton, name="Send", relx=inventory_width + art_width - 7, rely=top_division_height + 3) \ No newline at end of file + self.sendButton = self.add(SendButton, + name="Send", + relx=inventory_width + art_width - 7, + rely=top_division_height + 3) + self.quitButton = self.add(QuitButton, + name="Quit", + relx=1, + rely=1) diff --git a/Adventure Game/adventure_game/MainMenu.py b/Adventure Game/adventure_game/MainMenu.py new file mode 100644 index 0000000..7afc67d --- /dev/null +++ b/Adventure Game/adventure_game/MainMenu.py @@ -0,0 +1,11 @@ +import npyscreen + +class MainMenu(npyscreen.Form): + def afterEditing(self): + # TODO: the game needs to happen after this inital main menu + self.parentApp.setNextForm('GAME') + + def create(self): + self.add(npyscreen.FixedText, value='You cannot select a file yet! Just hit OK', editable=False) + self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Your save file:") + self.add(npyscreen.MultiLineEdit, value=self.parentApp.gamelib['menu']['graphics']['logo'], editable=False) \ No newline at end of file diff --git a/Adventure Game/adventure_game/Player.py b/Adventure Game/adventure_game/Player.py new file mode 100644 index 0000000..b27cb37 --- /dev/null +++ b/Adventure Game/adventure_game/Player.py @@ -0,0 +1,11 @@ +from yaml_parser import parse_datafile as parse + +class Player: + """ + This class intended to abstract out the actual yaml data into a player.(item) that is more + friendly to handle in code. + """ + def __init__(self, save_location): + self.save_location = save_location + + self.playerData = parse(save_location) \ No newline at end of file diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index e99b86b..092fedb 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,20 +1,11 @@ -import npyscreen, sys +import npyscreen from npyscreen import NotEnoughSpaceForWidget from os import system from yaml_parser import parse_datafile as parse from GameNavigator import GameNavigator - - -class MainMenu(npyscreen.Form): - def afterEditing(self): - # TODO: the game needs to happen after this inital main menu - self.parentApp.setNextForm('GAME') - - def create(self): - self.add(npyscreen.FixedText, value='You cannot select a file yet! Just hit OK', editable=False) - self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Your save file:") - self.add(npyscreen.MultiLineEdit, value=self.parentApp.gamelib['menu']['graphics']['logo'], editable=False) +from MainMenu import MainMenu +from Player import Player class AlphaWarning(npyscreen.Popup): @@ -33,7 +24,9 @@ class AdventureGame(npyscreen.NPSAppManaged): # Setup some important 'global' values we'll need later self.gamelib = parse( 'gamedata/gamelib.yaml') # parse this data first (since it includes graphics for the main menu - self.playerSaveLocation = None # We'll load the save location after the player gets to the save select screen + self.playerSaveLocation = 'playerdata/defaults/default_player.yaml' #TODO: Actually load the player data + + self.player = Player(self.playerSaveLocation) # Set screen size before drawing windows dimensions = self.gamelib['menu']['graphics']['dimensions'] @@ -50,6 +43,9 @@ class AdventureGame(npyscreen.NPSAppManaged): if __name__ == '__main__': + # Set the screen size bigger + system('mode con: cols={0} lines={1}'.format(124, 30)) + # Make a new adventure game if not imported adventure_game = AdventureGame() diff --git a/Adventure Game/adventure_game/player.py b/Adventure Game/adventure_game/player.py deleted file mode 100644 index 81620ec..0000000 --- a/Adventure Game/adventure_game/player.py +++ /dev/null @@ -1,7 +0,0 @@ -from yaml_parser import parse_datafile as parse - -class Player: - def __init__(self, save_location): - self.save_location = save_location - - self.playerData = parse(save_location) \ No newline at end of file diff --git a/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml b/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml new file mode 100644 index 0000000..811f696 --- /dev/null +++ b/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml @@ -0,0 +1,4 @@ +player: + name: 'Default' + location: 'office' + inventory: ['test', 'test2'] \ No newline at end of file -- 2.43.0 From eb70e4a438288424b65c65ab0eb03ebfdb568a53 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sun, 21 Feb 2021 17:07:14 -0500 Subject: [PATCH 14/29] Organize where the player() is initalized --- Adventure Game/adventure_game/MainMenu.py | 6 ++++++ Adventure Game/adventure_game/main.py | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Adventure Game/adventure_game/MainMenu.py b/Adventure Game/adventure_game/MainMenu.py index 7afc67d..3943b0c 100644 --- a/Adventure Game/adventure_game/MainMenu.py +++ b/Adventure Game/adventure_game/MainMenu.py @@ -1,5 +1,9 @@ import npyscreen + +from Player import Player + + class MainMenu(npyscreen.Form): def afterEditing(self): # TODO: the game needs to happen after this inital main menu @@ -8,4 +12,6 @@ class MainMenu(npyscreen.Form): def create(self): self.add(npyscreen.FixedText, value='You cannot select a file yet! Just hit OK', editable=False) self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Your save file:") + + self.parentApp.player = Player('playerdata/defaults/default_player.yaml') self.add(npyscreen.MultiLineEdit, value=self.parentApp.gamelib['menu']['graphics']['logo'], editable=False) \ No newline at end of file diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 092fedb..ff04146 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -5,7 +5,6 @@ from os import system from yaml_parser import parse_datafile as parse from GameNavigator import GameNavigator from MainMenu import MainMenu -from Player import Player class AlphaWarning(npyscreen.Popup): @@ -24,9 +23,8 @@ class AdventureGame(npyscreen.NPSAppManaged): # Setup some important 'global' values we'll need later self.gamelib = parse( 'gamedata/gamelib.yaml') # parse this data first (since it includes graphics for the main menu - self.playerSaveLocation = 'playerdata/defaults/default_player.yaml' #TODO: Actually load the player data - self.player = Player(self.playerSaveLocation) + self.player = None # Intalize the player as none, the player will be created in the main menu. # Set screen size before drawing windows dimensions = self.gamelib['menu']['graphics']['dimensions'] -- 2.43.0 From fa0c2cac9e982e82dd7332567c52d1edf01efc92 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sun, 21 Feb 2021 17:07:20 -0500 Subject: [PATCH 15/29] handle a redraw! --- Adventure Game/adventure_game/GameNavigator.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index 81fd744..7e90d40 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -8,12 +8,17 @@ class QuitButton(npyscreen.ButtonPress): class SendButton(npyscreen.ButtonPress): def whenPressed(self): - self.parent.parentApp.switchForm('GAME') + self.parent.artContent.value = 'Undraw!' + #self.parent.parentApp.switchForm('GAME') + self.parent.artContent.display() class GameNavigator(npyscreen.FormBaseNew): # def afterEditing(self): #it self.parentApp.setNextForm('GAME') + def render(self): + self.artContent.value = 'Undraw!' + def create(self): top_division_height = 20 inventory_width = 20 -- 2.43.0 From 5fb78fece87d1656ed52c6ad89078856cec7f988 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sun, 21 Feb 2021 17:15:26 -0500 Subject: [PATCH 16/29] Move around/clean up game renderer Also add space for log window --- .../adventure_game/GameNavigator.py | 23 +++++++++---------- Adventure Game/adventure_game/main.py | 8 +++---- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index 7e90d40..77803f8 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -6,18 +6,17 @@ class QuitButton(npyscreen.ButtonPress): def whenPressed(self): sys.exit(0) -class SendButton(npyscreen.ButtonPress): + +class Render(npyscreen.ButtonPress): def whenPressed(self): self.parent.artContent.value = 'Undraw!' - #self.parent.parentApp.switchForm('GAME') self.parent.artContent.display() + self.parent.parentApp.switchForm('GAME') + class GameNavigator(npyscreen.FormBaseNew): -# def afterEditing(self): -#it self.parentApp.setNextForm('GAME') - - def render(self): - self.artContent.value = 'Undraw!' + # def afterEditing(self): + # it self.parentApp.setNextForm('GAME') def create(self): top_division_height = 20 @@ -52,20 +51,20 @@ class GameNavigator(npyscreen.FormBaseNew): max_width=inventory_width + art_width, max_height=3, relx=1, - rely=top_division_height + 2, + rely=top_division_height + 2 + 9, editable=False) self.dialogueBox = self.add(npyscreen.Textfield, name='Type Here', - max_width=inventory_width + art_width - 7, + max_width=inventory_width + art_width - 14, max_height=1, relx=2, - rely=top_division_height + 3) + rely=top_division_height + 3 + 9) - self.sendButton = self.add(SendButton, + self.sendButton = self.add(Render, name="Send", relx=inventory_width + art_width - 7, - rely=top_division_height + 3) + rely=top_division_height + 3 + 9) self.quitButton = self.add(QuitButton, name="Quit", relx=1, diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index ff04146..741a2e1 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -28,9 +28,9 @@ class AdventureGame(npyscreen.NPSAppManaged): # Set screen size before drawing windows dimensions = self.gamelib['menu']['graphics']['dimensions'] - system('mode con: cols={0} lines={1}'.format( - dimensions['inventory_width']+dimensions['art_width'], - 30)) # TODO: Finish setting this up. + #system('mode con: cols={0} lines={1}'.format( + # dimensions['inventory_width']+dimensions['art_width'], + # 30)) # TODO: Finish setting this up. # Draw game windows self.addForm('GAME', GameNavigator, name='Unnamed Adventure Game') # This window should draw the actual game @@ -42,7 +42,7 @@ class AdventureGame(npyscreen.NPSAppManaged): if __name__ == '__main__': # Set the screen size bigger - system('mode con: cols={0} lines={1}'.format(124, 30)) + system('mode con: cols={0} lines={1}'.format(124, 36)) # Make a new adventure game if not imported adventure_game = AdventureGame() -- 2.43.0 From fa3e73498def8bb11bb8c6a05876aac21b5e2672 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sun, 21 Feb 2021 17:17:19 -0500 Subject: [PATCH 17/29] Add in log window! --- Adventure Game/adventure_game/GameNavigator.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index 77803f8..620d33c 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -47,6 +47,21 @@ class GameNavigator(npyscreen.FormBaseNew): rely=2, editable=False) + self.logBoxOutline = self.add(npyscreen.BoxBasic, + max_width=inventory_width + art_width, + max_height=9, + relx=1, + rely=top_division_height + 2, + editable=False) + + self.logBox = self.add(npyscreen.Textfield, + name='Type Here', + max_width=inventory_width + art_width - 7, + max_height=7, + relx=2, + rely=top_division_height + 3, + editable=False) + self.dialogueBoxOutline = self.add(npyscreen.BoxBasic, max_width=inventory_width + art_width, max_height=3, -- 2.43.0 From 2dd8b15a9d7f82ce5406abe525ca257a0057cced Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sun, 21 Feb 2021 20:20:05 -0500 Subject: [PATCH 18/29] fix this bit --- Adventure Game/adventure_game/GameNavigator.py | 12 +++--------- Adventure Game/adventure_game/handler.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 Adventure Game/adventure_game/handler.py diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index 620d33c..44ba48e 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -1,19 +1,14 @@ import npyscreen import sys +from Handler import Handler + class QuitButton(npyscreen.ButtonPress): def whenPressed(self): sys.exit(0) -class Render(npyscreen.ButtonPress): - def whenPressed(self): - self.parent.artContent.value = 'Undraw!' - self.parent.artContent.display() - self.parent.parentApp.switchForm('GAME') - - class GameNavigator(npyscreen.FormBaseNew): # def afterEditing(self): # it self.parentApp.setNextForm('GAME') @@ -55,7 +50,6 @@ class GameNavigator(npyscreen.FormBaseNew): editable=False) self.logBox = self.add(npyscreen.Textfield, - name='Type Here', max_width=inventory_width + art_width - 7, max_height=7, relx=2, @@ -76,7 +70,7 @@ class GameNavigator(npyscreen.FormBaseNew): relx=2, rely=top_division_height + 3 + 9) - self.sendButton = self.add(Render, + self.sendButton = self.add(Handler, name="Send", relx=inventory_width + art_width - 7, rely=top_division_height + 3 + 9) diff --git a/Adventure Game/adventure_game/handler.py b/Adventure Game/adventure_game/handler.py new file mode 100644 index 0000000..874cb99 --- /dev/null +++ b/Adventure Game/adventure_game/handler.py @@ -0,0 +1,15 @@ +import npyscreen + + +class Handler(npyscreen.ButtonPress): + """ + Very important, called when the player hits send, there are several things we need to do here: + 1: handle the player's input, and run logic, this is done in handler.py + 2: prepare new items to display on the screen + 3: re-render the screen + """ + def whenPressed(self): + self.parent.logBox.value = self.parent.dialogueBox.value + self.parent.dialogueBox.value = '' + self.parent.artContent.display() + self.parent.parentApp.switchForm('GAME') \ No newline at end of file -- 2.43.0 From b396cee469dac703b81d87b4d66deebf40d9d9da Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 16:48:01 -0500 Subject: [PATCH 19/29] Logbox echo works! --- Adventure Game/adventure_game/GameNavigator.py | 14 +++++++++++++- Adventure Game/adventure_game/handler.py | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index 44ba48e..b80c284 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -13,10 +13,22 @@ class GameNavigator(npyscreen.FormBaseNew): # def afterEditing(self): # it self.parentApp.setNextForm('GAME') + def update_log(self, newline): + self.logList.append(newline) # Append the newline + self.logList = self.logList[-7:] # Truncate to only the last 5 lines + + res = '' # Convert the list to a string + for element in self.logList: + res = res + str(element) + '\n' + res = res.upper() # Log is always uppercase + + self.logBox.value = res # Set the logbox to that value + def create(self): top_division_height = 20 inventory_width = 20 art_width = 100 + self.logList = [] self.artBox = self.add(npyscreen.BoxBasic, name='ArtBox', @@ -49,7 +61,7 @@ class GameNavigator(npyscreen.FormBaseNew): rely=top_division_height + 2, editable=False) - self.logBox = self.add(npyscreen.Textfield, + self.logBox = self.add(npyscreen.MultiLineEdit, max_width=inventory_width + art_width - 7, max_height=7, relx=2, diff --git a/Adventure Game/adventure_game/handler.py b/Adventure Game/adventure_game/handler.py index 874cb99..c12c38a 100644 --- a/Adventure Game/adventure_game/handler.py +++ b/Adventure Game/adventure_game/handler.py @@ -9,7 +9,7 @@ class Handler(npyscreen.ButtonPress): 3: re-render the screen """ def whenPressed(self): - self.parent.logBox.value = self.parent.dialogueBox.value + self.parent.update_log(self.parent.dialogueBox.value) self.parent.dialogueBox.value = '' self.parent.artContent.display() - self.parent.parentApp.switchForm('GAME') \ No newline at end of file + self.parent.parentApp.switchForm('GAME') -- 2.43.0 From b55bcf77b8b762b7505f8329bd9eeed66276b999 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 16:59:45 -0500 Subject: [PATCH 20/29] Replace some helptext --- Adventure Game/adventure_game/GameNavigator.py | 9 +++++++-- Adventure Game/adventure_game/MainMenu.py | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index b80c284..c24e3f2 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -10,8 +10,13 @@ class QuitButton(npyscreen.ButtonPress): class GameNavigator(npyscreen.FormBaseNew): - # def afterEditing(self): - # it self.parentApp.setNextForm('GAME') + """ + This class handles all the drawing and 'graphics' of our game. + only basic logic like initial loading should happen here. re-drawing + and game logic should be done in Handler.py + TODO: Find a fix for initial room startup + TODO: Find a way to reset the cursor after a user hits sendButton + """ def update_log(self, newline): self.logList.append(newline) # Append the newline diff --git a/Adventure Game/adventure_game/MainMenu.py b/Adventure Game/adventure_game/MainMenu.py index 3943b0c..02ec615 100644 --- a/Adventure Game/adventure_game/MainMenu.py +++ b/Adventure Game/adventure_game/MainMenu.py @@ -5,6 +5,10 @@ from Player import Player class MainMenu(npyscreen.Form): + """ + This is the main menu, code here should only be for + initializing the player data and any settings they want to change + """ def afterEditing(self): # TODO: the game needs to happen after this inital main menu self.parentApp.setNextForm('GAME') -- 2.43.0 From 8b3dba02cc5e512afb17219a3fe4a8e2a9bc8aae Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 19:46:39 -0500 Subject: [PATCH 21/29] Experiment with themes --- Adventure Game/adventure_game/main.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 741a2e1..286b32d 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -32,6 +32,10 @@ class AdventureGame(npyscreen.NPSAppManaged): # dimensions['inventory_width']+dimensions['art_width'], # 30)) # TODO: Finish setting this up. + # Set theme + #TODO: modify custom theme? + npyscreen.setTheme(npyscreen.Themes.ElegantTheme) + # Draw game windows self.addForm('GAME', GameNavigator, name='Unnamed Adventure Game') # This window should draw the actual game self.addForm('MENU', MainMenu, name='Welcome to the main menu') # This window should draw the main menu -- 2.43.0 From 5ba6a20f1324321c12dc3895ff09248d6839522b Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 20:11:47 -0500 Subject: [PATCH 22/29] Update Handler.py How was this not fixed? --- Adventure Game/adventure_game/{handler.py => Handler.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Adventure Game/adventure_game/{handler.py => Handler.py} (100%) diff --git a/Adventure Game/adventure_game/handler.py b/Adventure Game/adventure_game/Handler.py similarity index 100% rename from Adventure Game/adventure_game/handler.py rename to Adventure Game/adventure_game/Handler.py -- 2.43.0 From 832e26232b9863542e51bff5dc08ca0cbb6d8d1f Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 20:17:54 -0500 Subject: [PATCH 23/29] Modualerize! --- Adventure Game/adventure_game/MainMenu.py | 2 +- .../adventure_game/{main.py => __main__.py} | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) rename Adventure Game/adventure_game/{main.py => __main__.py} (84%) diff --git a/Adventure Game/adventure_game/MainMenu.py b/Adventure Game/adventure_game/MainMenu.py index 02ec615..b01614b 100644 --- a/Adventure Game/adventure_game/MainMenu.py +++ b/Adventure Game/adventure_game/MainMenu.py @@ -17,5 +17,5 @@ class MainMenu(npyscreen.Form): self.add(npyscreen.FixedText, value='You cannot select a file yet! Just hit OK', editable=False) self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Your save file:") - self.parentApp.player = Player('playerdata/defaults/default_player.yaml') + self.parentApp.player = Player(self.parentApp.mainPath / 'playerdata/defaults/default_player.yaml') self.add(npyscreen.MultiLineEdit, value=self.parentApp.gamelib['menu']['graphics']['logo'], editable=False) \ No newline at end of file diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/__main__.py similarity index 84% rename from Adventure Game/adventure_game/main.py rename to Adventure Game/adventure_game/__main__.py index 286b32d..f035b1a 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/__main__.py @@ -1,3 +1,4 @@ +import pathlib import npyscreen from npyscreen import NotEnoughSpaceForWidget from os import system @@ -21,10 +22,17 @@ class AdventureGame(npyscreen.NPSAppManaged): # Do on creation def onStart(self): # Setup some important 'global' values we'll need later + # Set the path all other files will follow + self.mainPath = pathlib.Path(__file__).parent + + # Parse world self.gamelib = parse( - 'gamedata/gamelib.yaml') # parse this data first (since it includes graphics for the main menu + self.mainPath / 'gamedata/gamelib.yaml') # parse this data first (since it includes graphics for the main menu + + # Intalize the player as none, the player will be created in the main menu. + self.player = None + - self.player = None # Intalize the player as none, the player will be created in the main menu. # Set screen size before drawing windows dimensions = self.gamelib['menu']['graphics']['dimensions'] -- 2.43.0 From 9fc4ed130c05c3625d506beca1b640bb15e7aa0d Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 23:30:38 -0500 Subject: [PATCH 24/29] Add error handling to handler --- Adventure Game/adventure_game/Handler.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index c12c38a..fb4cc49 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -9,7 +9,20 @@ class Handler(npyscreen.ButtonPress): 3: re-render the screen """ def whenPressed(self): - self.parent.update_log(self.parent.dialogueBox.value) + # This is the raw command from the user + raw_command = self.parent.dialogueBox.value + + # This is the raw command from the user + parsed_command = raw_command.split() + + try: + command = parsed_command.pop(0) + except IndexError: + pass + arguments = parsed_command + + self.parent.update_log('command: ' + command) + self.parent.update_log('args: {0}'.format(arguments)) self.parent.dialogueBox.value = '' self.parent.artContent.display() self.parent.parentApp.switchForm('GAME') -- 2.43.0 From e32e9895e5da0340188306a0c7814b173246e8b8 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 23:30:49 -0500 Subject: [PATCH 25/29] Prepare logging! --- Adventure Game/adventure_game/__main__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/__main__.py b/Adventure Game/adventure_game/__main__.py index f035b1a..7422f06 100644 --- a/Adventure Game/adventure_game/__main__.py +++ b/Adventure Game/adventure_game/__main__.py @@ -1,5 +1,6 @@ import pathlib import npyscreen +import logging from npyscreen import NotEnoughSpaceForWidget from os import system @@ -19,12 +20,19 @@ class AlphaWarning(npyscreen.Popup): class AdventureGame(npyscreen.NPSAppManaged): + """ + This is the 'root' of the entire game! + """ # Do on creation def onStart(self): # Setup some important 'global' values we'll need later # Set the path all other files will follow self.mainPath = pathlib.Path(__file__).parent - + + # Setup logging + self.log = logging + self.log.basicConfig(filename=self.mainPath / 'logs/AdventureGame.log', filemode='w', level=logging.DEBUG) + # Parse world self.gamelib = parse( self.mainPath / 'gamedata/gamelib.yaml') # parse this data first (since it includes graphics for the main menu -- 2.43.0 From e58af07b5e28da46c26c872383a8eda711eb3c2a Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 23:30:53 -0500 Subject: [PATCH 26/29] Create AdventureGame.log --- Adventure Game/adventure_game/logs/AdventureGame.log | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Adventure Game/adventure_game/logs/AdventureGame.log diff --git a/Adventure Game/adventure_game/logs/AdventureGame.log b/Adventure Game/adventure_game/logs/AdventureGame.log new file mode 100644 index 0000000..e69de29 -- 2.43.0 From 87fdc6b91ea45e9f3c145c3730b9985524f30604 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 23:48:07 -0500 Subject: [PATCH 27/29] Add log to gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 11e2a47..46b3e76 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.pyc -.idea \ No newline at end of file +.idea +Adventure Game/adventure_game/logs/AdventureGame.log -- 2.43.0 From 0c1770ef0ace5cb9b9789309ac2e9932877dd435 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 23:48:20 -0500 Subject: [PATCH 28/29] add some extra verbose logging to __main__ --- Adventure Game/adventure_game/__main__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Adventure Game/adventure_game/__main__.py b/Adventure Game/adventure_game/__main__.py index 7422f06..64ca805 100644 --- a/Adventure Game/adventure_game/__main__.py +++ b/Adventure Game/adventure_game/__main__.py @@ -31,11 +31,15 @@ class AdventureGame(npyscreen.NPSAppManaged): # Setup logging self.log = logging - self.log.basicConfig(filename=self.mainPath / 'logs/AdventureGame.log', filemode='w', level=logging.DEBUG) + self.log.basicConfig(filename=self.mainPath / 'logs/AdventureGame.log', + filemode='w', + level=logging.DEBUG) + self.log.info('Logging started!') - # Parse world + # parse this data first (since it includes graphics for the main menu self.gamelib = parse( - self.mainPath / 'gamedata/gamelib.yaml') # parse this data first (since it includes graphics for the main menu + self.mainPath / 'gamedata/gamelib.yaml') + self.log.debug('Gamelib at {0}'.format(self.mainPath / 'gamedata/gamelib.yaml')) # Intalize the player as none, the player will be created in the main menu. self.player = None -- 2.43.0 From cc0f6f9f9eff2a858cbb1596461811534be11ed7 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 23:48:33 -0500 Subject: [PATCH 29/29] Clean up logging in handler.py --- Adventure Game/adventure_game/Handler.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index fb4cc49..78ac1a7 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -9,8 +9,10 @@ class Handler(npyscreen.ButtonPress): 3: re-render the screen """ def whenPressed(self): + self.parent.parentApp.log.debug('Send button pressed!') # This is the raw command from the user raw_command = self.parent.dialogueBox.value + self.parent.dialogueBox.value = '' # Clear the dialogue box, TODO: This may become unneeded if issue #8 is fixed # This is the raw command from the user parsed_command = raw_command.split() @@ -18,11 +20,12 @@ class Handler(npyscreen.ButtonPress): try: command = parsed_command.pop(0) except IndexError: - pass - arguments = parsed_command + self.parent.parentApp.log.warn('Command "{0}" could not be split, was it malformed or incomplete?'.format(raw_command)) + command = '' + arguments = parsed_command # Whatever is left in the list, are arguments. + self.parent.parentApp.log.info('Parsed command "{0}" with arguments "{1}"'.format(command, arguments)) self.parent.update_log('command: ' + command) self.parent.update_log('args: {0}'.format(arguments)) - self.parent.dialogueBox.value = '' self.parent.artContent.display() self.parent.parentApp.switchForm('GAME') -- 2.43.0