Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
dist/
build/
**/*.egg-info
.DS_Store

.idea
scrap_engine.py
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
POKETE_SERVER_CLIENT_VERSION="0.10.0-rc3"
POKETE_SERVER_CLIENT_VERSION="0.10.0-rc4"
POKETE_SERVER_HOST="localhost"
POKETE_SERVER_PORT="9988"
POKETE_API_PORT="9989"
Expand Down
25 changes: 12 additions & 13 deletions src/pokete/base/ui/views/choose_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,15 @@ def __init__(
self.elems: list[HasArea] = []
self.up_down_switch = UpDownSwitch(self)
self.__special_ret: Optional[T] = None
self.add_ob(
self.up_down_switch,
self.width - 3 - self.up_down_switch.width,
self.height - 1,
)
self.__add_up_down_switch()

def __add_up_down_switch(self):
if len(self.elems) / (self.height - 2) > 1:
self.add_ob(
self.up_down_switch,
self.width - 3 - self.up_down_switch.width,
self.height - 1,
)

@override
def get_partial_interactors(self) -> list[MouseInteractor]:
Expand Down Expand Up @@ -145,19 +149,13 @@ def add_elems(self):
@abstractmethod
def new_size(self) -> tuple[int, int]: ...

def resize(self, height, width):
super().resize(height, width)
self.add_ob(
self.up_down_switch,
self.width - 3 - self.up_down_switch.width,
self.height - 1,
)

def resize_view(self):
"""Manages recursive view resizing"""
self.remove()
self.overview.resize_view()
self.rem_ob(self.up_down_switch)
self.resize(*self.new_size())
self.__add_up_down_switch()
self.rem_elems()
self.add_elems()
if len(self.c_obs) == 0:
Expand Down Expand Up @@ -193,6 +191,7 @@ def change_page(self, add_page, n_idx):
def __call__(self, ctx: Context) -> Optional[T]:
self.set_ctx(ctx)
ctx = change_ctx(ctx, self)
self.__add_up_down_switch()

while True:
action, _ = get_action()
Expand Down
19 changes: 11 additions & 8 deletions src/pokete/classes/interactions/multi_text_choose_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .. import movemap as mvp


class MultiTextChooseBox(ChooseBoxView[str]):
class MultiTextChooseBox(ChooseBoxView[tuple[int, str]]):
"""ChooseBox wrapper for multitext conversations"""

def __init__(self, keys: list[str], name: str):
Expand All @@ -26,13 +26,13 @@ def __init__(self, keys: list[str], name: str):
def new_size(self) -> tuple[int, int]:
return self.height, self.width

def choose(self, ctx: Context, idx: int) -> Optional[str]:
def choose(self, ctx: Context, idx: int) -> Optional[tuple[int, str]]:
if idx >= 0:
return self.keys[idx]
return idx, self.keys[idx]
else:
return None

def add(self, _map, x, y):
def add_relative(self, _map, x, y):
assert self.fig
mvp.movemap.assure_distance(
self.fig.x, self.fig.y, self.width + 2, self.height + 2
Expand All @@ -41,9 +41,12 @@ def add(self, _map, x, y):
_map, self.fig.x - mvp.movemap.x, self.fig.y - mvp.movemap.y + 1
)

def __call__(self, ctx: Context) -> Optional[str]:
def __call__(self, ctx: Context) -> tuple[int, str]:
self.fig = ctx.figure
self.add_elems()
ret: Optional[tuple[int, str]] = None

with self.add(ctx.map, -1, -1):
return super().__call__(ctx)
while ret is None:
self.add_elems()
with self.add_relative(ctx.map, -1, -1):
ret = super().__call__(ctx)
return ret
77 changes: 60 additions & 17 deletions src/pokete/classes/map_additions/center.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import random
import time

import scrap_engine as se

from pokete.base import loops
from pokete.base.input import Action, _ev, get_action
from pokete.base.input import _ev
from pokete.classes import deck
from pokete.classes import movemap as mvp
from pokete.classes.classes import PlayMap
from pokete.classes.doors import CenterDoor
from pokete.classes.interactions.multi_text_choose_box import MultiTextChooseBox
from pokete.classes.inv import buy
from pokete.classes.landscape import MapInteract
from pokete.release import SPEED_OF_TIME

CUDDLE_MESSAGES = [
"{name} nuzzles against you affectionately!",
"{name} nuzzles against you lovingly!",
"{name} nuzzles against you happily!",
"{name} purrs contentedly in your arms!",
"{name} looks up at you with adoring eyes!",
"{name} snuggles closer to you!",
]


class CenterMap(PlayMap):
"""Contains all relevant objects for centermap
Expand Down Expand Up @@ -87,6 +97,22 @@ def __init__(self, _he, _wi):
class CenterInteract(se.Object, MapInteract):
"""Triggers a conversation in the Pokete center"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.menu = MultiTextChooseBox(
[
"See your full deck",
"Heal all your Poketes",
"Cuddle with the Poketes",
"Quit",
],
"Select",
)

def __normalize_pokes(self, ob):
while "__fallback__" in [p.identifier for p in ob.pokes]:
ob.pokes.pop([p.identifier for p in ob.pokes].index("__fallback__"))

def action(self, ob):
"""Triggers the interaction in the Pokete center
ARGS:
Expand All @@ -100,21 +126,15 @@ def action(self, ob):
[
"Welcome to the Pokete-Center",
"What do you want to do?",
"1: See your full deck\n 2: Heal all your Poketes\n 3: Cuddle with the Poketes",
],
passthrough=True,
)
while True:
action, _ = get_action()
if action.triggers(Action.ACT_1):
while "__fallback__" in [p.identifier for p in ob.pokes]:
ob.pokes.pop(
[p.identifier for p in ob.pokes].index("__fallback__")
)

match self.menu(self.ctx)[0]:
case 0:
self.__normalize_pokes(ob)
ob.balls_label_rechar()
deck.deck(self.ctx, len(ob.pokes))
break
elif action.triggers(Action.ACT_2):
case 1:
ob.heal()
time.sleep(SPEED_OF_TIME * 0.5)
mvp.movemap.text(
Expand All @@ -123,10 +143,33 @@ def action(self, ob):
3,
["...", "Your Poketes are now healed!"],
)
break
elif action.triggers(Action.CANCEL, Action.ACT_3):
break
loops.std(self.ctx)
case 2:
self.__normalize_pokes(ob)
if ob.pokes:
selected_idx = deck.deck(
self.ctx,
len(ob.pokes),
label="Choose a Pokete to cuddle",
in_fight=True,
)
if selected_idx is not None:
poke = ob.pokes[selected_idx]
message = random.choice(CUDDLE_MESSAGES).format(
name=poke.name
)
mvp.movemap.text(
self.ctx,
mvp.movemap.bmap.inner.x - mvp.movemap.x + 8,
3,
["...", message],
)
else:
mvp.movemap.text(
self.ctx,
mvp.movemap.bmap.inner.x - mvp.movemap.x + 8,
3,
["You don't have any Poketes to cuddle with!"],
)
mvp.movemap.full_show(init=True)


Expand Down
5 changes: 2 additions & 3 deletions src/pokete/classes/movemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def assure_distance(self, _x: int, _y: int, width: int, height: int):
self.show()
time.sleep(SPEED_OF_TIME * 0.045)

def text(self, ctx: Context, _x, _y, inp_arr, passthrough=False):
def text(self, ctx: Context, _x, _y, inp_arr):
"""Shows dialog text on movemap
ARGS:
_x: The message's X
Expand Down Expand Up @@ -133,8 +133,7 @@ def text(self, ctx: Context, _x, _y, inp_arr, passthrough=False):
loops.std(ctx.with_overview(self))
self.full_show()
self.multitext.remove()
if not passthrough:
_ev.clear()
_ev.clear()

def resize_view(self):
"""Manages recursive view resizing"""
Expand Down
9 changes: 5 additions & 4 deletions src/pokete/classes/multiplayer/interactions/context_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ def __call__(self, ctx: Context):
rmtpl = pc_manager.get_interactable(ctx.figure)
if rmtpl is None:
return
match self.menu(ctx):
case "Fight":
match self.menu(ctx)[0]:
case 0:
resp = com_service.request_fight(rmtpl.name)
# ask_ok(ctx, f"{resp}")
if resp:
remote_fight_controller.start(rmtpl.ctx, rmtpl.name)
case "Trade":
case 1:
# TODO impl trading
pass
case "Quit...":
case 2:
pass
16 changes: 9 additions & 7 deletions src/pokete/classes/multiplayer/pc_manager/pc_manager.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Manages remote players"""

import logging

from .remote_player import RemotePlayer
from ..interactions import movemap_deco
from ...multiplayer.msg.position.update import UpdateDict
from ... import ob_maps as obmp
from ...multiplayer.msg.position.update import UpdateDict
from ..interactions import movemap_deco
from .remote_player import RemotePlayer


class PCManager:
Expand Down Expand Up @@ -48,7 +49,8 @@ def remove(self, name):
logging.warning(
"[PCManager] Trying to remove player with name `%s`, "
"but is not present",
name)
name,
)
return
pc.remove()
del self.reg[name]
Expand All @@ -62,9 +64,9 @@ def movemap_move(self):
def get_interactable(self, figure) -> RemotePlayer | None:
for _, rmtpl in self.reg.items():
if (
rmtpl.map == figure.map and
(figure.x - 2 <= rmtpl.x <= figure.x + 2) and
(figure.y - 2 <= rmtpl.y <= figure.y + 2)
rmtpl.map == figure.map
and (figure.x - 2 <= rmtpl.x <= figure.x + 2)
and (figure.y - 2 <= rmtpl.y <= figure.y + 2)
):
return rmtpl
return None
Expand Down
6 changes: 2 additions & 4 deletions src/pokete/classes/multiplayer/pc_manager/remote_player.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import scrap_engine as se

from pokete.base.color import Color
from ...interactions import Interactor, MultiTextChooseBox

from ...interactions import Interactor
from ...landscape import MapInteract


Expand All @@ -14,9 +15,6 @@ def __init__(self, name):
super().__init__("a", "float")
self.name = name
self.name_tag = NameTag(name)
self.interaction_choose_box = MultiTextChooseBox(
["fight", "cancel"],
"Interact")

def add(self, _map, x, y):
"""Adds the player remoteplayer to the map
Expand Down
4 changes: 2 additions & 2 deletions src/pokete/classes/npcs/npcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ def chat(self):
return
while True:
self.text(q_a.q)
while get_action() is None:
while get_action()[0] is None:
loops.std(self.ctx)
if q_a.a == {}:
break
q_a = q_a.a[
MultiTextChooseBox(list(q_a.a.keys()), "Answer")(self.ctx)
MultiTextChooseBox(list(q_a.a.keys()), "Answer")(self.ctx)[1]
]


Expand Down