Visualizer Package#

Subpackages#

Submodules#

Adapter Class#

class visualizer.adapter.Adapter(screen)[source]#

Bases: object

The Adapter class can be considered the “Master Controller” of the Visualizer; it works in tandem with main.py. Main.py will call many of the methods that are provided in here to keep the Visualizer moving smoothly.

clean_up() None[source]#

This method is called after rendering each frame. :return: None

continue_animation() None[source]#

This method is used after the main.py continue_animation() method. :return: None

on_event(event) PlaybackButtons[source]#

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: The pygame event triggered each frame. See pygame for more information. :return: None

populate_bytesprite_factories() dict[int, Callable[[pygame.surface.Surface], visualizer.bytesprites.bytesprite.ByteSprite]][source]#

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]]

prerender() None[source]#

This will handle anything that needs to be completed before animations start every turn. :return: None

recalc_animation(turn_log: dict) None[source]#

This method is called every time the turn changes :param turn_log: A dictionary containing the entire turn state :return: None

render() None[source]#

This method contains all logic for rendering additional text, buttons, and other visuals during the playback phase. :return: None

results_event(event: <module 'pygame.event' from 'C:\\Users\\ianth\\.virtualenvs\\byte_le_engine\\Lib\\site-packages\\pygame\\event.cp311-win_amd64.pyd'>) Any[source]#

This method is called to handle events of the visualizer in the end screen :param event: The pygame event triggered each frame. See pygame for more information. :return: Any value that is defined in the results_events

results_load(results: dict) None[source]#

This method is called to load the end screen for the visualizer. :param results: A dictionary containing the results of the run :return: None

results_render() None[source]#

This renders the end screen for the visualizer :return:

start_menu_event(event: <module 'pygame.event' from 'C:\\Users\\ianth\\.virtualenvs\\byte_le_engine\\Lib\\site-packages\\pygame\\event.cp311-win_amd64.pyd'>) Any[source]#

This method is used to manage any events that will occur on the starting screen. For example, a start button 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: The pygame event triggered each frame. See pygame for more information. :return: Any specified event desired in the start_events method

start_menu_render() None[source]#

Renders and shows everything in the start menu. :return: None

Config File#

class visualizer.config.Config[source]#

Bases: object

Configuration class for the game visualizer. By encapsulating the visualizer settings in a class, the readonly nature of the following settings are enforced to a greater degree.

Number Of Frames Per Turn

Number of frames per turn is an int representing the number of animation frames on each turn. See spritesheets for an example of what is needed for 4 frames per turn. Set this to 1 if you do not want any animations.


Tile Size

Tile size is an int that represents the size of each sprite (it’s a square, so this applies to both width and height).


Scale

Scale is an int that represents the ratio between the tile size and the number of pixels that it will take on the visualizer itself.


Screen Size

Screen size is a Vector that represents the dimensions of the visualizer.


Frame Rate

Frame rate is an int that represents the number of frames per second.


Background Color

Background Color is a tuple of 3 ints representing the red, green, and blue values of the background.


Gameboard Margin Left

Gameboard Margin Left is an int representing the margin from the left side of the screen that the gameboard will adhere to.


Gameboard Margin Top

Gameboard Margin Top is an int representing the margin from the top side of the screen that the gameboard will adhere to.


Visualize Held Items

Visualize Held Items is a boolean that represents if held items should be rendered and has supporting ByteSprites.


property BACKGROUND_COLOR: (<class 'int'>, <class 'int'>, <class 'int'>)#

This is where you can set the default background color. :return: tuple of 3 ints representing the red, blue, and green values.

property FRAME_RATE: int#

Frame Rate is the overall frames per second. :return: int

property GAME_BOARD_MARGIN_LEFT: int#

This is where you can set the left margin for the main game board. :return: int

property GAME_BOARD_MARGIN_TOP: int#

This is where you can set the top margin for the main game board. :return: int

property NUMBER_OF_FRAMES_PER_TURN: int#

If you have an animation, this will be the number of frames the animation goes through for each turn. :return: int

property SCALE: int#

Scale is for the tile size being scaled larger. For example: With a 16x16 tile, it can be scaled by 4 to be a 64x64 tile on the visualizer. :return: int

property SCREEN_SIZE: Vector#

The screen size is the overall screen size. The x and y values of the Vector object returned represent the horizontal and vertical lengths of the screen respectively. :return: Vector

property TILE_SIZE: int#

This will be the size of the tile; it is a square. :return: int

property VISUALIZE_HELD_ITEMS: bool#

This is where you can set if you want held items to be displayed in the visualizer. :return: bool

Main Class#

class visualizer.main.ByteVisualiser(end_time: int = -1, skip_start: bool = False, playback_speed: float = 1.0, fullscreen: bool = False, save_video: bool = False, loop_count: int = 1, turn_start: int = 0, turn_end: int = -1, log_dir: str | None = None)#

Bases: object

The Byte Visualiser is a generic visualiser that uses pygame to visualise the game board using the 2-dimensional list of tiles and the occupied by and, optionally, the held_item attribute. It also calls the adapter class method to minimize the edits needed to this file.

property adapter: Adapter#

Property getter. :return: An instance of the Adapter class.

property bytesprite_factories: dict[slice(<class 'int'>, typing.Callable[[pygame.surface.Surface], visualizer.bytesprites.bytesprite.ByteSprite], None)]#

Property getter. :return: A dictionary with the int representation of the target ObjectType as the key and

the ByteSprite factory child classes’ create method as the value.

property bytesprite_map: list[list[list[visualizer.bytesprites.bytesprite.ByteSprite]]]#

Property getter. :return: A list[list[list[ByteSprite]]] containing the rows, columns, and layers of the ByteSprites to

be rendered each frame of the playback phase.

property clock: Clock#

Property getter. :return: An instance of the Clock class.

property config: Config#

Property getter. :return: The Config file

continue_animation() None#

Continue the animation between each turn increment. :return: None

property default_frame_rate: int#

Property getter. :return: The default frame rate of the visualizer as an int.

property end_time: int#

Property getter :return: The amount of seconds, as an int, to wait on the results phase of the visualizer.

property fullscreen: bool#

Property getter. :return: A bool representing if the fullscreen option should be enabled

load() None#

Loads the ByteSprite factories by calling the adapter and loads the logs as a dictionary :return: None

loop() None#

The main loop for the visualizer. This method triggers the different phases. :return: None

property loop_count: int#

Property getter. :return: The amount of times the visualizer should repeat the same game as an int.

property paused: bool#

Property getter. :return: A bool representing if playback is paused or not.

property playback_speed: float#

Property getter. :return: The scale to apply to the default frame rate of the visualizer as a float.

postrender() None#

Called after the render method in playback. This method calls the clean up method in the adapter and enforces the frames per second. :return:

prerender() None#

Fills the screen with the background color and calls the prerender method in the adapter class. :return: None

recalc_animation(turn_data: dict) None#

Determine what bytesprites are needed at which location and calls logic to determine active spritesheet and render. :param turn_data: A dictionary of all the turn data for current turn :return: None

property recording: bool#

Property getter. :return: A bool representing if playback is being recorded.

render(button_pressed: PlaybackButtons) bool#

Render every frame in the playback loop, the main loop of the visualizer. :param button_pressed: The bitflag enum of the buttons pressed during playback. :return: bool indicating whether the playback loop was successful or can’t find the next turn.

save_video() None#

Method to deal with saving game to mp4 (called in render if save button pressed) :return: None

property scaled: tuple[int, int]#

Property getter. :return: A tuple of two ints representing the size of the saved video.

property screen: Surface#

Property getter. :return: A pygame.Surface object representing the main window of the visualizer.

property size: Vector#

Property getter :return: Vector class representing the size of the gameboard.

property skip_start: bool#

Property getter. :return: A bool representing whether the starting screen should be skipped.

property tick: int#

Property getter. :return: The number of frames the visualizer has gone through in the playback section, as an int.

property tile_size: int#

Property getter. :return: Tile Size is an int that represents the size of a tile in px. It is a square.

property turn_end: int#

Property getter. :return: The turn, as an int, to end the playback on.

property turn_logs: dict[str, dict]#

Property getter. :return: The turn logs of type dict[str, dict].

property writer: VideoWriter#

Property getter. :return: A cv2.VideoWriter to write the video to an output file.

Module contents#