def get_time(self):
"""Convenience method to get the elapsed time counter."""
- return self.groups["internal"]["counters"].get("elapsed")
+ try:
+ return self.groups["internal"]["counters"].get("elapsed", 0)
+ except KeyError:
+ return 0
+
+ def set_time(self, elapsed):
+ """Convenience method to set the elapsed time counter."""
+ try:
+ self.groups["internal"]["counters"].set("elapsed", elapsed)
+ except KeyError:
+ # add an element for counters if it doesn't exist
+ Element("internal.counters", universe)
+ self.groups["internal"]["counters"].set("elapsed", elapsed)
def add_group(self, group, fallback=None):
"""Set up group tracking/metadata."""
if "$_(time)" in prompt:
prompt = prompt.replace(
"$_(time)",
- str(universe.groups["internal"]["counters"].get("elapsed")))
+ str(universe.get_time()))
# Append a single space for clear separation from user input
if prompt[-1] != " ":
def on_pulse():
"""The things which should happen on each pulse, aside from reloads."""
- # open the listening socket if it hasn't been already
- if not hasattr(universe, "listening_socket"):
- universe.initialize_server_socket()
-
- # assign a user if a new connection is waiting
- user = check_for_connection(universe.listening_socket)
- if user:
- universe.userlist.append(user)
-
- # iterate over the connected users
- for user in universe.userlist:
- user.pulse()
-
- # add an element for counters if it doesn't exist
- if "counters" not in universe.groups.get("internal", {}):
- Element("internal.counters", universe)
+ # increase the elapsed increment counter
+ universe.set_time(universe.get_time() + 1)
# update the log every now and then
if not universe.groups["internal"]["counters"].get("mark"):
) - 1
)
+ # open the listening socket if it hasn't been already
+ if not hasattr(universe, "listening_socket"):
+ universe.initialize_server_socket()
+
+ # assign a user if a new connection is waiting
+ user = check_for_connection(universe.listening_socket)
+ if user:
+ universe.userlist.append(user)
+
+ # iterate over the connected users
+ for user in universe.userlist:
+ user.pulse()
+
# pause for a configurable amount of time (decimal seconds)
time.sleep(universe.contents["mudpy.timing"].get("increment"))
- # increase the elapsed increment counter
- universe.groups["internal"]["counters"].set(
- "elapsed", universe.groups["internal"]["counters"].get(
- "elapsed", 0
- ) + 1
- )
-
def reload_data():
"""Reload all relevant objects."""