mima-engine 0.2.2__py3-none-any.whl → 0.2.4__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.
Potentially problematic release.
This version of mima-engine might be problematic. Click here for more details.
- mima/__init__.py +4 -1
- mima/backend/pygame_assets.py +67 -9
- mima/backend/pygame_backend.py +5 -2
- mima/backend/pygame_events.py +210 -194
- mima/backend/touch_control_scheme_a.py +126 -0
- mima/backend/touch_control_scheme_b.py +132 -0
- mima/core/__init__.py +0 -0
- mima/{collision.py → core/collision.py} +45 -28
- mima/core/database.py +58 -0
- mima/{engine.py → core/engine.py} +51 -33
- mima/{mode_engine.py → core/mode_engine.py} +7 -6
- mima/{scene_engine.py → core/scene_engine.py} +3 -7
- mima/maps/template.py +31 -1
- mima/maps/tiled/tiled_object.py +1 -1
- mima/maps/tiled/tiled_tileset.py +10 -5
- mima/maps/tilemap.py +4 -10
- mima/maps/tileset.py +5 -4
- mima/objects/animated_sprite.py +79 -68
- mima/objects/creature.py +20 -7
- mima/objects/dynamic.py +3 -1
- mima/objects/effects/colorize_screen.py +9 -1
- mima/objects/effects/debug_box.py +11 -2
- mima/objects/effects/light.py +6 -1
- mima/objects/effects/show_sprite.py +17 -6
- mima/objects/effects/walking_on_grass.py +27 -13
- mima/objects/effects/walking_on_water.py +36 -31
- mima/objects/loader.py +6 -9
- mima/objects/projectile.py +15 -5
- mima/objects/sprite.py +8 -1
- mima/objects/world/color_gate.py +10 -15
- mima/objects/world/color_switch.py +18 -28
- mima/objects/world/container.py +32 -37
- mima/objects/world/floor_switch.py +22 -28
- mima/objects/world/gate.py +21 -24
- mima/objects/world/light_source.py +27 -32
- mima/objects/world/logic_gate.py +30 -37
- mima/objects/world/movable.py +106 -89
- mima/objects/world/oneway.py +63 -41
- mima/objects/world/pickup.py +81 -17
- mima/objects/world/switch.py +46 -35
- mima/objects/world/teleport.py +21 -22
- mima/scripts/commands/oneway_move.py +4 -3
- mima/scripts/commands/present_item.py +10 -10
- mima/types/graphic_state.py +1 -0
- mima/usables/item.py +28 -9
- mima/usables/weapon.py +28 -8
- mima/util/constants.py +3 -3
- mima/util/input_defaults.py +12 -0
- mima/util/runtime_config.py +8 -15
- mima/util/trading_item.py +4 -1
- mima/view/mima_mode.py +8 -2
- mima/view/mima_scene.py +6 -0
- mima/view/mima_window.py +91 -0
- {mima_engine-0.2.2.dist-info → mima_engine-0.2.4.dist-info}/METADATA +4 -4
- {mima_engine-0.2.2.dist-info → mima_engine-0.2.4.dist-info}/RECORD +57 -53
- {mima_engine-0.2.2.dist-info → mima_engine-0.2.4.dist-info}/WHEEL +1 -1
- {mima_engine-0.2.2.dist-info → mima_engine-0.2.4.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import time
|
|
2
|
+
|
|
3
|
+
import pygame
|
|
4
|
+
|
|
5
|
+
from ..types.keys import Key as K
|
|
6
|
+
from ..util.constants import DOUBLE_TAP_SPEED
|
|
7
|
+
from ..util.input_defaults import BUTTONS, DEFAULT_TOUCHSCREEN_MAP
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TouchControlSchemeA:
|
|
11
|
+
|
|
12
|
+
def __init__(self):
|
|
13
|
+
|
|
14
|
+
self._left_finger_tap_pos = 0.0
|
|
15
|
+
self._right_finger_tap_pos = 0.0
|
|
16
|
+
|
|
17
|
+
self._last_left_tap = 0.0
|
|
18
|
+
self._last_right_tap = 0.0
|
|
19
|
+
|
|
20
|
+
def handle_touch(self, event, width=1.0, height=1.0):
|
|
21
|
+
set_keys = []
|
|
22
|
+
unset_keys = []
|
|
23
|
+
|
|
24
|
+
tap_pos = pygame.Vector2(event.x * width, event.y * height)
|
|
25
|
+
|
|
26
|
+
if event.type == pygame.FINGERDOWN:
|
|
27
|
+
tap_time = time.time()
|
|
28
|
+
for key, area in DEFAULT_TOUCHSCREEN_MAP.items():
|
|
29
|
+
|
|
30
|
+
if (
|
|
31
|
+
area[0][0] <= event.x < area[1][0]
|
|
32
|
+
and area[0][1] <= event.y < area[1][1]
|
|
33
|
+
):
|
|
34
|
+
if key == K.P1_UP:
|
|
35
|
+
self._left_finger_tap_pos = tap_pos
|
|
36
|
+
if tap_time - self._last_left_tap < DOUBLE_TAP_SPEED:
|
|
37
|
+
# print("Left Double Tap")
|
|
38
|
+
set_keys.append(K.P1_SELECT)
|
|
39
|
+
self._last_left_tap = tap_time
|
|
40
|
+
elif key == K.P1_L:
|
|
41
|
+
set_keys.append(K.P1_L)
|
|
42
|
+
else:
|
|
43
|
+
set_keys.append(key)
|
|
44
|
+
self._right_finger_tap_pos = tap_pos
|
|
45
|
+
self._last_right_tap = tap_time
|
|
46
|
+
|
|
47
|
+
if event.type == pygame.FINGERUP:
|
|
48
|
+
# release = time.time()
|
|
49
|
+
# finger_dist = (finger_pos - self._left_finger_tap_pos).length()
|
|
50
|
+
|
|
51
|
+
if event.x < 0.5:
|
|
52
|
+
# print(f"Left Finger Up: {finger_pos}")
|
|
53
|
+
# if (
|
|
54
|
+
# SINGLE_TAP_MIN
|
|
55
|
+
# < release - self._last_left_tap
|
|
56
|
+
# < SINGLE_TAP_MAX
|
|
57
|
+
# ) and finger_dist < 2.5:
|
|
58
|
+
# print("Left Single Tap")
|
|
59
|
+
# # set_keys.append(K.START)
|
|
60
|
+
|
|
61
|
+
unset_keys.append(K.P1_SELECT)
|
|
62
|
+
unset_keys.append(K.P1_RIGHT)
|
|
63
|
+
unset_keys.append(K.P1_LEFT)
|
|
64
|
+
unset_keys.append(K.P1_UP)
|
|
65
|
+
unset_keys.append(K.P1_DOWN)
|
|
66
|
+
unset_keys.append(K.P1_L)
|
|
67
|
+
# print(
|
|
68
|
+
# f"Left Finger moved {finger_dist} "
|
|
69
|
+
# f"({release - self._last_left_tap} s)"
|
|
70
|
+
# )
|
|
71
|
+
else:
|
|
72
|
+
unset_keys.append(K.P1_START)
|
|
73
|
+
unset_keys.append(K.P1_A)
|
|
74
|
+
unset_keys.append(K.P1_B)
|
|
75
|
+
unset_keys.append(K.P1_Y)
|
|
76
|
+
unset_keys.append(K.P1_X)
|
|
77
|
+
unset_keys.append(K.P1_R)
|
|
78
|
+
|
|
79
|
+
if event.type == pygame.FINGERMOTION:
|
|
80
|
+
if event.x < 0.5:
|
|
81
|
+
vd = tap_pos - self._left_finger_tap_pos
|
|
82
|
+
unset_keys.append(K.P1_RIGHT)
|
|
83
|
+
unset_keys.append(K.P1_LEFT)
|
|
84
|
+
unset_keys.append(K.P1_UP)
|
|
85
|
+
unset_keys.append(K.P1_DOWN)
|
|
86
|
+
if abs(vd.x) > 2 * abs(vd.y):
|
|
87
|
+
# Horizontal
|
|
88
|
+
if vd.x > 5.0:
|
|
89
|
+
set_keys.append(K.P1_RIGHT)
|
|
90
|
+
unset_keys.append(K.P1_LEFT)
|
|
91
|
+
unset_keys.append(K.P1_UP)
|
|
92
|
+
unset_keys.append(K.P1_DOWN)
|
|
93
|
+
elif vd.x < -5.0:
|
|
94
|
+
set_keys.append(K.P1_LEFT)
|
|
95
|
+
unset_keys.append(K.P1_RIGHT)
|
|
96
|
+
unset_keys.append(K.P1_UP)
|
|
97
|
+
unset_keys.append(K.P1_DOWN)
|
|
98
|
+
elif abs(vd.x) * 2 < abs(vd.y):
|
|
99
|
+
# Vertical
|
|
100
|
+
if vd.y > 5.0:
|
|
101
|
+
unset_keys.append(K.P1_RIGHT)
|
|
102
|
+
unset_keys.append(K.P1_LEFT)
|
|
103
|
+
unset_keys.append(K.P1_UP)
|
|
104
|
+
set_keys.append(K.P1_DOWN)
|
|
105
|
+
elif vd.y < -5.0:
|
|
106
|
+
unset_keys.append(K.P1_LEFT)
|
|
107
|
+
unset_keys.append(K.P1_RIGHT)
|
|
108
|
+
set_keys.append(K.P1_UP)
|
|
109
|
+
unset_keys.append(K.P1_DOWN)
|
|
110
|
+
elif abs(vd.x) * 1.05 > abs(vd.y) or abs(vd.x) < 1.05 * abs(
|
|
111
|
+
vd.y
|
|
112
|
+
):
|
|
113
|
+
if vd.x < 0:
|
|
114
|
+
set_keys.append(K.P1_LEFT)
|
|
115
|
+
elif vd.x > 0:
|
|
116
|
+
set_keys.append(K.P1_RIGHT)
|
|
117
|
+
if vd.y < 0:
|
|
118
|
+
set_keys.append(K.P1_UP)
|
|
119
|
+
elif vd.y > 0:
|
|
120
|
+
set_keys.append(K.P1_DOWN)
|
|
121
|
+
self.vd = vd
|
|
122
|
+
|
|
123
|
+
return set_keys, unset_keys
|
|
124
|
+
|
|
125
|
+
def get_touch_state(self):
|
|
126
|
+
return {}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import time
|
|
2
|
+
|
|
3
|
+
import pygame
|
|
4
|
+
|
|
5
|
+
from ..types.keys import Key as K
|
|
6
|
+
from ..util.constants import DOUBLE_TAP_SPEED
|
|
7
|
+
from ..util.input_defaults import ALT_TOUCHSCREEN_MAP, BUTTONS
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TouchControlSchemeB:
|
|
11
|
+
|
|
12
|
+
def __init__(self):
|
|
13
|
+
|
|
14
|
+
self.move_start_pos = pygame.Vector2()
|
|
15
|
+
self.move_pos = pygame.Vector2()
|
|
16
|
+
self.move_sy = 0.0
|
|
17
|
+
self.move_px = 0.0
|
|
18
|
+
self.move_py = 0.0
|
|
19
|
+
self._left_finger_tap_pos = 0.0
|
|
20
|
+
self._right_finger_tap_pos = 0.0
|
|
21
|
+
|
|
22
|
+
self._last_left_tap = 0.0
|
|
23
|
+
self._last_right_tap = 0.0
|
|
24
|
+
self._keys_active = {k: False for k in K}
|
|
25
|
+
self._state = {}
|
|
26
|
+
for key, conf in ALT_TOUCHSCREEN_MAP.items():
|
|
27
|
+
px, py = conf["pos"]
|
|
28
|
+
w, h = conf["size"]
|
|
29
|
+
self._state[key] = {
|
|
30
|
+
"rpx": px,
|
|
31
|
+
"rpy": py,
|
|
32
|
+
"rwidth": w,
|
|
33
|
+
"rheight": h,
|
|
34
|
+
"active": False,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
def handle_touch(self, event, width=1.0, height=1.0):
|
|
38
|
+
set_keys = []
|
|
39
|
+
unset_keys = []
|
|
40
|
+
|
|
41
|
+
tap_pos = pygame.Vector2(event.x * width, event.y * height)
|
|
42
|
+
keys_active = {k: False for k in K}
|
|
43
|
+
# print(f"{event.x:.2f}, {event.y:.2f}", end="")
|
|
44
|
+
for key, conf in ALT_TOUCHSCREEN_MAP.items():
|
|
45
|
+
px, py = conf["pos"]
|
|
46
|
+
w, h = conf["size"]
|
|
47
|
+
area = [[px, py], [px + w, py + h]]
|
|
48
|
+
|
|
49
|
+
if (
|
|
50
|
+
area[0][0] <= event.x < area[1][0]
|
|
51
|
+
and area[0][1] <= event.y < area[1][1]
|
|
52
|
+
):
|
|
53
|
+
if key == K.P1_UP:
|
|
54
|
+
if event.type == pygame.FINGERDOWN:
|
|
55
|
+
self.move_start_pos = pygame.Vector2(tap_pos)
|
|
56
|
+
self.move_pos = pygame.Vector2(tap_pos)
|
|
57
|
+
self._state[key]["rsx"] = event.x
|
|
58
|
+
self._state[key]["rsy"] = event.y
|
|
59
|
+
self._state[key]["rpx"] = event.x
|
|
60
|
+
self._state[key]["rpy"] = event.y
|
|
61
|
+
elif event.type == pygame.FINGERMOTION:
|
|
62
|
+
self.move_pos = tap_pos
|
|
63
|
+
self._state[key]["rpx"] = event.x
|
|
64
|
+
self._state[key]["rpy"] = event.y
|
|
65
|
+
|
|
66
|
+
vd = self.move_pos - self.move_start_pos
|
|
67
|
+
if abs(vd.x) > 2 * abs(vd.y):
|
|
68
|
+
# Horizontal
|
|
69
|
+
if vd.x > 5.0:
|
|
70
|
+
keys_active[K.P1_RIGHT] = True
|
|
71
|
+
# print("..>", end="")
|
|
72
|
+
elif vd.x < -5.0:
|
|
73
|
+
keys_active[K.P1_LEFT] = True
|
|
74
|
+
# print("..<", end="")
|
|
75
|
+
elif abs(vd.x) * 2 < abs(vd.y):
|
|
76
|
+
# Vertical
|
|
77
|
+
if vd.y > 5.0:
|
|
78
|
+
keys_active[K.P1_DOWN] = True
|
|
79
|
+
# print("..v", end="")
|
|
80
|
+
elif vd.y < -5.0:
|
|
81
|
+
keys_active[K.P1_UP] = True
|
|
82
|
+
# print("..^", end="")
|
|
83
|
+
elif abs(vd.x) * 1.05 > abs(vd.y) or abs(
|
|
84
|
+
vd.x
|
|
85
|
+
) < 1.05 * abs(vd.y):
|
|
86
|
+
# Diagonal
|
|
87
|
+
if vd.x < 0:
|
|
88
|
+
keys_active[K.P1_LEFT] = True
|
|
89
|
+
# print("..<", end="")
|
|
90
|
+
elif vd.x > 0:
|
|
91
|
+
keys_active[K.P1_RIGHT] = True
|
|
92
|
+
# print("..>", end="")
|
|
93
|
+
if vd.y < 0:
|
|
94
|
+
keys_active[K.P1_UP] = True
|
|
95
|
+
# print("..^", end="")
|
|
96
|
+
elif vd.y > 0:
|
|
97
|
+
keys_active[K.P1_DOWN] = True
|
|
98
|
+
# print("..v", end="")
|
|
99
|
+
# elif event.type == pygame.FINGERUP:
|
|
100
|
+
# unset_keys.append(K.P1_RIGHT)
|
|
101
|
+
# unset_keys.append(K.P1_LEFT)
|
|
102
|
+
# unset_keys.append(K.P1_UP)
|
|
103
|
+
# unset_keys.append(K.P1_DOWN)
|
|
104
|
+
else:
|
|
105
|
+
if event.type == pygame.FINGERDOWN:
|
|
106
|
+
keys_active[key] = True
|
|
107
|
+
# print(f"..{key.name}", end="")
|
|
108
|
+
if event.type == pygame.FINGERMOTION:
|
|
109
|
+
keys_active[key] = True
|
|
110
|
+
# print(f"..{key.name}", end="")
|
|
111
|
+
# print()
|
|
112
|
+
for k, val in keys_active.items():
|
|
113
|
+
if val:
|
|
114
|
+
set_keys.append(k)
|
|
115
|
+
# self._state.setdefault(k, {})["active"] = True
|
|
116
|
+
if k in self._state:
|
|
117
|
+
self._state[k]["active"] = True
|
|
118
|
+
if k in [K.P1_LEFT, K.P1_RIGHT, K.P1_DOWN]:
|
|
119
|
+
self._state[K.P1_UP]["active"] = True
|
|
120
|
+
else:
|
|
121
|
+
unset_keys.append(k)
|
|
122
|
+
if k in self._state:
|
|
123
|
+
self._state[k]["active"] = False
|
|
124
|
+
return set_keys, unset_keys
|
|
125
|
+
|
|
126
|
+
def get_touch_state(self):
|
|
127
|
+
state = {}
|
|
128
|
+
for key, conf in self._state.items():
|
|
129
|
+
nkey = K(key.value - 12)
|
|
130
|
+
state[nkey] = conf
|
|
131
|
+
|
|
132
|
+
return state
|
mima/core/__init__.py
ADDED
|
File without changes
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import math
|
|
4
|
+
from itertools import product
|
|
4
5
|
from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Tuple
|
|
5
6
|
|
|
6
|
-
from
|
|
7
|
-
from
|
|
8
|
-
from
|
|
9
|
-
from
|
|
10
|
-
from
|
|
11
|
-
from
|
|
7
|
+
from ..maps.tilemap import Tilemap
|
|
8
|
+
from ..types.direction import Direction
|
|
9
|
+
from ..types.graphic_state import GraphicState, Until
|
|
10
|
+
from ..types.nature import Nature
|
|
11
|
+
from ..types.object import ObjectType
|
|
12
|
+
from ..types.tile_collision import TileCollision
|
|
12
13
|
|
|
13
14
|
if TYPE_CHECKING:
|
|
14
15
|
# from .engine import MimaEngine
|
|
15
|
-
from
|
|
16
|
-
from
|
|
16
|
+
from ..objects.dynamic import Dynamic
|
|
17
|
+
from ..states.quest import Quest
|
|
17
18
|
|
|
18
19
|
# from .view.view import View
|
|
19
20
|
|
|
@@ -248,34 +249,50 @@ def add_to_collision_chunk(
|
|
|
248
249
|
# collision_chunks[chidx].insert(0, obj)
|
|
249
250
|
# else:
|
|
250
251
|
# collision_chunks[chidx].append(obj)
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
collision_chunks, obj, obj.px, obj.py + 1, chunk_size, chunks_per_row
|
|
261
|
-
)
|
|
262
|
-
|
|
263
|
-
chunk_ids.append(chid)
|
|
264
|
-
if chid != chid_right:
|
|
265
|
-
chunk_ids.append(chid_right)
|
|
266
|
-
if chid != chid_bottom:
|
|
267
|
-
chunk_ids.append(chid_bottom)
|
|
268
|
-
if chid != chid_right and chid != chid_bottom:
|
|
252
|
+
centerx = obj.px + (obj.hitbox_px + obj.hitbox_width) / 2
|
|
253
|
+
centery = obj.py + (obj.hitbox_py + obj.hitbox_height) / 2
|
|
254
|
+
# chid = _test_chunk_position(
|
|
255
|
+
# collision_chunks, obj, centerx, centery, chunk_size, chunks_per_row
|
|
256
|
+
# )
|
|
257
|
+
offsets = [[0, 0]] + [
|
|
258
|
+
list(p) for p in product([-1, 0, 1], repeat=2) if p != (0, 0)
|
|
259
|
+
]
|
|
260
|
+
for x, y in offsets:
|
|
269
261
|
chunk_ids.append(
|
|
270
262
|
_test_chunk_position(
|
|
271
263
|
collision_chunks,
|
|
272
264
|
obj,
|
|
273
|
-
|
|
274
|
-
|
|
265
|
+
centerx + x,
|
|
266
|
+
centery + y,
|
|
275
267
|
chunk_size,
|
|
276
268
|
chunks_per_row,
|
|
277
269
|
)
|
|
278
270
|
)
|
|
271
|
+
chunk_ids = list(dict.fromkeys(chunk_ids))
|
|
272
|
+
# chid_right = _test_chunk_position(
|
|
273
|
+
# collision_chunks, obj, obj.px + 1, obj.py, chunk_size, chunks_per_row
|
|
274
|
+
# )
|
|
275
|
+
|
|
276
|
+
# chid_bottom = _test_chunk_position(
|
|
277
|
+
# collision_chunks, obj, obj.px, obj.py + 1, chunk_size, chunks_per_row
|
|
278
|
+
# )
|
|
279
|
+
|
|
280
|
+
# chunk_ids.append(chid)
|
|
281
|
+
# if chid != chid_right:
|
|
282
|
+
# chunk_ids.append(chid_right)
|
|
283
|
+
# if chid != chid_bottom:
|
|
284
|
+
# chunk_ids.append(chid_bottom)
|
|
285
|
+
# if chid != chid_right and chid != chid_bottom:
|
|
286
|
+
# chunk_ids.append(
|
|
287
|
+
# _test_chunk_position(
|
|
288
|
+
# collision_chunks,
|
|
289
|
+
# obj,
|
|
290
|
+
# obj.px + 1,
|
|
291
|
+
# obj.py + 1,
|
|
292
|
+
# chunk_size,
|
|
293
|
+
# chunks_per_row,
|
|
294
|
+
# )
|
|
295
|
+
# )
|
|
279
296
|
|
|
280
297
|
for chid in obj.chunks:
|
|
281
298
|
if (
|
mima/core/database.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from typing import TYPE_CHECKING, Any, Dict
|
|
5
|
+
|
|
6
|
+
from ..objects.animated_sprite import AnimatedSprite
|
|
7
|
+
from ..types.damage import Damage
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from .engine import MimaEngine
|
|
11
|
+
|
|
12
|
+
LOG = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Database:
|
|
16
|
+
engine: MimaEngine
|
|
17
|
+
|
|
18
|
+
def __init__(self):
|
|
19
|
+
self._cache = {}
|
|
20
|
+
self._known_locale = ""
|
|
21
|
+
self._active_sprites = []
|
|
22
|
+
|
|
23
|
+
def get_usable_data(self, usable_id) -> Dict[str, Any]:
|
|
24
|
+
if usable_id in self._cache:
|
|
25
|
+
return self._cache[usable_id]
|
|
26
|
+
|
|
27
|
+
data = {}
|
|
28
|
+
tpl = self.engine.assets.get_template(usable_id)
|
|
29
|
+
|
|
30
|
+
data["usable_id"] = tpl.get_string("usable_id")
|
|
31
|
+
data["name"] = tpl.get_string(f"display_name_{self.engine.rtc.locale}")
|
|
32
|
+
data["description"] = tpl.get_string(f"description_{self.engine.rtc.locale}")
|
|
33
|
+
data["sprite_name"] = tpl.get_string("sprite_name")
|
|
34
|
+
data["dtype"] = Damage[tpl.get_string("dtype", "body").upper()]
|
|
35
|
+
for pid, prop in tpl.properties.items():
|
|
36
|
+
if not pid.startswith("attr_"):
|
|
37
|
+
continue
|
|
38
|
+
_, attr = pid.split("_", 1)
|
|
39
|
+
data[attr] = tpl.get(pid)
|
|
40
|
+
# data["attr_price"] = tpl.get_int("attr_price")
|
|
41
|
+
# data["attr_swing_timer"] = tpl.get_float("attr_swing_timer")
|
|
42
|
+
# data["attr_damage"] = tpl.get_int("attr_damage")
|
|
43
|
+
# data["attr_health_cost"] = tpl.get_int("attr_health_cost")
|
|
44
|
+
# data["attr_magic_cost"] = tpl.get_int("attr_magic_cost")
|
|
45
|
+
# data["attr_stamina_cost"] = tpl.get_int("attr_stamina_cost")
|
|
46
|
+
# data["attr_bomb_cost"] = tpl.get_int("attr_bomb_cost")
|
|
47
|
+
# data["attr_arrow_cost"] = tpl.get_int("attr_arrow_cost")
|
|
48
|
+
|
|
49
|
+
self._cache[usable_id] = data
|
|
50
|
+
return data
|
|
51
|
+
|
|
52
|
+
def get_object_data(self, object_id) -> Dict[str, Any]:
|
|
53
|
+
return {}
|
|
54
|
+
|
|
55
|
+
def get_sprite(self, sprite_id):
|
|
56
|
+
sprite = AnimatedSprite(sprite_id)
|
|
57
|
+
self._active_sprites.append(sprite)
|
|
58
|
+
return sprite
|
|
@@ -4,32 +4,30 @@ import logging
|
|
|
4
4
|
from abc import ABC, abstractmethod
|
|
5
5
|
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
|
|
6
6
|
|
|
7
|
-
from
|
|
8
|
-
from
|
|
9
|
-
from
|
|
10
|
-
from
|
|
11
|
-
from
|
|
12
|
-
from
|
|
13
|
-
from
|
|
14
|
-
from
|
|
15
|
-
from
|
|
16
|
-
from
|
|
17
|
-
from
|
|
18
|
-
from
|
|
19
|
-
from
|
|
20
|
-
from
|
|
21
|
-
from
|
|
22
|
-
from
|
|
23
|
-
from
|
|
24
|
-
from
|
|
25
|
-
from .
|
|
26
|
-
from
|
|
27
|
-
from .
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
from .
|
|
31
|
-
|
|
32
|
-
# from .view.scene import Scene
|
|
7
|
+
from ..backend.pygame_assets import PygameAssets
|
|
8
|
+
from ..backend.pygame_audio import PygameAudio
|
|
9
|
+
from ..backend.pygame_backend import PygameBackend
|
|
10
|
+
from ..backend.pygame_events import PygameUserInput
|
|
11
|
+
from ..maps.template import Template
|
|
12
|
+
from ..maps.tilemap import Tilemap
|
|
13
|
+
from ..objects.animated_sprite import AnimatedSprite
|
|
14
|
+
from ..objects.creature import Creature
|
|
15
|
+
from ..objects.dynamic import Dynamic
|
|
16
|
+
from ..objects.loader import ObjectLoader
|
|
17
|
+
from ..objects.sprite import Sprite
|
|
18
|
+
from ..scripts import Command, ScriptProcessor
|
|
19
|
+
from ..states.memory import Memory
|
|
20
|
+
from ..states.quest import Quest
|
|
21
|
+
from ..types.gate_color import GateColor
|
|
22
|
+
from ..types.mode import Mode
|
|
23
|
+
from ..types.player import Player
|
|
24
|
+
from ..usables.item import Item
|
|
25
|
+
from ..usables.weapon import Weapon
|
|
26
|
+
from ..util import RuntimeConfig
|
|
27
|
+
from ..util.logging import install_trace_logger
|
|
28
|
+
from ..view.camera import Camera
|
|
29
|
+
from ..view.mima_view import MimaView
|
|
30
|
+
from .database import Database
|
|
33
31
|
|
|
34
32
|
if TYPE_CHECKING:
|
|
35
33
|
from .states.game_state import GameState
|
|
@@ -52,7 +50,7 @@ class MimaEngine(ABC):
|
|
|
52
50
|
self.backend: PygameBackend = PygameBackend(
|
|
53
51
|
self.rtc, init_file, platform
|
|
54
52
|
)
|
|
55
|
-
|
|
53
|
+
self.db: Database
|
|
56
54
|
self._caption: str = caption
|
|
57
55
|
self.seconds_total: float = 0.0
|
|
58
56
|
self.app_fps: float = 0.0
|
|
@@ -60,6 +58,9 @@ class MimaEngine(ABC):
|
|
|
60
58
|
self.elapsed_time: float = 0.00022
|
|
61
59
|
self._app_time: float = 0.0
|
|
62
60
|
|
|
61
|
+
self.enable_touch_controls: bool = False
|
|
62
|
+
self.show_touch_controls: bool = False
|
|
63
|
+
|
|
63
64
|
self.mode: Mode = Mode.LOADING
|
|
64
65
|
self.gate_color: GateColor = GateColor.RED
|
|
65
66
|
self.n_gate_colors = 2
|
|
@@ -67,9 +68,6 @@ class MimaEngine(ABC):
|
|
|
67
68
|
self.memory: Memory = Memory()
|
|
68
69
|
self.all_games: Dict[str, GameState] = {}
|
|
69
70
|
self.current_game: str = ""
|
|
70
|
-
# self.player: Creature
|
|
71
|
-
# self.quests: List[Quest] = []
|
|
72
|
-
# self._items: Dict[str, Item] = {}
|
|
73
71
|
self.cameras: List[str] = []
|
|
74
72
|
|
|
75
73
|
def construct(
|
|
@@ -86,6 +84,7 @@ class MimaEngine(ABC):
|
|
|
86
84
|
AnimatedSprite.engine = self
|
|
87
85
|
Camera.engine = self
|
|
88
86
|
Command.engine = self
|
|
87
|
+
Database.engine = self
|
|
89
88
|
Dynamic.engine = self
|
|
90
89
|
# GameMode.engine = self
|
|
91
90
|
Item.engine = self
|
|
@@ -100,6 +99,7 @@ class MimaEngine(ABC):
|
|
|
100
99
|
MimaView.engine = self
|
|
101
100
|
|
|
102
101
|
self.script = ScriptProcessor()
|
|
102
|
+
self.db = Database()
|
|
103
103
|
self.backend.init(
|
|
104
104
|
keyboard_map=self.rtc.get_keyboard_map(),
|
|
105
105
|
joystick_map=self.rtc.get_joystick_map(),
|
|
@@ -108,6 +108,9 @@ class MimaEngine(ABC):
|
|
|
108
108
|
self.backend.construct(
|
|
109
109
|
width, height, pixel_size, fullscreen, target_fps, resizable
|
|
110
110
|
)
|
|
111
|
+
self.backend.user_input.enable_touch_controls = (
|
|
112
|
+
self.enable_touch_controls
|
|
113
|
+
)
|
|
111
114
|
|
|
112
115
|
return True
|
|
113
116
|
|
|
@@ -200,9 +203,24 @@ class MimaEngine(ABC):
|
|
|
200
203
|
def get_map(self, map_name: str):
|
|
201
204
|
return self.backend.assets.get_map(map_name)
|
|
202
205
|
|
|
203
|
-
def
|
|
204
|
-
LOG.debug(
|
|
205
|
-
self.
|
|
206
|
+
def load_usable(self, item: Item, item_id) -> None:
|
|
207
|
+
LOG.debug("Loading usable %s.", item_id)
|
|
208
|
+
item.init(self.db.get_usable_data(item_id))
|
|
209
|
+
self.memory.items[item_id] = item
|
|
210
|
+
|
|
211
|
+
# def load_weapon(self, weapon: Weapon, weapon_id: str) -> None:
|
|
212
|
+
# LOG.debug("Loading weapon %s.", weapon_id)
|
|
213
|
+
# weapon.init(self.db.get_weapon_data(weapon_id))
|
|
214
|
+
# self.memory.items[weapon_id] = weapon
|
|
215
|
+
|
|
216
|
+
# def load_item(self, item: Item, item_id: str) -> None:
|
|
217
|
+
# LOG.debug("Loading item %s.", item_id)
|
|
218
|
+
# item.init(self.db.get_item_data(item_id))
|
|
219
|
+
# self.memory.items[item_id] = item
|
|
220
|
+
|
|
221
|
+
# def load_item(self, item: Item):
|
|
222
|
+
# LOG.debug(f"Loading item {item.name}.")
|
|
223
|
+
# self.memory.items[item.name] = item
|
|
206
224
|
|
|
207
225
|
def get_item(self, item_id: str):
|
|
208
226
|
try:
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
|
|
3
3
|
|
|
4
|
+
from ..states.game_state import GameState
|
|
5
|
+
from ..types.keys import Key as K
|
|
6
|
+
from ..types.mode import Mode
|
|
7
|
+
from ..types.nature import Nature
|
|
8
|
+
from ..types.player import Player
|
|
9
|
+
from ..view.mima_mode import MimaMode
|
|
4
10
|
from .engine import MimaEngine
|
|
5
|
-
from .states.game_state import GameState
|
|
6
|
-
from .types.keys import Key as K
|
|
7
|
-
from .types.mode import Mode
|
|
8
|
-
from .types.nature import Nature
|
|
9
|
-
from .types.player import Player
|
|
10
|
-
from .view.mima_mode import MimaMode
|
|
11
11
|
|
|
12
12
|
# from .view.mima_scene import MimaScene
|
|
13
13
|
LOG = logging.getLogger(__name__)
|
|
@@ -33,6 +33,7 @@ class MimaModeEngine(MimaEngine):
|
|
|
33
33
|
|
|
34
34
|
self.draw_chunks: bool = False
|
|
35
35
|
self.draw_chunk_info: bool = False
|
|
36
|
+
self.draw_dyn_ids: bool = False
|
|
36
37
|
self.disable_filter: bool = False
|
|
37
38
|
self._timer = 1.0
|
|
38
39
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import TYPE_CHECKING, Dict, List, Optional, Union
|
|
1
|
+
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
|
|
2
2
|
|
|
3
3
|
from .engine import MimaEngine
|
|
4
4
|
from .states.game_state import GameState
|
|
@@ -18,9 +18,7 @@ class MimaSceneEngine(MimaEngine):
|
|
|
18
18
|
platform: str = "PC",
|
|
19
19
|
caption: str = "MimaEngine",
|
|
20
20
|
):
|
|
21
|
-
super().__init__(
|
|
22
|
-
init_file, config_path, default_config, platform, caption
|
|
23
|
-
)
|
|
21
|
+
super().__init__(init_file, config_path, default_config, platform, caption)
|
|
24
22
|
|
|
25
23
|
self.scene_stack: List[str] = []
|
|
26
24
|
self._scenes: Dict[str, Scene] = {}
|
|
@@ -46,9 +44,7 @@ class MimaSceneEngine(MimaEngine):
|
|
|
46
44
|
if self._current_scene.autosave:
|
|
47
45
|
for quest in self.quests:
|
|
48
46
|
for obj in self.scene.dynamics:
|
|
49
|
-
quest.on_interaction(
|
|
50
|
-
self.scene.dynamics, obj, Nature.SAVE
|
|
51
|
-
)
|
|
47
|
+
quest.on_interaction(self.scene.dynamics, obj, Nature.SAVE)
|
|
52
48
|
quest.save_state()
|
|
53
49
|
if self.keys.new_key_press(K.SELECT):
|
|
54
50
|
self.game_state.save_to_disk()
|
mima/maps/template.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import TYPE_CHECKING, Dict, Optional
|
|
3
|
+
from typing import TYPE_CHECKING, Dict, Optional, Union
|
|
4
4
|
|
|
5
5
|
from ..util.functions import strtobool
|
|
6
6
|
from ..util.property import Property
|
|
@@ -39,3 +39,33 @@ class Template:
|
|
|
39
39
|
return bool(strtobool(self.properties[key].value))
|
|
40
40
|
else:
|
|
41
41
|
return default_val
|
|
42
|
+
|
|
43
|
+
def get(
|
|
44
|
+
self, key: str, default_val: Optional[str, int, float, bool] = None
|
|
45
|
+
) -> Union[str, int, float, bool]:
|
|
46
|
+
|
|
47
|
+
if key in self.properties:
|
|
48
|
+
if self.properties[key].dtype == "str":
|
|
49
|
+
if default_val is None:
|
|
50
|
+
return self.get_string(key)
|
|
51
|
+
return self.get_string(key, default_val)
|
|
52
|
+
if self.properties[key].dtype == "int":
|
|
53
|
+
if default_val is None:
|
|
54
|
+
return self.get_int(key)
|
|
55
|
+
return self.get_int(key, int(default_val))
|
|
56
|
+
if self.properties[key].dtype == "float":
|
|
57
|
+
if default_val is None:
|
|
58
|
+
return self.get_float(key)
|
|
59
|
+
return self.get_float(key, float(default_val))
|
|
60
|
+
if self.properties[key].dtype == "bool":
|
|
61
|
+
if default_val is None:
|
|
62
|
+
return self.get_bool(key)
|
|
63
|
+
elif not isinstance(default_val, bool):
|
|
64
|
+
msg = (
|
|
65
|
+
"Trying to access a bool value but default value "
|
|
66
|
+
f"{default_val} is of type {type(default_val)}"
|
|
67
|
+
)
|
|
68
|
+
raise TypeError(msg)
|
|
69
|
+
return self.get_bool(key, default_val)
|
|
70
|
+
|
|
71
|
+
return default_val
|
mima/maps/tiled/tiled_object.py
CHANGED
|
@@ -47,7 +47,7 @@ class TiledObject(Template):
|
|
|
47
47
|
name="tileset_name", dtype="str", value=tpl.tileset_name
|
|
48
48
|
)
|
|
49
49
|
self.properties["image_name"] = Property(
|
|
50
|
-
name="image_name", dtype="str", value=
|
|
50
|
+
name="image_name", dtype="str", value=""
|
|
51
51
|
)
|
|
52
52
|
self.properties["sprite_offset_x"] = Property(
|
|
53
53
|
name="sprite_offset_x",
|