Skip to content

Commit

Permalink
#267 Fixed mapStations
Browse files Browse the repository at this point in the history
  • Loading branch information
lxgr-linux committed May 15, 2023
1 parent 533e862 commit e262a26
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 38 deletions.
9 changes: 4 additions & 5 deletions pokete.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@
from pokete_classes.pokete_care import PoketeCare, DummyFigure
from pokete_classes.generate import gen_maps, gen_obs
from pokete_classes import deck, detail, game, timer, ob_maps as obmp, \
movemap as mvp, fightmap as fm, buy
movemap as mvp, fightmap as fm, buy, roadmap
# import pokete_classes.generic_map_handler as gmh
from pokete_classes.landscape import HighGrass, Poketeball
from pokete_classes.doors import Door
from pokete_classes.learnattack import LearnAttack
from pokete_classes.roadmap import RoadMap
from pokete_classes.npcs import NPC, Trainer
from pokete_classes.notify import notifier
from pokete_classes.achievements import achievements, AchievementOverview
Expand Down Expand Up @@ -998,7 +997,7 @@ def _game(_map):
pevm = PeriodicEventManager(_map)
inp_dict = {
Action.DECK: [deck.deck, (mvp.movemap, 6, "Your deck")],
Action.MAP: [roadmap, (mvp.movemap,)],
Action.MAP: [roadmap.roadmap, (mvp.movemap,)],
Action.INVENTORY: [inv, ()],
Action.POKEDEX: [pokete_dex, ()],
Action.CLOCK: [timer.clock, (mvp.movemap,)],
Expand Down Expand Up @@ -1258,8 +1257,8 @@ def recogniser():
detail.detail = detail.Detail(tss.height - 1, tss.width)
pokete_dex = Dex(figure)
help_page = Help(mvp.movemap)
RoadMap.check_maps()
roadmap = RoadMap(figure)
roadmap.RoadMap.check_maps()
roadmap.roadmap = roadmap.RoadMap(figure)
deck.deck = deck.Deck(tss.height - 1, tss.width, figure, abb_funcs)
about = About(VERSION, CODENAME, mvp.movemap)
inv = Inv(mvp.movemap)
Expand Down
3 changes: 2 additions & 1 deletion pokete_classes/multiplayer/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging

import release
from pokete_classes import ob_maps as obmp
from pokete_classes import ob_maps as obmp, roadmap
from pokete_classes.generate import gen_maps, gen_obs
from pokete_classes.input import ask_text, ask_ok
from pokete_classes.multiplayer.pc_manager import pc_manager
Expand Down Expand Up @@ -118,6 +118,7 @@ def handshake(self):
d["Body"]["Trainers"],
self.figure,
)
roadmap.roadmap = roadmap.RoadMap(self.figure, d["Body"]["MapStations"])
pos = d["Body"]["Position"]
self.saved_pos = (
self.figure.map.name,
Expand Down
12 changes: 8 additions & 4 deletions pokete_classes/roadmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from .loops import std_loop, easy_exit_loop
from .color import Color
from .ui_elements import Box, InfoBox
from .tss import tss
from . import movemap as mvp


Expand Down Expand Up @@ -76,7 +75,7 @@ def next(self, inp: ActionList):
Action.LEFT: 'a',
Action.RIGHT: 'd',
}[inp]
if (n_e := getattr(self, inp + "_next")) != "":
if (n_e := getattr(self, inp + "_next")) not in ["", None]:
self.unchoose()
getattr(self.roadmap, n_e).choose()

