pyxil-framework 0.1.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyxil/__init__.py ADDED
@@ -0,0 +1,6 @@
1
+ from . import framework
2
+
3
+ __all__ = [
4
+ "framework",
5
+ "framework.graphics",
6
+ ]
@@ -0,0 +1,15 @@
1
+ import pyxil.framework.graphics as graphics
2
+
3
+ from pyxil.framework.game import Game
4
+ from pyxil.framework.gametime import GameTime
5
+ from pyxil.framework.gameconsole import GameConsole
6
+ from pyxil.framework.gamewindow import GameWindow
7
+
8
+ __all__ = [
9
+ "Game",
10
+ "GameTime",
11
+ "GameConsole",
12
+ "GameWindow",
13
+
14
+ "graphics"
15
+ ]
@@ -0,0 +1,124 @@
1
+ """Core classes for creating and running Pyxil applications."""
2
+
3
+ import time
4
+ from datetime import timedelta
5
+ from typing import Union
6
+
7
+ from pyxil.framework.gametime import GameTime
8
+ from pyxil.framework.gamewindow import GameWindow
9
+ from pyxil.framework.gameconsole import GameConsole
10
+
11
+ from pyxil.framework.graphics import SpriteBatch
12
+
13
+
14
+ class Game(object):
15
+ """Base class for creating a Pyxil application.
16
+
17
+ Override :meth:`initialize`, :meth:`update`, and :meth:`draw` to configure
18
+ resources, implement game logic, and render the current frame.
19
+ """
20
+
21
+ def __init__(self, console: bool = False):
22
+ """
23
+ Initialize a new :class:`Game` instance.
24
+
25
+ Args:
26
+ console (bool, optional): Whether to use a console window. Defaults to False.
27
+ """
28
+ self.spriteBatch: Union[SpriteBatch, None] = SpriteBatch() if not console else None
29
+ self.gameWindow: Union[GameWindow, GameConsole] = self.__set_window()
30
+ self.gameTime: GameTime = GameTime()
31
+ self._lastFrameTime = None
32
+ self._targetElapsedGameTime = timedelta(seconds=1 / 60)
33
+ self.initialize()
34
+
35
+ @property
36
+ def targetElapsedGameTime(self):
37
+ """timedelta: Desired elapsed time for each game frame."""
38
+ return self._targetElapsedGameTime
39
+
40
+ @targetElapsedGameTime.setter
41
+ def targetElapsedGameTime(self, value):
42
+ """Set the desired elapsed time for each game frame.
43
+
44
+ Args:
45
+ value (timedelta): A positive frame interval.
46
+
47
+ Raises:
48
+ TypeError: If ``value`` is not a :class:`datetime.timedelta`.
49
+ ValueError: If ``value`` is zero or negative.
50
+ """
51
+ if not isinstance(value, timedelta):
52
+ raise TypeError("targetElapsedGameTime must be a datetime.timedelta")
53
+ if value <= timedelta():
54
+ raise ValueError("targetElapsedGameTime must be greater than zero")
55
+ self._targetElapsedGameTime = value
56
+
57
+ def tick(self):
58
+ """Measure and apply elapsed time for the next game frame.
59
+
60
+ The first call starts the clock and reports no elapsed time. Subsequent
61
+ calls use a monotonic high-resolution timer and update
62
+ :attr:`gameTime`.
63
+
64
+ Returns:
65
+ GameTime: The timing information associated with the current frame.
66
+ """
67
+ currentTime = time.perf_counter()
68
+
69
+ if self._lastFrameTime is None:
70
+ elapsed = timedelta()
71
+ else:
72
+ elapsed = timedelta(
73
+ seconds=max(0.0, currentTime - self._lastFrameTime)
74
+ )
75
+
76
+ self._lastFrameTime = currentTime
77
+ isRunningSlowly = elapsed > self._targetElapsedGameTime * 2
78
+ self.gameTime._advance(elapsed, isRunningSlowly)
79
+ return self.gameTime
80
+
81
+ def initialize(self):
82
+ """Initialize the game and prepare its components.
83
+
84
+ Override this method to create resources, configure instance variables,
85
+ and perform one-time setup before the game starts updating.
86
+ """
87
+ pass
88
+
89
+ def update(self, gameTime: None):
90
+ """Update the game state for the current frame.
91
+
92
+ Args:
93
+ gameTime (None | GameTime): Information about the elapsed time and
94
+ the current frame. Pass ``None`` only for applications that do
95
+ not use a game loop.
96
+
97
+ Notes:
98
+ When ``gameTime`` is this game's :attr:`gameTime` instance,
99
+ :meth:`tick` advances the timing state before the override completes.
100
+ """
101
+ if gameTime is self.gameTime:
102
+ self.tick()
103
+ pass
104
+
105
+ def draw(self, spriteBatch: None):
106
+ """Render the current game frame.
107
+
108
+ Args:
109
+ spriteBatch (None | SpriteBatch): The sprite batch used to submit
110
+ graphics for rendering. Pass ``None`` when rendering is not
111
+ needed or is handled by another mechanism.
112
+ """
113
+ pass
114
+
115
+ def __set_window(self):
116
+ """Create the window or console appropriate for this game instance.
117
+
118
+ Returns:
119
+ GameWindow | GameConsole: A graphical window when a sprite batch is
120
+ available, otherwise a console window.
121
+ """
122
+ if self.spriteBatch is not None:
123
+ return GameWindow()
124
+ return GameConsole()
@@ -0,0 +1,47 @@
1
+ import curses
2
+
3
+
4
+ class GameConsole(object):
5
+ """Manage a curses terminal window for a Pyxil console application.
6
+
7
+ The console initializes curses in a raw keyboard-friendly mode and restores
8
+ the terminal to its previous state when :meth:`close` is called.
9
+ """
10
+
11
+ def __init__(self):
12
+ """Initialize curses and prepare the standard screen.
13
+
14
+ The initialization disables terminal echo and line buffering, enables
15
+ keypad mode, and clears and refreshes the standard screen.
16
+ """
17
+ self.__stdscr = curses.initscr()
18
+ self.__closed = False
19
+ curses.noecho()
20
+ curses.cbreak()
21
+ self.__stdscr.keypad(True)
22
+ self.__stdscr.clear()
23
+ self.__stdscr.refresh()
24
+
25
+ def get_stdscr(self):
26
+ """Return the curses standard screen used by the console.
27
+
28
+ Returns:
29
+ curses.window: The initialized curses window.
30
+ """
31
+ return self.__stdscr
32
+
33
+ def close(self):
34
+ """Restore the terminal and shut down the curses environment.
35
+
36
+ This method disables keypad mode, restores normal terminal buffering
37
+ and echo, and calls the curses shutdown routine. Repeated calls have no
38
+ additional effect.
39
+ """
40
+ if self.__closed:
41
+ return
42
+
43
+ self.__stdscr.keypad(False)
44
+ curses.nocbreak()
45
+ curses.echo()
46
+ curses.endwin()
47
+ self.__closed = True
@@ -0,0 +1,112 @@
1
+ """Timing data for a Pyxil game frame."""
2
+
3
+ from datetime import timedelta
4
+
5
+
6
+ class GameTime(object):
7
+ """Timing information for the current game frame.
8
+
9
+ The class tracks the total game time, elapsed time for the latest frame,
10
+ and whether the game is running slower than its target frame interval.
11
+
12
+ Public timing values are exposed through camelCase properties. Use
13
+ :meth:`_advance` to update the clock and :meth:`_reset` to return it to its
14
+ initial state.
15
+ """
16
+
17
+ def __init__(
18
+ self,
19
+ totalGameTime=None,
20
+ elapsedGameTime=None,
21
+ isRunningSlowly=False,
22
+ ):
23
+ """Initialize timing information for a game.
24
+
25
+ Args:
26
+ totalGameTime (timedelta, optional): Total time elapsed in the game.
27
+ elapsedGameTime (timedelta, optional): Time elapsed in the latest
28
+ frame.
29
+ isRunningSlowly (bool, optional): Whether the previous frame ran
30
+ slower than the target interval.
31
+ Raises:
32
+ TypeError: If a timing value is not a :class:`datetime.timedelta`
33
+ or the slow-frame value is not a bool.
34
+ ValueError: If a timing value is negative.
35
+ """
36
+ self._total_game_time = self._validate_timedelta(
37
+ totalGameTime if totalGameTime is not None else timedelta(),
38
+ "totalGameTime",
39
+ )
40
+ self._elapsed_game_time = self._validate_timedelta(
41
+ elapsedGameTime if elapsedGameTime is not None else timedelta(),
42
+ "elapsedGameTime",
43
+ )
44
+ self._is_running_slowly = self._validate_bool(
45
+ isRunningSlowly,
46
+ "isRunningSlowly",
47
+ )
48
+
49
+ @staticmethod
50
+ def _validate_timedelta(value, name):
51
+ """Validate and return a non-negative :class:`datetime.timedelta`."""
52
+ if not isinstance(value, timedelta):
53
+ raise TypeError(f"{name} must be a datetime.timedelta")
54
+ if value < timedelta():
55
+ raise ValueError(f"{name} cannot be negative")
56
+ return value
57
+
58
+ @staticmethod
59
+ def _validate_bool(value, name):
60
+ """Validate and return a boolean value."""
61
+ if not isinstance(value, bool):
62
+ raise TypeError(f"{name} must be a bool")
63
+ return value
64
+
65
+ @property
66
+ def totalGameTime(self):
67
+ """timedelta: Total time elapsed since the game started."""
68
+ return self._total_game_time
69
+
70
+ @property
71
+ def elapsedGameTime(self):
72
+ """timedelta: Time elapsed since the previous frame."""
73
+ return self._elapsed_game_time
74
+
75
+ @property
76
+ def isRunningSlowly(self):
77
+ """bool: Whether the latest frame ran slower than target performance."""
78
+ return self._is_running_slowly
79
+
80
+ def _advance(self, elapsedGameTime, isRunningSlowly=False):
81
+ """Advance the clock by one elapsed frame.
82
+
83
+ Args:
84
+ elapsedGameTime (timedelta): Non-negative time elapsed since the
85
+ previous frame.
86
+ isRunningSlowly (bool, optional): Whether this frame ran slower
87
+ than the target interval.
88
+
89
+ Raises:
90
+ TypeError: If ``elapsedGameTime`` is not a
91
+ :class:`datetime.timedelta`, or ``isRunningSlowly`` is not a
92
+ bool.
93
+ ValueError: If ``elapsedGameTime`` is negative.
94
+ """
95
+ elapsed = self._validate_timedelta(elapsedGameTime, "elapsedGameTime")
96
+ slow = self._validate_bool(isRunningSlowly, "isRunningSlowly")
97
+ self._total_game_time += elapsed
98
+ self._elapsed_game_time = elapsed
99
+ self._is_running_slowly = slow
100
+
101
+ def _reset(self):
102
+ """Reset all timing values to their initial state."""
103
+ self._total_game_time = timedelta()
104
+ self._elapsed_game_time = timedelta()
105
+ self._is_running_slowly = False
106
+
107
+ def __repr__(self):
108
+ return (
109
+ f"{type(self).__name__}(totalGameTime={self.totalGameTime!r}, "
110
+ f"elapsedGameTime={self.elapsedGameTime!r}, "
111
+ f"isRunningSlowly={self.isRunningSlowly!r})"
112
+ )
@@ -0,0 +1,5 @@
1
+
2
+ class GameWindow(object):
3
+
4
+ def __init__(self):
5
+ pass
@@ -0,0 +1,3 @@
1
+ from pyxil.framework.graphics.spritebatch import SpriteBatch
2
+
3
+ __all__ = ["SpriteBatch"]
@@ -0,0 +1,5 @@
1
+
2
+ class SpriteBatch:
3
+ def __init__(self):
4
+ """Initialize a new :class:`SpriteBatch` instance."""
5
+ pass
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.5
2
+ Name: pyxil-framework
3
+ Version: 0.1.3
4
+ Summary: A Python framework for game development
5
+ Project-URL: Homepage, https://github.com/Peixe2b/Pyxil
6
+ Project-URL: Repository, https://github.com/Peixe2b/Pyxil
7
+ Author: 1x1 Studio
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: ascii,game-development,game-framework,python
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Games/Entertainment
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+
17
+ # Pyxil
18
+ A powerful framework for creating desktop games with Python.
@@ -0,0 +1,12 @@
1
+ pyxil/__init__.py,sha256=2nsLNCcrb5G3nMuDjmFebQ3nQiwaz0kIUtvtGtU-39M,86
2
+ pyxil/framework/__init__.py,sha256=Q8o5g1RZ6f1UNXcLcWDztOFX_WrhGx21I0cn2nzbqWM,340
3
+ pyxil/framework/game.py,sha256=wrc4e-pXzEW0CCx0h0Bf0z5676mJHGwxhyZNSCtLNkk,4412
4
+ pyxil/framework/gameconsole.py,sha256=Rr3TdGOQm0mhDi9stsjekifDZTlV6Ip3iXRuo0hZzvM,1463
5
+ pyxil/framework/gametime.py,sha256=Ttul5qH9X20e_EBJYzM1Og9iWzO_-BqpW7tzYoX05wo,4173
6
+ pyxil/framework/gamewindow.py,sha256=EOdC9EVsNOOnpuO584mr4nte7lpdUXs3VkfkPM5njN8,70
7
+ pyxil/framework/graphics/__init__.py,sha256=D9ep1HoI0F5-dFdFTLRxm8XDjmhpE4j1eUwz40Wek1U,89
8
+ pyxil/framework/graphics/spritebatch.py,sha256=jyEU8pa7tjNdXCX1JqH8IulfrYkHWl_M6kDBfbwsJ3I,124
9
+ pyxil_framework-0.1.3.dist-info/METADATA,sha256=TKrm-gy5FsH9FyMQm_Zag_l-WUTyNqW8rWtT_MHaN7A,609
10
+ pyxil_framework-0.1.3.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
11
+ pyxil_framework-0.1.3.dist-info/licenses/LICENSE,sha256=qWdjeXlMbssixTLLJ8dtC89rn-NP4TEmFVzgDwZwoPE,1088
12
+ pyxil_framework-0.1.3.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 1x1 Studio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.