forked from MatthiasHu/seekers
-
Notifications
You must be signed in to change notification settings - Fork 1
Fix multiple open issues #79
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
94bbd87
Rename python files
Kiyotoko bbe7cd6
Add os to release archive
Kiyotoko 1879c17
Rename parser arguments
Kiyotoko 7561857
Split seekers types into multiple files
Kiyotoko 85bdf8c
Fix circular imports
Kiyotoko 230e1d9
Fix grpc imports
Kiyotoko cc78197
Lint files
Kiyotoko 551fad9
Revert "Rename python files"
Belissimo-T c263a28
fix imports
Belissimo-T 29fac5e
fix cc781970
Belissimo-T 484fb0e
Merge branch 'master' into master
Kiyotoko 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
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
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
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
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,3 +1,3 @@ | ||
pygame>=2.1.0 | ||
pygame~=2.6.0 | ||
grpcio==1.64.1 | ||
protobuf==5.27.2 |
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
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
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,14 +1,12 @@ | ||
from __future__ import annotations | ||
|
||
from .vector import * | ||
from .config import * | ||
from .colors import Color | ||
from .seekers_types import ( | ||
Config, | ||
Vector, | ||
Physical, | ||
Goal, | ||
Magnet, | ||
Seeker, | ||
Player, | ||
World, | ||
Camp, | ||
) | ||
|
||
from .player import * | ||
from .goal import * | ||
from .seeker import * | ||
from .physical import * | ||
from .camp import * | ||
from .world import * | ||
|
||
from . import debug_drawing |
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,32 @@ | ||
from __future__ import annotations | ||
|
||
import dataclasses | ||
|
||
from .vector import * | ||
from . import player | ||
|
||
|
||
__all__ = [ | ||
"Camp" | ||
] | ||
|
||
|
||
@dataclasses.dataclass | ||
class Camp: | ||
id: str | ||
owner: player.Player | ||
position: Vector | ||
width: float | ||
height: float | ||
|
||
def contains(self, pos: Vector) -> bool: | ||
delta = self.position - pos | ||
return 2 * abs(delta.x) < self.width and 2 * abs(delta.y) < self.height | ||
|
||
@property | ||
def top_left(self) -> Vector: | ||
return self.position - Vector(self.width, self.height) / 2 | ||
|
||
@property | ||
def bottom_right(self) -> Vector: | ||
return self.position + Vector(self.width, self.height) / 2 |
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,3 +1,5 @@ | ||
from __future__ import annotations | ||
|
||
import random | ||
import typing | ||
import colorsys | ||
|
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,130 @@ | ||
from __future__ import annotations | ||
|
||
import configparser | ||
import dataclasses | ||
import typing | ||
|
||
__all__ = [ | ||
"Config", | ||
] | ||
|
||
|
||
@dataclasses.dataclass | ||
class Config: | ||
"""Configuration for the Seekers game.""" | ||
global_wait_for_players: bool | ||
global_playtime: int | ||
global_seed: int | ||
global_fps: int | ||
global_speed: int | ||
global_players: int | ||
global_seekers: int | ||
global_goals: int | ||
global_color_threshold: float | ||
|
||
map_width: int | ||
map_height: int | ||
|
||
camp_width: int | ||
camp_height: int | ||
|
||
seeker_thrust: float | ||
seeker_magnet_slowdown: float | ||
seeker_disabled_time: int | ||
seeker_radius: float | ||
seeker_mass: float | ||
seeker_friction: float | ||
|
||
goal_scoring_time: int | ||
goal_radius: float | ||
goal_mass: float | ||
goal_thrust: float | ||
goal_friction: float | ||
|
||
@property | ||
def map_dimensions(self): | ||
return self.map_width, self.map_height | ||
|
||
@classmethod | ||
def from_file(cls, file) -> "Config": | ||
cp = configparser.ConfigParser() | ||
cp.read_file(file) | ||
|
||
return cls( | ||
global_wait_for_players=cp.getboolean("global", "wait-for-players"), | ||
global_playtime=cp.getint("global", "playtime"), | ||
global_seed=cp.getint("global", "seed"), | ||
global_fps=cp.getint("global", "fps"), | ||
global_speed=cp.getint("global", "speed"), | ||
global_players=cp.getint("global", "players"), | ||
global_seekers=cp.getint("global", "seekers"), | ||
global_goals=cp.getint("global", "goals"), | ||
global_color_threshold=cp.getfloat("global", "color-threshold"), | ||
|
||
map_width=cp.getint("map", "width"), | ||
map_height=cp.getint("map", "height"), | ||
|
||
camp_width=cp.getint("camp", "width"), | ||
camp_height=cp.getint("camp", "height"), | ||
|
||
seeker_thrust=cp.getfloat("seeker", "thrust"), | ||
seeker_magnet_slowdown=cp.getfloat("seeker", "magnet-slowdown"), | ||
seeker_disabled_time=cp.getint("seeker", "disabled-time"), | ||
seeker_radius=cp.getfloat("seeker", "radius"), | ||
seeker_mass=cp.getfloat("seeker", "mass"), | ||
seeker_friction=cp.getfloat("seeker", "friction"), | ||
|
||
goal_scoring_time=cp.getint("goal", "scoring-time"), | ||
goal_radius=cp.getfloat("goal", "radius"), | ||
goal_mass=cp.getfloat("goal", "mass"), | ||
goal_thrust=cp.getfloat("goal", "thrust"), | ||
goal_friction=cp.getfloat("goal", "friction"), | ||
) | ||
|
||
@classmethod | ||
def from_filepath(cls, filepath: str) -> "Config": | ||
with open(filepath) as f: | ||
return cls.from_file(f) | ||
|
||
@staticmethod | ||
def value_to_str(value: bool | float | int | str) -> str: | ||
if isinstance(value, bool): | ||
return str(value).lower() | ||
elif isinstance(value, float): | ||
return f"{value:.2f}" | ||
else: | ||
return str(value) | ||
|
||
@staticmethod | ||
def value_from_str(value: str, type_: typing.Literal["bool", "float", "int", "str"]) -> bool | float | int | str: | ||
if type_ == "bool": | ||
return value.lower() == "true" | ||
elif type_ == "float": | ||
return float(value) | ||
elif type_ == "int": | ||
return int(float(value)) | ||
else: | ||
return value | ||
|
||
@staticmethod | ||
def get_section_and_key(attribute_name: str) -> tuple[str, str]: | ||
"""Split an attribute name into the config header name and the key name.""" | ||
|
||
section, key = attribute_name.split("_", 1) | ||
|
||
return section, key.replace("_", "-") | ||
|
||
@staticmethod | ||
def get_attribute_name(section: str, key: str) -> str: | ||
return f"{section}_{key.replace('-', '_')}" | ||
|
||
@classmethod | ||
def get_field_type(cls, field_name: str) -> typing.Literal["bool", "float", "int", "str"]: | ||
field_types = {f.name: f.type for f in dataclasses.fields(cls)} | ||
return field_types[field_name] | ||
|
||
def import_option(self, section: str, key: str, value: str): | ||
field_name = self.get_attribute_name(section, key) | ||
field_type = self.get_field_type(field_name) | ||
|
||
setattr(self, field_name, self.value_from_str(value, field_type)) |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.