Implement style property retrieval with inheritance.
This commit is contained in:
+33
-5
@@ -223,19 +223,47 @@ cdef class StyleCore:
|
||||
Retrieves the property at `index` from this style or its parents.
|
||||
"""
|
||||
|
||||
cdef PyObject *o
|
||||
|
||||
# The current style object we're looking at.
|
||||
cdef StyleCore s
|
||||
|
||||
# The style object we'll backtrack to when s has no down-parent.
|
||||
cdef StyleCore left
|
||||
|
||||
index += self.offset
|
||||
|
||||
if not self.built:
|
||||
build_style(self)
|
||||
|
||||
cdef PyObject *o
|
||||
s = self
|
||||
left = None
|
||||
|
||||
while True:
|
||||
|
||||
# If we have the style, return it.
|
||||
if s.cache != NULL:
|
||||
o = s.cache[index]
|
||||
if o != NULL:
|
||||
return <object> o
|
||||
|
||||
# If there is no left-parent, and we have one, store it.
|
||||
if left is None and s.left_parent is not None:
|
||||
left = s.left_parent
|
||||
|
||||
s = s.down_parent
|
||||
|
||||
# If no down-parent, try left.
|
||||
if s is None:
|
||||
s = left
|
||||
left = None
|
||||
|
||||
# If no down-parent or left-parent, default to None.
|
||||
if s is None:
|
||||
return None
|
||||
|
||||
o = self.cache[index]
|
||||
|
||||
if o == NULL:
|
||||
return None
|
||||
|
||||
return <object> o
|
||||
|
||||
from renpy.styleclass import Style
|
||||
|
||||
|
||||
@@ -65,7 +65,11 @@ class TestStyles(unittest.TestCase):
|
||||
|
||||
build_styles()
|
||||
|
||||
|
||||
s = sm.prefs_default["foo"]
|
||||
|
||||
assert s.bold == "default_foo"
|
||||
assert s.italic == "prefs_default"
|
||||
assert s.size == "default"
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user