set_variables_as_attrs method on Scene

This commit is contained in:
Grant Sanderson 2017-10-20 16:29:30 -07:00
parent 065a34fb51
commit 666fe16e8c

View file

@ -75,20 +75,23 @@ class Scene(object):
self.name = name self.name = name
return self return self
def update_shared_locals(self, *keys): def set_variables_as_attrs(self, *objects, **newly_named_objects):
""" """
Often in constructing a scene, it's nice to refer to This method is slightly hacky, making it a little easier
what was a local variable from a previous subroutine, for certain methods (typically subroutines of construct)
so a dict of shared_locals is recorded, and it can be updated to share local variables.
by passing in the objects directly.
""" """
caller_locals = inspect.currentframe().f_back.f_locals caller_locals = inspect.currentframe().f_back.f_locals
self.shared_locals.update(dict([ for key, value in caller_locals.items():
(key, caller_locals[key]) if value in objects:
for key in keys setattr(self, key, value)
])) for key, value in newly_named_objects.items():
setattr(self, key, value)
return self return self
def get_attrs(self, *keys):
return [getattr(self, key) for key in keys]
### Only these methods should touch the camera ### Only these methods should touch the camera
def set_camera(self, camera): def set_camera(self, camera):