Complete overhaul from start to finish.
This commit is contained in:
parent
3d3bd5e9d7
commit
ff6f0bebb8
3 changed files with 10 additions and 12 deletions
|
|
@ -158,7 +158,7 @@ Damage roll: 1d6
|
||||||
Here's the start of how the function could look:
|
Here's the start of how the function could look:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# in mygame/evadventure/utils.py
|
# in mygame/evadventure/time.py
|
||||||
|
|
||||||
_OBJ_STATS = """
|
_OBJ_STATS = """
|
||||||
|c{key}|n
|
|c{key}|n
|
||||||
|
|
|
||||||
|
|
@ -187,10 +187,11 @@ def _run_code_snippet(
|
||||||
|
|
||||||
if show_input:
|
if show_input:
|
||||||
for session in sessions:
|
for session in sessions:
|
||||||
|
data = {"text": (f">>> {pycode}", {"type": "py_input"}), "options": {"raw": True}}
|
||||||
try:
|
try:
|
||||||
caller.msg(">>> %s" % pycode, session=session, options={"raw": True})
|
caller.msg(session=session, **data)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
caller.msg(">>> %s" % pycode, options={"raw": True})
|
caller.msg(**data)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# reroute standard output to game client console
|
# reroute standard output to game client console
|
||||||
|
|
@ -202,10 +203,7 @@ def _run_code_snippet(
|
||||||
self.caller = caller
|
self.caller = caller
|
||||||
|
|
||||||
def write(self, string):
|
def write(self, string):
|
||||||
if string.endswith("\n"):
|
self.caller.msg(text=(string.rstrip("\n"), {"type": "py_output"}))
|
||||||
self.caller.msg(string[:-1])
|
|
||||||
else:
|
|
||||||
self.caller.msg(string)
|
|
||||||
|
|
||||||
fake_std = FakeStd(caller)
|
fake_std = FakeStd(caller)
|
||||||
sys.stdout = fake_std
|
sys.stdout = fake_std
|
||||||
|
|
@ -222,7 +220,7 @@ def _run_code_snippet(
|
||||||
t0 = time.time()
|
t0 = time.time()
|
||||||
ret = eval(pycode_compiled, {}, available_vars)
|
ret = eval(pycode_compiled, {}, available_vars)
|
||||||
t1 = time.time()
|
t1 = time.time()
|
||||||
duration = " (runtime ~ %.4f ms)" % ((t1 - t0) * 1000)
|
duration = f" (runtime ~ {(t1 - t0) * 1000:.4f} ms)"
|
||||||
caller.msg(duration)
|
caller.msg(duration)
|
||||||
else:
|
else:
|
||||||
ret = eval(pycode_compiled, {}, available_vars)
|
ret = eval(pycode_compiled, {}, available_vars)
|
||||||
|
|
@ -246,9 +244,9 @@ def _run_code_snippet(
|
||||||
|
|
||||||
for session in sessions:
|
for session in sessions:
|
||||||
try:
|
try:
|
||||||
caller.msg(ret, session=session, options={"raw": True, "client_raw": client_raw})
|
caller.msg((ret, {"type": "py_output"}), session=session, options={"raw": True, "client_raw": client_raw})
|
||||||
except TypeError:
|
except TypeError:
|
||||||
caller.msg(ret, options={"raw": True, "client_raw": client_raw})
|
caller.msg((ret, {"type": "py_output"}), options={"raw": True, "client_raw": client_raw})
|
||||||
|
|
||||||
|
|
||||||
def evennia_local_vars(caller):
|
def evennia_local_vars(caller):
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ class TestDedent(TestCase):
|
||||||
|
|
||||||
class TestListToString(TestCase):
|
class TestListToString(TestCase):
|
||||||
"""
|
"""
|
||||||
Default function header from utils.py:
|
Default function header from time.py:
|
||||||
list_to_string(inlist, sep=",", endsep=", and", addquote=False)
|
list_to_string(inlist, sep=",", endsep=", and", addquote=False)
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
@ -175,7 +175,7 @@ class TestANSIString(TestCase):
|
||||||
|
|
||||||
class TestTimeformat(TestCase):
|
class TestTimeformat(TestCase):
|
||||||
"""
|
"""
|
||||||
Default function header from utils.py:
|
Default function header from time.py:
|
||||||
time_format(seconds, style=0)
|
time_format(seconds, style=0)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue