home · contact · privacy
c1d61419dd8edb997394ba1d837abe2ebea283b4
[plomrogue] / client / commands.py
1 # This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
2 # or any later version. For details on its copyright, license, and warranties,
3 # see the file NOTICE in the root directory of the PlomRogue source package.
4
5
6 from client.config.world_data import world_data
7 from client.io import send
8 from client.query_mapcell import query_mapcell
9
10
11 def command_quit():
12     send("QUIT")
13     raise SystemExit("Received QUIT command, forwarded to server, leaving.")
14
15
16 def command_toggle_look_mode():
17     if not world_data["look_mode"]:
18         world_data["look_mode"] = True
19     else:
20         world_data["look_mode"] = False
21         world_data["map_center"] = world_data["avatar_position"]
22         query_mapcell()
23
24
25 def command_sender(string, int_field=None):
26     def command_send():
27         int_string = ""
28         if int_field:
29             int_string = " " + str(world_data[int_field])
30         send(string + int_string)
31     return command_send
32
33
34 def command_looker(string):
35     def command_look():
36         if string == "west" \
37                 and world_data["map_center"][1] > 0:
38             world_data["map_center"][1] -= 1
39         elif string == "east" \
40                 and world_data["map_center"][1] < world_data["map_size"] - 1:
41             world_data["map_center"][1] += 1
42         else:
43             y_unevenness = world_data["map_center"][0] % 2
44             y_evenness = int(not(y_unevenness))
45             if string[6:] == "west" and \
46                     world_data["map_center"][1] > -y_unevenness:
47                 if string[:5] == "north" and world_data["map_center"][0] > 0:
48                     world_data["map_center"][0] -= 1
49                     world_data["map_center"][1] -= y_evenness
50                 if string[:5] == "south" and world_data["map_center"][0] \
51                         < world_data["map_size"] - 1:
52                     world_data["map_center"][0] += 1
53                     world_data["map_center"][1] -= y_evenness
54             elif string[6:] == "east" and world_data["map_center"][1] \
55                     < world_data["map_size"] - y_unevenness:
56                 if string[:5] == "north" and world_data["map_center"][0] > 0:
57                     world_data["map_center"][0] -= 1
58                     world_data["map_center"][1] += y_unevenness
59                 if string[:5] == "south" and world_data["map_center"][0] \
60                         < world_data["map_size"] - 1:
61                     world_data["map_center"][0] += 1
62                     world_data["map_center"][1] += y_unevenness
63         query_mapcell()
64     return command_look
65
66
67 def command_look_scroller(string):
68     def command_look_scroll():
69         win_size = next(win["size"] for win in windows
70                                     if win["func"] == win_look)
71         if string == "up" and world_data["look_scroll"] > 0:
72             world_data["look_scroll"] -= 1
73         elif string == "down" and world_data["look_scroll"] \
74                 < len(world_data["look"]) - win_size[0]:
75             world_data["look_scroll"] += 1
76     return command_look_scroll
77
78
79 def command_inventory_selector(string):
80     def command_inventory_select():
81         if string == "up" and world_data["inventory_selection"] > 0:
82             world_data["inventory_selection"] -= 1
83         elif string == "down" and world_data["inventory_selection"] \
84                 < len(world_data["inventory"]) - 1:
85             world_data["inventory_selection"] += 1
86     return command_inventory_select