Skip to content

Commit

Permalink
#267 Made position updating way nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
lxgr-linux committed May 11, 2023
1 parent 75139b8 commit fc5adf2
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 57 deletions.
12 changes: 10 additions & 2 deletions pokete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion pokete_classes/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"],
Expand Down
44 changes: 1 addition & 43 deletions pokete_classes/map_additions/map_addtions.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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("""##########################################
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(""" ####
Expand Down Expand Up @@ -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)
56 changes: 56 additions & 0 deletions pokete_data/map_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@
"args": {"map": "playmap_51", "x": 1, "y": 29}
},
},
"special_dors": {
"dor": {
"x": 25,
"y":4
}
},
"balls": {
"ball_1": {
"x": 54,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
29 changes: 20 additions & 9 deletions server/map_repository/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions server/res/map_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@
}
}
},
"special_dors": {
"dor": {
"x": 25,
"y": 6
},
"shopdor": {
"x": 61,
"y": 6
}
},
"balls": {
"ball_1": {
"x": 56,
Expand Down
4 changes: 2 additions & 2 deletions server/user_repository/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit fc5adf2

Please sign in to comment.