Skip to content

Commit 234c273

Browse files
committed
wip
1 parent 7421638 commit 234c273

File tree

523 files changed

+2516
-11114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

523 files changed

+2516
-11114
lines changed

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
*.pyc
1+
.venv/
2+
.vscode/*
3+
!.vscode/launch.json
4+
5+
__pycache__

.pylintrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[MASTER]
2+
disable=
3+
C0114,
4+
C0115,
5+
C0116,

.python-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12.1

.vscode/launch.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// Utilisez IntelliSense pour en savoir plus sur les attributs possibles.
3+
// Pointez pour afficher la description des attributs existants.
4+
// Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python : fichier actif",
9+
"type": "python",
10+
"request": "launch",
11+
"program": "${file}",
12+
"console": "integratedTerminal",
13+
"justMyCode": true
14+
}
15+
]
16+
}

.vscode/settings.json

-3
This file was deleted.

Pipfile

-16
This file was deleted.

Pipfile.lock

-347
This file was deleted.

poetry.lock

+361
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

pyoro/activity/__init__.py

Whitespace-only changes.

pyoro/activity/activities/__init__.py

Whitespace-only changes.

pyoro/activity/activities/activity.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from pyglet import event, clock
2+
3+
from pyoro.views.view import View
4+
5+
6+
class Activity(event.EventDispatcher):
7+
def __init__(self) -> None:
8+
self.running = False
9+
10+
self.view: View | None = None
11+
12+
self.register_event_type("on_start") # type: ignore
13+
self.register_event_type("on_stop") # type: ignore
14+
15+
def start(self):
16+
self.running = True
17+
18+
def update_view(_dt: float) -> None:
19+
if self.view:
20+
self.view.refresh()
21+
22+
clock.schedule(update_view) # type: ignore
23+
self.dispatch_event("on_start") # type: ignore
24+
25+
def stop(self):
26+
self.running = False
27+
self.dispatch_event("on_stop") # type: ignore
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import logging
2+
3+
from pyoro.activity.activities.activity import Activity
4+
from pyoro.game.controllers.user_controller import UserController
5+
from pyoro.game.game_engine import GameEngine
6+
from pyoro.game.game_state import GameMode
7+
from pyoro.views.game_view import GameView
8+
9+
10+
class GameActivity(Activity):
11+
def __init__(self, game_mode: GameMode):
12+
super().__init__()
13+
14+
self.controller = UserController()
15+
self.game_engine = GameEngine(game_mode, self.controller)
16+
self.view = GameView(self.game_engine)
17+
18+
def start(self) -> None:
19+
logging.info("Starting")
20+
self.game_engine.run()
21+
return super().start()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import logging
2+
3+
from pyoro.activity.activities.activity import Activity
4+
from pyoro.activity.activities.game_activity import GameActivity
5+
from pyoro.activity.activities.settings_activity import SettingsActivity
6+
from pyoro.activity.activity_manager import ActivityManager
7+
from pyoro.game.game_engine import GameEngine
8+
from pyoro.game.game_state import GameMode
9+
from pyoro.views.main_menu_view import MainMenuView
10+
11+
12+
class MainMenuActivity(Activity):
13+
def __init__(self):
14+
super().__init__()
15+
self.game_engine = GameEngine(GameMode.TONGUE)
16+
self.view = MainMenuView(
17+
self.game_engine, self.on_play, self.on_show_settings, self.on_quit
18+
)
19+
20+
def start(self) -> None:
21+
logging.info("Starting")
22+
self.game_engine.run()
23+
return super().start()
24+
25+
def on_play(self, mode: GameMode) -> None:
26+
activity_manager = ActivityManager()
27+
activity_manager.push_activity(GameActivity(mode))
28+
self.stop()
29+
30+
def on_show_settings(self) -> None:
31+
activity_manager = ActivityManager()
32+
activity_manager.push_activity(SettingsActivity())
33+
self.stop()
34+
35+
def on_quit(self) -> None:
36+
activity_manager = ActivityManager()
37+
activity_manager.stop()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import logging
2+
from pyoro.activity.activities.activity import Activity
3+
4+
5+
class SettingsActivity(Activity):
6+
def start(self):
7+
logging.info("Starting")

pyoro/activity/activity_manager.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import logging
2+
import pyglet
3+
4+
from pyoro.activity.activities.activity import Activity
5+
from pyoro.graphics.window import Window
6+
from pyoro.utils.singleton import singleton
7+
8+
9+
@singleton
10+
class ActivityManager:
11+
def __init__(self):
12+
self._activities: list[Activity] = []
13+
self._current_activity: Activity | None = None
14+
15+
window = Window()
16+
window.push_handlers(on_close=self.stop) # type: ignore
17+
18+
def push_activity(self, activity: Activity) -> None:
19+
logging.debug(
20+
f"New activity of type {activity.__class__.__name__} added to the stack"
21+
)
22+
self._activities.append(activity)
23+
24+
def on_activity_stop(self) -> None:
25+
logging.info("Current activity stopped. Starting next activity")
26+
27+
self._current_activity.pop_handlers() # type: ignore
28+
29+
if self._activities:
30+
self.set_current_activity(self._activities.pop(0))
31+
else:
32+
logging.info("No activity left on stack")
33+
self.stop()
34+
35+
def set_current_activity(self, activity: Activity) -> None:
36+
self._current_activity = activity
37+
self._current_activity.push_handlers(on_stop=self.on_activity_stop) # type: ignore
38+
self._current_activity.start()
39+
40+
def start(self) -> None:
41+
logging.info("Starting")
42+
43+
if not self._activities:
44+
logging.warn("No activity to start")
45+
return self.stop()
46+
self.set_current_activity(self._activities.pop(0))
47+
48+
pyglet.app.run()
49+
50+
def stop(self) -> None:
51+
logging.info("Stopping")
52+
pyglet.app.exit()

pyoro/banks/__init__.py

Whitespace-only changes.

pyoro/banks/animation_bank.py

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import logging
2+
import pyglet
3+
from pyoro.banks.bank import Bank
4+
from pyoro.banks.image_bank import ImageBank
5+
from pyoro.utils.singleton import singleton
6+
7+
ANIMATION_IDS: dict[str, tuple[tuple[str, float], ...]] = {
8+
"bean_green": (
9+
("bean_green_left", 0.4),
10+
("bean_green_middle", 0.4),
11+
("bean_green_right", 0.4),
12+
("bean_green_middle", 0.4),
13+
),
14+
"bean_pink": (
15+
("bean_pink_left", 0.4),
16+
("bean_pink_middle", 0.4),
17+
("bean_pink_right", 0.4),
18+
("bean_pink_middle", 0.4),
19+
),
20+
"explosion": (
21+
("explosion_0", 0.4),
22+
("explosion_1", 0.4),
23+
("explosion_2", 0.4),
24+
),
25+
"score_300": (
26+
("score_300_0", 0.05),
27+
("score_300_1", 0.05),
28+
("score_300_2", 0.05),
29+
("score_300_3", 0.05),
30+
("score_300_4", 0.05),
31+
("score_300_5", 0.05),
32+
),
33+
"score_1000": (
34+
("score_1000_0", 0.05),
35+
("score_1000_1", 0.05),
36+
("score_1000_2", 0.05),
37+
("score_1000_3", 0.05),
38+
("score_1000_4", 0.05),
39+
("score_1000_5", 0.05),
40+
),
41+
}
42+
43+
44+
@singleton
45+
class AnimationBank(Bank[pyglet.image.Animation]):
46+
def __init__(self):
47+
logging.info("Initializing")
48+
49+
image_bank = ImageBank()
50+
self.fallback = pyglet.image.Animation(
51+
[pyglet.image.AnimationFrame(image_bank.get_fallback(), 1)]
52+
)
53+
super().__init__()
54+
55+
def load(self):
56+
logging.info("Generating animations")
57+
58+
image_bank = ImageBank()
59+
60+
for key, value in ANIMATION_IDS.items():
61+
self.data[key] = pyglet.image.Animation(
62+
[
63+
pyglet.image.AnimationFrame(
64+
image_bank.get(image_id), frame_duration
65+
)
66+
for (image_id, frame_duration) in value
67+
]
68+
)
69+
70+
return super().load()

pyoro/banks/bank.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import typing
2+
3+
T = typing.TypeVar("T")
4+
5+
6+
class Bank(typing.Generic[T]):
7+
def __init__(self):
8+
self.data: dict[str, T] = {}
9+
self.fallback: T | None = None
10+
11+
def load(self) -> None:
12+
pass
13+
14+
def get(self, key: str) -> T:
15+
if key not in self.data:
16+
raise KeyError(f"Key '{key}' not found in bank '{self.__class__.__name__}'")
17+
return self.data[key]
18+
19+
def __getitem__(self, key: str):
20+
return self.get(key)
21+
22+
def get_fallback(self) -> T:
23+
if not self.fallback:
24+
raise NotImplementedError()
25+
return self.fallback

0 commit comments

Comments
 (0)