batframework 1.0.8a9__tar.gz → 1.0.8a11__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.0.8a11/LICENCE +21 -0
- batframework-1.0.8a11/PKG-INFO +43 -0
- batframework-1.0.8a11/README.md +29 -0
- batframework-1.0.8a11/pyproject.toml +18 -0
- batframework-1.0.8a11/src/batFramework/__init__.py +83 -0
- batframework-1.0.8a11/src/batFramework/action.py +279 -0
- batframework-1.0.8a11/src/batFramework/actionContainer.py +82 -0
- batframework-1.0.8a11/src/batFramework/animatedSprite.py +176 -0
- batframework-1.0.8a11/src/batFramework/audioManager.py +128 -0
- batframework-1.0.8a11/src/batFramework/camera.py +313 -0
- batframework-1.0.8a11/src/batFramework/character.py +27 -0
- batframework-1.0.8a11/src/batFramework/constants.py +37 -0
- {batframework-1.0.8a9 → batframework-1.0.8a11}/src/batFramework/cutscene.py +39 -29
- {batframework-1.0.8a9 → batframework-1.0.8a11}/src/batFramework/cutsceneBlocks.py +36 -43
- batframework-1.0.8a11/src/batFramework/dynamicEntity.py +32 -0
- batframework-1.0.8a11/src/batFramework/easingController.py +58 -0
- batframework-1.0.8a11/src/batFramework/entity.py +74 -0
- batframework-1.0.8a11/src/batFramework/enums.py +113 -0
- batframework-1.0.8a11/src/batFramework/fontManager.py +65 -0
- batframework-1.0.8a11/src/batFramework/gui/__init__.py +22 -0
- batframework-1.0.8a11/src/batFramework/gui/button.py +15 -0
- batframework-1.0.8a11/src/batFramework/gui/clickableWidget.py +220 -0
- batframework-1.0.8a11/src/batFramework/gui/constraints/__init__.py +1 -0
- batframework-1.0.8a11/src/batFramework/gui/constraints/constraints.py +815 -0
- batframework-1.0.8a11/src/batFramework/gui/container.py +191 -0
- batframework-1.0.8a11/src/batFramework/gui/debugger.py +135 -0
- batframework-1.0.8a11/src/batFramework/gui/dialogueBox.py +99 -0
- batframework-1.0.8a11/src/batFramework/gui/draggableWidget.py +40 -0
- batframework-1.0.8a11/src/batFramework/gui/image.py +59 -0
- batframework-1.0.8a11/src/batFramework/gui/indicator.py +57 -0
- batframework-1.0.8a11/src/batFramework/gui/interactiveWidget.py +201 -0
- batframework-1.0.8a11/src/batFramework/gui/label.py +345 -0
- batframework-1.0.8a11/src/batFramework/gui/layout.py +249 -0
- batframework-1.0.8a11/src/batFramework/gui/meter.py +74 -0
- batframework-1.0.8a11/src/batFramework/gui/radioButton.py +84 -0
- batframework-1.0.8a11/src/batFramework/gui/root.py +156 -0
- batframework-1.0.8a11/src/batFramework/gui/shape.py +266 -0
- batframework-1.0.8a11/src/batFramework/gui/slider.py +240 -0
- batframework-1.0.8a11/src/batFramework/gui/style.py +10 -0
- batframework-1.0.8a11/src/batFramework/gui/styleManager.py +48 -0
- batframework-1.0.8a11/src/batFramework/gui/textInput.py +247 -0
- batframework-1.0.8a11/src/batFramework/gui/toggle.py +112 -0
- batframework-1.0.8a11/src/batFramework/gui/widget.py +415 -0
- batframework-1.0.8a11/src/batFramework/manager.py +121 -0
- batframework-1.0.8a11/src/batFramework/object.py +123 -0
- batframework-1.0.8a11/src/batFramework/particle.py +115 -0
- batframework-1.0.8a11/src/batFramework/renderGroup.py +67 -0
- batframework-1.0.8a11/src/batFramework/resourceManager.py +100 -0
- batframework-1.0.8a11/src/batFramework/scene.py +384 -0
- batframework-1.0.8a11/src/batFramework/sceneManager.py +227 -0
- batframework-1.0.8a11/src/batFramework/scrollingSprite.py +114 -0
- batframework-1.0.8a11/src/batFramework/sprite.py +51 -0
- {batframework-1.0.8a9 → batframework-1.0.8a11}/src/batFramework/stateMachine.py +11 -8
- batframework-1.0.8a11/src/batFramework/templates/__init__.py +2 -0
- batframework-1.0.8a11/src/batFramework/templates/character.py +44 -0
- batframework-1.0.8a11/src/batFramework/templates/states.py +166 -0
- batframework-1.0.8a11/src/batFramework/tileset.py +46 -0
- batframework-1.0.8a11/src/batFramework/time.py +162 -0
- batframework-1.0.8a11/src/batFramework/transition.py +228 -0
- {batframework-1.0.8a9 → batframework-1.0.8a11}/src/batFramework/triggerZone.py +1 -1
- batframework-1.0.8a11/src/batFramework/utils.py +149 -0
- batframework-1.0.8a11/src/batframework.egg-info/PKG-INFO +43 -0
- {batframework-1.0.8a9 → batframework-1.0.8a11}/src/batframework.egg-info/SOURCES.txt +26 -6
- batframework-1.0.8a9/PKG-INFO +0 -53
- batframework-1.0.8a9/README.md +0 -45
- batframework-1.0.8a9/pyproject.toml +0 -11
- batframework-1.0.8a9/src/batFramework/__init__.py +0 -66
- batframework-1.0.8a9/src/batFramework/action.py +0 -252
- batframework-1.0.8a9/src/batFramework/actionContainer.py +0 -38
- batframework-1.0.8a9/src/batFramework/animatedSprite.py +0 -117
- batframework-1.0.8a9/src/batFramework/audioManager.py +0 -85
- batframework-1.0.8a9/src/batFramework/camera.py +0 -123
- batframework-1.0.8a9/src/batFramework/constants.py +0 -75
- batframework-1.0.8a9/src/batFramework/debugger.py +0 -48
- batframework-1.0.8a9/src/batFramework/dynamicEntity.py +0 -23
- batframework-1.0.8a9/src/batFramework/easing.py +0 -71
- batframework-1.0.8a9/src/batFramework/entity.py +0 -123
- batframework-1.0.8a9/src/batFramework/gui/__init__.py +0 -14
- batframework-1.0.8a9/src/batFramework/gui/button.py +0 -84
- batframework-1.0.8a9/src/batFramework/gui/constraints.py +0 -204
- batframework-1.0.8a9/src/batFramework/gui/container.py +0 -49
- batframework-1.0.8a9/src/batFramework/gui/debugger.py +0 -47
- batframework-1.0.8a9/src/batFramework/gui/frame.py +0 -19
- batframework-1.0.8a9/src/batFramework/gui/image.py +0 -23
- batframework-1.0.8a9/src/batFramework/gui/indicator.py +0 -40
- batframework-1.0.8a9/src/batFramework/gui/interactiveWidget.py +0 -22
- batframework-1.0.8a9/src/batFramework/gui/label.py +0 -110
- batframework-1.0.8a9/src/batFramework/gui/layout.py +0 -81
- batframework-1.0.8a9/src/batFramework/gui/root.py +0 -60
- batframework-1.0.8a9/src/batFramework/gui/shape.py +0 -86
- batframework-1.0.8a9/src/batFramework/gui/toggle.py +0 -62
- batframework-1.0.8a9/src/batFramework/gui/widget.py +0 -307
- batframework-1.0.8a9/src/batFramework/manager.py +0 -50
- batframework-1.0.8a9/src/batFramework/particles.py +0 -77
- batframework-1.0.8a9/src/batFramework/scene.py +0 -226
- batframework-1.0.8a9/src/batFramework/sceneManager.py +0 -165
- batframework-1.0.8a9/src/batFramework/time.py +0 -75
- batframework-1.0.8a9/src/batFramework/transition.py +0 -157
- batframework-1.0.8a9/src/batFramework/transitionManager.py +0 -0
- batframework-1.0.8a9/src/batFramework/utils.py +0 -184
- batframework-1.0.8a9/src/batframework.egg-info/PKG-INFO +0 -53
- {batframework-1.0.8a9 → batframework-1.0.8a11}/setup.cfg +0 -0
- {batframework-1.0.8a9 → batframework-1.0.8a11}/src/batframework.egg-info/dependency_links.txt +0 -0
- {batframework-1.0.8a9 → batframework-1.0.8a11}/src/batframework.egg-info/requires.txt +0 -0
- {batframework-1.0.8a9 → batframework-1.0.8a11}/src/batframework.egg-info/top_level.txt +0 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) [2023] [TURAN BATURAY]
|
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.
|
@@ -0,0 +1,43 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: batframework
|
3
|
+
Version: 1.0.8a11
|
4
|
+
Summary: Pygame framework for making games easier.
|
5
|
+
Author-email: Turan Baturay <baturayturan@gmail.com>
|
6
|
+
Project-URL: Homepage, https://github.com/TuranBaturay/batFramework
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
9
|
+
Classifier: Operating System :: OS Independent
|
10
|
+
Requires-Python: >=3.11
|
11
|
+
Description-Content-Type: text/markdown
|
12
|
+
License-File: LICENCE
|
13
|
+
Requires-Dist: pygame-ce
|
14
|
+
|
15
|
+
# batFramework
|
16
|
+
|
17
|
+
Welcome to the `batFramework`. This README provides an overview of the game framework.
|
18
|
+
|
19
|
+
## batFramework
|
20
|
+
|
21
|
+
The `batFramework` is a Python game development framework based on pygame, designed to streamline the process of creating 2D games. It provides a set of tools and components to handle scenes, transitions, cutscenes, audio, sprites, and more. The framework is built with flexibility in mind, allowing you to focus on game design while abstracting away low-level details.
|
22
|
+
|
23
|
+
### Features
|
24
|
+
|
25
|
+
- Scene management
|
26
|
+
- Cutscene support
|
27
|
+
- Audio management (music and sound effects with volume control)
|
28
|
+
- Entity, sprite, and animated sprite handling
|
29
|
+
- Transition effects
|
30
|
+
- Utility modules (time management, constants, etc.)
|
31
|
+
- No external dependency except for pygame
|
32
|
+
|
33
|
+
### Explore batFramework
|
34
|
+
|
35
|
+
1. Install Python (version 3.11 or higher) and the latest stable version of pygame-ce.
|
36
|
+
2. Clone or download this repository.
|
37
|
+
4. Explore the framework's modules in the `batFramework` directory and integrate them into your own game project.
|
38
|
+
|
39
|
+
For more detailed information on how to use the framework, refer to the documentation (if available) or explore the source code in the `batFramework` directory.
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# batFramework
|
2
|
+
|
3
|
+
Welcome to the `batFramework`. This README provides an overview of the game framework.
|
4
|
+
|
5
|
+
## batFramework
|
6
|
+
|
7
|
+
The `batFramework` is a Python game development framework based on pygame, designed to streamline the process of creating 2D games. It provides a set of tools and components to handle scenes, transitions, cutscenes, audio, sprites, and more. The framework is built with flexibility in mind, allowing you to focus on game design while abstracting away low-level details.
|
8
|
+
|
9
|
+
### Features
|
10
|
+
|
11
|
+
- Scene management
|
12
|
+
- Cutscene support
|
13
|
+
- Audio management (music and sound effects with volume control)
|
14
|
+
- Entity, sprite, and animated sprite handling
|
15
|
+
- Transition effects
|
16
|
+
- Utility modules (time management, constants, etc.)
|
17
|
+
- No external dependency except for pygame
|
18
|
+
|
19
|
+
### Explore batFramework
|
20
|
+
|
21
|
+
1. Install Python (version 3.11 or higher) and the latest stable version of pygame-ce.
|
22
|
+
2. Clone or download this repository.
|
23
|
+
4. Explore the framework's modules in the `batFramework` directory and integrate them into your own game project.
|
24
|
+
|
25
|
+
For more detailed information on how to use the framework, refer to the documentation (if available) or explore the source code in the `batFramework` directory.
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
[build-system]
|
2
|
+
requires = [ "setuptools>=61.0",]
|
3
|
+
build-backend = "setuptools.build_meta"
|
4
|
+
|
5
|
+
[project]
|
6
|
+
name = "batframework"
|
7
|
+
version = "1.0.8a11"
|
8
|
+
description = "Pygame framework for making games easier."
|
9
|
+
readme = "README.md"
|
10
|
+
classifiers = [ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent",]
|
11
|
+
requires-python = ">=3.11"
|
12
|
+
dependencies = [ "pygame-ce",]
|
13
|
+
[[project.authors]]
|
14
|
+
name = "Turan Baturay"
|
15
|
+
email = "baturayturan@gmail.com"
|
16
|
+
|
17
|
+
[project.urls]
|
18
|
+
Homepage = "https://github.com/TuranBaturay/batFramework"
|
@@ -0,0 +1,83 @@
|
|
1
|
+
import pygame
|
2
|
+
import batFramework as bf
|
3
|
+
import sys
|
4
|
+
from .constants import Constants as const
|
5
|
+
from .utils import Singleton
|
6
|
+
from .enums import *
|
7
|
+
from .resourceManager import ResourceManager
|
8
|
+
from .fontManager import FontManager
|
9
|
+
from .utils import Utils as utils
|
10
|
+
from .tileset import Tileset
|
11
|
+
from .time import *
|
12
|
+
from .easingController import EasingController
|
13
|
+
from .cutscene import Cutscene, CutsceneManager
|
14
|
+
from .cutsceneBlocks import *
|
15
|
+
from .audioManager import AudioManager
|
16
|
+
import batFramework.transition as transition
|
17
|
+
from .action import Action
|
18
|
+
from .actionContainer import *
|
19
|
+
from .camera import Camera
|
20
|
+
from .object import Object
|
21
|
+
from .entity import Entity
|
22
|
+
from .renderGroup import RenderGroup
|
23
|
+
from .dynamicEntity import DynamicEntity
|
24
|
+
from .sprite import Sprite
|
25
|
+
from .scrollingSprite import ScrollingSprite
|
26
|
+
from .particle import *
|
27
|
+
from .animatedSprite import AnimatedSprite, Animation
|
28
|
+
from .character import Character
|
29
|
+
from .stateMachine import State, StateMachine
|
30
|
+
from .scene import Scene
|
31
|
+
from .gui import *
|
32
|
+
from .sceneManager import SceneManager
|
33
|
+
from .manager import Manager
|
34
|
+
from .templates import *
|
35
|
+
import importlib.metadata
|
36
|
+
|
37
|
+
|
38
|
+
def init_screen(resolution: tuple[int, int], flags: int = 0, vsync: int = 0):
|
39
|
+
const.RESOLUTION = resolution
|
40
|
+
const.FLAGS = flags
|
41
|
+
const.VSYNC = vsync
|
42
|
+
const.SCREEN = pygame.display.set_mode(
|
43
|
+
const.RESOLUTION, const.FLAGS, vsync=const.VSYNC
|
44
|
+
)
|
45
|
+
print(
|
46
|
+
f"Window : {resolution[0]}x{resolution[1]} [vsync:{pygame.display.is_vsync()}]"
|
47
|
+
)
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
def print_version():
|
52
|
+
package_name = "batFramework"
|
53
|
+
try:
|
54
|
+
version = importlib.metadata.version(package_name)
|
55
|
+
print(f"{package_name} version: {version}")
|
56
|
+
except importlib.metadata.PackageNotFoundError:
|
57
|
+
print(f"{package_name} is not installed")
|
58
|
+
|
59
|
+
|
60
|
+
def init(
|
61
|
+
resolution: tuple[int, int],
|
62
|
+
flags: int = 0,
|
63
|
+
vsync: int = 0,
|
64
|
+
default_text_size=None,
|
65
|
+
default_font=None,
|
66
|
+
resource_path: str | None = None,
|
67
|
+
window_title: str = "BatFramework Project",
|
68
|
+
fps_limit: int = 0,
|
69
|
+
):
|
70
|
+
print_version()
|
71
|
+
pygame.display.set_caption(window_title)
|
72
|
+
init_screen(resolution, flags, vsync)
|
73
|
+
|
74
|
+
ResourceManager().set_resource_path(
|
75
|
+
resource_path if resource_path is not None else "."
|
76
|
+
)
|
77
|
+
if resource_path is not None:
|
78
|
+
ResourceManager().load_dir(ResourceManager().RESOURCE_PATH)
|
79
|
+
if default_text_size is not None:
|
80
|
+
FontManager().set_default_text_size(default_text_size)
|
81
|
+
FontManager().init_font(default_font)
|
82
|
+
const.BF_INITIALIZED = True
|
83
|
+
const.set_fps_limit(fps_limit)
|
@@ -0,0 +1,279 @@
|
|
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 set_consume_event(self, val: bool) -> Self:
|
28
|
+
"""
|
29
|
+
Set whether this action is unique (exclusive).
|
30
|
+
When in an action Container, unique actions -when active - break the propagation of their event to other actions.
|
31
|
+
|
32
|
+
Args:
|
33
|
+
val (bool): True if the action is unique, False otherwise.
|
34
|
+
"""
|
35
|
+
self.consume_event = val
|
36
|
+
return self
|
37
|
+
|
38
|
+
def set_active(self, value: bool) -> None:
|
39
|
+
"""
|
40
|
+
Set the action's active state.
|
41
|
+
|
42
|
+
Args:
|
43
|
+
value (bool): True to activate the action, False to deactivate it.
|
44
|
+
"""
|
45
|
+
self.active = value
|
46
|
+
# self._holding = set()
|
47
|
+
|
48
|
+
def add_event_control(self, *events) -> Self:
|
49
|
+
self._event_control.update(events)
|
50
|
+
return self
|
51
|
+
|
52
|
+
def remove_event_control(self, *events) -> Self:
|
53
|
+
self._event_control = self._event_control - events
|
54
|
+
return self
|
55
|
+
|
56
|
+
def add_key_control(self, *keys) -> Self:
|
57
|
+
"""
|
58
|
+
Add key controls to the action.
|
59
|
+
|
60
|
+
Args:
|
61
|
+
*keys (int): Key codes to control this action.
|
62
|
+
|
63
|
+
Returns:
|
64
|
+
Action: The updated Action object for method chaining.
|
65
|
+
"""
|
66
|
+
self._key_control.update(keys)
|
67
|
+
return self
|
68
|
+
|
69
|
+
def remove_key_control(self, *keys: int) -> Self:
|
70
|
+
"""
|
71
|
+
Remove key controls to the action.
|
72
|
+
|
73
|
+
Args:
|
74
|
+
*keys (int): Key codes to control this action.
|
75
|
+
|
76
|
+
Returns:
|
77
|
+
Action: The updated Action object for method chaining.
|
78
|
+
"""
|
79
|
+
self._key_control = self._key_control - set(keys)
|
80
|
+
return self
|
81
|
+
|
82
|
+
def replace_key_control(self, key, new_key) -> Self:
|
83
|
+
if not key in self._key_control:
|
84
|
+
return self
|
85
|
+
self.remove_key_control(key)
|
86
|
+
self.add_key_control(new_key)
|
87
|
+
return self
|
88
|
+
|
89
|
+
def add_mouse_control(self, *mouse: int) -> Self:
|
90
|
+
"""
|
91
|
+
Add mouse control to the action.
|
92
|
+
|
93
|
+
Args:
|
94
|
+
*mouse_buttons (int): Mouse button codes to control this action.
|
95
|
+
|
96
|
+
Returns:
|
97
|
+
Action: The updated Action object for method chaining.
|
98
|
+
"""
|
99
|
+
self._mouse_control.update(mouse)
|
100
|
+
return self
|
101
|
+
|
102
|
+
def remove_mouse_control(self, *mouse: int) -> Self:
|
103
|
+
self._mouse_control = self._mouse_control - set(mouse)
|
104
|
+
return self
|
105
|
+
|
106
|
+
def replace_mouse_control(self, mouse, new_mouse) -> Self:
|
107
|
+
if not mouse in self._mouse_control:
|
108
|
+
return self
|
109
|
+
self.remove_mouse_control(mouse)
|
110
|
+
self.add_mouse_control(new_mouse)
|
111
|
+
return self
|
112
|
+
|
113
|
+
def set_continuous(self) -> Self:
|
114
|
+
"""
|
115
|
+
Set the action type to continuous.
|
116
|
+
|
117
|
+
Returns:
|
118
|
+
Action: The updated Action object for method chaining.
|
119
|
+
"""
|
120
|
+
self._holding = set()
|
121
|
+
self._type = actionType.CONTINUOUS
|
122
|
+
return self
|
123
|
+
|
124
|
+
def is_continuous(self) -> bool:
|
125
|
+
"""
|
126
|
+
Check if the action type is continuous.
|
127
|
+
|
128
|
+
Returns:
|
129
|
+
bool: True if the action type is continuous, False otherwise.
|
130
|
+
"""
|
131
|
+
return self._type == actionType.CONTINUOUS
|
132
|
+
|
133
|
+
def set_instantaneous(self) -> Self:
|
134
|
+
"""
|
135
|
+
Set the action type to instantaneous.
|
136
|
+
|
137
|
+
Returns:
|
138
|
+
Action: The updated Action object for method chaining.
|
139
|
+
"""
|
140
|
+
self._type = actionType.INSTANTANEOUS
|
141
|
+
self._holding = set()
|
142
|
+
return self
|
143
|
+
|
144
|
+
def is_instantaneous(self) -> bool:
|
145
|
+
"""
|
146
|
+
Check if the action type is instantaneous.
|
147
|
+
|
148
|
+
Returns:
|
149
|
+
bool: True if the action type is instantaneous, False otherwise.
|
150
|
+
"""
|
151
|
+
return self._type == actionType.INSTANTANEOUS
|
152
|
+
|
153
|
+
def set_holding(self) -> Self:
|
154
|
+
"""
|
155
|
+
Set the action type to holding.
|
156
|
+
|
157
|
+
Returns:
|
158
|
+
Action: The updated Action object for method chaining.
|
159
|
+
"""
|
160
|
+
self._type = actionType.HOLDING
|
161
|
+
return self
|
162
|
+
|
163
|
+
def is_holding_type(self) -> bool:
|
164
|
+
"""
|
165
|
+
Check if the action type is holding.
|
166
|
+
|
167
|
+
Returns:
|
168
|
+
bool: True if the action type is holding, False otherwise.
|
169
|
+
"""
|
170
|
+
return self._type == actionType.HOLDING
|
171
|
+
|
172
|
+
def process_update(self, event: pygame.Event) -> None:
|
173
|
+
if (
|
174
|
+
event.type == pygame.MOUSEMOTION
|
175
|
+
and self._type == actionType.HOLDING
|
176
|
+
and pygame.MOUSEMOTION in self._mouse_control
|
177
|
+
) or self._event_control:
|
178
|
+
self.data = event.dict
|
179
|
+
|
180
|
+
def process_activate(self, event: pygame.event.Event):
|
181
|
+
"""
|
182
|
+
Process activation of the action based on a pygame event.
|
183
|
+
|
184
|
+
Args:
|
185
|
+
event (pygame.event.Event): The pygame event to process.
|
186
|
+
|
187
|
+
Returns:
|
188
|
+
bool: True if the action was activated by the event, False otherwise.
|
189
|
+
"""
|
190
|
+
|
191
|
+
if event.type == pygame.KEYDOWN and event.key in self._key_control:
|
192
|
+
self._activate_action(event.key)
|
193
|
+
|
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 == pygame.MOUSEMOTION and event.type in self._mouse_control:
|
200
|
+
self._activate_action(event.type)
|
201
|
+
|
202
|
+
elif event.type in self._event_control:
|
203
|
+
self._activate_action(event.type)
|
204
|
+
self.data = event.dict
|
205
|
+
else:
|
206
|
+
return
|
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 == pygame.MOUSEMOTION and event.type in self._mouse_control:
|
232
|
+
self._deactivate_action(event.type)
|
233
|
+
elif event.type in self._event_control:
|
234
|
+
self._deactivate_action(event.type)
|
235
|
+
else:
|
236
|
+
event.consumed = False
|
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()
|
@@ -0,0 +1,82 @@
|
|
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 clear(self):
|
15
|
+
self._actions = {}
|
16
|
+
|
17
|
+
def add_actions(self, *actions: bf.Action):
|
18
|
+
for action in actions:
|
19
|
+
self._actions[action.name] = action
|
20
|
+
|
21
|
+
def get(self, name: str) -> bf.Action:
|
22
|
+
return self._actions.get(name)
|
23
|
+
|
24
|
+
def has_action(self, name: str):
|
25
|
+
return name in self._actions
|
26
|
+
|
27
|
+
def get_all(self) -> list[bf.Action]:
|
28
|
+
return self._actions
|
29
|
+
|
30
|
+
def is_active(self, *names: str) -> bool:
|
31
|
+
return all(
|
32
|
+
self._actions.get(name).active if name in self._actions else False
|
33
|
+
for name in names
|
34
|
+
)
|
35
|
+
|
36
|
+
def process_event(self, event):
|
37
|
+
if event.consumed:
|
38
|
+
return
|
39
|
+
for action in self._actions.values():
|
40
|
+
action.process_event(event)
|
41
|
+
if event.consumed == True:
|
42
|
+
break
|
43
|
+
|
44
|
+
def reset(self):
|
45
|
+
for action in self._actions.values():
|
46
|
+
action.reset()
|
47
|
+
|
48
|
+
def hard_reset(self):
|
49
|
+
for action in self._actions.values():
|
50
|
+
action.hard_reset()
|
51
|
+
|
52
|
+
|
53
|
+
class DirectionalKeyControls(ActionContainer):
|
54
|
+
def __init__(self):
|
55
|
+
super().__init__(
|
56
|
+
bf.Action("up").add_key_control(pygame.K_UP).set_holding(),
|
57
|
+
bf.Action("down").add_key_control(pygame.K_DOWN).set_holding(),
|
58
|
+
bf.Action("left").add_key_control(pygame.K_LEFT).set_holding(),
|
59
|
+
bf.Action("right").add_key_control(pygame.K_RIGHT).set_holding(),
|
60
|
+
)
|
61
|
+
|
62
|
+
|
63
|
+
class WASDControls(ActionContainer):
|
64
|
+
def __init__(self):
|
65
|
+
super().__init__(
|
66
|
+
bf.Action("up").add_key_control(pygame.K_w).set_holding(),
|
67
|
+
bf.Action("down").add_key_control(pygame.K_s).set_holding(),
|
68
|
+
bf.Action("left").add_key_control(pygame.K_a).set_holding(),
|
69
|
+
bf.Action("right").add_key_control(pygame.K_d).set_holding(),
|
70
|
+
)
|
71
|
+
|
72
|
+
|
73
|
+
class HybridControls(ActionContainer):
|
74
|
+
def __init__(self):
|
75
|
+
super().__init__(
|
76
|
+
bf.Action("up").add_key_control(pygame.K_UP, pygame.K_w).set_holding(),
|
77
|
+
bf.Action("down").add_key_control(pygame.K_DOWN, pygame.K_s).set_holding(),
|
78
|
+
bf.Action("left").add_key_control(pygame.K_LEFT, pygame.K_a).set_holding(),
|
79
|
+
bf.Action("right")
|
80
|
+
.add_key_control(pygame.K_RIGHT, pygame.K_r)
|
81
|
+
.set_holding(),
|
82
|
+
)
|