Skip to content

Commit

Permalink
Added documentation to the Adapter (#145)
Browse files Browse the repository at this point in the history
* Added documentation to visualizer adapter

* linked the event docs
  • Loading branch information
JeanAEckelberg authored Jan 12, 2024
1 parent 2aca4de commit c66ff3c
Showing 1 changed file with 45 additions and 14 deletions.
59 changes: 45 additions & 14 deletions visualizer/adapter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
import pygame
from game.config import *
Expand Down Expand Up @@ -36,7 +37,9 @@ def start_menu_event(self, event: pygame.event) -> Any:
is implemented currently. Pressing it or pressing enter will start the visualizer to show the game's results.
This method will manage any specified events and return them (hence why the return type is Any). Refer to
menu_templates.py's start_events method for more info.
:param event:
:param event: The pygame event triggered each frame. See pygame
`docs <https://www.pygame.org/docs/ref/event.html for more information>`_
for more information.
:return: Any specified event desired in the start_events method
"""
return self.menu.start_events(event)
Expand All @@ -52,7 +55,9 @@ def on_event(self, event) -> PlaybackButtons:
"""
By giving this method an event, this method can execute whatever is specified. An example is provided below
and commented out. Use as necessary.
:param event:
:param event: The pygame event triggered each frame. See pygame
`docs <https://www.pygame.org/docs/ref/event.html for more information>`_
for more information.
:return: None
"""

Expand All @@ -62,51 +67,77 @@ def on_event(self, event) -> PlaybackButtons:

def prerender(self) -> None:
"""
This will handle anything that needs to be completed before animations start.
This will handle anything that needs to be completed before animations start every turn.
:return: None
"""
...

def continue_animation(self) -> None:
"""
This method is used after the main.py continue_animation() method.
:return:
:return: None
"""
...

# re-renders the animation
def recalc_animation(self, turn_log: dict) -> None:
"""
This method is called every time the turn changes
:param turn_log: A dictionary containing the entire turn state
:return: None
"""
self.turn_number = turn_log['tick']

def populate_bytesprite_factories(self) -> dict[int: Callable[[pygame.Surface], ByteSprite]]:
# Instantiate all bytesprites for each object and add them here
def populate_bytesprite_factories(self) -> dict[int, Callable[[pygame.Surface], ByteSprite]]:
"""
Instantiate all bytesprites for each objectType and add them here using the value of ObjectType as the key
and the factory function as the value
:return: dict[int, Callable[[pygame.Surface], ByteSprite]]
"""
return {
4: AvatarBytespriteFactoryExample().create_bytesprite,
7: TileBytespriteFactoryExample().create_bytesprite,
8: WallBytespriteFactoryExample().create_bytesprite,
4: AvatarBytespriteFactoryExample.create_bytesprite,
7: TileBytespriteFactoryExample.create_bytesprite,
8: WallBytespriteFactoryExample.create_bytesprite,
}

def render(self) -> None:
# self.button.render()
# any logic for rendering text, buttons, and other visuals
"""
This method contains all logic for rendering additional text, buttons, and other visuals
during the playback phase.
:return: None
"""
text = Text(self.screen, f'{self.turn_number} / {self.turn_max}', 48)
text.rect.center = Vector.add_vectors(Vector(*self.screen.get_rect().midtop), Vector(0, 50)).as_tuple()
text.render()
self.playback.playback_render()

# is used in post render - post render is used to clear the playback buttons
def clean_up(self) -> None:
"""
This method is called after rendering each frame.
:return: None
"""
...

def results_load(self, results: dict) -> None:
"""
This method is called to load the end screen for the visualizer.
:param results: A dictionary containing the results of the run
:return: None
"""
self.menu.load_results_screen(results)

def results_event(self, event: pygame.event) -> Any:
"""
This method is called to handle events of the visualizer in the end screen
:param event: The pygame event triggered each frame. See pygame
`docs <https://www.pygame.org/docs/ref/event.html>`_
for more information.
:return: Any value that is defined in the results_events
"""
return self.menu.results_events(event)

def results_render(self) -> None:
"""
This renders the results for the
This renders the end screen for the visualizer
:return:
"""
self.menu.results_render()

0 comments on commit c66ff3c

Please sign in to comment.