From c02177e4967c63b579b4b936b8f8f87663a4560a Mon Sep 17 00:00:00 2001 From: vg Date: Mon, 28 Nov 2022 00:27:42 +0100 Subject: git-sync on dita --- .gitignore | 2 + assets/dynotherm.zip | Bin 0 -> 40811 bytes assets/futurex_arthur.zip | Bin 0 -> 338843 bytes assets/galactica_s.zip | Bin 0 -> 103187 bytes assets/individigital.zip | Bin 0 -> 291586 bytes assets/kg_happy.zip | Bin 0 -> 202028 bytes assets/medabots.zip | Bin 0 -> 22650 bytes assets/music/140481__eliasyian__opening-scene.flac | Bin 0 -> 10073179 bytes assets/music/161615__logicmoon__deep-space.flac | Bin 0 -> 6930347 bytes assets/music/476772__andrewkn__decline-loop.flac | Bin 0 -> 5023565 bytes ...ndrewkn__andrew-kn-at-the-edge-of-space-ii.flac | Bin 0 -> 8355902 bytes .../513479__andrewkn__higher-than-possible.flac | Bin 0 -> 31106350 bytes assets/music/518910__andrewkn__fantasy.flac | Bin 0 -> 6429297 bytes assets/sfx/108336__qat__click-01-fast.flac | Bin 0 -> 8696 bytes .../sfx/422836__gamedevc__g-ui-button-hover-1.flac | Bin 0 -> 17447 bytes assets/sfx/467951__benzix2__ui-button-click.ogg | Bin 0 -> 9997 bytes assets/sfx/488534__ranner__ui-click.flac | Bin 0 -> 29664 bytes ...sinus-sytrus-arpegio-multiprocessing-rsmpl.flac | Bin 0 -> 68410 bytes ...lip-2-sytrus-arpegio-multiprocessing-rsmpl.flac | Bin 0 -> 43388 bytes ...-blip-sytrus-arpegio-multiprocessing-rsmpl.flac | Bin 0 -> 28356 bytes .../sfx/594210__steaq__robo-nope-16bit-flac.flac | Bin 0 -> 62991 bytes assets/sfx/629020__kolombooo__button-click.ogg | Bin 0 -> 9304 bytes assets/sfx/635915__earth-cord__button-push.flac | Bin 0 -> 44439 bytes ...nspect-sound-ui-or-in-game-notification-02.flac | Bin 0 -> 44604 bytes assets/ui/RPG_GUI_moonmod_source.xcf | Bin 0 -> 7291414 bytes assets/veteran_typewriter.zip | Bin 0 -> 33562 bytes pygame/gamechest | 1 + pygame/main.py | 178 ++++++++++++++++++--- pygame/profiledb.py | 14 ++ pygame/requirements.txt | 1 + 30 files changed, 174 insertions(+), 22 deletions(-) create mode 100644 .gitignore create mode 100644 assets/dynotherm.zip create mode 100644 assets/futurex_arthur.zip create mode 100644 assets/galactica_s.zip create mode 100644 assets/individigital.zip create mode 100644 assets/kg_happy.zip create mode 100644 assets/medabots.zip create mode 100644 assets/music/140481__eliasyian__opening-scene.flac create mode 100644 assets/music/161615__logicmoon__deep-space.flac create mode 100644 assets/music/476772__andrewkn__decline-loop.flac create mode 100644 assets/music/482919__andrewkn__andrew-kn-at-the-edge-of-space-ii.flac create mode 100644 assets/music/513479__andrewkn__higher-than-possible.flac create mode 100644 assets/music/518910__andrewkn__fantasy.flac create mode 100644 assets/sfx/108336__qat__click-01-fast.flac create mode 100644 assets/sfx/422836__gamedevc__g-ui-button-hover-1.flac create mode 100644 assets/sfx/467951__benzix2__ui-button-click.ogg create mode 100644 assets/sfx/488534__ranner__ui-click.flac create mode 100644 assets/sfx/515827__newlocknew__ui-3-1-fhsandal-sinus-sytrus-arpegio-multiprocessing-rsmpl.flac create mode 100644 assets/sfx/515836__newlocknew__ui-7-confusion-blip-2-sytrus-arpegio-multiprocessing-rsmpl.flac create mode 100644 assets/sfx/515837__newlocknew__ui-6-confusion-blip-sytrus-arpegio-multiprocessing-rsmpl.flac create mode 100644 assets/sfx/594210__steaq__robo-nope-16bit-flac.flac create mode 100644 assets/sfx/629020__kolombooo__button-click.ogg create mode 100644 assets/sfx/635915__earth-cord__button-push.flac create mode 100644 assets/sfx/657950__matrixxx__scifi-inspect-sound-ui-or-in-game-notification-02.flac create mode 100644 assets/ui/RPG_GUI_moonmod_source.xcf create mode 100644 assets/veteran_typewriter.zip create mode 120000 pygame/gamechest create mode 100644 pygame/profiledb.py create mode 100644 pygame/requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7c6571e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +venv +*.pyc diff --git a/assets/dynotherm.zip b/assets/dynotherm.zip new file mode 100644 index 0000000..51857ee Binary files /dev/null and b/assets/dynotherm.zip differ diff --git a/assets/futurex_arthur.zip b/assets/futurex_arthur.zip new file mode 100644 index 0000000..a22a146 Binary files /dev/null and b/assets/futurex_arthur.zip differ diff --git a/assets/galactica_s.zip b/assets/galactica_s.zip new file mode 100644 index 0000000..7e6a8d5 Binary files /dev/null and b/assets/galactica_s.zip differ diff --git a/assets/individigital.zip b/assets/individigital.zip new file mode 100644 index 0000000..1345de9 Binary files /dev/null and b/assets/individigital.zip differ diff --git a/assets/kg_happy.zip b/assets/kg_happy.zip new file mode 100644 index 0000000..f6869c7 Binary files /dev/null and b/assets/kg_happy.zip differ diff --git a/assets/medabots.zip b/assets/medabots.zip new file mode 100644 index 0000000..1ac1358 Binary files /dev/null and b/assets/medabots.zip differ diff --git a/assets/music/140481__eliasyian__opening-scene.flac b/assets/music/140481__eliasyian__opening-scene.flac new file mode 100644 index 0000000..3d177dc Binary files /dev/null and b/assets/music/140481__eliasyian__opening-scene.flac differ diff --git a/assets/music/161615__logicmoon__deep-space.flac b/assets/music/161615__logicmoon__deep-space.flac new file mode 100644 index 0000000..b9a8f7e Binary files /dev/null and b/assets/music/161615__logicmoon__deep-space.flac differ diff --git a/assets/music/476772__andrewkn__decline-loop.flac b/assets/music/476772__andrewkn__decline-loop.flac new file mode 100644 index 0000000..abac192 Binary files /dev/null and b/assets/music/476772__andrewkn__decline-loop.flac differ diff --git a/assets/music/482919__andrewkn__andrew-kn-at-the-edge-of-space-ii.flac b/assets/music/482919__andrewkn__andrew-kn-at-the-edge-of-space-ii.flac new file mode 100644 index 0000000..12e07b1 Binary files /dev/null and b/assets/music/482919__andrewkn__andrew-kn-at-the-edge-of-space-ii.flac differ diff --git a/assets/music/513479__andrewkn__higher-than-possible.flac b/assets/music/513479__andrewkn__higher-than-possible.flac new file mode 100644 index 0000000..ef23233 Binary files /dev/null and b/assets/music/513479__andrewkn__higher-than-possible.flac differ diff --git a/assets/music/518910__andrewkn__fantasy.flac b/assets/music/518910__andrewkn__fantasy.flac new file mode 100644 index 0000000..4550175 Binary files /dev/null and b/assets/music/518910__andrewkn__fantasy.flac differ diff --git a/assets/sfx/108336__qat__click-01-fast.flac b/assets/sfx/108336__qat__click-01-fast.flac new file mode 100644 index 0000000..0b5e1fc Binary files /dev/null and b/assets/sfx/108336__qat__click-01-fast.flac differ diff --git a/assets/sfx/422836__gamedevc__g-ui-button-hover-1.flac b/assets/sfx/422836__gamedevc__g-ui-button-hover-1.flac new file mode 100644 index 0000000..27e25c1 Binary files /dev/null and b/assets/sfx/422836__gamedevc__g-ui-button-hover-1.flac differ diff --git a/assets/sfx/467951__benzix2__ui-button-click.ogg b/assets/sfx/467951__benzix2__ui-button-click.ogg new file mode 100644 index 0000000..dc51c87 Binary files /dev/null and b/assets/sfx/467951__benzix2__ui-button-click.ogg differ diff --git a/assets/sfx/488534__ranner__ui-click.flac b/assets/sfx/488534__ranner__ui-click.flac new file mode 100644 index 0000000..ba661e1 Binary files /dev/null and b/assets/sfx/488534__ranner__ui-click.flac differ diff --git a/assets/sfx/515827__newlocknew__ui-3-1-fhsandal-sinus-sytrus-arpegio-multiprocessing-rsmpl.flac b/assets/sfx/515827__newlocknew__ui-3-1-fhsandal-sinus-sytrus-arpegio-multiprocessing-rsmpl.flac new file mode 100644 index 0000000..cc01c34 Binary files /dev/null and b/assets/sfx/515827__newlocknew__ui-3-1-fhsandal-sinus-sytrus-arpegio-multiprocessing-rsmpl.flac differ diff --git a/assets/sfx/515836__newlocknew__ui-7-confusion-blip-2-sytrus-arpegio-multiprocessing-rsmpl.flac b/assets/sfx/515836__newlocknew__ui-7-confusion-blip-2-sytrus-arpegio-multiprocessing-rsmpl.flac new file mode 100644 index 0000000..9c39fc9 Binary files /dev/null and b/assets/sfx/515836__newlocknew__ui-7-confusion-blip-2-sytrus-arpegio-multiprocessing-rsmpl.flac differ diff --git a/assets/sfx/515837__newlocknew__ui-6-confusion-blip-sytrus-arpegio-multiprocessing-rsmpl.flac b/assets/sfx/515837__newlocknew__ui-6-confusion-blip-sytrus-arpegio-multiprocessing-rsmpl.flac new file mode 100644 index 0000000..57988cf Binary files /dev/null and b/assets/sfx/515837__newlocknew__ui-6-confusion-blip-sytrus-arpegio-multiprocessing-rsmpl.flac differ diff --git a/assets/sfx/594210__steaq__robo-nope-16bit-flac.flac b/assets/sfx/594210__steaq__robo-nope-16bit-flac.flac new file mode 100644 index 0000000..e4d25e9 Binary files /dev/null and b/assets/sfx/594210__steaq__robo-nope-16bit-flac.flac differ diff --git a/assets/sfx/629020__kolombooo__button-click.ogg b/assets/sfx/629020__kolombooo__button-click.ogg new file mode 100644 index 0000000..86e0fe0 Binary files /dev/null and b/assets/sfx/629020__kolombooo__button-click.ogg differ diff --git a/assets/sfx/635915__earth-cord__button-push.flac b/assets/sfx/635915__earth-cord__button-push.flac new file mode 100644 index 0000000..b21686d Binary files /dev/null and b/assets/sfx/635915__earth-cord__button-push.flac differ diff --git a/assets/sfx/657950__matrixxx__scifi-inspect-sound-ui-or-in-game-notification-02.flac b/assets/sfx/657950__matrixxx__scifi-inspect-sound-ui-or-in-game-notification-02.flac new file mode 100644 index 0000000..1ba5a21 Binary files /dev/null and b/assets/sfx/657950__matrixxx__scifi-inspect-sound-ui-or-in-game-notification-02.flac differ diff --git a/assets/ui/RPG_GUI_moonmod_source.xcf b/assets/ui/RPG_GUI_moonmod_source.xcf new file mode 100644 index 0000000..f651fb6 Binary files /dev/null and b/assets/ui/RPG_GUI_moonmod_source.xcf differ diff --git a/assets/veteran_typewriter.zip b/assets/veteran_typewriter.zip new file mode 100644 index 0000000..5c83c10 Binary files /dev/null and b/assets/veteran_typewriter.zip differ diff --git a/pygame/gamechest b/pygame/gamechest new file mode 120000 index 0000000..c2e0730 --- /dev/null +++ b/pygame/gamechest @@ -0,0 +1 @@ +../gamechestcli/gamechest \ No newline at end of file diff --git a/pygame/main.py b/pygame/main.py index 948b95a..ba61077 100755 --- a/pygame/main.py +++ b/pygame/main.py @@ -7,6 +7,11 @@ from pathlib import Path import pygame import yaml +from profiledb import ProfileDB + +from gamechest.cliactions import run +from gamechest.gamedb import GameDB + #WINDOW_RESOLUTION = (1280, 720) WINDOW_RESOLUTION = (800, 600) @@ -24,19 +29,32 @@ class AppState: menu_selected_index: int = 0 +class Parameters: + key_delay = 330 + key_interval = 1000//25 + + + + class GuiApp: def __init__(self): pygame.init() + pygame.key.set_repeat(Parameters.key_delay, Parameters.key_interval) #print(pygame.display.list_modes()) self.window = pygame.display.set_mode(WINDOW_RESOLUTION) self.clock = pygame.time.Clock() + self.cycles_per_second = 60 + #self.render_factor_div = 2 # 60/2 => 30fps + #self.input_factor_div = 6 # 60/6 => 10 input repeat per second self.menu_font = pygame.font.Font(pygame.font.get_default_font(), 32) self.font_antialias = True #self.font_antialias = False self.menu_color = (0, 0, 200) + self.render_timer = 0 + self.render_timeout = 1000//30 # 30 fps - def process_input(self, event=None): + def process_input(self, last_frame_time, event=None): if event is None: event = pygame.event.poll() if event.type == pygame.KEYDOWN: @@ -46,10 +64,15 @@ class GuiApp: if event.type == pygame.QUIT: raise QuitEvent() - def update(self): + def update(self, last_frame_time): pass - def render(self): + def render(self, last_frame_time): + self.render_timer += last_frame_time + if self.render_timer < self.render_timeout: + return + self.render_timer = 0 + self.window.fill((0, 0, 0)) # Initial y @@ -98,13 +121,26 @@ class GuiApp: def loop(self): - + #current_render_div = self.render_factor_div + #current_input_div = self.input_factor_div + last_frame_time = 1 # equivalent to 0 but avoid div0 + last_render_time = 1 try: while 1: - self.process_input() - self.update() - self.render() - self.clock.tick(30) # 30 fps + #current_render_div -= 1 + #current_input_div -= 1 + self.process_input(last_frame_time) + #self.update(current_input_div) + self.update(last_frame_time) + self.render(last_frame_time) + #if current_render_div <= 0: + # self.render(last_render_time) + # current_render_div = self.render_factor_div + # last_render_time = 0 + #if current_input_div <= 0: + # current_input_div = self.input_factor_div + last_frame_time = self.clock.tick(self.cycles_per_second) + #last_render_time += last_frame_time except QuitEvent: pass @@ -112,23 +148,107 @@ class GuiApp: pygame.quit() -class GuiAppSub1(GuiApp): +class ProfileDataObserver: + + def event_current_profile_changed(self, new_profile): + pass + + +class ObservedSubject: + def __init__(self): + self.observers = [] + + def add_observer(self, observer): + self.observers.append(observer) + + def del_observer(self, observer): + self.observers.remove(observer) + + def notify_event(self, event_name, *args, **kws): + for observer in self.observers: + getattr(observer, event_name)(*args, **kws) + + +class ProfileData(ObservedSubject): def __init__(self): super().__init__() + self.profiledb = ProfileDB() + self.profiles_len = len(self.profiledb.get_profiles()) + self.current_profile_index = 0 + + def change_active_profile(self, new_index): + if new_index < 0: + new_index = 0 + elif new_index >= self.profiles_len: + new_index = self.profiles_len-1 + if self.current_profile_index != new_index: + print('new index', self.current_profile_index, '->', new_index) + self.current_profile_index = new_index + print(id(self), 'new index', self.current_profile_index) + self.notify_event('event_current_profile_changed', + self.get_current_profile()) + + def change_profile_increase(self): + self.change_active_profile(self.current_profile_index +1) + + def change_profile_decrease(self): + self.change_active_profile(self.current_profile_index -1) + + def get_current_profile(self): + return self.profiledb.get_profiles()[self.current_profile_index]['name'] + + def get_current_display(self): + return self.profiledb.get_profiles()[self.current_profile_index]['display'] + + +class ProfileRenderer(ProfileDataObserver): + + def __init__(self, profiledata): + self.profiledata = profiledata + self.surface_to_render = None + profiledata.add_observer(self) + self.font_filename = pygame.font.match_font('bitstreamverasans') + print('ProfileRenderer font:', self.font_filename) + self.font = pygame.font.Font(self.font_filename, 24) + self.font_antialias = True + self.font_fg_color = (0, 200, 200) + + def event_current_profile_changed(self, new_profile): + self.surface_to_render = None + print('changing rendering profile to', new_profile) + + def render(self, surface): + if self.surface_to_render is None: + profile_name = self.profiledata.get_current_profile() + new_surface = self.font.render(self.profiledata.get_current_display(), self.font_antialias, self.font_fg_color) + self.surface_to_render = new_surface + surface.blit(self.surface_to_render, (50, 50)) + + +class GuiAppSub1(GuiApp): + def __init__(self): + super().__init__() + self.input_timer = 0 + self.input_timeout = 1000//10 self.state = AppState() self.base_window_fill_color = (0, 0, 0) self.user_move_vector = (0, 0) - with Path('~/games/.saves/gamedata.yaml').expanduser().open() as fp: - self.gamedb = yaml.safe_load(fp) - self.menu_items = [x['title'] for x in self.gamedb['games']] + #with Path('~/games/.saves/gamedata.yaml').expanduser().open() as fp: + # self.gamedb = yaml.safe_load(fp) + self.game_db = GameDB() + #self.menu_items = [x['title'] for x in self.gamedb['games']] + self.menu_items = list(self.game_db.get_ids()) self.menu_font_cache = ({}, []) self.menu_font_cache_max = 40 - self.image_right_arrow = pygame.image.load('arrow-right.png') + self.image_right_arrow = pygame.image.load('arrow-right.png').convert() #self.last_movement_update_time = self.clock. self.joysticks = {} self.joysticks_axis_threshold = 0 + self.profile_data = ProfileData() + self.profile_renderer = ProfileRenderer(self.profile_data) + def menu_font_render(self, text): cached_surface = self.menu_font_cache[0].get(text, None) @@ -153,7 +273,8 @@ class GuiAppSub1(GuiApp): return new_surface - def process_input(self): + def process_input(self, last_frame_time): + movement_up_keys = ( pygame.K_UP, pygame.K_k, @@ -168,22 +289,22 @@ class GuiAppSub1(GuiApp): x, y = self.user_move_vector if event.type == pygame.KEYDOWN: if event.key in (*movement_up_keys, *movement_down_keys): - y += 1 if event.key in movement_down_keys else -1 + y = 1 if event.key in movement_down_keys else -1 go_super = 0 elif event.key in (pygame.K_LEFT, pygame.K_RIGHT): - x += 1 if event.key == pygame.K_LEFT else -1 + x = -1 if event.key == pygame.K_LEFT else 1 go_super = 0 elif event.type == pygame.KEYUP: x, y = self.user_move_vector if event.key in (*movement_up_keys, *movement_down_keys): - y -= 1 if event.key in movement_down_keys else -1 + y = 0 go_super = 0 elif event.key in (pygame.K_LEFT, pygame.K_RIGHT): - x -= 1 if event.key == pygame.K_LEFT else -1 + x = 0 go_super = 0 elif event.type in (pygame.JOYBUTTONDOWN, pygame.JOYBUTTONUP): go_super = 0 - factor = 1 if pygame.JOYBUTTONDOWN else -1 + factor = 1 if pygame.JOYBUTTONDOWN else 0 joystick = self.joysticks[event.instance_id] print('gamepad event', event) #if event.button == 0: @@ -226,9 +347,14 @@ class GuiAppSub1(GuiApp): self.user_move_vector = (x, y) print('new move vector:', self.user_move_vector) else: - super().process_input(event) + super().process_input(last_frame_time, event) + + def update(self, last_frame_time): + #self.input_timer += last_frame_time + #if self.input_timer < self.input_timeout: + # return + #self.input_timer = 0 - def update(self): menu_new_index = self.state.menu_selected_index if self.user_move_vector[1] < 0: menu_new_index -= 1 @@ -240,7 +366,14 @@ class GuiAppSub1(GuiApp): menu_new_index = len(self.menu_items)-1 self.state.menu_selected_index = menu_new_index - def render(self): + if self.user_move_vector[0] < 0: + self.profile_data.change_profile_decrease() + elif self.user_move_vector[0] > 0: + self.profile_data.change_profile_increase() + + self.user_move_vector = (0, 0) + + def render(self, last_frame_time): self.window.fill(self.base_window_fill_color) # Initial y @@ -299,6 +432,7 @@ class GuiAppSub1(GuiApp): #pygame.draw.rect(self.window, # (0,0,255), # (120,120,400,240)) + self.profile_renderer.render(self.window) pygame.display.update() diff --git a/pygame/profiledb.py b/pygame/profiledb.py new file mode 100644 index 0000000..190d401 --- /dev/null +++ b/pygame/profiledb.py @@ -0,0 +1,14 @@ +from pathlib import Path + +import yaml + + +class ProfileDB: + + def __init__(self): + with Path('~/games/.saves/profiles.yaml').expanduser().open() as fp: + self.profiledb = yaml.safe_load(fp) + + def get_profiles(self): + # currently contains {name, display} + return self.profiledb['profiles'] diff --git a/pygame/requirements.txt b/pygame/requirements.txt new file mode 100644 index 0000000..0cb7ff1 --- /dev/null +++ b/pygame/requirements.txt @@ -0,0 +1 @@ +pygame -- cgit v1.2.3