Fixed a lingering bug with @set that made it not work when assigning normal strings without quotes. Changed so that proper Python constructs (lists, dicts etc) now requires you to entering proper Python syntax (since this is parsed).
This commit is contained in:
parent
bcf214ee0d
commit
5a2228763f
3 changed files with 219 additions and 200 deletions
|
|
@ -872,12 +872,12 @@ archway
|
||||||
# split by commas (so each entry cannot contain commas).
|
# split by commas (so each entry cannot contain commas).
|
||||||
#
|
#
|
||||||
@set ghost/irregular_echoes =
|
@set ghost/irregular_echoes =
|
||||||
[The foggy thing gives off a high-pitched shriek., For a moment the
|
["The foggy thing gives off a high-pitched shriek.","For a moment the
|
||||||
fog wraps around a nearby pillar., The fog drifts lower to the ground
|
fog wraps around a nearby pillar.", "The fog drifts lower to the ground
|
||||||
as if looking for something., The fog momentarily takes on a reddish
|
as if looking for something.", "The fog momentarily takes on a reddish
|
||||||
hue.,The fog temporarily fills most of the area as it changes
|
hue.", "The fog temporarily fills most of the area as it changes
|
||||||
shape.,You accidentally breathes in some of the fog - you start
|
shape.", "You accidentally breathes in some of the fog - you start
|
||||||
coughing from the cold moisture.]
|
coughing from the cold moisture."]
|
||||||
#
|
#
|
||||||
# give the enemy a tentacle weapon
|
# give the enemy a tentacle weapon
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -1153,10 +1153,19 @@ class CmdSetAttribute(ObjManipCommand):
|
||||||
Sets attributes on objects. The second form clears
|
Sets attributes on objects. The second form clears
|
||||||
a previously set attribute while the last form
|
a previously set attribute while the last form
|
||||||
inspects the current value of the attribute
|
inspects the current value of the attribute
|
||||||
(if any). You can also set lists [...] and dicts {...}
|
(if any).
|
||||||
on attributes with @set (but not nested combinations). Also
|
|
||||||
note that such lists/dicts will always hold strings (never numbers).
|
The most common data to save with this command are strings and
|
||||||
Use @py if you need to set arbitrary lists and dicts.
|
numbers. You can however also set Python primities such as lists,
|
||||||
|
dictionaries and tuples on objects (this might be important for
|
||||||
|
the functionality of certain custom objects). This is indicated
|
||||||
|
by you starting your value with one of {c'{n, {c"{n, {c({n, {c[{n or {c{ {n.
|
||||||
|
Note that you should leave a space after starting a dictionary ('{ ')
|
||||||
|
so as to not confuse the dictionary start with a colour code.
|
||||||
|
Remember that if you use Python primitives like this, you must
|
||||||
|
write proper Python syntax too - notably you must include quotes
|
||||||
|
around your strings or you will get an error.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key = "@set"
|
key = "@set"
|
||||||
|
|
@ -1201,7 +1210,9 @@ class CmdSetAttribute(ObjManipCommand):
|
||||||
for pair in obj[1:-1].split(',') if ":" in pair])
|
for pair in obj[1:-1].split(',') if ":" in pair])
|
||||||
# if nothing matches, return as-is
|
# if nothing matches, return as-is
|
||||||
return obj
|
return obj
|
||||||
|
if strobj.strip() and strobj.strip()[0] in ("'", '"', "(", "{ ", "["):
|
||||||
|
# this is a structure starting with a proper python structure,
|
||||||
|
# so treat it as such.
|
||||||
try:
|
try:
|
||||||
# under python 2.6, literal_eval can do this for us.
|
# under python 2.6, literal_eval can do this for us.
|
||||||
from ast import literal_eval
|
from ast import literal_eval
|
||||||
|
|
@ -1210,6 +1221,7 @@ class CmdSetAttribute(ObjManipCommand):
|
||||||
# fall back to old recursive solution (don't support nested lists/dicts)
|
# fall back to old recursive solution (don't support nested lists/dicts)
|
||||||
return rec_convert(strobj.strip())
|
return rec_convert(strobj.strip())
|
||||||
|
|
||||||
|
|
||||||
def func(self):
|
def func(self):
|
||||||
"Implement the set attribute - a limited form of @py."
|
"Implement the set attribute - a limited form of @py."
|
||||||
|
|
||||||
|
|
@ -1253,8 +1265,15 @@ class CmdSetAttribute(ObjManipCommand):
|
||||||
else:
|
else:
|
||||||
# setting attribute(s). Make sure to convert to real Python type before saving.
|
# setting attribute(s). Make sure to convert to real Python type before saving.
|
||||||
for attr in attrs:
|
for attr in attrs:
|
||||||
|
try:
|
||||||
obj.set_attribute(attr, self.convert_from_string(value))
|
obj.set_attribute(attr, self.convert_from_string(value))
|
||||||
string += "\nCreated attribute %s/%s = %s" % (obj.name, attr, value)
|
string += "\nCreated attribute %s/%s = %s" % (obj.name, attr, value)
|
||||||
|
except SyntaxError:
|
||||||
|
# this means literal_eval tried to parse a faulty string
|
||||||
|
string = "{RPython syntax error in your value. By assigning a value starting with"
|
||||||
|
string += "\none of {r'{R, {r\"{R, {r[{R, {r({R or {r{{R we assume you are entering a proper Python"
|
||||||
|
string += "\nprimitive such as a list or a dictionary. You must then also use correct"
|
||||||
|
string += "\nPython syntax. Remember especially to put quotes around all strings.{n"
|
||||||
# send feedback
|
# send feedback
|
||||||
caller.msg(string.strip('\n'))
|
caller.msg(string.strip('\n'))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,7 @@ class ANSIParser(object):
|
||||||
if red == green and red == blue and red < 2:
|
if red == green and red == blue and red < 2:
|
||||||
if background: return ANSI_BACK_BLACK
|
if background: return ANSI_BACK_BLACK
|
||||||
elif red >= 1: return ANSI_HILITE + ANSI_BLACK
|
elif red >= 1: return ANSI_HILITE + ANSI_BLACK
|
||||||
else: return ANSO_NORMAL + ANSI_BLACK
|
else: return ANSI_NORMAL + ANSI_BLACK
|
||||||
elif red == green and red == blue:
|
elif red == green and red == blue:
|
||||||
if background: return ANSI_BACK_WHITE
|
if background: return ANSI_BACK_WHITE
|
||||||
elif red >= 4: return ANSI_HILITE + ANSI_WHITE
|
elif red >= 4: return ANSI_HILITE + ANSI_WHITE
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue