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