X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=koperkapel%2Fworld.py;h=2272a7a3f01c1df2a695552e109fc6123c1c2888;hb=4eb5a9fa50cc64aeddad74161b915bbb5fc4e2c2;hp=f06d3bcbca1f4063e91dd9f300191c3f1f1639e1;hpb=a3a4e8d31e4e44d4f245b4c2de9d32b37a530c5c;p=koperkapel.git diff --git a/koperkapel/world.py b/koperkapel/world.py index f06d3bc..2272a7a 100644 --- a/koperkapel/world.py +++ b/koperkapel/world.py @@ -20,31 +20,35 @@ class World: def _build_initial_state(self): state = {} state["roaches"] = [ - self._build_roach("roachel", intelligence=3), - self._build_roach("roeginald", strength=3), - self._build_roach("roichard", quickness=3), + self._build_roach("roachel", smart=True), + self._build_roach("roeginald", strong=True), + self._build_roach("roichard", fast=True), + self._build_roach("roupert"), + ] + state["serums"] = [ + "smart", "strong", "fast", ] state["vehicles"] = { "current": "walking", - "available": ["walking"], + "walking": { + "seating": [ + "roachel", None, "roeginald", + None, None, None, + ] + } } state["level"] = { "name": "level1", } return state - def _build_roach(self, name, **kw): - attributes = { - "intelligence": 1, - "strength": 1, - "quickness": 1, - "health": 5, - } - attributes.update(kw) - return { + def _build_roach(self, name, health=5, **kw): + roach = { "name": name, - "attributes": attributes, + "health": health, } + roach.update(kw) + return roach def _apply_set(self, updates): for name, value in updates.items(): @@ -116,7 +120,9 @@ class WorldDictProxy(WorldBaseProxy): self._top._record_change("%s%s" % (self._prefix, name), value) def __getattr__(self, name): - return _maybe_subproxy(self, name, self._state[name]) + # return None for attributes that don't exist + value = self._state.get(name) + return _maybe_subproxy(self, name, value) class WorldListProxy(WorldBaseProxy): @@ -127,3 +133,9 @@ class WorldListProxy(WorldBaseProxy): def __getitem__(self, index): return _maybe_subproxy(self, index, self._state[index]) + + def __len__(self): + return len(self._state) + + def __bool__(self): + return bool(self._state)