saltpaper 0.0.5a0__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 CHANGED
@@ -2,5 +2,5 @@ from saltpaper.services import *
2
2
  from saltpaper.functions import *
3
3
  from saltpaper.worldsystem.world import World
4
4
 
5
- SALTPAPER_VER = "0.0.5 (pre-alpha)"
5
+ SALTPAPER_VER = "0.0.6 (pre-alpha)"
6
6
  print(f"saltPAPER {SALTPAPER_VER}")
@@ -1,3 +1,2 @@
1
1
  from .test import make_test_entity
2
- from .spawn import *
3
2
  from .vectortools import VectorTools
@@ -1,6 +1,11 @@
1
1
  from saltpaper.worldsystem.entity import Entity
2
2
  from saltpaper.worldsystem.components import Position, Sprite
3
3
 
4
+ from typing import TYPE_CHECKING
5
+
6
+ if TYPE_CHECKING:
7
+ from saltpaper import Event, Layer, World, AssetService
8
+
4
9
  def make_display_entity(world, layer, position, asset_id) -> Entity:
5
10
 
6
11
  ent = Entity(world)
@@ -8,4 +13,26 @@ def make_display_entity(world, layer, position, asset_id) -> Entity:
8
13
  sprite = Sprite(asset_id)
9
14
  ent.add_many(position, sprite)
10
15
 
11
- return ent
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
+
@@ -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 .inputservice import Event
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
@@ -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,11 @@
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
- import pygame._sdl2.video as sdl_video
7
+
8
+ from saltpaper.services.event import Event
17
9
 
18
10
  KEY_VALUE_TO_NAME = {
19
11
  value: name
@@ -57,43 +49,6 @@ if __name__ == "__main__":
57
49
  for item in MOUSE_VALUE_TO_NAME.values():
58
50
  f.write(f"{item}\n")
59
51
 
60
- class Criteria():
61
- @staticmethod
62
- def on_press(f):
63
- return True if f==1 else False
64
-
65
- @staticmethod
66
- def on_held(f):
67
- return True if f>0 else False
68
-
69
- @staticmethod
70
- def on_release(f):
71
- return True if f==-1 else False
72
-
73
- @staticmethod
74
- def make_on_held_interval(x):
75
- def on_held_interval(f):
76
- return True if f % x == 0 else False
77
- return on_held_interval
78
-
79
- class Event():
80
- def __init__(
81
- self,
82
- triggers: str | list,
83
- criteria: Callable,
84
- callback: Callable,
85
- args: list = None,
86
- priority: int = 0,
87
- eat_trigger: bool = False
88
- ):
89
- self.triggers = triggers if isinstance(triggers, list) else [triggers]
90
- self.criteria = criteria
91
- self.callback = callback
92
- self.args = args if args else []
93
- self.priority = priority
94
- self.eat_trigger = eat_trigger
95
-
96
-
97
52
  class InputService():
98
53
  def __init__(self):
99
54
  self.gamepad = None
@@ -1,2 +1,3 @@
1
1
  from .position import Position
2
- from .sprite import Sprite
2
+ from .sprite import Sprite
3
+ from .clickable import Clickable
@@ -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)
@@ -3,13 +3,13 @@ class Position():
3
3
  self,
4
4
  layer:int=0,
5
5
  position:tuple[int,int]=(0,0),
6
+ width:int=0,
6
7
  height:int=0,
7
- width:int=0
8
8
  ):
9
9
  self.layer = layer
10
10
  self.position = position
11
- self.height = height
12
11
  self.width = width
12
+ self.height = height
13
13
 
14
14
  @property
15
15
  def x(self):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: saltpaper
3
- Version: 0.0.5a0
3
+ Version: 0.0.6a0
4
4
  Summary: A small game-engine/framework built on top of pygame
5
5
  Author-email: Lauren Kinder <mail@hermod.uk>
6
6
  License-Expression: MIT
@@ -1,4 +1,4 @@
1
- saltpaper/__init__.py,sha256=LrY78Ej9y8JGqZOdjYKMsydpIYJzZy9AgAMsPG5rTWE,185
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
@@ -7,24 +7,26 @@ saltpaper/assets/music/catacomb.wav,sha256=Rx3u6xe2YnST9c7KKJ6seF9bG6rJyC683Sc6j
7
7
  saltpaper/assets/tilemaps/test.aseprite,sha256=ZmWh2Ima2Lha5t4kjgNMsnlCamBNEKUsO547Hhtoa2w,416
8
8
  saltpaper/assets/tilemaps/test.png,sha256=Q2LU88aK3DOLHrXBjuT86ZJTP_ckODwo1g5Pe9Jut7g,927
9
9
  saltpaper/assets/tilemaps/test.yaml,sha256=8YWZeFfbxKxSK8MnEYxERjJIpSszMzRxp5lzGNl2yYw,220
10
- saltpaper/functions/__init__.py,sha256=aI9Lkm4SRTeWn40xEh9nfuN-b-jq9ImleO-ky690z8w,92
11
- saltpaper/functions/spawn.py,sha256=YRvnuEImANzvuB872k5D1VwivG5cfGQEkcbJwmvqHso,330
10
+ saltpaper/functions/__init__.py,sha256=seVutHUkY36p2YR6oMHmh4RA9ofWhpMKjVxCl-YNxVA,71
11
+ saltpaper/functions/spawn.py,sha256=GVqLyglPhrQMPrZd1rka-u3WBLDbBAr1GsgEXnw8Ne4,1115
12
12
  saltpaper/functions/test.py,sha256=sNpRCjy1CrMrlHv770RTtN6iDwB3Hq7-rKdKaTi3b8s,323
13
- saltpaper/functions/vectortools.py,sha256=I2ok4i0kZqGq5YXgY1nLblgA14mnlC53D2BBSHrbsHM,752
14
- saltpaper/services/__init__.py,sha256=Sseu7zdeaB3InIIcs5DIRFK4hhGBqxwvTQaAQP8ksaw,292
13
+ saltpaper/functions/vectortools.py,sha256=Isr4NdXTxwlxKbzvBdgEzKUAd0dsmN6b6eeYyt-bLiw,963
14
+ saltpaper/services/__init__.py,sha256=MVY4sPLsWzIQGgcxOqot5aCwzgdoZWyuFq1U0gJEsh4,278
15
15
  saltpaper/services/assetservice.py,sha256=KqVD9UXnDB8JUH4XjTcdRBQkFeSPEcijXiSQHYnAlxw,2133
16
16
  saltpaper/services/displayservice.py,sha256=NzBmzuaVMcygNv2HnEJZDU5AqV3I_9giGGybvcu2sgY,2999
17
- saltpaper/services/inputservice.py,sha256=MRIbdwspCw4hS1zVy2VI7_n2UY0Vp9H6omKZK3yCBnE,5131
17
+ saltpaper/services/event.py,sha256=F5itHUv1TSOl17raaDcjbMNAtBuFdNwCY6zwc_VN9Qc,1194
18
+ saltpaper/services/inputservice.py,sha256=3Y3WkE4DGyY6zk379C0_DTmqwoyM5lPmBKpAkuzhBZQ,3973
18
19
  saltpaper/services/layer.py,sha256=eIDzZmt1CwjbApnzGsGkM-rJQ-TXmBF-6ho_hNSCPGc,3339
19
20
  saltpaper/services/renderservice.py,sha256=jwhnWoa1a_mHXkoHnK-wREGR0cIBKkGf-pVythHkU1E,1250
20
21
  saltpaper/services/stateservice.py,sha256=KviqdOkEgZyOiwadOz1nn5QB4jdHUwbGYf355NcqkhM,287
21
22
  saltpaper/worldsystem/entity.py,sha256=bRyFMfHblzMwzo81YshDkDjvpMXZrEVrvWjgXtdlS5c,987
22
23
  saltpaper/worldsystem/world.py,sha256=-8ckweO6pcwaLb42PGKPveuuHNeR_o0cVqUDFcEt93w,442
23
- saltpaper/worldsystem/components/__init__.py,sha256=ZYfSsWkkqC-Dkl9QwAjPBydca7ifBzxEhG9_OOcMgRs,57
24
- saltpaper/worldsystem/components/position.py,sha256=QIJHVc8r1i0KhBBJdAN1dnlPky_8AWkpRJWLvBrGKo0,618
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
25
27
  saltpaper/worldsystem/components/sprite.py,sha256=pQHkyNNKv_iy33LLbqZlOXTU-dqoPzFX7ojjYMOH_BY,102
26
- saltpaper-0.0.5a0.dist-info/licenses/LICENSE,sha256=Fh0aFC8RSdix3JzjFyLJ3IuzsD1FfsbGFkyqDj5qvXQ,1075
27
- saltpaper-0.0.5a0.dist-info/METADATA,sha256=6X29jU0N0cGWwRUshm1uhiiVNMDKsK9bAenhvtuv8u0,646
28
- saltpaper-0.0.5a0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
29
- saltpaper-0.0.5a0.dist-info/top_level.txt,sha256=JACZnZhYYkgmdSz3T1JXacHS4L0UM6NbeReLoNLu6jw,10
30
- saltpaper-0.0.5a0.dist-info/RECORD,,
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,,