diff --git a/pokete.py b/pokete.py index 1afb53c1..c98f716f 100755 --- a/pokete.py +++ b/pokete.py @@ -839,8 +839,8 @@ def root_fn(ex: str, options: list[str], figure = Figure(session_info) NameTag.set_args(figure) - gen_obs(p_data.map_data, p_data.npcs, p_data.trainers, figure) - map_additions(figure) + # gen_obs(p_data.map_data, p_data.npcs, p_data.trainers, figure) + # map_additions(figure) # Definiton of all additionaly needed obs and maps ############################################################# @@ -852,8 +852,6 @@ def root_fn(ex: str, options: list[str], # side fn definitions detail.detail = detail.Detail(tss.height - 1, tss.width) - roadmap.RoadMap.check_maps() - roadmap.roadmap = roadmap.RoadMap() deck.deck = deck.Deck(tss.height - 1, tss.width, figure, abb_funcs) pokete_care.from_dict(session_info.get("pokete_care", { "entry": 0, diff --git a/pokete_classes/asset_service/asset_types/assets.py b/pokete_classes/asset_service/asset_types/assets.py index 40b97634..56e1ce9e 100644 --- a/pokete_classes/asset_service/asset_types/assets.py +++ b/pokete_classes/asset_service/asset_types/assets.py @@ -1,6 +1,6 @@ from typing import TypedDict -from .base import Items, Pokes, Natures, Weathers, Types, Achievements +from .base import Items, Pokes, Natures, Weathers, Types, Achievements, Attacks from .maps import Maps from .npcs import NPCs from .stations import Stations, Decorations @@ -11,9 +11,11 @@ class BaseAssets(TypedDict): items: Items pokes: Pokes + attacks: Attacks natures: Natures weathers: Weathers types: Types + sub_types: list[str] achievements: Achievements diff --git a/pokete_classes/asset_service/asset_types/base/poke.py b/pokete_classes/asset_service/asset_types/base/poke.py index 0b1a6ad9..c8d9fd5e 100644 --- a/pokete_classes/asset_service/asset_types/base/poke.py +++ b/pokete_classes/asset_service/asset_types/base/poke.py @@ -21,6 +21,7 @@ class Poke(TypedDict): evolve_poke: str evolve_lvl: int initiative: int + night_active: bool | None ico: list[BaseIco] diff --git a/pokete_classes/asset_service/service.py b/pokete_classes/asset_service/service.py index c966d850..6ff831e9 100644 --- a/pokete_classes/asset_service/service.py +++ b/pokete_classes/asset_service/service.py @@ -32,13 +32,15 @@ def load_base_assets_from_p_data(self): self.__load_base_assets({ "items": p_data.items, "pokes": p_data.pokes, + "attacks": p_data.attacks, "natures": p_data.natures, "weathers": p_data.weathers, "types": p_data.types, + "sub_types": p_data.sub_types, "achievements": p_data.achievements }) - def get_assets(self) -> Assets | None: + def get_assets(self) -> Assets: return self.__assets def get_base_assets(self) -> BaseAssets: diff --git a/pokete_classes/dex.py b/pokete_classes/dex.py index 2e07ceca..eb85387f 100644 --- a/pokete_classes/dex.py +++ b/pokete_classes/dex.py @@ -1,9 +1,9 @@ """Contains the Pokete dex that gives information about all Poketes""" import scrap_engine as se -import pokete_data as p_data from util import liner +from .asset_service.service import asset_service from .context import Context from .input import Action, ACTION_UP_DOWN, get_action from .poke import Poke @@ -53,7 +53,7 @@ def detail(self, ctx: Context, poke): }[poke.night_active] desc_text = liner(poke.desc.text.replace("\n", " ") + (f"""\n\n Evolves into { - p_data.pokes[poke.evolve_poke]['name'] if + asset_service.get_base_assets()["pokes"][poke.evolve_poke]['name'] if poke.evolve_poke in ctx.figure.caught_pokes else '???' }.""" @@ -96,7 +96,7 @@ def __call__(self, ctx: Context): """Opens the dex""" self.box.overview = ctx.overview self.box.resize(ctx.map.height - 3, 35) - pokes = p_data.pokes + pokes = asset_service.get_base_assets()["pokes"] self.idx = 0 p_dict = {i[1]: i[-1] for i in sorted([(pokes[j]["types"][0], j, pokes[j]) diff --git a/pokete_classes/fight/fight_items.py b/pokete_classes/fight/fight_items.py index 2a902e95..60479261 100644 --- a/pokete_classes/fight/fight_items.py +++ b/pokete_classes/fight/fight_items.py @@ -2,7 +2,6 @@ import random import time -import pokete_data as p_data from pokete_classes import ob_maps as obmp from pokete_classes.achievements import achievements from pokete_classes.audio import audio @@ -10,6 +9,7 @@ from pokete_classes.fight.providers import NatureProvider, Provider from release import SPEED_OF_TIME from .. import movemap as mvp +from ..asset_service.service import asset_service class FightItems: @@ -62,7 +62,8 @@ def __throw(fightmap: FightMap, obj, enem: Provider, chance, name): mvp.movemap.balls_label_rechar(obj.pokes) logging.info("[Fighitem][%s] Caught %s", name, enem.curr.name) achievements.achieve("first_poke") - if all(poke in obj.caught_pokes for poke in p_data.pokes): + if all(poke in obj.caught_pokes for poke in + asset_service.get_base_assets()["pokes"]): achievements.achieve("catch_em_all") return 2 fightmap.outp.outp("You missed!") diff --git a/pokete_classes/generate.py b/pokete_classes/generate.py index b736372e..c40a019f 100644 --- a/pokete_classes/generate.py +++ b/pokete_classes/generate.py @@ -1,10 +1,8 @@ """Generating maps""" import scrap_engine as se -from .asset_service.asset_types import Maps, NPCs -from pokete_classes.asset_service.asset_types.npcs import NPCs -from pokete_classes.asset_service.asset_types.obmaps import Obmaps -from pokete_classes.asset_service.asset_types.trainers import Trainers +from pokete_classes.asset_service.service import asset_service +from .asset_service.asset_types import Maps from pokete_classes.map_additions.center import CenterMap, ShopMap from pokete_classes.tss import tss from .landscape import Meadow, Water, Sand, Poketeball @@ -57,7 +55,7 @@ def gen_maps( return maps -def gen_obs(map_data: Obmaps, npcs: NPCs, trainers: Trainers, figure): +def gen_obs(figure): """Generates all objects on the maps ARSG: map_data: Contains map_data @@ -65,8 +63,10 @@ def gen_obs(map_data: Obmaps, npcs: NPCs, trainers: Trainers, figure): trainers: Contains trainers data figure: Figure instance""" + assets = asset_service.get_assets() + # adding all trainer to map - for i, trainer_list in trainers.items(): + for i, trainer_list in assets["trainers"].items(): _map = obmp.ob_maps[i] for j in trainer_list: args = j["args"] @@ -80,7 +80,7 @@ def gen_obs(map_data: Obmaps, npcs: NPCs, trainers: Trainers, figure): _map.trainers.append(trainer) # generating objects from map_data - for ob_map, single_map in map_data.items(): + for ob_map, single_map in assets["obmaps"].items(): _map = obmp.ob_maps[ob_map] for hard_ob, single_hard_ob in single_map["hard_obs"].items(): __parse_obj(_map, hard_ob, @@ -118,7 +118,7 @@ def gen_obs(map_data: Obmaps, npcs: NPCs, trainers: Trainers, figure): single_map["special_dors"][name]["y"]) # NPCs - for npc, _npc in npcs.items(): + for npc, _npc in assets["npcs"].items(): NPC(npc, _npc["texts"], _fn=_npc["fn"], chat=_npc.get("chat", None)).add(obmp.ob_maps[_npc["map"]], _npc["x"], _npc["y"]) diff --git a/pokete_classes/inv/items.py b/pokete_classes/inv/items.py index f28e16a3..798e34ee 100644 --- a/pokete_classes/inv/items.py +++ b/pokete_classes/inv/items.py @@ -1,13 +1,12 @@ """All classes needed for Item management""" - -import pokete_data as p_data +from pokete_classes.asset_service.service import asset_service class Items: """Has all items as attributes""" def __init__(self): - for item in p_data.items.items(): + for item in asset_service.get_base_assets()["items"].items(): _obj = InvItem(item[0], item[1]["pretty_name"], item[1]["desc"], item[1]["price"], item[1]["fn"]) @@ -41,7 +40,8 @@ class LearnDisc(InvItem): def __init__(self, attack_name): self.attack_name = attack_name - self.attack_dict = p_data.attacks[attack_name] + self.attack_dict = asset_service.get_base_assets()["attacks"][ + attack_name] pretty_name = f"LD-{self.attack_dict['name']}" name = f"ld_{attack_name}" desc = f"Teaches a Pokete the attack '{self.attack_dict['name']}'." diff --git a/pokete_classes/landscape.py b/pokete_classes/landscape.py index e47dabba..da1547a8 100644 --- a/pokete_classes/landscape.py +++ b/pokete_classes/landscape.py @@ -2,8 +2,8 @@ import random import scrap_engine as se -import pokete_data as p_data from pokete_classes import timer, movemap as mvp +from .asset_service.service import asset_service from .context import Context from .fight import Fight, NatureProvider from .color import Color @@ -29,9 +29,10 @@ def action(self, ob): ob: The object triggering this action""" is_night = (360 > timer.time.normalized or timer.time.normalized > 1320) - pokes = {i: p_data.pokes[i] + all_pokes = asset_service.get_base_assets()["pokes"] + pokes = {i: all_pokes[i] for i in self.arg_proto["pokes"] - if (n_a := p_data.pokes[i].get("night_active", None)) is None + if (n_a := all_pokes[i].get("night_active", None)) is None or (not n_a and not is_night) or (n_a and is_night)} if random.randint(0, 8) == 0: @@ -113,5 +114,5 @@ def action(self, ob): self.remove() mvp.movemap.full_show() ask_ok(self.ctx, f"You found {amount if amount > 1 else 'a'} \ -{p_data.items[item]['pretty_name']}{'s' if amount > 1 else ''}!") +{asset_service.get_base_assets()["items"][item]['pretty_name']}{'s' if amount > 1 else ''}!") self.ctx.figure.used_npcs.append(self.name) diff --git a/pokete_classes/learnattack.py b/pokete_classes/learnattack.py index c0eb79fc..ef9821b8 100644 --- a/pokete_classes/learnattack.py +++ b/pokete_classes/learnattack.py @@ -3,8 +3,8 @@ import random import scrap_engine as se -import pokete_data as p_data from util import liner +from .asset_service.service import asset_service from .context import Context from .input import Action, get_action from .input_loops import ask_bool, ask_ok @@ -16,8 +16,7 @@ class AttackInfo(Box): """Gives information about a certain attack ARGS: - attack: The attack's name - _map: se.Map this should be shown on""" + attack: The attack's name""" def __init__(self, attack): atc = Attack(attack) @@ -47,8 +46,7 @@ def __enter__(self): class LearnAttack: """Lets a Pokete learn a new attack ARGS: - poke: The Poke that should learn an attack - _map: The se.Map this should happen on""" + poke: The Poke that should learn an attack""" def __init__(self, poke): self.poke = poke @@ -64,7 +62,7 @@ def get_attack(poke): poke: The pokete RETURNS: The attacks name, None if none is found""" - attacks = p_data.attacks + attacks = asset_service.get_base_assets()["attacks"] pool = [i for i, atc in attacks.items() if all(j in [i.name for i in poke.types] for j in atc["types"]) @@ -84,7 +82,7 @@ def __call__(self, ctx: Context, attack=None): attack will be chosen randomly RETURNS: bool: Whether or not the attack was learned""" - attacks = p_data.attacks + attacks = asset_service.get_base_assets()["attacks"] self.box.set_ctx(ctx) if attack is None: if (new_attack := self.get_attack(self.poke)) is None: diff --git a/pokete_classes/map_additions/center.py b/pokete_classes/map_additions/center.py index 5c1544a6..a67eb325 100644 --- a/pokete_classes/map_additions/center.py +++ b/pokete_classes/map_additions/center.py @@ -1,4 +1,3 @@ -import logging import time import scrap_engine as se diff --git a/pokete_classes/multiplayer/communication.py b/pokete_classes/multiplayer/communication.py index 1f6493db..cccda276 100644 --- a/pokete_classes/multiplayer/communication.py +++ b/pokete_classes/multiplayer/communication.py @@ -2,6 +2,7 @@ import socket import bs_rpc +from pokete_classes.asset_service.service import asset_service from pokete_classes.context import Context from pokete_classes.generate import gen_maps, gen_obs from pokete_classes.multiplayer import msg @@ -84,16 +85,7 @@ def handshake( case map_info.INFO_TYPE: data: map_info.InfoData = resp.data obmp.ob_maps = gen_maps(data["assets"]["maps"], fix_center=True) - gen_obs( - data["assets"]["obmaps"], - data["assets"]["npcs"], - data["assets"]["trainers"], - ctx.figure, - ) - roadmap.roadmap = roadmap.RoadMap( - data["assets"]["stations"], - data["assets"]["decorations"] - ) + asset_service.load_assets(data["assets"]) pos = data["position"] self.saved_pos = ( ctx.figure.map.name, diff --git a/pokete_classes/multiplayer/menu.py b/pokete_classes/multiplayer/menu.py index 8eed6058..5611460d 100644 --- a/pokete_classes/multiplayer/menu.py +++ b/pokete_classes/multiplayer/menu.py @@ -4,8 +4,10 @@ import scrap_engine as se -from .. import loops +from .. import loops, roadmap +from ..asset_service.service import asset_service from ..context import Context +from ..generate import gen_obs from ..input import get_action, ACTION_DIRECTIONS, Action from ..multiplayer.modeprovider import modeProvider, Mode from ..ui.elements import BetterChooseBox @@ -40,12 +42,15 @@ def __call__(self, ctx: Context): num = self.index[0] if num == 0: modeProvider.mode = Mode.SINGLE - return + asset_service.load_assets_from_p_data() elif num == 1: connector.connector(ctx.with_overview(self)) modeProvider.mode = Mode.MULTI com_service() - return else: sys.exit() + # roadmap.RoadMap.check_maps() + roadmap.roadmap = roadmap.RoadMap() + gen_obs(ctx.figure) + return loops.std(ctx.with_overview(self)) diff --git a/pokete_classes/poke/evomap.py b/pokete_classes/poke/evomap.py index 32fbee4a..0fea6b46 100644 --- a/pokete_classes/poke/evomap.py +++ b/pokete_classes/poke/evomap.py @@ -2,12 +2,12 @@ import logging import time -import pokete_data as p_data import scrap_engine as se import pokete_classes.game_map as gm from release import SPEED_OF_TIME from .. import loops from ..achievements import achievements +from ..asset_service.service import asset_service from ..classes import OutP from ..context import Context from ..game import PeriodicEventManager @@ -72,7 +72,8 @@ def __call__(self, ctx: Context, poke: Poke) -> bool: new.moves.shine() self.outp.outp(f"{self.name} evolved into {new.name}!") time.sleep(SPEED_OF_TIME * 5) - for i in range(max(len(p_data.pokes[new.identifier]["attacks"]) + for i in range(max(len( + asset_service.get_base_assets()["pokes"][new.identifier]["attacks"]) - len(poke.attack_obs), 0)): LearnAttack(new)(ctx) ctx.figure.pokes[ctx.figure.pokes.index(self)] = new diff --git a/pokete_classes/poke/nature.py b/pokete_classes/poke/nature.py index 1207c9cd..6b11ab37 100644 --- a/pokete_classes/poke/nature.py +++ b/pokete_classes/poke/nature.py @@ -3,9 +3,9 @@ import random import scrap_engine as se -import pokete_data as p_data from util import liner from .dicts import NatureDict +from ..asset_service.service import asset_service from ..context import Context from ..input import Action from ..ui.elements import LabelBox @@ -41,7 +41,7 @@ class PokeNature: natures = { name: Nature(name, **_dict) - for name, _dict in p_data.natures.items() + for name, _dict in asset_service.get_base_assets()["natures"].items() } def __init__(self, nature, grade): diff --git a/pokete_classes/poke/poke.py b/pokete_classes/poke/poke.py index 99a04145..c67c0ee8 100644 --- a/pokete_classes/poke/poke.py +++ b/pokete_classes/poke/poke.py @@ -6,9 +6,9 @@ from datetime import datetime import scrap_engine as se -import pokete_data as p_data from util import liner from .dicts import PokeDict +from ..asset_service.service import asset_service from ..attack import Attack from ..context import Context from ..health_bar import HealthBar @@ -36,7 +36,7 @@ def __init__(self, poke, _xp, _hp="SKIP", _ap=None, _attacks=None, stats=None): self.nature = PokeNature.random() if nature is None \ else PokeNature.from_dict(nature) - self.inf = p_data.pokes[poke] + self.inf = asset_service.get_base_assets()["pokes"][poke] self.moves = Moves(self) # Attributes self.player = None @@ -66,12 +66,16 @@ def __init__(self, poke, _xp, _hp="SKIP", _ap=None, _attacks=None, else: _attacks = self.inf["attacks"][:4] self.attacks = [atc for atc in _attacks - if self.lvl() >= p_data.attacks[atc]["min_lvl"]] + if self.lvl() >= + asset_service.get_base_assets()["attacks"][atc][ + "min_lvl"]] if self.shiny: self.hp += 5 self.attack_obs = [Attack(atc, str(i + 1)) for i, atc in enumerate(self.attacks) - if self.lvl() >= p_data.attacks[atc]["min_lvl"]] + if self.lvl() >= + asset_service.get_base_assets()["attacks"][atc][ + "min_lvl"]] self.set_player(player) # Backup vars self.full_hp = self.hp diff --git a/pokete_classes/roadmap.py b/pokete_classes/roadmap.py index 78c360f0..8892205d 100644 --- a/pokete_classes/roadmap.py +++ b/pokete_classes/roadmap.py @@ -1,8 +1,7 @@ """Contains all classes relevant to show the roadmap""" import scrap_engine as se -import pokete_data as p_data import pokete_classes.ob_maps as obmp -from pokete_classes.asset_service.asset_types import Stations, Decorations +from pokete_classes.asset_service.service import asset_service from pokete_classes.context import Context from pokete_classes.game import PeriodicEvent from util import liner @@ -112,8 +111,9 @@ def has_been_visited(self, figure): def is_city(self): """Returns if the station is a city""" - return "pokecenter" in p_data.map_data[self.associates[0].name][ - "hard_obs"] + return "pokecenter" in \ + asset_service.get_assets()["obmaps"][self.associates[0].name][ + "hard_obs"] def hide_if_visited(self, figure, choose=False): self.text = self.base_text @@ -134,12 +134,9 @@ def hide_if_visited(self, figure, choose=False): class RoadMap: """Map you can see and navigate maps on""" - def __init__(self, stations: Stations = None, - decorations: Decorations = None): - if stations is None: - stations = p_data.stations - if decorations is None: - decorations = p_data.decorations + def __init__(self): + stations = asset_service.get_assets()["stations"] + decorations = asset_service.get_assets()["decorations"] self.box = Box( 17, 61, "Roadmap", f"{Action.CANCEL.mapping}:close", ) @@ -224,7 +221,7 @@ def __call__(self, ctx: Context, choose=False): ): p_list = ", ".join( set( - p_data.pokes[j]["name"] + asset_service.get_base_assets()["pokes"][j]["name"] for i in self.sta.associates for j in i.poke_args.get("pokes", []) + i.w_poke_args.get("pokes", []) @@ -248,17 +245,18 @@ def __call__(self, ctx: Context, choose=False): ctx.map.full_show() self.sta.unchoose() - @staticmethod - def check_maps(): - """Checks for PlayMaps not having a corresponding MapStation""" - all_road_maps = ["centermap", "shopmap"] - for i, _dict in p_data.stations.items(): - all_road_maps.append(i) - all_road_maps += _dict["gen"]["additionals"] - - for _, _map in obmp.ob_maps.items(): - if _map.name not in all_road_maps: - raise RoadMapException(_map) + # @staticmethod + # TODO: Add to assetloading validation + # def check_maps(): + # """Checks for PlayMaps not having a corresponding MapStation""" + # all_road_maps = ["centermap", "shopmap"] + # for i, _dict in p_data.stations.items(): + # all_road_maps.append(i) + # all_road_maps += _dict["gen"]["additionals"] + # + # for _, _map in obmp.ob_maps.items(): + # if _map.name not in all_road_maps: + # raise RoadMapException(_map) roadmap: RoadMap | None = None diff --git a/pokete_classes/types.py b/pokete_classes/types.py index 694aa0df..4f087790 100644 --- a/pokete_classes/types.py +++ b/pokete_classes/types.py @@ -1,6 +1,5 @@ """Type and PokeType class""" - -import pokete_data as p_data +from pokete_classes.asset_service.service import asset_service from .color import Color @@ -8,9 +7,9 @@ class Types: """Class to organize PokeTypese""" def __init__(self): - for i, typ in p_data.types.items(): + for i, typ in asset_service.get_base_assets()["types"].items(): setattr(self, i, PokeType(i, **typ)) - for i in p_data.sub_types: + for i in asset_service.get_base_assets()["sub_types"]: setattr(self, i, PokeSubType(i))