Revision a5c338e8
Added by Vincent Le Goff over 4 years ago
src/client.py | ||
---|---|---|
54 | 54 |
|
55 | 55 |
"""Class to receive data from the MUD.""" |
56 | 56 |
|
57 |
def __init__(self, host, port=4000, timeout=0.1, engine=None): |
|
57 |
def __init__(self, host, port=4000, timeout=0.1, engine=None, |
|
58 |
world=None): |
|
58 | 59 |
"""Connects to the MUD.""" |
59 | 60 |
threading.Thread.__init__(self) |
60 | 61 |
self.client = None |
61 | 62 |
self.timeout = timeout |
62 | 63 |
self.engine = engine |
64 |
self.world = world |
|
63 | 65 |
self.running = False |
64 |
self.sharp_engine = SharpScript(engine, self) |
|
65 |
self.triggers = [] |
|
66 |
self.macros = [] |
|
66 |
self.sharp_engine = SharpScript(engine, self, world) |
|
67 | 67 |
|
68 | 68 |
# Try to connect to the specified host and port |
69 | 69 |
self.client = Telnet(host, port) |
... | ... | |
76 | 76 |
msg = self.client.read_very_eager() |
77 | 77 |
if msg: |
78 | 78 |
for line in msg.splitlines(): |
79 |
for trigger in self.triggers: |
|
79 |
for trigger in self.world.triggers:
|
|
80 | 80 |
trigger.feed(line) |
81 | 81 |
|
82 | 82 |
self.handle_message(msg) |
... | ... | |
111 | 111 |
|
112 | 112 |
""" |
113 | 113 |
|
114 |
def __init__(self, host, port=4000, timeout=0.1, engine=None): |
|
115 |
Client.__init__(self, host, port, timeout, engine) |
|
114 |
def __init__(self, host, port=4000, timeout=0.1, engine=None, |
|
115 |
world=None): |
|
116 |
Client.__init__(self, host, port, timeout, engine, world) |
|
116 | 117 |
self.window = None |
117 | 118 |
if self.client: |
118 | 119 |
self.client.set_option_negotiation_callback(self.handle_option) |
119 | 120 |
|
120 |
def load_script(self, world): |
|
121 |
"""Load the config.set script.""" |
|
122 |
from game import Level |
|
123 |
level = self.engine.level |
|
124 |
self.engine.level = Level.world |
|
125 |
path = world.path |
|
126 |
path = os.path.join(path, "config.set") |
|
127 |
if os.path.exists(path): |
|
128 |
file = open(path, "r") |
|
129 |
content = file.read() |
|
130 |
file.close() |
|
131 |
|
|
132 |
# Execute the script |
|
133 |
self.sharp_engine.execute(content) |
|
134 |
|
|
135 |
# Put the engine level back |
|
136 |
self.engine.level = level |
|
137 |
|
|
138 | 121 |
def link_window(self, window): |
139 | 122 |
"""Link to a window (a GUI object). |
140 | 123 |
|
... | ... | |
147 | 130 |
""" |
148 | 131 |
self.window = window |
149 | 132 |
window.client = self |
150 |
self.load_script(window.world) |
|
151 | 133 |
|
152 | 134 |
def handle_message(self, msg, force_TTS=False, screen=True, |
153 | 135 |
speech=True, braille=True): |
Also available in: Unified diff
Put the macros and triggers in the world itself