Skip to content

Commit

Permalink
feat(#293): Added context to timer
Browse files Browse the repository at this point in the history
  • Loading branch information
lxgr-linux committed Jul 17, 2024
1 parent 74f2e7f commit 46db283
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 44 deletions.
11 changes: 5 additions & 6 deletions pokete.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import release
from pokete_classes import animations, loops
from pokete_classes.context import Context
from pokete_classes.inv import inv, Buy
from pokete_classes.inv import inv, buy
from pokete_classes.menu import menu
from pokete_classes.periodic_events import MovingGrassEvent, MovingWaterEvent, \
TreatNPCEvent
Expand Down Expand Up @@ -342,7 +342,7 @@ def action(self, ob):
mvp.movemap.text(mvp.movemap.bmap.inner.x - mvp.movemap.x + 9, 3,
["Welcome to the Pokete-Shop",
"Wanna buy something?"])
buy()
buy(Context(None, mvp.movemap, mvp.movemap, figure))
mvp.movemap.full_show(init=True)
mvp.movemap.text(mvp.movemap.bmap.inner.x - mvp.movemap.x + 9, 3,
["Have a great day!"])
Expand Down Expand Up @@ -737,9 +737,9 @@ def _game(_map: PlayMap):
Action.MAP: [RoadMap(), (ctx,)],
Action.INVENTORY: [inv, (ctx,)],
Action.POKEDEX: [Dex(), (ctx,)],
Action.CLOCK: [timer.clock, (mvp.movemap,)],
Action.CLOCK: [timer.clock, (ctx,)],
Action.MENU: [menu, (ctx,)],
Action.HELP: [Help(), (mvp.movemap,)]
Action.HELP: [Help(), (ctx,)]
}
if _map.weather is not None:
notifier.notify("Weather", "Info", _map.weather.info)
Expand Down Expand Up @@ -1270,13 +1270,12 @@ def recogniser():
detail.detail = detail.Detail(tss.height - 1, tss.width)
RoadMap.check_maps()
deck.deck = deck.Deck(tss.height - 1, tss.width, figure, abb_funcs)
buy = Buy(figure, mvp.movemap)
pokete_care.from_dict(session_info.get("pokete_care", {
"entry": 0,
"poke": None,
}))
timer.time = timer.Time(session_info.get("time", 0))
timer.clock = timer.Clock(timer.time, mvp.movemap)
timer.clock = timer.Clock(timer.time)
HighGrass.figure = figure
Poketeball.figure = figure
_ev.set_emit_fn(timer.time.emit_input)
Expand Down
2 changes: 1 addition & 1 deletion pokete_classes/inv/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .inv import inv
from .items import invitems
from .buy import Buy
from .buy import buy
49 changes: 25 additions & 24 deletions pokete_classes/inv/buy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,28 @@

import scrap_engine as se

from pokete_classes.context import Context
from util import liner
from .box import InvBox
from .items import invitems
from ..ui import Overview
from ..input import ACTION_UP_DOWN, Action, get_action
from ..ui.elements import ChooseBox
from .. import movemap as mvp, loops


class Buy:
"""Menu to buy items in, is triggered in shop
Args:
figure: Figure object
_map: The se.Map the menu is shown on"""
class Buy(Overview):
"""Menu to buy items in, is triggered in shop"""

def __init__(self, figure, _map):
self.map = _map
self.box = ChooseBox(_map.height - 3, 35, "Shop")
def __init__(self):
self.box = ChooseBox(50, 35, "Shop")
self.box2 = InvBox(7, 21, overview=self)
self.fig = figure
self.map = _map
self.items = [invitems.poketeball, invitems.superball,
invitems.healing_potion,
invitems.super_potion, invitems.ap_potion]
self.box.add_c_obs([se.Text(f"{obj.pretty_name} : {obj.price}$")
for obj in self.items])
self.money_label = se.Text(f"{figure.get_money()}$")
self.money_label = se.Text("0$")
self.desc_label = se.Text(" ")
# adding
self.box.add_ob(self.money_label,
Expand All @@ -37,18 +33,21 @@ def __init__(self, figure, _map):
def resize_view(self):
"""Manages recursive view resizing"""
self.box.remove()
self.map.resize_view()
self.box.resize(self.map.height - 3, 35)
self.box.add(self.map, self.map.width - self.box.width, 0)
self.box.map.resize_view()
self.box.resize(self.box.map.height - 3, 35)
self.box.add(self.box.map, self.box.map.width - self.box.width, 0)
mvp.movemap.full_show()

def __call__(self):
def __call__(self, ctx: Context):
"""Opens the buy menu"""
self.box.resize(self.map.height - 3, 35)
with self.box.add(self.map, self.map.width - 35, 0):
self.box2.add(self.map, self.box.x - 19, 3)
self.money_label.rechar(f"{ctx.figure.get_money()}$")
self.box.set_ob(self.money_label,
self.box.width - 2 - len(self.money_label.text), 0)
self.box.resize(ctx.map.height - 3, 35)
with self.box.add(ctx.map, ctx.map.width - 35, 0):
self.box2.add(ctx.map, self.box.x - 19, 3)
self.rechar()
self.map.show()
ctx.map.show()
while True:
action = get_action()
if action.triggers(*ACTION_UP_DOWN):
Expand All @@ -58,11 +57,11 @@ def __call__(self):
break
elif action.triggers(Action.ACCEPT):
obj = self.items[self.box.index.index]
if self.fig.get_money() - obj.price >= 0:
self.fig.add_money(-obj.price)
self.fig.give_item(obj.name)
loops.std(box=self.box2)
self.map.show()
if ctx.figure.get_money() - obj.price >= 0:
ctx.figure.add_money(-obj.price)
ctx.figure.give_item(obj.name)
loops.std(box=self.box2, pevm=ctx.pevm)
ctx.map.full_show()
self.box2.remove()

def rechar(self):
Expand All @@ -72,5 +71,7 @@ def rechar(self):
self.desc_label.rechar(liner(obj.desc, 19))


buy = Buy()

if __name__ == "__main__":
print("\033[31;1mDo not execute this!\033[0m")
4 changes: 2 additions & 2 deletions pokete_classes/movemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from .classes import OutP
from .color import Color
from .input import _ev, Action
from .ui import notifier
from .ui import notifier, Overview
from .tss import tss
from . import loops, ob_maps as obmp, game_map as gm


class Movemap(gm.GameSubmap):
class Movemap(gm.GameSubmap, Overview):
"""Movemap class to remove bad code
ARGS:
height: Height of the map
Expand Down
21 changes: 10 additions & 11 deletions pokete_classes/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time as time_mod
import scrap_engine as se
from release import SPEED_OF_TIME
from .context import Context
from .input import Action, get_action
from .ui.elements import Box
from . import loops
Expand Down Expand Up @@ -99,33 +100,31 @@ def normalized(self):
class Clock(Box):
"""Clock class to display the current time
ARGS:
time_ob: Time object
overview: The overview this happens on"""
time_ob: Time object"""

def __init__(self, time_ob, overview):
def __init__(self, time_ob):
self.time = time_ob
super().__init__(
9, 28, "Clock", f"{Action.CANCEL.mapping}:close",
overview
)

def __call__(self, _map):
"""Shows the clock
ARGS:
_map: The map to show on"""
def __call__(self, ctx: Context):
"""Shows the clock"""

d_p = True
letter_obs = self.draw_letters(d_p)
raw_time = self.time.time
with self.center_add(_map):
self.overview = ctx.overview
with self.center_add(ctx.map):
while True:
if get_action().triggers(*(Action.CANCEL, Action.CLOCK)):
break
if self.time.time == raw_time + 1:
d_p = not d_p
letter_obs = self.draw_letters(d_p, letter_obs)
raw_time = self.time.time
self.map.show()
loops.std(box=self)
loops.std(box=self, pevm=ctx.pevm)
self.map.full_show()
self.__rem_obs(letter_obs)

def __rem_obs(self, letter_obs):
Expand Down

0 comments on commit 46db283

Please sign in to comment.