Skip to content

Commit

Permalink
#51: Add pre-anchored warp beacon entities
Browse files Browse the repository at this point in the history
  • Loading branch information
ecdavis committed Sep 24, 2016
1 parent b7dd5a0 commit 246c5a9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spacegame/modules/warp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pantsmud.driver import auxiliary, command, hook, parser
from pantsmud.util import error, message
from spacegame.core import aux_types, hook_types
from spacegame.universe import entity


class WarpAux(object):
Expand Down Expand Up @@ -29,6 +30,16 @@ def warp_command(brain, cmd, args):
message.command_success(mobile, cmd)


def warp_beacon_command(brain, cmd, args):
parser.parse([], args)
mobile = brain.mobile
beacon = entity.Entity()
beacon.celestial = mobile.celestial
beacon.position = mobile.position
pantsmud.game.environment.add_entity(beacon)
message.command_success(mobile, cmd)


def warp_scan_command(brain, cmd, args):
parser.parse([], args)
mobile = brain.mobile
Expand Down Expand Up @@ -58,6 +69,7 @@ def clear_warp_scanner(_, mobile):
def init():
auxiliary.install(aux_types.AUX_TYPE_ENTITY, "warp", WarpAux)
command.add_command("warp", warp_command)
command.add_command("warp.beacon", warp_beacon_command)
command.add_command("warp.scan", warp_scan_command)
command.add_command("warp.scan.activate", warp_scan_activate_command)
hook.add("celestial.exit", clear_warp_scanner)
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/test_warp.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,20 @@ def test_warp_scan_after_active_scan(self):
self.assertEqual("command.success", response2["message"])
self.assertEqual("warp.scan", response2["data"]["command"])
self.assertEqual(set(["Sol", "Earth"]), set(response2["data"]["result"]["celestial_names"]))

def test_warp_beacon(self):
client = self.get_client()
self.register_and_login(client, "test_warp_beacon")
client.send("warp.beacon\r\n")
response = json.loads(client.recv(4096))
self.assertEqual("command.success", response["message"])
self.assertEqual("warp.beacon", response["data"]["command"])

def test_warp_beacon_with_parameters_returns_error(self):
client = self.get_client()
self.register_and_login(client, "test_warp_beacon_with_parameters")
client.send("warp.beacon one\r\n")
response = json.loads(client.recv(4096))
self.assertEqual("command.error", response["message"])
self.assertEqual("warp.beacon", response["data"]["command"])
# TODO Verify error message

0 comments on commit 246c5a9

Please sign in to comment.