- def _build_roach(self, name, health=5, **kw):
- roach = {
- "name": name,
- "health": health,
- }
- roach.update(kw)
- return roach
+ def _get_obj(self, name):
+ parts = name.split(".")
+ obj = self._state
+ for p in parts[:-1]:
+ if isinstance(obj, dict):
+ obj = obj[p]
+ elif isinstance(obj, list):
+ obj = obj[int(p)]
+ else:
+ raise KeyError("%r not found in world" % (name,))
+ return obj, parts[-1]
+
+ def _apply_set(self, action, updates):
+ for name, value in updates.items():
+ obj, key = self._get_obj(name)
+ obj[key] = value