saltpaper 0.0.4a0__py3-none-any.whl → 0.0.6a0__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.
- saltpaper/__init__.py +1 -1
- saltpaper/functions/spawn.py +38 -0
- saltpaper/functions/vectortools.py +7 -1
- saltpaper/services/__init__.py +3 -3
- saltpaper/services/assetservice.py +6 -1
- saltpaper/services/event.py +45 -0
- saltpaper/services/inputservice.py +2 -36
- saltpaper/worldsystem/components/__init__.py +2 -1
- saltpaper/worldsystem/components/clickable.py +27 -0
- saltpaper/worldsystem/components/position.py +10 -8
- {saltpaper-0.0.4a0.dist-info → saltpaper-0.0.6a0.dist-info}/METADATA +1 -1
- {saltpaper-0.0.4a0.dist-info → saltpaper-0.0.6a0.dist-info}/RECORD +15 -12
- {saltpaper-0.0.4a0.dist-info → saltpaper-0.0.6a0.dist-info}/WHEEL +0 -0
- {saltpaper-0.0.4a0.dist-info → saltpaper-0.0.6a0.dist-info}/licenses/LICENSE +0 -0
- {saltpaper-0.0.4a0.dist-info → saltpaper-0.0.6a0.dist-info}/top_level.txt +0 -0
saltpaper/__init__.py
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from saltpaper.worldsystem.entity import Entity
|
|
2
|
+
from saltpaper.worldsystem.components import Position, Sprite
|
|
3
|
+
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from saltpaper import Event, Layer, World, AssetService
|
|
8
|
+
|
|
9
|
+
def make_display_entity(world, layer, position, asset_id) -> Entity:
|
|
10
|
+
|
|
11
|
+
ent = Entity(world)
|
|
12
|
+
position = Position(layer, position)
|
|
13
|
+
sprite = Sprite(asset_id)
|
|
14
|
+
ent.add_many(position, sprite)
|
|
15
|
+
|
|
16
|
+
return ent
|
|
17
|
+
|
|
18
|
+
def make_button(
|
|
19
|
+
world: 'World',
|
|
20
|
+
assetservice:'AssetService',
|
|
21
|
+
layer:'Layer',
|
|
22
|
+
position:tuple[int,int],
|
|
23
|
+
asset_id:str,
|
|
24
|
+
event:'Event',
|
|
25
|
+
eat_trigger:bool=True
|
|
26
|
+
) -> tuple[Entity, 'Event']:
|
|
27
|
+
from saltpaper.worldsystem.components import Clickable
|
|
28
|
+
|
|
29
|
+
ent = Entity(world)
|
|
30
|
+
asset_dims = assetservice.get_asset(asset_id).get_size()
|
|
31
|
+
position_obj = Position(layer, position, *asset_dims)
|
|
32
|
+
bounds = (*position, *asset_dims)
|
|
33
|
+
sprite = Sprite(asset_id)
|
|
34
|
+
event.eat_trigger = eat_trigger
|
|
35
|
+
clickable = Clickable(event, layer, bounds)
|
|
36
|
+
|
|
37
|
+
ent.add_many(position_obj, sprite, clickable)
|
|
38
|
+
return ent, event
|
|
@@ -25,4 +25,10 @@ class VectorTools:
|
|
|
25
25
|
return (
|
|
26
26
|
ax + (bx - ax) * progress,
|
|
27
27
|
ay + (by - ay) * progress
|
|
28
|
-
)
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
@staticmethod
|
|
31
|
+
def is_point_inside(point:tuple[int,int], x:int, y:int, width:int, height:int) -> bool:
|
|
32
|
+
px, py = point
|
|
33
|
+
return (x <= px < x + width) and (y <= py < y + height)
|
|
34
|
+
|
saltpaper/services/__init__.py
CHANGED
|
@@ -2,7 +2,7 @@ from .assetservice import AssetService
|
|
|
2
2
|
from .displayservice import DisplayService
|
|
3
3
|
from .layer import Layer
|
|
4
4
|
from .inputservice import InputService
|
|
5
|
-
from .
|
|
6
|
-
from .inputservice import Criteria
|
|
5
|
+
from .event import Criteria
|
|
7
6
|
from .renderservice import RenderService
|
|
8
|
-
from .stateservice import StateService
|
|
7
|
+
from .stateservice import StateService
|
|
8
|
+
from .event import Event
|
|
@@ -12,10 +12,12 @@ filetypes = {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
class AssetService():
|
|
15
|
-
def __init__(self):
|
|
15
|
+
def __init__(self, assets_folder_path):
|
|
16
16
|
self.cache = {}
|
|
17
17
|
self.roots = []
|
|
18
18
|
|
|
19
|
+
self.set_assets_folder(assets_folder_path)
|
|
20
|
+
|
|
19
21
|
def set_assets_folder(self, path):
|
|
20
22
|
path = Path(path)
|
|
21
23
|
self.roots.append(path)
|
|
@@ -41,6 +43,9 @@ class AssetService():
|
|
|
41
43
|
self.cache[id] = asset
|
|
42
44
|
return asset
|
|
43
45
|
|
|
46
|
+
if id == "image_missing":
|
|
47
|
+
raise FileNotFoundError(f"No /image/missing.png is set")
|
|
48
|
+
|
|
44
49
|
print(
|
|
45
50
|
f"asset not found: '{id}' (type='{kind}', name='{name}'). "
|
|
46
51
|
f"tried locations:" + '\n'.join(searched) + "\n",
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from typing import Callable
|
|
2
|
+
|
|
3
|
+
class Event():
|
|
4
|
+
def __init__(
|
|
5
|
+
self,
|
|
6
|
+
triggers: str | list,
|
|
7
|
+
criteria: Callable,
|
|
8
|
+
callback: Callable,
|
|
9
|
+
args: list = None,
|
|
10
|
+
priority: int = 0,
|
|
11
|
+
eat_trigger: bool = False
|
|
12
|
+
):
|
|
13
|
+
self.triggers = triggers if isinstance(triggers, list) else [triggers]
|
|
14
|
+
self.criteria = criteria
|
|
15
|
+
self.callback = callback
|
|
16
|
+
self.args = args if args else []
|
|
17
|
+
self.priority = priority
|
|
18
|
+
self.eat_trigger = eat_trigger
|
|
19
|
+
|
|
20
|
+
class Criteria():
|
|
21
|
+
@staticmethod
|
|
22
|
+
def on_press(f):
|
|
23
|
+
return True if f==1 else False
|
|
24
|
+
|
|
25
|
+
@staticmethod
|
|
26
|
+
def on_held(f):
|
|
27
|
+
return True if f>0 else False
|
|
28
|
+
|
|
29
|
+
@staticmethod
|
|
30
|
+
def on_release(f):
|
|
31
|
+
return True if f==-1 else False
|
|
32
|
+
|
|
33
|
+
@staticmethod
|
|
34
|
+
def make_on_held_interval(x):
|
|
35
|
+
def on_held_interval(f):
|
|
36
|
+
return True if f % x == 0 else False
|
|
37
|
+
return on_held_interval
|
|
38
|
+
|
|
39
|
+
@staticmethod
|
|
40
|
+
def make_combined_criteria(func_a, func_b) -> bool:
|
|
41
|
+
def combined_criteria(f):
|
|
42
|
+
truth = func_a(f) and func_b(f)
|
|
43
|
+
return truth
|
|
44
|
+
return combined_criteria
|
|
45
|
+
|
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
# input mapping service
|
|
3
|
-
# initialises with a mapping dict of
|
|
4
|
-
# key trigger -> "event" (arbitrary string)
|
|
5
|
-
# i.e. K_up
|
|
6
1
|
import sys
|
|
7
2
|
from pathlib import Path
|
|
8
3
|
from typing import Callable
|
|
9
|
-
|
|
10
|
-
if __name__ == "__main__":
|
|
11
|
-
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
|
|
12
|
-
|
|
13
4
|
import pygame
|
|
14
5
|
import pygame.locals as pl
|
|
15
6
|
import pygame._sdl2.controller as ctrl
|
|
16
7
|
|
|
8
|
+
from saltpaper.services.event import Event
|
|
9
|
+
|
|
17
10
|
KEY_VALUE_TO_NAME = {
|
|
18
11
|
value: name
|
|
19
12
|
for name, value in vars(pl).items()
|
|
@@ -56,33 +49,6 @@ if __name__ == "__main__":
|
|
|
56
49
|
for item in MOUSE_VALUE_TO_NAME.values():
|
|
57
50
|
f.write(f"{item}\n")
|
|
58
51
|
|
|
59
|
-
class Criteria():
|
|
60
|
-
@staticmethod
|
|
61
|
-
def on_press(f):
|
|
62
|
-
return True if f==1 else False
|
|
63
|
-
|
|
64
|
-
@staticmethod
|
|
65
|
-
def on_held(f):
|
|
66
|
-
return True if f>0 else False
|
|
67
|
-
|
|
68
|
-
@staticmethod
|
|
69
|
-
def on_release(f):
|
|
70
|
-
return True if f==-1 else False
|
|
71
|
-
|
|
72
|
-
@staticmethod
|
|
73
|
-
def make_on_held_interval(x):
|
|
74
|
-
def on_held_interval(f):
|
|
75
|
-
return True if f % x == 0 else False
|
|
76
|
-
return on_held_interval
|
|
77
|
-
|
|
78
|
-
class Event():
|
|
79
|
-
def __init__(self, triggers: str | list, criteria: Callable, callback: Callable, args: list = None):
|
|
80
|
-
self.triggers = triggers if isinstance(triggers, list) else [triggers]
|
|
81
|
-
self.criteria = criteria
|
|
82
|
-
self.callback = callback
|
|
83
|
-
self.args = args if args else []
|
|
84
|
-
|
|
85
|
-
|
|
86
52
|
class InputService():
|
|
87
53
|
def __init__(self):
|
|
88
54
|
self.gamepad = None
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING
|
|
2
|
+
|
|
3
|
+
import pygame.mouse as mouse
|
|
4
|
+
from saltpaper.services.event import Criteria
|
|
5
|
+
from saltpaper.functions.vectortools import VectorTools
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from saltpaper import Event, Layer
|
|
9
|
+
|
|
10
|
+
class Clickable:
|
|
11
|
+
"""format bounds as x, y, width, height"""
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
event:'Event',
|
|
15
|
+
layer:'Layer',
|
|
16
|
+
bounds:list[int,int,int,int]
|
|
17
|
+
):
|
|
18
|
+
self.event = event
|
|
19
|
+
self.layer = layer
|
|
20
|
+
self.bounds = bounds
|
|
21
|
+
|
|
22
|
+
main_criteria = Criteria.make_combined_criteria(event.criteria, self.is_mouse_inside)
|
|
23
|
+
event.criteria = main_criteria
|
|
24
|
+
|
|
25
|
+
def is_mouse_inside(self, f):
|
|
26
|
+
rel_pos = self.layer.relative_coords(mouse.get_pos())
|
|
27
|
+
return VectorTools.is_point_inside(rel_pos, *self.bounds)
|
|
@@ -2,20 +2,22 @@ class Position():
|
|
|
2
2
|
def __init__(
|
|
3
3
|
self,
|
|
4
4
|
layer:int=0,
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
position:tuple[int,int]=(0,0),
|
|
6
|
+
width:int=0,
|
|
7
7
|
height:int=0,
|
|
8
|
-
width:int=0
|
|
9
8
|
):
|
|
10
9
|
self.layer = layer
|
|
11
|
-
self.
|
|
12
|
-
self.y = y
|
|
13
|
-
self.height = height
|
|
10
|
+
self.position = position
|
|
14
11
|
self.width = width
|
|
12
|
+
self.height = height
|
|
15
13
|
|
|
16
14
|
@property
|
|
17
|
-
def
|
|
18
|
-
return
|
|
15
|
+
def x(self):
|
|
16
|
+
return self.position[0]
|
|
17
|
+
|
|
18
|
+
@property
|
|
19
|
+
def y(self):
|
|
20
|
+
return self.position[1]
|
|
19
21
|
|
|
20
22
|
def set_layer(self, layer):
|
|
21
23
|
self.layer = layer
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
saltpaper/__init__.py,sha256=
|
|
1
|
+
saltpaper/__init__.py,sha256=Om10tKkLEB95vHgzS6Ktl_UOncKDkzoeDzUS5tRREyw,185
|
|
2
2
|
saltpaper/assets/.DS_Store,sha256=7-Z-79uIc0CMx4UUj3sSlYE6KAWyk5qlKRTLRnrq8N8,8196
|
|
3
3
|
saltpaper/assets/talk.wav,sha256=rRmMxGFBFGiU59VqfmhIcwdZfuYdY9fUdkv7Os7S3hU,30624
|
|
4
4
|
saltpaper/assets/fonts/LibertinusMono-Regular.ttf,sha256=q9MJTt9ehi35gD8LH8jgr66CFH2oyxsylV3nqPsIOPA,153120
|
|
@@ -8,22 +8,25 @@ saltpaper/assets/tilemaps/test.aseprite,sha256=ZmWh2Ima2Lha5t4kjgNMsnlCamBNEKUsO
|
|
|
8
8
|
saltpaper/assets/tilemaps/test.png,sha256=Q2LU88aK3DOLHrXBjuT86ZJTP_ckODwo1g5Pe9Jut7g,927
|
|
9
9
|
saltpaper/assets/tilemaps/test.yaml,sha256=8YWZeFfbxKxSK8MnEYxERjJIpSszMzRxp5lzGNl2yYw,220
|
|
10
10
|
saltpaper/functions/__init__.py,sha256=seVutHUkY36p2YR6oMHmh4RA9ofWhpMKjVxCl-YNxVA,71
|
|
11
|
+
saltpaper/functions/spawn.py,sha256=GVqLyglPhrQMPrZd1rka-u3WBLDbBAr1GsgEXnw8Ne4,1115
|
|
11
12
|
saltpaper/functions/test.py,sha256=sNpRCjy1CrMrlHv770RTtN6iDwB3Hq7-rKdKaTi3b8s,323
|
|
12
|
-
saltpaper/functions/vectortools.py,sha256=
|
|
13
|
-
saltpaper/services/__init__.py,sha256=
|
|
14
|
-
saltpaper/services/assetservice.py,sha256=
|
|
13
|
+
saltpaper/functions/vectortools.py,sha256=Isr4NdXTxwlxKbzvBdgEzKUAd0dsmN6b6eeYyt-bLiw,963
|
|
14
|
+
saltpaper/services/__init__.py,sha256=MVY4sPLsWzIQGgcxOqot5aCwzgdoZWyuFq1U0gJEsh4,278
|
|
15
|
+
saltpaper/services/assetservice.py,sha256=KqVD9UXnDB8JUH4XjTcdRBQkFeSPEcijXiSQHYnAlxw,2133
|
|
15
16
|
saltpaper/services/displayservice.py,sha256=NzBmzuaVMcygNv2HnEJZDU5AqV3I_9giGGybvcu2sgY,2999
|
|
16
|
-
saltpaper/services/
|
|
17
|
+
saltpaper/services/event.py,sha256=F5itHUv1TSOl17raaDcjbMNAtBuFdNwCY6zwc_VN9Qc,1194
|
|
18
|
+
saltpaper/services/inputservice.py,sha256=3Y3WkE4DGyY6zk379C0_DTmqwoyM5lPmBKpAkuzhBZQ,3973
|
|
17
19
|
saltpaper/services/layer.py,sha256=eIDzZmt1CwjbApnzGsGkM-rJQ-TXmBF-6ho_hNSCPGc,3339
|
|
18
20
|
saltpaper/services/renderservice.py,sha256=jwhnWoa1a_mHXkoHnK-wREGR0cIBKkGf-pVythHkU1E,1250
|
|
19
21
|
saltpaper/services/stateservice.py,sha256=KviqdOkEgZyOiwadOz1nn5QB4jdHUwbGYf355NcqkhM,287
|
|
20
22
|
saltpaper/worldsystem/entity.py,sha256=bRyFMfHblzMwzo81YshDkDjvpMXZrEVrvWjgXtdlS5c,987
|
|
21
23
|
saltpaper/worldsystem/world.py,sha256=-8ckweO6pcwaLb42PGKPveuuHNeR_o0cVqUDFcEt93w,442
|
|
22
|
-
saltpaper/worldsystem/components/__init__.py,sha256=
|
|
23
|
-
saltpaper/worldsystem/components/
|
|
24
|
+
saltpaper/worldsystem/components/__init__.py,sha256=ddkZE-SqWQouHwUdcrJUVj4VJymZAHmUvwVD7OFOq4c,90
|
|
25
|
+
saltpaper/worldsystem/components/clickable.py,sha256=m9hKGqYd7_V3vI-ek_gaYXLXXFA8kVT96hDAcPp3UUk,806
|
|
26
|
+
saltpaper/worldsystem/components/position.py,sha256=pTNQej1TnAuNDQkRtxtGAzSOWelzUw206oISySx4a7E,619
|
|
24
27
|
saltpaper/worldsystem/components/sprite.py,sha256=pQHkyNNKv_iy33LLbqZlOXTU-dqoPzFX7ojjYMOH_BY,102
|
|
25
|
-
saltpaper-0.0.
|
|
26
|
-
saltpaper-0.0.
|
|
27
|
-
saltpaper-0.0.
|
|
28
|
-
saltpaper-0.0.
|
|
29
|
-
saltpaper-0.0.
|
|
28
|
+
saltpaper-0.0.6a0.dist-info/licenses/LICENSE,sha256=Fh0aFC8RSdix3JzjFyLJ3IuzsD1FfsbGFkyqDj5qvXQ,1075
|
|
29
|
+
saltpaper-0.0.6a0.dist-info/METADATA,sha256=aH--BF8xBPrtCPQQQhXSWgo0Q4_Is_nHZ4dwdbpgWsY,646
|
|
30
|
+
saltpaper-0.0.6a0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
31
|
+
saltpaper-0.0.6a0.dist-info/top_level.txt,sha256=JACZnZhYYkgmdSz3T1JXacHS4L0UM6NbeReLoNLu6jw,10
|
|
32
|
+
saltpaper-0.0.6a0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|