batframework 1.1.0__tar.gz → 2.0.0a1__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.0a1}/LICENSE +20 -20
- {batframework-1.1.0 → batframework-2.0.0a1}/PKG-INFO +7 -2
- {batframework-1.1.0 → batframework-2.0.0a1}/README.md +36 -36
- batframework-2.0.0a1/pyproject.toml +25 -0
- batframework-2.0.0a1/src/batFramework/__init__.py +98 -0
- batframework-2.0.0a1/src/batFramework/action.py +280 -0
- batframework-2.0.0a1/src/batFramework/actionContainer.py +105 -0
- batframework-2.0.0a1/src/batFramework/animatedSprite.py +81 -0
- batframework-2.0.0a1/src/batFramework/animation.py +91 -0
- batframework-2.0.0a1/src/batFramework/audioManager.py +156 -0
- batframework-2.0.0a1/src/batFramework/baseScene.py +249 -0
- batframework-2.0.0a1/src/batFramework/camera.py +245 -0
- batframework-2.0.0a1/src/batFramework/constants.py +57 -0
- batframework-2.0.0a1/src/batFramework/cutscene.py +239 -0
- batframework-2.0.0a1/src/batFramework/cutsceneManager.py +34 -0
- batframework-2.0.0a1/src/batFramework/drawable.py +107 -0
- batframework-2.0.0a1/src/batFramework/dynamicEntity.py +30 -0
- batframework-2.0.0a1/src/batFramework/easingController.py +58 -0
- batframework-2.0.0a1/src/batFramework/entity.py +130 -0
- batframework-2.0.0a1/src/batFramework/enums.py +171 -0
- batframework-2.0.0a1/src/batFramework/fontManager.py +65 -0
- batframework-2.0.0a1/src/batFramework/gui/__init__.py +28 -0
- batframework-2.0.0a1/src/batFramework/gui/animatedLabel.py +90 -0
- batframework-2.0.0a1/src/batFramework/gui/button.py +18 -0
- batframework-2.0.0a1/src/batFramework/gui/clickableWidget.py +244 -0
- batframework-2.0.0a1/src/batFramework/gui/collapseContainer.py +98 -0
- batframework-2.0.0a1/src/batFramework/gui/constraints/__init__.py +1 -0
- batframework-2.0.0a1/src/batFramework/gui/constraints/constraints.py +1066 -0
- batframework-2.0.0a1/src/batFramework/gui/container.py +220 -0
- batframework-2.0.0a1/src/batFramework/gui/debugger.py +140 -0
- batframework-2.0.0a1/src/batFramework/gui/draggableWidget.py +63 -0
- batframework-2.0.0a1/src/batFramework/gui/image.py +61 -0
- batframework-2.0.0a1/src/batFramework/gui/indicator.py +116 -0
- batframework-2.0.0a1/src/batFramework/gui/interactiveWidget.py +243 -0
- batframework-2.0.0a1/src/batFramework/gui/label.py +147 -0
- batframework-2.0.0a1/src/batFramework/gui/layout.py +442 -0
- batframework-2.0.0a1/src/batFramework/gui/meter.py +155 -0
- batframework-2.0.0a1/src/batFramework/gui/radioButton.py +43 -0
- batframework-2.0.0a1/src/batFramework/gui/root.py +228 -0
- batframework-2.0.0a1/src/batFramework/gui/scrollingContainer.py +282 -0
- batframework-2.0.0a1/src/batFramework/gui/selector.py +232 -0
- batframework-2.0.0a1/src/batFramework/gui/shape.py +286 -0
- batframework-2.0.0a1/src/batFramework/gui/slider.py +353 -0
- batframework-2.0.0a1/src/batFramework/gui/style.py +10 -0
- batframework-2.0.0a1/src/batFramework/gui/styleManager.py +49 -0
- batframework-2.0.0a1/src/batFramework/gui/syncedVar.py +43 -0
- batframework-2.0.0a1/src/batFramework/gui/textInput.py +331 -0
- batframework-2.0.0a1/src/batFramework/gui/textWidget.py +308 -0
- batframework-2.0.0a1/src/batFramework/gui/toggle.py +140 -0
- batframework-2.0.0a1/src/batFramework/gui/tooltip.py +35 -0
- batframework-2.0.0a1/src/batFramework/gui/widget.py +546 -0
- batframework-2.0.0a1/src/batFramework/manager.py +131 -0
- batframework-2.0.0a1/src/batFramework/particle.py +118 -0
- batframework-2.0.0a1/src/batFramework/propertyEaser.py +79 -0
- batframework-2.0.0a1/src/batFramework/renderGroup.py +34 -0
- batframework-2.0.0a1/src/batFramework/resourceManager.py +130 -0
- batframework-2.0.0a1/src/batFramework/scene.py +31 -0
- batframework-2.0.0a1/src/batFramework/sceneLayer.py +134 -0
- batframework-2.0.0a1/src/batFramework/sceneManager.py +200 -0
- batframework-2.0.0a1/src/batFramework/scrollingSprite.py +115 -0
- batframework-2.0.0a1/src/batFramework/sprite.py +46 -0
- {batframework-1.1.0 → batframework-2.0.0a1}/src/batFramework/stateMachine.py +49 -51
- batframework-2.0.0a1/src/batFramework/templates/__init__.py +2 -0
- batframework-2.0.0a1/src/batFramework/templates/character.py +15 -0
- batframework-2.0.0a1/src/batFramework/templates/controller.py +158 -0
- batframework-2.0.0a1/src/batFramework/templates/stateMachine.py +39 -0
- batframework-2.0.0a1/src/batFramework/tileset.py +46 -0
- batframework-2.0.0a1/src/batFramework/timeManager.py +213 -0
- batframework-2.0.0a1/src/batFramework/transition.py +162 -0
- {batframework-1.1.0 → batframework-2.0.0a1}/src/batFramework/triggerZone.py +22 -22
- batframework-2.0.0a1/src/batFramework/utils.py +306 -0
- {batframework-1.1.0 → batframework-2.0.0a1}/src/batframework.egg-info/PKG-INFO +7 -2
- batframework-2.0.0a1/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.0a1}/setup.cfg +0 -0
- {batframework-1.1.0 → batframework-2.0.0a1}/src/batframework.egg-info/dependency_links.txt +0 -0
- {batframework-1.1.0 → batframework-2.0.0a1}/src/batframework.egg-info/requires.txt +0 -0
- {batframework-1.1.0 → batframework-2.0.0a1}/src/batframework.egg-info/top_level.txt +0 -0
@@ -1,21 +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
|
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
21
|
SOFTWARE.
|
@@ -1,7 +1,8 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: batframework
|
3
|
-
Version:
|
3
|
+
Version: 2.0.0a1
|
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,10 @@ 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
|
+
Project-URL: Homepage, https://github.com/TuranBaturay/batFramework
|
28
|
+
Classifier: Programming Language :: Python :: 3
|
29
|
+
Classifier: License :: OSI Approved :: MIT License
|
30
|
+
Classifier: Operating System :: OS Independent
|
26
31
|
Requires-Python: >=3.11
|
27
32
|
Description-Content-Type: text/markdown
|
28
33
|
License-File: LICENSE
|
@@ -30,7 +35,7 @@ Requires-Dist: pygame-ce
|
|
30
35
|
|
31
36
|
# batFramework
|
32
37
|
|
33
|
-
batFramework is a Python game framework built using Pygame, designed to simplify game development
|
38
|
+
batFramework is a Python game framework built using Pygame, designed to simplify game development.
|
34
39
|
|
35
40
|
## Purpose and Overview
|
36
41
|
The primary objective of batFramework is to streamline game development. It is mainly designed to program small 2D games
|
@@ -1,36 +1,36 @@
|
|
1
|
-
# batFramework
|
2
|
-
|
3
|
-
batFramework is a Python game framework built using Pygame, designed to simplify game development
|
4
|
-
|
5
|
-
## Purpose and Overview
|
6
|
-
The primary objective of batFramework is to streamline game development. It is mainly designed to program small 2D games
|
7
|
-
|
8
|
-
## Installation and Setup
|
9
|
-
To install batFramework, you can use pip:
|
10
|
-
```pip install batFramework```
|
11
|
-
|
12
|
-
The only dependency required is pygame-ce.
|
13
|
-
|
14
|
-
## Usage Instructions
|
15
|
-
To create a basic app using batFramework, here's an example:
|
16
|
-
|
17
|
-
```python
|
18
|
-
import batFramework as bf
|
19
|
-
|
20
|
-
# Initialize the framework
|
21
|
-
bf.init(resolution=(1280, 720), window_caption="My Amazing Program")
|
22
|
-
|
23
|
-
# Create a manager and a scene
|
24
|
-
bf.Manager(bf.Scene("main")).run()
|
25
|
-
```
|
26
|
-
In practice, users can inherit bf.Scene to create their own scenes, adding specific behaviors, entities, etc.
|
27
|
-
|
28
|
-
## Features and Functionalities
|
29
|
-
|
30
|
-
For more detailed information, please refer to the [documentation](https://batframework.github.io/batDocumentation/).
|
31
|
-
|
32
|
-
|
33
|
-
# License
|
34
|
-
MIT License
|
35
|
-
|
36
|
-
|
1
|
+
# batFramework
|
2
|
+
|
3
|
+
batFramework is a Python game framework built using Pygame, designed to simplify game development.
|
4
|
+
|
5
|
+
## Purpose and Overview
|
6
|
+
The primary objective of batFramework is to streamline game development. It is mainly designed to program small 2D games
|
7
|
+
|
8
|
+
## Installation and Setup
|
9
|
+
To install batFramework, you can use pip:
|
10
|
+
```pip install batFramework```
|
11
|
+
|
12
|
+
The only dependency required is pygame-ce.
|
13
|
+
|
14
|
+
## Usage Instructions
|
15
|
+
To create a basic app using batFramework, here's an example:
|
16
|
+
|
17
|
+
```python
|
18
|
+
import batFramework as bf
|
19
|
+
|
20
|
+
# Initialize the framework
|
21
|
+
bf.init(resolution=(1280, 720), window_caption="My Amazing Program")
|
22
|
+
|
23
|
+
# Create a manager and a scene
|
24
|
+
bf.Manager(bf.Scene("main")).run()
|
25
|
+
```
|
26
|
+
In practice, users can inherit bf.Scene to create their own scenes, adding specific behaviors, entities, etc.
|
27
|
+
|
28
|
+
## Features and Functionalities
|
29
|
+
|
30
|
+
For more detailed information, please refer to the [documentation](https://batframework.github.io/batDocumentation/).
|
31
|
+
|
32
|
+
|
33
|
+
# License
|
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.0a1"
|
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,98 @@
|
|
1
|
+
import pathlib
|
2
|
+
import tomllib
|
3
|
+
from importlib.metadata import version, PackageNotFoundError
|
4
|
+
|
5
|
+
import os
|
6
|
+
import pygame
|
7
|
+
import json
|
8
|
+
import batFramework as bf
|
9
|
+
from .constants import Constants as const
|
10
|
+
from .utils import Singleton
|
11
|
+
from .enums import *
|
12
|
+
from .resourceManager import ResourceManager
|
13
|
+
from .fontManager import FontManager
|
14
|
+
from .utils import Utils as utils
|
15
|
+
from .tileset import Tileset
|
16
|
+
from .timeManager import TimeManager,Timer,SceneTimer
|
17
|
+
from .easingController import EasingController
|
18
|
+
from .propertyEaser import PropertyEaser
|
19
|
+
from .cutsceneManager import CutsceneManager
|
20
|
+
import batFramework.cutscene as cutscene
|
21
|
+
from .audioManager import AudioManager
|
22
|
+
import batFramework.transition as transition
|
23
|
+
from .action import Action
|
24
|
+
from .actionContainer import *
|
25
|
+
from .camera import Camera
|
26
|
+
from .entity import Entity
|
27
|
+
from .drawable import Drawable
|
28
|
+
from .renderGroup import RenderGroup
|
29
|
+
from .dynamicEntity import DynamicEntity
|
30
|
+
from .sprite import Sprite
|
31
|
+
from .scrollingSprite import ScrollingSprite
|
32
|
+
from .particle import *
|
33
|
+
from .animation import Animation
|
34
|
+
from .animatedSprite import AnimatedSprite
|
35
|
+
from .stateMachine import State, StateMachine
|
36
|
+
from .sceneLayer import SceneLayer
|
37
|
+
from .scene import Scene
|
38
|
+
from .baseScene import BaseScene
|
39
|
+
import batFramework.gui as gui
|
40
|
+
from .sceneManager import SceneManager
|
41
|
+
from .manager import Manager
|
42
|
+
from .templates import *
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
def get_version() -> str:
|
47
|
+
try:
|
48
|
+
return version("batframework")
|
49
|
+
except PackageNotFoundError:
|
50
|
+
pyproject = pathlib.Path(__file__).resolve().parent.parent / "pyproject.toml"
|
51
|
+
if pyproject.exists():
|
52
|
+
with open(pyproject, "rb") as f:
|
53
|
+
data = tomllib.load(f)
|
54
|
+
return data["project"]["version"]
|
55
|
+
return "0.0.0"
|
56
|
+
|
57
|
+
__version__ = get_version()
|
58
|
+
|
59
|
+
def init_screen(resolution: tuple[int, int], flags: int = 0, vsync: int = 0):
|
60
|
+
const.set_resolution(resolution)
|
61
|
+
const.FLAGS = flags
|
62
|
+
const.VSYNC = vsync
|
63
|
+
const.SCREEN = pygame.display.set_mode(
|
64
|
+
const.RESOLUTION, const.FLAGS, vsync=const.VSYNC
|
65
|
+
)
|
66
|
+
print(
|
67
|
+
f"Window : {resolution[0]}x{resolution[1]}"
|
68
|
+
)
|
69
|
+
|
70
|
+
|
71
|
+
def print_version():
|
72
|
+
print(f"BatFramework version: {__version__}")
|
73
|
+
|
74
|
+
def init(
|
75
|
+
resolution: tuple[int, int],
|
76
|
+
flags: int = 0,
|
77
|
+
window_caption: str = "BatFramework Project",
|
78
|
+
resource_path: str | None = None,
|
79
|
+
default_font_size=None,
|
80
|
+
default_font=None,
|
81
|
+
fps_limit: int = 0,
|
82
|
+
vsync: int = 0,
|
83
|
+
):
|
84
|
+
print_version()
|
85
|
+
pygame.display.set_caption(window_caption)
|
86
|
+
init_screen(resolution, flags, vsync)
|
87
|
+
pygame.mixer.init()
|
88
|
+
|
89
|
+
ResourceManager().set_resource_path(
|
90
|
+
resource_path if resource_path is not None else "."
|
91
|
+
)
|
92
|
+
if resource_path is not None:
|
93
|
+
ResourceManager().load_resources(ResourceManager().RESOURCE_PATH)
|
94
|
+
if default_font_size is not None:
|
95
|
+
FontManager().set_default_text_size(default_font_size)
|
96
|
+
FontManager().init_font(default_font)
|
97
|
+
const.BF_INITIALIZED = True
|
98
|
+
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
|
+
)
|