Add paint mode for terrain editing
This commit is contained in:
parent
c3884e236b
commit
889a0d7bcf
3 changed files with 67 additions and 2 deletions
|
|
@ -68,11 +68,15 @@ async def move_player(player: Player, dx: int, dy: int, direction_name: str) ->
|
||||||
assert isinstance(zone, Zone), "Player must be in a zone to move"
|
assert isinstance(zone, Zone), "Player must be in a zone to move"
|
||||||
target_x, target_y = zone.wrap(player.x + dx, player.y + dy)
|
target_x, target_y = zone.wrap(player.x + dx, player.y + dy)
|
||||||
|
|
||||||
# Check if the target is passable
|
# Check if the target is passable (skip check in paint mode)
|
||||||
if not zone.is_passable(target_x, target_y):
|
if not player.paint_mode and not zone.is_passable(target_x, target_y):
|
||||||
await player.send("You can't go that way.\r\n")
|
await player.send("You can't go that way.\r\n")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# If painting, place the brush tile at the current position before moving
|
||||||
|
if player.paint_mode and player.painting:
|
||||||
|
zone.terrain[player.y][player.x] = player.paint_brush
|
||||||
|
|
||||||
# Send departure message to players in the old area
|
# Send departure message to players in the old area
|
||||||
opposite = OPPOSITE_DIRECTIONS[direction_name]
|
opposite = OPPOSITE_DIRECTIONS[direction_name]
|
||||||
await send_nearby_message(
|
await send_nearby_message(
|
||||||
|
|
|
||||||
58
src/mudlib/commands/paint.py
Normal file
58
src/mudlib/commands/paint.py
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
"""Paint mode commands for terrain editing."""
|
||||||
|
|
||||||
|
from mudlib.commands import CommandDefinition, register
|
||||||
|
from mudlib.player import Player
|
||||||
|
|
||||||
|
|
||||||
|
async def cmd_paint(player: Player, args: str) -> None:
|
||||||
|
"""Toggle paint mode on/off.
|
||||||
|
|
||||||
|
Paint mode allows admin to edit terrain tile-by-tile.
|
||||||
|
"""
|
||||||
|
if player.paint_mode:
|
||||||
|
# Exit paint mode
|
||||||
|
player.paint_mode = False
|
||||||
|
player.painting = False
|
||||||
|
await player.send("Paint mode off.\r\n")
|
||||||
|
else:
|
||||||
|
# Enter paint mode
|
||||||
|
player.paint_mode = True
|
||||||
|
player.painting = False
|
||||||
|
await player.send(
|
||||||
|
"Paint mode on. Use 'p' to toggle painting, "
|
||||||
|
"type a character to set brush.\r\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def cmd_toggle_painting(player: Player, args: str) -> None:
|
||||||
|
"""Toggle between survey and painting states within paint mode."""
|
||||||
|
if not player.paint_mode:
|
||||||
|
await player.send("You must be in paint mode to do that.\r\n")
|
||||||
|
return
|
||||||
|
|
||||||
|
player.painting = not player.painting
|
||||||
|
if player.painting:
|
||||||
|
await player.send(f"Painting with '{player.paint_brush}'.\r\n")
|
||||||
|
else:
|
||||||
|
await player.send("Survey mode.\r\n")
|
||||||
|
|
||||||
|
|
||||||
|
async def cmd_set_brush(player: Player, args: str) -> None:
|
||||||
|
"""Set the brush character for painting."""
|
||||||
|
if not player.paint_mode:
|
||||||
|
await player.send("You must be in paint mode to do that.\r\n")
|
||||||
|
return
|
||||||
|
|
||||||
|
char = args.strip()
|
||||||
|
if len(char) != 1:
|
||||||
|
await player.send("Brush must be a single character.\r\n")
|
||||||
|
return
|
||||||
|
|
||||||
|
player.paint_brush = char
|
||||||
|
await player.send(f"Brush set to '{char}'.\r\n")
|
||||||
|
|
||||||
|
|
||||||
|
# Register paint mode commands
|
||||||
|
register(CommandDefinition("@paint", cmd_paint))
|
||||||
|
register(CommandDefinition("p", cmd_toggle_painting))
|
||||||
|
register(CommandDefinition("brush", cmd_set_brush))
|
||||||
|
|
@ -25,6 +25,9 @@ class Player(Entity):
|
||||||
caps: ClientCaps = field(default_factory=lambda: ClientCaps(ansi=True))
|
caps: ClientCaps = field(default_factory=lambda: ClientCaps(ansi=True))
|
||||||
editor: Editor | None = None
|
editor: Editor | None = None
|
||||||
if_session: IFSession | EmbeddedIFSession | None = None
|
if_session: IFSession | EmbeddedIFSession | None = None
|
||||||
|
paint_mode: bool = False
|
||||||
|
painting: bool = False
|
||||||
|
paint_brush: str = "."
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def mode(self) -> str:
|
def mode(self) -> str:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue