-
Notifications
You must be signed in to change notification settings - Fork 0
Develop #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
dmccoystephenson
wants to merge
17
commits into
main
Choose a base branch
from
develop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Develop #8
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f52dabb
feat: implement rendering with new renderer classes
dmccoystephenson dc6acba
refactor: improve environment loading logic
dmccoystephenson 0d39f8a
refactor: rename functions for consistency and clarity
dmccoystephenson 4549bc4
fix: save environments to file
dmccoystephenson 18a7530
chore: update subproject commit reference
dmccoystephenson 90c2bfa
chore: update subproject commit reference
dmccoystephenson a48ef7c
chore: update subproject commit reference
dmccoystephenson d06eceb
refactor: update `up.bat` to start program after spinning up dependen…
dmccoystephenson 386300e
refactor: update `up.bat` to start program after spinning up dependen…
dmccoystephenson 28bbc47
chore: update subproject commit reference
dmccoystephenson 18ac187
feat: extract EnvironmentRenderer, GridRenderer, and LocationRenderer…
dmccoystephenson d8e2afc
refactor: remove unused grid_size parameter from EnvironmentRenderer
dmccoystephenson 8104e2f
refactor: standardize variable naming for display dimensions and grid…
dmccoystephenson 7030d56
refactor: add type hints for parameters in EnvironmentRenderer, GridR…
dmccoystephenson 6679be6
fix: add delay in main loop to improve rendering performance
dmccoystephenson 5e11d32
Merge pull request #7 from Preponderous-Software/refactor/modular-ren…
dmccoystephenson 27fdf5a
Update gridRenderer.py
dmccoystephenson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule Viron
updated
4 files
| +2 −2 | Dockerfile | |
| +121 −56 | README.md | |
| +1 −1 | pom.xml | |
| +2 −2 | src/main/python/preponderous/viron/models/grid.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| from Viron.src.main.python.preponderous.viron.models.environment import Environment | ||
| from Viron.src.main.python.preponderous.viron.services.gridService import GridService | ||
| from graphik import Graphik | ||
| from gridRenderer import GridRenderer | ||
|
|
||
|
|
||
| class EnvironmentRenderer: | ||
| def __init__(self, graphik: Graphik, url: str, port: int): | ||
| self.graphik = graphik | ||
| self.grid_service = GridService(url, port) | ||
| self.grid_renderer = GridRenderer(graphik, url, port) | ||
|
|
||
| def draw(self, environment: Environment): | ||
| grids = self.grid_service.get_grids_in_environment(environment.getEnvironmentId()) | ||
| # assume one grid for now, can be extended later | ||
| if grids: | ||
| self.grid_renderer.draw(grids[0]) | ||
| else: | ||
| self.graphik.drawText("No grids found in environment.", self.graphik.getGameDisplay().get_width()/2, self.graphik.getGameDisplay().get_height()/2, 20, "red") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| from Viron.src.main.python.preponderous.viron.models.grid import Grid | ||
| from Viron.src.main.python.preponderous.viron.services.locationService import LocationService | ||
| from graphik import Graphik | ||
| from locationRenderer import LocationRenderer | ||
|
|
||
|
|
||
| class GridRenderer: | ||
| def __init__(self, graphik: Graphik, url: str, port: int): | ||
| self.graphik = graphik | ||
| self.location_service = LocationService(url, port) | ||
| self.location_renderer = LocationRenderer(graphik) | ||
| self.locations_cache = {} | ||
|
|
||
| def draw(self, grid: Grid): | ||
| grid_id = grid.get_grid_id() | ||
| if grid_id not in self.locations_cache: | ||
| self.locations_cache[grid_id] = self.location_service.get_locations_in_grid(grid_id) | ||
|
|
||
| locations = self.locations_cache[grid_id] | ||
| width = int(self.graphik.getGameDisplay().get_width() / grid.get_columns()) | ||
| height = int(self.graphik.getGameDisplay().get_height() / grid.get_rows()) | ||
| for location in locations: | ||
| self.location_renderer.draw(location, width, height) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import random | ||
|
|
||
| from Viron.src.main.python.preponderous.viron.models.location import Location | ||
| from graphik import Graphik | ||
|
|
||
|
|
||
| class LocationRenderer: | ||
| def __init__(self, graphik: Graphik): | ||
| self.graphik = graphik | ||
|
|
||
| def draw(self, location: Location, width: int, height: int): | ||
| x = location.get_x() * width | ||
| y = location.get_y() * height | ||
| color = self.get_random_color() | ||
| self.graphik.drawRectangle(x - 1, y - 1, width * 1.5, height * 1.5, color) | ||
|
|
||
| def get_random_color(self): | ||
| red = random.randrange(50, 200) | ||
| green = random.randrange(50, 200) | ||
| blue = random.randrange(50, 200) | ||
| return (red, green, blue) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,7 +1,6 @@ | ||||||||
| import random | ||||||||
| import pygame | ||||||||
| from Viron.src.main.python.preponderous.viron.services.environmentService import EnvironmentService | ||||||||
| from Viron.src.main.python.preponderous.viron.services.locationService import LocationService | ||||||||
| from environmentRenderer import EnvironmentRenderer | ||||||||
| from graphik import Graphik | ||||||||
| import os | ||||||||
| import json | ||||||||
|
|
@@ -12,115 +11,119 @@ | |||||||
| black = (0,0,0) | ||||||||
| white = (255,255,255) | ||||||||
|
|
||||||||
| displayWidth = 800 | ||||||||
| displayHeight = 800 | ||||||||
| display_width = 800 | ||||||||
| display_height = 800 | ||||||||
|
|
||||||||
| def log(message): | ||||||||
| print(message) | ||||||||
|
|
||||||||
| numGrids = 1 | ||||||||
| num_grids = 1 | ||||||||
| if len(sys.argv) > 1: | ||||||||
| try: | ||||||||
| gridSize = int(sys.argv[1]) | ||||||||
| grid_size = int(sys.argv[1]) | ||||||||
| except ValueError: | ||||||||
| log("Invalid grid size argument, using default of 50.") | ||||||||
| gridSize = 50 | ||||||||
| grid_size = 50 | ||||||||
| else: | ||||||||
| gridSize = 50 | ||||||||
| grid_size = 50 | ||||||||
|
|
||||||||
| url = "http://localhost" | ||||||||
| port = 9999 | ||||||||
|
|
||||||||
| locationService = LocationService(url, port) | ||||||||
| environmentService = EnvironmentService(url, port) | ||||||||
| exit_after_create = False | ||||||||
| if len(sys.argv) > 2 and sys.argv[2] == "--exit-after-create": | ||||||||
| exit_after_create = True | ||||||||
| def drawEnvironment(locations, graphik, locationWidth, locationHeight): | ||||||||
| for location in locations: | ||||||||
| red = random.randrange(50, 200) | ||||||||
| green = random.randrange(50, 200) | ||||||||
| blue = random.randrange(50, 200) | ||||||||
| x = location.get_x() * locationWidth | ||||||||
| y = location.get_y() * locationHeight | ||||||||
| graphik.drawRectangle(x - 1, y - 1, locationWidth * 1.5, locationHeight * 1.5, (red,green,blue)) | ||||||||
|
|
||||||||
| def load_environments_file(env_file): | ||||||||
| if os.path.exists(env_file): | ||||||||
| log("Environments file exists, loading...") | ||||||||
| with open(env_file, "r") as f: | ||||||||
| return json.load(f) | ||||||||
| else: | ||||||||
| log("No existing environments found.") | ||||||||
| return {} | ||||||||
|
|
||||||||
| def load_existing_environment(graphik, env_key, environments, environmentService): | ||||||||
| graphik.drawText("Loading existing environment, please wait...", display_width/2, display_height/2, 20, "white") | ||||||||
| env_id = environments[env_key]["environment_id"] | ||||||||
| try: | ||||||||
| return environmentService.get_environment_by_id(env_id) | ||||||||
| except Exception as e: | ||||||||
| log(f"Error loading existing environment: {e}") | ||||||||
| graphik.drawText("Error loading environment, please check logs.", display_width/2, display_height/2 + 30, 20, "red") | ||||||||
| pygame.display.update() | ||||||||
| time.sleep(2) | ||||||||
| pygame.quit() | ||||||||
| return | ||||||||
|
|
||||||||
| def create_environment(graphik, num_grids, grid_size): | ||||||||
| environmentService = EnvironmentService(url, port) | ||||||||
|
Comment on lines
+59
to
+60
|
||||||||
| def create_environment(graphik, num_grids, grid_size): | |
| environmentService = EnvironmentService(url, port) | |
| def create_environment(graphik, num_grids, grid_size, environmentService): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| # This script is used to start the Docker containers defined in the Docker Compose file. | ||
|
|
||
| docker compose -f .\viron\compose.yml up -d --build | ||
| REM The -d flag runs the containers in detached mode, allowing them to run in the background. | ||
| REM The --build flag forces a rebuild of the images before starting the containers. | ||
|
|
||
| python main.py |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function doesn't return a value when an exception occurs (lines 51-57), but the caller on line 90 expects a return value. Consider returning None or raising the exception instead of just logging and returning from the function.