Expand Down Expand Up @@ -105,7 +104,9 @@ class RoadMap:
ARGS:
fig: Figure object"""

def __init__(self, fig):
def __init__(self, fig, stations=None):
if stations is None:
stations = p_data.stations
self.fig = fig
self.box = Box(
11, 40, "Roadmap",
Expand All @@ -114,7 +115,7 @@ def __init__(self, fig):
)
self.info_label = se.Text("", state="float")
self.box.add_ob(self.info_label, self.box.width - 2, 0)
for sta, _dict in p_data.stations.items():
for sta, _dict in stations.items():
obj = Station(self, obmp.ob_maps[sta], **_dict['gen'])
self.box.add_ob(obj, **_dict['add'])
setattr(self, sta, obj)
Expand Down Expand Up @@ -192,5 +193,8 @@ def check_maps():
raise RoadMapException(_map)


roadmap: RoadMap = None


if __name__ == "__main__":
print("\033[31;1mDo not execute this!\033[0m")
58 changes: 34 additions & 24 deletions server/map_repository/map_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,31 @@ import (
)

type MapRepo struct {
obmaps *Obmaps
maps *Maps
npcs *NPCs
trainers *Trainers
obmaps *Obmaps
maps *Maps
npcs *NPCs
trainers *Trainers
stations *Stations
}

func (m MapRepo)GetObmaps() Obmaps {
return *m.obmaps
func (m MapRepo) GetObmaps() Obmaps {
return *m.obmaps
}

func (m MapRepo)GetMaps() Maps {
return *m.maps
func (m MapRepo) GetMaps() Maps {
return *m.maps
}

func (m MapRepo)GetNPCs() NPCs {
return *m.npcs
func (m MapRepo) GetNPCs() NPCs {
return *m.npcs
}

func (m MapRepo)GetTrainers() Trainers {
return *m.trainers
func (m MapRepo) GetTrainers() Trainers {
return *m.trainers
}

func (m MapRepo) GetStations() Stations {
return *m.stations
}

func NewMapRepo() (mapRepo MapRepo, err error) {
Expand All @@ -45,22 +50,27 @@ func NewMapRepo() (mapRepo MapRepo, err error) {
if err != nil {
return
}
tempStations, err := readFile[Stations]("res/mapstations.json")
if err != nil {
return
}

return MapRepo {
obmaps: &tempObmaps,
maps: &tempMaps,
npcs: &tempNPCs,
trainers: &tempTrainers,
}, nil
return MapRepo{
obmaps: &tempObmaps,
maps: &tempMaps,
npcs: &tempNPCs,
trainers: &tempTrainers,
stations: &tempStations,
}, nil
}

func readFile[T any](fileName string) (temp T, err error) {
content, err := os.ReadFile(fileName)
if err != nil {
return
}
content, err := os.ReadFile(fileName)
if err != nil {
return
}

err = json.Unmarshal(content, &temp)
err = json.Unmarshal(content, &temp)

return
return
}
24 changes: 21 additions & 3 deletions server/map_repository/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ type Obmap struct {
}

type SpecialDors struct {
Dor *SpecialDor `json:"dor"`
ShopDor *SpecialDor `json:"shopdor"`
Dor *Coords `json:"dor"`
ShopDor *Coords `json:"shopdor"`
}

type SpecialDor struct {
type Coords struct {
X int32 `json:"x"`
Y int32 `json:"y"`
}
Expand Down Expand Up @@ -99,3 +99,21 @@ type TrainerArgs struct {
X int32 `json:"x"`
Y int32 `json:"y"`
}

type Stations map[string]Station

type Station struct {
Gen StationGen `json:"gen"`
Add Coords `json:"add"`
}

type StationGen struct {
Additionals []string `json:"additionals"`
Width int32 `json:"width"`
Height int32 `json:"height"`
Desc string `json:"desc"`
ANext *string `json:"a_next"`
WNext *string `json:"w_next"`
SNext *string `json:"s_next"`
DNext *string `json:"d_next"`
}
14 changes: 14 additions & 0 deletions server/res/mapstations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"servermap_1": {
"gen": {
"additionals": [],
"width": 2,
"height": 1,
"desc": "This server"
},
"add": {
"x": 4,
"y": 7
}
}
}
10 changes: 9 additions & 1 deletion server/responses/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type MapResponse struct {
Position user_repository.Position
Users []user_repository.User
GreetingText string
MapStations map_repository.Stations
}

func WritePositionChangeResponse(connection *net.Conn, user user_repository.User) error {
Expand Down Expand Up @@ -99,7 +100,13 @@ func WriteUserRemovedResponse(connection *net.Conn, userName string) error {
)
}

func WriteMapResponse(connection *net.Conn, position user_repository.Position, users []user_repository.User, mapRepo map_repository.MapRepo, greetingtext string) error {
func WriteMapResponse(
connection *net.Conn,
position user_repository.Position,
users []user_repository.User,
mapRepo map_repository.MapRepo,
greetingtext string,
) error {
return writeResponse(
connection,
Response{
Expand All @@ -112,6 +119,7 @@ func WriteMapResponse(connection *net.Conn, position user_repository.Position, u
Position: position,
Users: users,
GreetingText: greetingtext,
MapStations: mapRepo.GetStations(),
},
},
)
Expand Down

0 comments on commit e262a26

Please sign in to comment.