Skip to content

Commit

Permalink
feat(#296): Added AssetService
Browse files Browse the repository at this point in the history
  • Loading branch information
lxgr-linux committed Aug 8, 2024
1 parent 5ebe7db commit ce1019e
Show file tree
Hide file tree
Showing 36 changed files with 275 additions and 85 deletions.
36 changes: 21 additions & 15 deletions pkg/server/pokete/msg/map_info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ const InfoType msg.Type = "pokete.map.info"

type Info struct {
msg.BaseMsg
Obmaps resources.Obmaps `json:"obmaps"`
Maps resources.Maps `json:"maps"`
NPCs resources.NPCs `json:"npcs"`
Trainers resources.Trainers `json:"trainers"`
MapStations resources.MapStations `json:"map_stations"`
MapDecorations resources.MapDecorations `json:"map_decorations"`
Position user.Position `json:"position"`
Users []user.User `json:"users"`
GreetingText string `json:"greeting_text"`
Assets Assets `json:"assets"`
Position user.Position `json:"position"`
Users []user.User `json:"users"`
GreetingText string `json:"greeting_text"`
}

type Assets struct {
Obmaps resources.Obmaps `json:"obmaps"`
Maps resources.Maps `json:"maps"`
NPCs resources.NPCs `json:"npcs"`
Trainers resources.Trainers `json:"trainers"`
Stations resources.MapStations `json:"stations"`
Decorations resources.MapDecorations `json:"decorations"`
}

func (i Info) GetType() msg.Type {
Expand All @@ -34,12 +38,14 @@ func NewInfo(
) Info {
return Info{
msg.BaseMsg{},
resources2.GetObmaps(),
resources2.GetMaps(),
resources2.GetNPCs(),
resources2.GetTrainers(),
resources2.GetMapStations(),
resources2.GetMapDecorations(),
Assets{
resources2.GetObmaps(),
resources2.GetMaps(),
resources2.GetNPCs(),
resources2.GetTrainers(),
resources2.GetMapStations(),
resources2.GetMapDecorations(),
},
position,
users.GetAllUsers(),
greetingtext,
Expand Down
Empty file.
7 changes: 7 additions & 0 deletions pokete_classes/asset_service/asset_types/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .assets import Assets, BaseAssets
from .maps import Map, Maps
from .npcs import NPCs, NPC
from .obmaps import Obmap, Obmaps
from .stations import Station, Stations, Decorations, Decoration
from .trainers import Trainer, Trainers
from .base import *
26 changes: 26 additions & 0 deletions pokete_classes/asset_service/asset_types/assets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from typing import TypedDict

from .base import Items, Pokes, Natures, Weathers, Types, Achievements
from .maps import Maps
from .npcs import NPCs
from .stations import Stations, Decorations
from .trainers import Trainers
from .obmaps import Obmaps


class BaseAssets(TypedDict):
items: Items
pokes: Pokes
natures: Natures
weathers: Weathers
types: Types
achievements: Achievements


class Assets(TypedDict):
trainers: Trainers
npcs: NPCs
obmaps: Obmaps
stations: Stations
decorations: Decorations
maps: Maps
7 changes: 7 additions & 0 deletions pokete_classes/asset_service/asset_types/base/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .items import Items, Item
from .poke import Pokes, Poke
from .natures import Natures, Nature
from .weather import Weather, Weathers
from .attacks import Attack, Attacks
from .types import Type, Types
from .achievements import Achievement, Achievements
9 changes: 9 additions & 0 deletions pokete_classes/asset_service/asset_types/base/achievements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import TypedDict


class Achievement(TypedDict):
title: str
desc: str


Achievements = dict[str, Achievement]
19 changes: 19 additions & 0 deletions pokete_classes/asset_service/asset_types/base/attacks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from typing import TypedDict


class Attack(TypedDict):
name: str
factor: float
action: str | None
world_action: str
move: list[str]
miss_chance: float
min_lvl: int
desc: str
types: list[str]
effect: str | None
is_generic: bool
ap: int


Attacks = dict[str, Attack]
11 changes: 11 additions & 0 deletions pokete_classes/asset_service/asset_types/base/items.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from typing import TypedDict


class Item(TypedDict):
pretty_name: str
desc: str
price: int
fn: str | None


Items = dict[str, Item]
10 changes: 10 additions & 0 deletions pokete_classes/asset_service/asset_types/base/natures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import TypedDict


class Nature(TypedDict):
esc: str
atc: float
_def: float


Natures = dict[str, Nature]
27 changes: 27 additions & 0 deletions pokete_classes/asset_service/asset_types/base/poke.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from typing import TypedDict


class BaseIco(TypedDict):
txt: str
esc: str | None


class Poke(TypedDict):
name: str
hp: int
atc: int
defense: int
attacks: list[str]
pool: list[str]
miss_chance: int
desc: str
lose_xp: int
rarity: int
types: list[str]
evolve_poke: str
evolve_lvl: int
initiative: int
ico: list[BaseIco]


Pokes = dict[str, Poke]
10 changes: 10 additions & 0 deletions pokete_classes/asset_service/asset_types/base/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import TypedDict


class Type(TypedDict):
effective: list[str]
ineffective: list[str]
color: list[str]


Types = dict[str, Type]
9 changes: 9 additions & 0 deletions pokete_classes/asset_service/asset_types/base/weather.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import TypedDict


class Weather(TypedDict):
info: str
effected: dict[str, float]


Weathers = dict[str, Weather]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
48 changes: 48 additions & 0 deletions pokete_classes/asset_service/service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import logging

import pokete_data as p_data
from .asset_types.assets import Assets, BaseAssets


class AssetSerice:
def __init__(self):
self.__assets: Assets | None = None
self.__base_assets: BaseAssets | None = None
self.load_base_assets_from_p_data()

def load_assets(self, assets: Assets):
self.__assets = assets

def __load_base_assets(self, base_assets: BaseAssets):
self.__base_assets = base_assets

def load_assets_from_p_data(self):
if self.__assets is not None:
logging.warning("[AssetService]: Assets already loaded")
self.load_assets({
"trainers": p_data.trainers,
"npcs": p_data.npcs,
"obmaps": p_data.map_data,
"stations": p_data.stations,
"decorations": p_data.decorations,
"maps": p_data.maps,
})

def load_base_assets_from_p_data(self):
self.__load_base_assets({
"items": p_data.items,
"pokes": p_data.pokes,
"natures": p_data.natures,
"weathers": p_data.weathers,
"types": p_data.types,
"achievements": p_data.achievements
})

def get_assets(self) -> Assets | None:
return self.__assets

def get_base_assets(self) -> BaseAssets:
return self.__base_assets


asset_service: AssetSerice = AssetSerice()
39 changes: 21 additions & 18 deletions pokete_classes/generate.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""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.map_additions.center import CenterMap, ShopMap
from pokete_classes.maps import Maps, Obmaps, NPCs, Trainers
from pokete_classes.tss import tss
from .landscape import Meadow, Water, Sand, Poketeball
from .classes import PlayMap
Expand All @@ -14,7 +17,7 @@
from . import ob_maps as obmp


def parse_obj(_map, name, obj, _dict):
def __parse_obj(_map, name, obj, _dict):
"""Parses an object to a maps attribute and adds it
ARGS:
_map: The given PlayMap
Expand Down Expand Up @@ -80,32 +83,32 @@ def gen_obs(map_data: Obmaps, npcs: NPCs, trainers: Trainers, figure):
for ob_map, single_map in map_data.items():
_map = obmp.ob_maps[ob_map]
for hard_ob, single_hard_ob in single_map["hard_obs"].items():
parse_obj(_map, hard_ob,
se.Text(single_hard_ob["txt"],
ignore=" "),
single_hard_ob)
__parse_obj(_map, hard_ob,
se.Text(single_hard_ob["txt"],
ignore=" "),
single_hard_ob)
for soft_ob, single_soft_ob in single_map["soft_obs"].items():
cls = {
"sand": Sand,
"meadow": Meadow,
"water": Water,
}[single_soft_ob.get("cls", "meadow")]
parse_obj(_map, soft_ob,
cls(single_soft_ob["txt"],
_map.poke_args
if cls != Water else _map.w_poke_args),
single_soft_ob)
__parse_obj(_map, soft_ob,
cls(single_soft_ob["txt"],
_map.poke_args
if cls != Water else _map.w_poke_args),
single_soft_ob)
for door, single_door in single_map["dors"].items():
parse_obj(_map, door,
Door(" ", state="float",
arg_proto=single_door["args"]),
single_door)
__parse_obj(_map, door,
Door(" ", state="float",
arg_proto=single_door["args"]),
single_door)
for ball, single_ball in single_map["balls"].items():
if f'{ob_map}.{ball}' not in figure.used_npcs or not \
settings("save_trainers").val:
parse_obj(_map, ball,
Poketeball(f"{ob_map}.{ball}"),
single_ball)
__parse_obj(_map, ball,
Poketeball(f"{ob_map}.{ball}"),
single_ball)
if "special_dors" in single_map:
for name, cls in [("dor", DoorToCenter), ("shopdor", DoorToShop)]:
if name in single_map["special_dors"]:
Expand Down
6 changes: 0 additions & 6 deletions pokete_classes/maps/__init__.py

This file was deleted.

12 changes: 6 additions & 6 deletions pokete_classes/multiplayer/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ def handshake(
raise InvalidPokeException(data["error"])
case map_info.INFO_TYPE:
data: map_info.InfoData = resp.data
obmp.ob_maps = gen_maps(data["maps"], fix_center=True)
obmp.ob_maps = gen_maps(data["assets"]["maps"], fix_center=True)
gen_obs(
data["obmaps"],
data["npcs"],
data["trainers"],
data["assets"]["obmaps"],
data["assets"]["npcs"],
data["assets"]["trainers"],
ctx.figure,
)
roadmap.roadmap = roadmap.RoadMap(
data["map_stations"],
data["map_decorations"]
data["assets"]["stations"],
data["assets"]["decorations"]
)
pos = data["position"]
self.saved_pos = (
Expand Down
10 changes: 2 additions & 8 deletions pokete_classes/multiplayer/msg/map_info/info.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
from typing import TypedDict

import bs_rpc
from pokete_classes.maps import Obmaps, Maps, NPCs, Trainers, Stations, \
Decorations
from pokete_classes.asset_service.asset_types import Assets
from pokete_classes.multiplayer.msg.position import Position
from pokete_classes.multiplayer.msg.position.update import User

INFO_TYPE = "pokete.map.info"


class InfoData(TypedDict):
obmaps: Obmaps
maps: Maps
npcs: NPCs
trainers: Trainers
map_stations: Stations
map_decorations: Decorations
assets: Assets
position: Position
users: list[User]
greeting_text: str
Expand Down
2 changes: 1 addition & 1 deletion pokete_classes/roadmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
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.context import Context
from pokete_classes.game import PeriodicEvent
from pokete_classes.maps import Stations, Decorations
from util import liner
from .input import ACTION_DIRECTIONS, Action, ActionList, get_action
from .color import Color
Expand Down
3 changes: 2 additions & 1 deletion pokete_data/achievements.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Contains raw achievement data"""
from pokete_classes.asset_service.asset_types import Achievements

achievements = {
achievements: Achievements = {
"first_poke": {
"title": "First Pokete",
"desc": "Catch your first Pokete!"
Expand Down
Loading

0 comments on commit ce1019e

Please sign in to comment.