batframework 1.1.0__tar.gz → 2.0.0__tar.gz
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.
- {batframework-1.1.0 → batframework-2.0.0}/LICENSE +1 -1
- {batframework-1.1.0 → batframework-2.0.0}/PKG-INFO +8 -4
- {batframework-1.1.0 → batframework-2.0.0}/README.md +1 -3
- batframework-2.0.0/pyproject.toml +25 -0
- batframework-2.0.0/src/batFramework/__init__.py +99 -0
- batframework-2.0.0/src/batFramework/action.py +280 -0
- batframework-2.0.0/src/batFramework/actionContainer.py +105 -0
- batframework-2.0.0/src/batFramework/animatedSprite.py +81 -0
- batframework-2.0.0/src/batFramework/animation.py +91 -0
- batframework-2.0.0/src/batFramework/audioManager.py +156 -0
- batframework-2.0.0/src/batFramework/baseScene.py +249 -0
- batframework-2.0.0/src/batFramework/camera.py +245 -0
- batframework-2.0.0/src/batFramework/constants.py +57 -0
- batframework-2.0.0/src/batFramework/cutscene.py +239 -0
- batframework-2.0.0/src/batFramework/cutsceneManager.py +34 -0
- batframework-2.0.0/src/batFramework/drawable.py +107 -0
- batframework-2.0.0/src/batFramework/dynamicEntity.py +30 -0
- batframework-2.0.0/src/batFramework/easingController.py +58 -0
- batframework-2.0.0/src/batFramework/entity.py +130 -0
- batframework-2.0.0/src/batFramework/enums.py +171 -0
- batframework-2.0.0/src/batFramework/fontManager.py +65 -0
- batframework-2.0.0/src/batFramework/gui/__init__.py +28 -0
- batframework-2.0.0/src/batFramework/gui/animatedLabel.py +90 -0
- batframework-2.0.0/src/batFramework/gui/button.py +18 -0
- batframework-2.0.0/src/batFramework/gui/clickableWidget.py +244 -0
- batframework-2.0.0/src/batFramework/gui/collapseContainer.py +98 -0
- batframework-2.0.0/src/batFramework/gui/constraints/__init__.py +1 -0
- batframework-2.0.0/src/batFramework/gui/constraints/constraints.py +1066 -0
- batframework-2.0.0/src/batFramework/gui/container.py +220 -0
- batframework-2.0.0/src/batFramework/gui/debugger.py +140 -0
- batframework-2.0.0/src/batFramework/gui/draggableWidget.py +63 -0
- batframework-2.0.0/src/batFramework/gui/image.py +61 -0
- batframework-2.0.0/src/batFramework/gui/indicator.py +116 -0
- batframework-2.0.0/src/batFramework/gui/interactiveWidget.py +243 -0
- batframework-2.0.0/src/batFramework/gui/label.py +147 -0
- batframework-2.0.0/src/batFramework/gui/layout.py +442 -0
- batframework-2.0.0/src/batFramework/gui/meter.py +155 -0
- batframework-2.0.0/src/batFramework/gui/radioButton.py +43 -0
- batframework-2.0.0/src/batFramework/gui/root.py +228 -0
- batframework-2.0.0/src/batFramework/gui/scrollingContainer.py +282 -0
- batframework-2.0.0/src/batFramework/gui/selector.py +232 -0
- batframework-2.0.0/src/batFramework/gui/shape.py +286 -0
- batframework-2.0.0/src/batFramework/gui/slider.py +353 -0
- batframework-2.0.0/src/batFramework/gui/style.py +10 -0
- batframework-2.0.0/src/batFramework/gui/styleManager.py +49 -0
- batframework-2.0.0/src/batFramework/gui/syncedVar.py +43 -0
- batframework-2.0.0/src/batFramework/gui/textInput.py +331 -0
- batframework-2.0.0/src/batFramework/gui/textWidget.py +308 -0
- batframework-2.0.0/src/batFramework/gui/toggle.py +140 -0
- batframework-2.0.0/src/batFramework/gui/tooltip.py +35 -0
- batframework-2.0.0/src/batFramework/gui/widget.py +546 -0
- batframework-2.0.0/src/batFramework/manager.py +131 -0
- batframework-2.0.0/src/batFramework/particle.py +118 -0
- batframework-2.0.0/src/batFramework/propertyEaser.py +79 -0
- batframework-2.0.0/src/batFramework/renderGroup.py +34 -0
- batframework-2.0.0/src/batFramework/resourceManager.py +130 -0
- batframework-2.0.0/src/batFramework/scene.py +31 -0
- batframework-2.0.0/src/batFramework/sceneLayer.py +134 -0
- batframework-2.0.0/src/batFramework/sceneManager.py +200 -0
- batframework-2.0.0/src/batFramework/scrollingSprite.py +115 -0
- batframework-2.0.0/src/batFramework/sprite.py +46 -0
- {batframework-1.1.0 → batframework-2.0.0}/src/batFramework/stateMachine.py +49 -51
- batframework-2.0.0/src/batFramework/templates/__init__.py +2 -0
- batframework-2.0.0/src/batFramework/templates/character.py +15 -0
- batframework-2.0.0/src/batFramework/templates/controller.py +158 -0
- batframework-2.0.0/src/batFramework/templates/stateMachine.py +39 -0
- batframework-2.0.0/src/batFramework/tileset.py +46 -0
- batframework-2.0.0/src/batFramework/timeManager.py +213 -0
- batframework-2.0.0/src/batFramework/transition.py +162 -0
- {batframework-1.1.0 → batframework-2.0.0}/src/batFramework/triggerZone.py +22 -22
- batframework-2.0.0/src/batFramework/utils.py +306 -0
- {batframework-1.1.0 → batframework-2.0.0}/src/batframework.egg-info/PKG-INFO +8 -4
- batframework-2.0.0/src/batframework.egg-info/SOURCES.txt +75 -0
- batframework-1.1.0/pyproject.toml +0 -23
- batframework-1.1.0/src/batFramework/__init__.py +0 -66
- batframework-1.1.0/src/batFramework/action.py +0 -252
- batframework-1.1.0/src/batFramework/actionContainer.py +0 -38
- batframework-1.1.0/src/batFramework/animatedSprite.py +0 -117
- batframework-1.1.0/src/batFramework/audioManager.py +0 -85
- batframework-1.1.0/src/batFramework/camera.py +0 -123
- batframework-1.1.0/src/batFramework/constants.py +0 -75
- batframework-1.1.0/src/batFramework/cutscene.py +0 -119
- batframework-1.1.0/src/batFramework/cutsceneBlocks.py +0 -176
- batframework-1.1.0/src/batFramework/debugger.py +0 -48
- batframework-1.1.0/src/batFramework/dynamicEntity.py +0 -23
- batframework-1.1.0/src/batFramework/easing.py +0 -71
- batframework-1.1.0/src/batFramework/entity.py +0 -123
- batframework-1.1.0/src/batFramework/gui/__init__.py +0 -14
- batframework-1.1.0/src/batFramework/gui/button.py +0 -84
- batframework-1.1.0/src/batFramework/gui/constraints.py +0 -204
- batframework-1.1.0/src/batFramework/gui/container.py +0 -49
- batframework-1.1.0/src/batFramework/gui/debugger.py +0 -47
- batframework-1.1.0/src/batFramework/gui/frame.py +0 -19
- batframework-1.1.0/src/batFramework/gui/image.py +0 -23
- batframework-1.1.0/src/batFramework/gui/indicator.py +0 -40
- batframework-1.1.0/src/batFramework/gui/interactiveWidget.py +0 -22
- batframework-1.1.0/src/batFramework/gui/label.py +0 -110
- batframework-1.1.0/src/batFramework/gui/layout.py +0 -81
- batframework-1.1.0/src/batFramework/gui/root.py +0 -60
- batframework-1.1.0/src/batFramework/gui/shape.py +0 -86
- batframework-1.1.0/src/batFramework/gui/toggle.py +0 -62
- batframework-1.1.0/src/batFramework/gui/widget.py +0 -307
- batframework-1.1.0/src/batFramework/manager.py +0 -50
- batframework-1.1.0/src/batFramework/particles.py +0 -77
- batframework-1.1.0/src/batFramework/scene.py +0 -226
- batframework-1.1.0/src/batFramework/sceneManager.py +0 -165
- batframework-1.1.0/src/batFramework/time.py +0 -75
- batframework-1.1.0/src/batFramework/transition.py +0 -157
- batframework-1.1.0/src/batFramework/transitionManager.py +0 -0
- batframework-1.1.0/src/batFramework/utils.py +0 -184
- batframework-1.1.0/src/batframework.egg-info/SOURCES.txt +0 -46
- {batframework-1.1.0 → batframework-2.0.0}/setup.cfg +0 -0
- {batframework-1.1.0 → batframework-2.0.0}/src/batframework.egg-info/dependency_links.txt +0 -0
- {batframework-1.1.0 → batframework-2.0.0}/src/batframework.egg-info/requires.txt +0 -0
- {batframework-1.1.0 → batframework-2.0.0}/src/batframework.egg-info/top_level.txt +0 -0
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
21
|
+
SOFTWARE.
|
@@ -1,7 +1,8 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: batframework
|
3
|
-
Version:
|
3
|
+
Version: 2.0.0
|
4
4
|
Summary: Pygame framework for making games easier.
|
5
|
+
Author-email: Turan Baturay <baturayturan@gmail.com>
|
5
6
|
License: MIT License
|
6
7
|
|
7
8
|
Copyright (c) [2023] [TURAN BATURAY]
|
@@ -23,6 +24,11 @@ License: MIT License
|
|
23
24
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
24
25
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
25
26
|
SOFTWARE.
|
27
|
+
|
28
|
+
Project-URL: Homepage, https://github.com/TuranBaturay/batFramework
|
29
|
+
Classifier: Programming Language :: Python :: 3
|
30
|
+
Classifier: License :: OSI Approved :: MIT License
|
31
|
+
Classifier: Operating System :: OS Independent
|
26
32
|
Requires-Python: >=3.11
|
27
33
|
Description-Content-Type: text/markdown
|
28
34
|
License-File: LICENSE
|
@@ -30,7 +36,7 @@ Requires-Dist: pygame-ce
|
|
30
36
|
|
31
37
|
# batFramework
|
32
38
|
|
33
|
-
batFramework is a Python game framework built using Pygame, designed to simplify game development
|
39
|
+
batFramework is a Python game framework built using Pygame, designed to simplify game development.
|
34
40
|
|
35
41
|
## Purpose and Overview
|
36
42
|
The primary objective of batFramework is to streamline game development. It is mainly designed to program small 2D games
|
@@ -62,5 +68,3 @@ For more detailed information, please refer to the [documentation](https://batfr
|
|
62
68
|
|
63
69
|
# License
|
64
70
|
MIT License
|
65
|
-
|
66
|
-
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# batFramework
|
2
2
|
|
3
|
-
batFramework is a Python game framework built using Pygame, designed to simplify game development
|
3
|
+
batFramework is a Python game framework built using Pygame, designed to simplify game development.
|
4
4
|
|
5
5
|
## Purpose and Overview
|
6
6
|
The primary objective of batFramework is to streamline game development. It is mainly designed to program small 2D games
|
@@ -32,5 +32,3 @@ For more detailed information, please refer to the [documentation](https://batfr
|
|
32
32
|
|
33
33
|
# License
|
34
34
|
MIT License
|
35
|
-
|
36
|
-
|
@@ -0,0 +1,25 @@
|
|
1
|
+
[build-system]
|
2
|
+
requires = ["setuptools==76.1.0 "]
|
3
|
+
build-backend = "setuptools.build_meta"
|
4
|
+
|
5
|
+
[project]
|
6
|
+
name = "batframework"
|
7
|
+
version = "2.0.0"
|
8
|
+
license = { file = "LICENSE" }
|
9
|
+
authors = [
|
10
|
+
{ name="Turan Baturay", email="baturayturan@gmail.com" }
|
11
|
+
]
|
12
|
+
description = "Pygame framework for making games easier."
|
13
|
+
readme = "README.md"
|
14
|
+
classifiers = [
|
15
|
+
"Programming Language :: Python :: 3",
|
16
|
+
"License :: OSI Approved :: MIT License",
|
17
|
+
"Operating System :: OS Independent",
|
18
|
+
]
|
19
|
+
requires-python = ">=3.11"
|
20
|
+
dependencies=[
|
21
|
+
"pygame-ce"
|
22
|
+
]
|
23
|
+
[project.urls]
|
24
|
+
Homepage = "https://github.com/TuranBaturay/batFramework"
|
25
|
+
|
@@ -0,0 +1,99 @@
|
|
1
|
+
import pathlib
|
2
|
+
import tomllib
|
3
|
+
from importlib.metadata import version, PackageNotFoundError
|
4
|
+
|
5
|
+
def get_version() -> str:
|
6
|
+
try:
|
7
|
+
return version("batframework")
|
8
|
+
except PackageNotFoundError:
|
9
|
+
pyproject = pathlib.Path(__file__).resolve().parent.parent / "pyproject.toml"
|
10
|
+
if pyproject.exists():
|
11
|
+
with open(pyproject, "rb") as f:
|
12
|
+
data = tomllib.load(f)
|
13
|
+
return data["project"]["version"]
|
14
|
+
return "0.0.0"
|
15
|
+
|
16
|
+
__version__ = get_version()
|
17
|
+
|
18
|
+
import os
|
19
|
+
import pygame
|
20
|
+
import json
|
21
|
+
import batFramework as bf
|
22
|
+
from .constants import Constants as const
|
23
|
+
from .utils import Singleton
|
24
|
+
from .enums import *
|
25
|
+
from .resourceManager import ResourceManager
|
26
|
+
from .fontManager import FontManager
|
27
|
+
from .utils import Utils as utils
|
28
|
+
from .tileset import Tileset
|
29
|
+
from .timeManager import TimeManager,Timer,SceneTimer
|
30
|
+
from .easingController import EasingController
|
31
|
+
from .propertyEaser import PropertyEaser
|
32
|
+
from .cutsceneManager import CutsceneManager
|
33
|
+
import batFramework.cutscene as cutscene
|
34
|
+
from .audioManager import AudioManager
|
35
|
+
import batFramework.transition as transition
|
36
|
+
from .action import Action
|
37
|
+
from .actionContainer import *
|
38
|
+
from .camera import Camera
|
39
|
+
from .entity import Entity
|
40
|
+
from .drawable import Drawable
|
41
|
+
from .renderGroup import RenderGroup
|
42
|
+
from .dynamicEntity import DynamicEntity
|
43
|
+
from .sprite import Sprite
|
44
|
+
from .scrollingSprite import ScrollingSprite
|
45
|
+
from .particle import *
|
46
|
+
from .animation import Animation
|
47
|
+
from .animatedSprite import AnimatedSprite
|
48
|
+
from .stateMachine import State, StateMachine
|
49
|
+
from .sceneLayer import SceneLayer
|
50
|
+
from .scene import Scene
|
51
|
+
from .baseScene import BaseScene
|
52
|
+
import batFramework.gui as gui
|
53
|
+
from .sceneManager import SceneManager
|
54
|
+
from .manager import Manager
|
55
|
+
from .templates import *
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
def init_screen(resolution: tuple[int, int], flags: int = 0, vsync: int = 0):
|
61
|
+
const.set_resolution(resolution)
|
62
|
+
const.FLAGS = flags
|
63
|
+
const.VSYNC = vsync
|
64
|
+
const.SCREEN = pygame.display.set_mode(
|
65
|
+
const.RESOLUTION, const.FLAGS, vsync=const.VSYNC
|
66
|
+
)
|
67
|
+
print(
|
68
|
+
f"Window : {resolution[0]}x{resolution[1]}"
|
69
|
+
)
|
70
|
+
|
71
|
+
|
72
|
+
def print_version():
|
73
|
+
print(f"BatFramework version: {__version__}")
|
74
|
+
|
75
|
+
def init(
|
76
|
+
resolution: tuple[int, int],
|
77
|
+
flags: int = 0,
|
78
|
+
window_caption: str = "BatFramework Project",
|
79
|
+
resource_path: str | None = None,
|
80
|
+
default_font_size=None,
|
81
|
+
default_font=None,
|
82
|
+
fps_limit: int = 0,
|
83
|
+
vsync: int = 0,
|
84
|
+
):
|
85
|
+
print_version()
|
86
|
+
pygame.display.set_caption(window_caption)
|
87
|
+
init_screen(resolution, flags, vsync)
|
88
|
+
pygame.mixer.init()
|
89
|
+
|
90
|
+
ResourceManager().set_resource_path(
|
91
|
+
resource_path if resource_path is not None else "."
|
92
|
+
)
|
93
|
+
if resource_path is not None:
|
94
|
+
ResourceManager().load_resources(ResourceManager().RESOURCE_PATH)
|
95
|
+
if default_font_size is not None:
|
96
|
+
FontManager().set_default_text_size(default_font_size)
|
97
|
+
FontManager().init_font(default_font)
|
98
|
+
const.BF_INITIALIZED = True
|
99
|
+
const.set_fps_limit(fps_limit)
|
@@ -0,0 +1,280 @@
|
|
1
|
+
from typing import Any, Self
|
2
|
+
from enum import Enum
|
3
|
+
import pygame
|
4
|
+
from .enums import actionType
|
5
|
+
|
6
|
+
|
7
|
+
class Action:
|
8
|
+
def __init__(self, name: str) -> None:
|
9
|
+
"""
|
10
|
+
Create a new action with the given name.
|
11
|
+
|
12
|
+
Args:
|
13
|
+
name (str): The name of the action.
|
14
|
+
"""
|
15
|
+
self.name: str = name
|
16
|
+
self.active: bool = False
|
17
|
+
self.data: dict = {}
|
18
|
+
self.consume_event: bool = False
|
19
|
+
self._type: actionType = actionType.INSTANTANEOUS
|
20
|
+
self._key_control: set = set()
|
21
|
+
self._mouse_control: set = set()
|
22
|
+
self._event_control: set = set()
|
23
|
+
self._gamepad_button_control: set = set()
|
24
|
+
self._gamepad_axis_control: set = set()
|
25
|
+
self._holding = set()
|
26
|
+
|
27
|
+
def __bool__(self) -> bool :
|
28
|
+
return self.active
|
29
|
+
|
30
|
+
def set_consume_event(self, val: bool) -> Self:
|
31
|
+
"""
|
32
|
+
Set whether this action is unique (exclusive).
|
33
|
+
When in an action Container, unique actions -when active - break the propagation of their event to other actions.
|
34
|
+
|
35
|
+
Args:
|
36
|
+
val (bool): True if the action is unique, False otherwise.
|
37
|
+
"""
|
38
|
+
self.consume_event = val
|
39
|
+
return self
|
40
|
+
|
41
|
+
def set_active(self, value: bool) -> None:
|
42
|
+
"""
|
43
|
+
Set the action's active state.
|
44
|
+
|
45
|
+
Args:
|
46
|
+
value (bool): True to activate the action, False to deactivate it.
|
47
|
+
"""
|
48
|
+
self.active = value
|
49
|
+
|
50
|
+
|
51
|
+
def add_event_control(self, *events) -> Self:
|
52
|
+
self._event_control.update(events)
|
53
|
+
return self
|
54
|
+
|
55
|
+
def remove_event_control(self, *events) -> Self:
|
56
|
+
self._event_control = self._event_control - events
|
57
|
+
return self
|
58
|
+
|
59
|
+
def add_key_control(self, *keys) -> Self:
|
60
|
+
"""
|
61
|
+
Add key controls to the action.
|
62
|
+
|
63
|
+
Args:
|
64
|
+
*keys (int): Key codes to control this action.
|
65
|
+
|
66
|
+
Returns:
|
67
|
+
Action: The updated Action object for method chaining.
|
68
|
+
"""
|
69
|
+
self._key_control.update(keys)
|
70
|
+
return self
|
71
|
+
|
72
|
+
def remove_key_control(self, *keys: int) -> Self:
|
73
|
+
"""
|
74
|
+
Remove key controls to the action.
|
75
|
+
|
76
|
+
Args:
|
77
|
+
*keys (int): Key codes to control this action.
|
78
|
+
|
79
|
+
Returns:
|
80
|
+
Action: The updated Action object for method chaining.
|
81
|
+
"""
|
82
|
+
self._key_control = self._key_control - set(keys)
|
83
|
+
return self
|
84
|
+
|
85
|
+
def replace_key_control(self, key, new_key) -> Self:
|
86
|
+
if not key in self._key_control:
|
87
|
+
return self
|
88
|
+
self.remove_key_control(key)
|
89
|
+
self.add_key_control(new_key)
|
90
|
+
return self
|
91
|
+
|
92
|
+
def add_mouse_control(self, *mouse: int) -> Self:
|
93
|
+
"""
|
94
|
+
Add mouse control to the action.
|
95
|
+
|
96
|
+
Args:
|
97
|
+
*mouse_buttons (int): Mouse button codes to control this action.
|
98
|
+
|
99
|
+
Returns:
|
100
|
+
Action: The updated Action object for method chaining.
|
101
|
+
"""
|
102
|
+
self._mouse_control.update(mouse)
|
103
|
+
return self
|
104
|
+
|
105
|
+
def remove_mouse_control(self, *mouse: int) -> Self:
|
106
|
+
self._mouse_control = self._mouse_control - set(mouse)
|
107
|
+
return self
|
108
|
+
|
109
|
+
def replace_mouse_control(self, mouse, new_mouse) -> Self:
|
110
|
+
if not mouse in self._mouse_control:
|
111
|
+
return self
|
112
|
+
self.remove_mouse_control(mouse)
|
113
|
+
self.add_mouse_control(new_mouse)
|
114
|
+
return self
|
115
|
+
|
116
|
+
def set_continuous(self) -> Self:
|
117
|
+
"""
|
118
|
+
Set the action type to continuous.
|
119
|
+
|
120
|
+
Returns:
|
121
|
+
Action: The updated Action object for method chaining.
|
122
|
+
"""
|
123
|
+
self._holding = set()
|
124
|
+
self._type = actionType.CONTINUOUS
|
125
|
+
return self
|
126
|
+
|
127
|
+
def is_continuous(self) -> bool:
|
128
|
+
"""
|
129
|
+
Check if the action type is continuous.
|
130
|
+
|
131
|
+
Returns:
|
132
|
+
bool: True if the action type is continuous, False otherwise.
|
133
|
+
"""
|
134
|
+
return self._type == actionType.CONTINUOUS
|
135
|
+
|
136
|
+
def set_instantaneous(self) -> Self:
|
137
|
+
"""
|
138
|
+
Set the action type to instantaneous.
|
139
|
+
|
140
|
+
Returns:
|
141
|
+
Action: The updated Action object for method chaining.
|
142
|
+
"""
|
143
|
+
self._type = actionType.INSTANTANEOUS
|
144
|
+
self._holding = set()
|
145
|
+
return self
|
146
|
+
|
147
|
+
def is_instantaneous(self) -> bool:
|
148
|
+
"""
|
149
|
+
Check if the action type is instantaneous.
|
150
|
+
|
151
|
+
Returns:
|
152
|
+
bool: True if the action type is instantaneous, False otherwise.
|
153
|
+
"""
|
154
|
+
return self._type == actionType.INSTANTANEOUS
|
155
|
+
|
156
|
+
def set_holding(self) -> Self:
|
157
|
+
"""
|
158
|
+
Set the action type to holding.
|
159
|
+
|
160
|
+
Returns:
|
161
|
+
Action: The updated Action object for method chaining.
|
162
|
+
"""
|
163
|
+
self._type = actionType.HOLDING
|
164
|
+
return self
|
165
|
+
|
166
|
+
def is_holding_type(self) -> bool:
|
167
|
+
"""
|
168
|
+
Check if the action type is holding.
|
169
|
+
|
170
|
+
Returns:
|
171
|
+
bool: True if the action type is holding, False otherwise.
|
172
|
+
"""
|
173
|
+
return self._type == actionType.HOLDING
|
174
|
+
|
175
|
+
def process_update(self, event: pygame.Event) -> None:
|
176
|
+
if event.type in self._event_control:
|
177
|
+
self.data = event.dict
|
178
|
+
self.data.update({"type":event.type})
|
179
|
+
|
180
|
+
|
181
|
+
def process_activate(self, event: pygame.event.Event):
|
182
|
+
"""
|
183
|
+
Process activation of the action based on a pygame event.
|
184
|
+
|
185
|
+
Args:
|
186
|
+
event (pygame.event.Event): The pygame event to process.
|
187
|
+
|
188
|
+
Returns:
|
189
|
+
bool: True if the action was activated by the event, False otherwise.
|
190
|
+
"""
|
191
|
+
|
192
|
+
if event.type == pygame.KEYDOWN and event.key in self._key_control:
|
193
|
+
self._activate_action(event.key)
|
194
|
+
elif (
|
195
|
+
event.type == pygame.MOUSEBUTTONDOWN and event.button in self._mouse_control
|
196
|
+
):
|
197
|
+
self._activate_action(event.button)
|
198
|
+
|
199
|
+
elif event.type in self._event_control:
|
200
|
+
self._activate_action(event.type)
|
201
|
+
else:
|
202
|
+
return
|
203
|
+
|
204
|
+
self.data = event.dict
|
205
|
+
self.data.update({"type":event.type})
|
206
|
+
|
207
|
+
if self.consume_event:
|
208
|
+
event.consumed = True
|
209
|
+
|
210
|
+
def _activate_action(self, control):
|
211
|
+
self.active = True
|
212
|
+
if self._type == actionType.HOLDING:
|
213
|
+
self._holding.add(control)
|
214
|
+
|
215
|
+
def process_deactivate(self, event: pygame.event.Event):
|
216
|
+
"""
|
217
|
+
Process deactivation of the action based on a pygame event.
|
218
|
+
|
219
|
+
Args:
|
220
|
+
event (pygame.event.Event): The pygame event to process.
|
221
|
+
|
222
|
+
"""
|
223
|
+
if self._type == actionType.HOLDING:
|
224
|
+
if event.type == pygame.KEYUP and event.key in self._key_control:
|
225
|
+
self._deactivate_action(event.key)
|
226
|
+
elif (
|
227
|
+
event.type == pygame.MOUSEBUTTONUP
|
228
|
+
and event.button in self._mouse_control
|
229
|
+
):
|
230
|
+
self._deactivate_action(event.button)
|
231
|
+
elif event.type in self._event_control:
|
232
|
+
self._deactivate_action(event.type)
|
233
|
+
|
234
|
+
else:
|
235
|
+
event.consumed = False
|
236
|
+
return
|
237
|
+
|
238
|
+
if self.consume_event:
|
239
|
+
event.consumed = True
|
240
|
+
|
241
|
+
def _deactivate_action(self, control) -> bool:
|
242
|
+
if control in self._holding:
|
243
|
+
self._holding.remove(control)
|
244
|
+
if not self._holding:
|
245
|
+
self.active = False
|
246
|
+
|
247
|
+
def process_event(self, event: pygame.event.Event):
|
248
|
+
"""
|
249
|
+
Process a pygame event and update the action's state.
|
250
|
+
|
251
|
+
Args:
|
252
|
+
event (pygame.event.Event): The pygame event to process.
|
253
|
+
"""
|
254
|
+
|
255
|
+
if event.consumed:
|
256
|
+
return
|
257
|
+
if not self.active:
|
258
|
+
self.process_activate(event)
|
259
|
+
else:
|
260
|
+
self.process_deactivate(event)
|
261
|
+
if self.active:
|
262
|
+
self.process_update(event)
|
263
|
+
return
|
264
|
+
|
265
|
+
def reset(self) -> None:
|
266
|
+
"""
|
267
|
+
Reset the action's state to the default state.
|
268
|
+
"""
|
269
|
+
if self._type in {actionType.CONTINUOUS, actionType.HOLDING}:
|
270
|
+
return
|
271
|
+
elif self._type == actionType.INSTANTANEOUS:
|
272
|
+
self.active = False
|
273
|
+
|
274
|
+
def hard_reset(self) -> None:
|
275
|
+
"""
|
276
|
+
Hard reset the action, deactivating it and clearing any holding controls.
|
277
|
+
"""
|
278
|
+
self.active = False
|
279
|
+
self._holding = set()
|
280
|
+
self.data = {}
|
@@ -0,0 +1,105 @@
|
|
1
|
+
import batFramework as bf
|
2
|
+
import pygame
|
3
|
+
|
4
|
+
|
5
|
+
class ActionContainer:
|
6
|
+
def __init__(self, *actions: list[bf.Action]) -> None:
|
7
|
+
self._actions: dict[str, bf.Action] = {}
|
8
|
+
if actions:
|
9
|
+
self.add_actions(*actions)
|
10
|
+
|
11
|
+
def __iter__(self):
|
12
|
+
return iter(self._actions.values())
|
13
|
+
|
14
|
+
def __getitem__(self, key):
|
15
|
+
return self._actions[key]
|
16
|
+
|
17
|
+
def __setitem__(self, key, value):
|
18
|
+
self._actions[key] = value
|
19
|
+
|
20
|
+
def __delitem__(self, key):
|
21
|
+
del self._actions[key]
|
22
|
+
|
23
|
+
def __contains__(self, key):
|
24
|
+
return key in self._actions
|
25
|
+
|
26
|
+
def __repr__(self):
|
27
|
+
return repr(self._actions)
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
def clear(self):
|
32
|
+
self._actions = {}
|
33
|
+
|
34
|
+
def add_actions(self, *actions: bf.Action):
|
35
|
+
for action in actions:
|
36
|
+
self._actions[action.name] = action
|
37
|
+
|
38
|
+
def get(self, name: str) -> bf.Action:
|
39
|
+
return self._actions.get(name)
|
40
|
+
|
41
|
+
def has_action(self, name: str):
|
42
|
+
return name in self._actions
|
43
|
+
|
44
|
+
def get_all(self) -> list[bf.Action]:
|
45
|
+
return self._actions
|
46
|
+
|
47
|
+
def is_active(self, *names: str) -> bool:
|
48
|
+
return all(
|
49
|
+
self._actions.get(name).active if name in self._actions else False
|
50
|
+
for name in names
|
51
|
+
)
|
52
|
+
|
53
|
+
def is_any_active(self,*names:str) -> bool:
|
54
|
+
return any(
|
55
|
+
self._actions.get(name).active if name in self._actions else False
|
56
|
+
for name in names
|
57
|
+
)
|
58
|
+
|
59
|
+
def process_event(self, event):
|
60
|
+
if event.consumed:
|
61
|
+
return
|
62
|
+
for action in self._actions.values():
|
63
|
+
action.process_event(event)
|
64
|
+
if event.consumed == True:
|
65
|
+
break
|
66
|
+
|
67
|
+
def reset(self):
|
68
|
+
for action in self._actions.values():
|
69
|
+
action.reset()
|
70
|
+
|
71
|
+
def hard_reset(self):
|
72
|
+
for action in self._actions.values():
|
73
|
+
action.hard_reset()
|
74
|
+
|
75
|
+
|
76
|
+
class DirectionalKeyControls(ActionContainer):
|
77
|
+
def __init__(self):
|
78
|
+
super().__init__(
|
79
|
+
bf.Action("up").add_key_control(pygame.K_UP).set_holding(),
|
80
|
+
bf.Action("down").add_key_control(pygame.K_DOWN).set_holding(),
|
81
|
+
bf.Action("left").add_key_control(pygame.K_LEFT).set_holding(),
|
82
|
+
bf.Action("right").add_key_control(pygame.K_RIGHT).set_holding(),
|
83
|
+
)
|
84
|
+
|
85
|
+
|
86
|
+
class WASDControls(ActionContainer):
|
87
|
+
def __init__(self):
|
88
|
+
super().__init__(
|
89
|
+
bf.Action("up").add_key_control(pygame.K_w).set_holding(),
|
90
|
+
bf.Action("down").add_key_control(pygame.K_s).set_holding(),
|
91
|
+
bf.Action("left").add_key_control(pygame.K_a).set_holding(),
|
92
|
+
bf.Action("right").add_key_control(pygame.K_d).set_holding(),
|
93
|
+
)
|
94
|
+
|
95
|
+
|
96
|
+
class HybridControls(ActionContainer):
|
97
|
+
def __init__(self):
|
98
|
+
super().__init__(
|
99
|
+
bf.Action("up").add_key_control(pygame.K_UP, pygame.K_w).set_holding(),
|
100
|
+
bf.Action("down").add_key_control(pygame.K_DOWN, pygame.K_s).set_holding(),
|
101
|
+
bf.Action("left").add_key_control(pygame.K_LEFT, pygame.K_a).set_holding(),
|
102
|
+
bf.Action("right")
|
103
|
+
.add_key_control(pygame.K_RIGHT, pygame.K_r)
|
104
|
+
.set_holding(),
|
105
|
+
)
|
@@ -0,0 +1,81 @@
|
|
1
|
+
import batFramework as bf
|
2
|
+
import pygame
|
3
|
+
from typing import List, Dict, Tuple, Union, Optional, Self, Callable, Any
|
4
|
+
from .animation import Animation
|
5
|
+
|
6
|
+
class AnimatedSprite(bf.Drawable):
|
7
|
+
def __init__(self,*args,**kwargs) -> None:
|
8
|
+
super().__init__((0,0),*args,**kwargs)
|
9
|
+
self.animations : dict[str,Animation] = {}
|
10
|
+
self.counter = 0 # int counter
|
11
|
+
self._fcounter = 0.0 # counter
|
12
|
+
self.current_animation : str = None
|
13
|
+
self.end_callback : Callable[[],Any] = None
|
14
|
+
self._flipX : bool = False
|
15
|
+
self.animation_loop : int = -1
|
16
|
+
self.queued_animation : str = None
|
17
|
+
|
18
|
+
@property
|
19
|
+
def flipX(self)->bool:
|
20
|
+
return self._flipX
|
21
|
+
|
22
|
+
@flipX.setter
|
23
|
+
def flipX(self,value:bool):
|
24
|
+
self._flipX = value
|
25
|
+
|
26
|
+
def set_animation_end_callback(self,callback : Callable[[],Any]):
|
27
|
+
self.end_callback = callback
|
28
|
+
|
29
|
+
def add_animation(self,animation:Animation)->Self:
|
30
|
+
self.animations[animation.name] = animation
|
31
|
+
if self.rect.size == (0,0):
|
32
|
+
self.rect.size = animation.frames[0].get_size()
|
33
|
+
self.surface = animation.frames[0].copy()
|
34
|
+
return self
|
35
|
+
|
36
|
+
def set_animation(self,name:str,reset_counter:bool=True,loop:int=-1,queued_animation:str=None):
|
37
|
+
"""
|
38
|
+
Sets the current animation,
|
39
|
+
if animation with given name hasn't been added, nothing happens
|
40
|
+
"""
|
41
|
+
if name not in self.animations :
|
42
|
+
return
|
43
|
+
self.current_animation = name
|
44
|
+
if reset_counter:
|
45
|
+
self._fcounter = 0
|
46
|
+
self.counter = 0
|
47
|
+
self.animation_loop = loop
|
48
|
+
if loop != -1:
|
49
|
+
self.queued_animation = queued_animation
|
50
|
+
else:
|
51
|
+
self.queued_animation = None
|
52
|
+
|
53
|
+
def get_current_frame(self)->int|None:
|
54
|
+
if not self.current_animation:
|
55
|
+
return None
|
56
|
+
return self.animations[self.current_animation].counter_to_frame(self._fcounter)
|
57
|
+
|
58
|
+
def update(self, dt):
|
59
|
+
super().update(dt)
|
60
|
+
if not self.current_animation:
|
61
|
+
return
|
62
|
+
self._fcounter += dt * 60
|
63
|
+
self.counter = int(self._fcounter)
|
64
|
+
# self.counter = self.get_current_frame()
|
65
|
+
# print(f"{self.current_animation}:{self.counter}/{self.animations[self.current_animation].duration_list_length}")
|
66
|
+
if self.counter >= self.animations[self.current_animation].duration_list_length:
|
67
|
+
#one animation cycle ended
|
68
|
+
if self.animation_loop > 0:
|
69
|
+
self.animation_loop -= 1
|
70
|
+
elif self.queued_animation is not None:
|
71
|
+
# print("set to queued :",self.queued_animation)
|
72
|
+
self.set_animation(self.queued_animation,True)
|
73
|
+
|
74
|
+
if self.end_callback:
|
75
|
+
self.end_callback()
|
76
|
+
|
77
|
+
def draw(self, camera):
|
78
|
+
# print(self.current_animation, f"{self.counter}/{self.animations[self.current_animation].duration_list_length}")
|
79
|
+
self.surface = self.animations[self.current_animation].get_frame(self.counter,self.flipX)#,(0,0)
|
80
|
+
super().draw(camera)
|
81
|
+
|