From fc5adf2fb1dd47a36881d92a5e2a09ebc3135f79 Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Thu, 11 May 2023 12:40:31 +0200 Subject: [PATCH] #267 Made position updating way nicer --- pokete.py | 12 ++++- pokete_classes/generate.py | 10 +++- pokete_classes/map_additions/map_addtions.py | 44 +-------------- pokete_data/map_data.py | 56 ++++++++++++++++++++ server/map_repository/types.go | 29 ++++++---- server/res/map_data.json | 10 ++++ server/user_repository/user.go | 4 +- 7 files changed, 108 insertions(+), 57 deletions(-) diff --git a/pokete.py b/pokete.py index a36b559d..0e474512 100755 --- a/pokete.py +++ b/pokete.py @@ -337,8 +337,16 @@ def set_args(self, _si): mvp.movemap.add_obs() def set(self, x, y): - if super().set(x, y) == 0 and modeProvider.mode == Mode.MULTI: - connector.connector.send_pos_update(self.map.name, x, y) + if super().set(x, y) == 0: + self.update_server_pos() + + def add(self, _map, x, y): + if super().add(_map, x, y) == 0: + self.update_server_pos() + + def update_server_pos(self): + if modeProvider.mode == Mode.MULTI: + connector.connector.send_pos_update(self.map.name, self.x, self.y) def add_money(self, money): """Adds money diff --git a/pokete_classes/generate.py b/pokete_classes/generate.py index 5c714cfc..60e11b67 100644 --- a/pokete_classes/generate.py +++ b/pokete_classes/generate.py @@ -8,7 +8,7 @@ from .classes import PlayMap from .npcs import Trainer from .poke import Poke -from .doors import Door +from .doors import Door, DoorToShop, DoorToCenter from .npcs import NPC from .settings import settings from . import ob_maps as obmp @@ -93,6 +93,14 @@ def gen_obs(map_data, npcs, trainers, figure): 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"]: + obj = cls() + setattr(_map, name, obj) + obj.add(_map, single_map["special_dors"][name]["x"], + single_map["special_dors"][name]["y"]) + # NPCs for npc, _npc in npcs.items(): NPC(npc, _npc["texts"], _fn=_npc["fn"], diff --git a/pokete_classes/map_additions/map_addtions.py b/pokete_classes/map_additions/map_addtions.py index 7dcf990c..d1b75ebf 100644 --- a/pokete_classes/map_additions/map_addtions.py +++ b/pokete_classes/map_additions/map_addtions.py @@ -1,7 +1,7 @@ import scrap_engine as se import pokete_data as p_data -from pokete_classes.doors import DoorToCenter, Door, DoorToShop, ChanceDoor +from pokete_classes.doors import Door, ChanceDoor from .. import ob_maps as obmp from ..landscape import HighGrass from ..settings import settings @@ -10,12 +10,6 @@ def map_additions(figure): """Applies additions to the maps""" - # playmap_1 - _map = obmp.ob_maps["playmap_1"] - _map.dor = DoorToCenter() - # adding - _map.dor.add(_map, 25, 4) - # cave_1 _map = obmp.ob_maps["cave_1"] _map.inner = se.Text("""########################################## @@ -44,14 +38,6 @@ def map_additions(figure): # adding _map.inner.add(_map, 0, 0) - # playmap_3 - _map = obmp.ob_maps["playmap_3"] - _map.dor = DoorToCenter() - _map.shopdor = DoorToShop() - # adding - _map.dor.add(_map, 25, 6) - _map.shopdor.add(_map, 61, 6) - # playmap_4 _map = obmp.ob_maps["playmap_4"] _map.dor_playmap_5 = ChanceDoor("~", state="float", @@ -117,14 +103,6 @@ def map_additions(figure): # adding _map.inner.add(_map, 2, 1) - # playmap_13 - _map = obmp.ob_maps["playmap_13"] - _map.dor = DoorToCenter() - _map.shopdor = DoorToShop() - # adding - _map.dor.add(_map, 14, 29) - _map.shopdor.add(_map, 52, 29) - # playmap_19 _map = obmp.ob_maps["playmap_19"] _map.inner = se.Text(""" #### @@ -166,25 +144,5 @@ def map_additions(figure): _map.dor_playmap_19 = Door("_", state="float", arg_proto={"map": "playmap_19", "x": 26, "y": 1}) - _map.dor = DoorToCenter() - _map.shopdor = DoorToShop() # adding _map.dor_playmap_19.add(_map, 5, 26) - _map.dor.add(_map, 10, 7) - _map.shopdor.add(_map, 34, 7) - - # playmap_30 - _map = obmp.ob_maps["playmap_30"] - _map.dor = DoorToCenter() - _map.shopdor = DoorToShop() - # adding - _map.dor.add(_map, 13, 7) - _map.shopdor.add(_map, 30, 7) - - # playmap_39 - _map = obmp.ob_maps["playmap_39"] - _map.dor = DoorToCenter() - _map.shopdor = DoorToShop() - # adding - _map.dor.add(_map, 44, 52) - _map.shopdor.add(_map, 122, 64) \ No newline at end of file diff --git a/pokete_data/map_data.py b/pokete_data/map_data.py index c3940c1d..68bca297 100644 --- a/pokete_data/map_data.py +++ b/pokete_data/map_data.py @@ -162,6 +162,12 @@ "args": {"map": "playmap_51", "x": 1, "y": 29} }, }, + "special_dors": { + "dor": { + "x": 25, + "y":4 + } + }, "balls": { "ball_1": { "x": 54, @@ -622,6 +628,16 @@ "args": {"map": "playmap_49", "x": 11, "y": 7} }, }, + "special_dors": { + "dor": { + "x": 25, + "y": 6, + }, + "shopdor": { + "x": 61, + "y": 6, + } + }, "balls": { "ball_1": { "x": 56, @@ -1584,6 +1600,16 @@ "args": {"map": "playmap_20", "x": 11, "y": 7} }, }, + "special_dors": { + "dor": { + "x": 14, + "y": 29, + }, + "shopdor": { + "x": 52, + "y": 29, + } + }, "balls": { "ball_1": { "x": 14, @@ -2431,6 +2457,16 @@ "args": {"map": "playmap_50", "x": 11, "y": 7} }, }, + "special_dors": { + "dor": { + "x": 10, + "y": 7, + }, + "shopdor": { + "x": 34, + "y": 7, + } + }, "balls": { "ball_1": { "x": 146, @@ -2922,6 +2958,16 @@ "args": {"map": "playmap_32", "x": 11, "y": 7} }, }, + "special_dors": { + "dor": { + "x": 13, + "y": 7, + }, + "shopdor": { + "x": 30, + "y": 7, + } + }, "balls": { "ball_1": { "x": 58, @@ -3853,6 +3899,16 @@ "args": {"map": "playmap_48", "x": 11, "y": 7} }, }, + "special_dors": { + "dor": { + "x": 44, + "y": 52, + }, + "shopdor": { + "x": 122, + "y": 64, + } + }, "balls": { "ball_1": { "x": 3, diff --git a/server/map_repository/types.go b/server/map_repository/types.go index e2a3062e..40021746 100644 --- a/server/map_repository/types.go +++ b/server/map_repository/types.go @@ -3,10 +3,21 @@ package map_repository type Obmaps map[string]Obmap type Obmap struct { - HardObs map[string]Ob `json:"hard_obs"` - SoftObs map[string]Ob `json:"soft_obs"` - Dors map[string]Dor `json:"dors"` - Balls map[string]Ball `json:"balls"` + HardObs map[string]Ob `json:"hard_obs"` + SoftObs map[string]Ob `json:"soft_obs"` + Dors map[string]Dor `json:"dors"` + SpecialDors *SpecialDors `json:"special_dors"` + Balls map[string]Ball `json:"balls"` +} + +type SpecialDors struct { + Dor *SpecialDor `json:"dor"` + ShopDor *SpecialDor `json:"shopdor"` +} + +type SpecialDor struct { + X int32 `json:"x"` + Y int32 `json:"y"` } type Ob struct { @@ -55,11 +66,11 @@ type NPCs map[string]NPC type NPC struct { Texts []string `json:"texts"` - Fn *string `json:"fn"` - Map string `json:"map"` - X int32 `json:"x"` - Y int32 `json:"y"` - Chat *Chat `json:"chat"` + Fn *string `json:"fn"` + Map string `json:"map"` + X int32 `json:"x"` + Y int32 `json:"y"` + Chat *Chat `json:"chat"` } type Chat struct { diff --git a/server/res/map_data.json b/server/res/map_data.json index eda1bf5f..6a648264 100644 --- a/server/res/map_data.json +++ b/server/res/map_data.json @@ -226,6 +226,16 @@ } } }, + "special_dors": { + "dor": { + "x": 25, + "y": 6 + }, + "shopdor": { + "x": 61, + "y": 6 + } + }, "balls": { "ball_1": { "x": 56, diff --git a/server/user_repository/user.go b/server/user_repository/user.go index dff2de81..6265c943 100644 --- a/server/user_repository/user.go +++ b/server/user_repository/user.go @@ -30,9 +30,9 @@ func (p *Position) Change(newPosition Position) error { } func (p Position) isPlausible(newPosition Position) bool { - return p.Map == newPosition.Map && slices.Contains( + return p.Map != newPosition.Map || slices.Contains( []Position{ - {p.Map, p.X, p.Y + 1,}, + {p.Map, p.X, p.Y + 1}, {p.Map, p.X, p.Y - 1}, {p.Map, p.X + 1, p.Y}, {p.Map, p.X - 1, p.Y},