def serialize_player(self, obj: Player, ser: serpent.Serializer, out: List[str], indentlevel: int) -> None: state = dict(vars(obj)) # remove stuff we don't want to serialize at all unserialized_attrs = { "subjective", "possessive", "objective", "teleported_from", "soul", "input_is_available", "transcript", "last_input_time", "previous_commandline" } skipped_attrs = set() for name in list(state): if name.startswith("_"): del state[name] elif name in unserialized_attrs: del state[name] skipped_attrs.add(name) if skipped_attrs != unserialized_attrs: raise TaleError("player unserialized_attrs inconsistency") # basic properties: self.add_basic_properties(state, obj) # attrs that are treated in a special way: state["race"] = obj.stats.race state["known_locations"] = { mudobj_ref(loc) for loc in state["known_locations"] } state["location"] = mudobj_ref(state["location"]) state["inventory"] = {mudobj_ref(thing) for thing in obj.inventory} state["following"] = mudobj_ref(state["following"]) ser._serialize(state, out, indentlevel)
def serialize_living(self, obj: Living, ser: serpent.Serializer, out: List[str], indentlevel: int) -> None: if obj.location and obj.location is not _limbo and obj not in obj.location: raise TaleError("living {} location inconsistency".format(obj)) state = dict(vars(obj)) # remove stuff we don't want to serialize at all unserialized_attrs = { "subjective", "possessive", "objective", "teleported_from", "soul", "previous_commandline" } skipped_attrs = set() for name in list(state): if name.startswith("_"): del state[name] elif name in unserialized_attrs: del state[name] skipped_attrs.add(name) if skipped_attrs != unserialized_attrs: raise TaleError("living unserialized_attrs inconsistency") self.add_basic_properties(state, obj) # basic properties # attrs that are treated in a special way: state["race"] = obj.stats.race state["location"] = mudobj_ref(state["location"]) state["inventory"] = {mudobj_ref(thing) for thing in obj.inventory} state["following"] = mudobj_ref(state["following"]) ser._serialize(state, out, indentlevel)
def serialize_shopbehavior(self, obj: ShopBehavior, ser: serpent.Serializer, out: List[str], indentlevel: int) -> None: state = dict(vars(obj)) state["__class__"] = qual_classname(obj) state["forsale"] = {mudobj_ref(i) for i in state["forsale"]} ser._serialize(state, out, indentlevel)
def serialize_deferred(self, obj: Deferred, ser: serpent.Serializer, out: List[str], indentlevel: int) -> None: state = dict(vars(obj)) state["__class__"] = qual_classname(obj) if not isinstance(state["owner"], str): try: state["owner"] = mudobj_ref(state["owner"]) except Exception: # owner is not a regular mudobj state["owner"] = "class:" + qual_classname(state["owner"]) ser._serialize(state, out, indentlevel)
def serialize_deferred(self, obj: Deferred, ser: serpent.Serializer, out: List[str], indentlevel: int) -> None: state = dict(vars(obj)) state["__class__"] = qual_classname(obj) if not isinstance(state["owner"], str): try: state["owner"] = mudobj_ref(state["owner"]) except Exception: # owner is not a regular mudobj state["owner"] = "class:" + qual_classname(state["owner"]) ser._serialize(state, out, indentlevel)
def serialize_location(self, obj: Location, ser: serpent.Serializer, out: List[str], indentlevel: int) -> None: state = dict(vars(obj)) # remove stuff we don't want to serialize at all for name in list(state): if name.startswith("_"): del state[name] self.add_basic_properties(state, obj) # livings and items, and the exits, present in this location: state["livings"] = {mudobj_ref(l) for l in state["livings"]} state["items"] = {mudobj_ref(i) for i in state["items"]} state["exits"] = {mudobj_ref(e) for e in state["exits"].values()} ser._serialize(state, out, indentlevel)
def serialize_exit(self, obj: Exit, ser: serpent.Serializer, out: List[str], indentlevel: int) -> None: state = dict(vars(obj)) # remove stuff we don't want to serialize at all for name in list(state): if name.startswith("_") and name != "_target_str": del state[name] self.add_basic_properties(state, obj) state["target"] = mudobj_ref(state["target"]) if "linked_door" in state: # it's probably a Door, and linked_door referes to another door (cyclic) state["linked_door"] = mudobj_ref(state["linked_door"]) ser._serialize(state, out, indentlevel)
def serialize_location(self, obj: Location, ser: serpent.Serializer, out: List[str], indentlevel: int) -> None: state = dict(vars(obj)) # remove stuff we don't want to serialize at all for name in list(state): if name.startswith("_"): del state[name] self.add_basic_properties(state, obj) # livings and items, and the exits, present in this location: state["livings"] = {mudobj_ref(l) for l in state["livings"]} state["items"] = {mudobj_ref(i) for i in state["items"]} state["exits"] = {mudobj_ref(e) for e in state["exits"].values()} ser._serialize(state, out, indentlevel)
def serialize_exit(self, obj: Exit, ser: serpent.Serializer, out: List[str], indentlevel: int) -> None: state = dict(vars(obj)) # remove stuff we don't want to serialize at all for name in list(state): if name.startswith("_") and name != "_target_str": del state[name] self.add_basic_properties(state, obj) state["target"] = mudobj_ref(state["target"]) if "linked_door" in state: # it's probably a Door, and linked_door referes to another door (cyclic) state["linked_door"] = mudobj_ref(state["linked_door"]) ser._serialize(state, out, indentlevel)
def serialize_item(self, obj: Item, ser: serpent.Serializer, out: List[str], indentlevel: int) -> None: if obj.contained_in and obj not in obj.contained_in: raise TaleError("item {} containment inconsistency".format(obj)) state = dict(vars(obj)) # remove stuff we don't want to serialize at all for name in list(state): if name.startswith("_"): del state[name] elif name == "contained_in": # where the item is located, is referenced from that container/living/location later. del state[name] self.add_basic_properties(state, obj) # basic properties self.add_inventory_property(state, obj) # inventory (of Container subtype) ser._serialize(state, out, indentlevel)
def serialize_item(self, obj: Item, ser: serpent.Serializer, out: List[str], indentlevel: int) -> None: if obj.contained_in and obj not in obj.contained_in: raise TaleError("item {} containment inconsistency".format(obj)) state = dict(vars(obj)) # remove stuff we don't want to serialize at all for name in list(state): if name.startswith("_"): del state[name] elif name == "contained_in": # where the item is located, is referenced from that container/living/location later. del state[name] self.add_basic_properties(state, obj) # basic properties self.add_inventory_property(state, obj) # inventory (of Container subtype) ser._serialize(state, out, indentlevel)
def serialize_stats(self, obj: Stats, ser: serpent.Serializer, out: List[str], indentlevel: int) -> None: state = { "__class__": qual_classname(obj), "race": obj.race, "gender": obj.gender, "level": obj.level, "xp": obj.xp, "hp": obj.hp, "maxhp_dice": obj.maxhp_dice, "ac": obj.ac, "attack_dice": obj.attack_dice, "alignment": obj.alignment # the other attributes are re-initialized from the races table } ser._serialize(state, out, indentlevel)
def serialize_stats(self, obj: Stats, ser: serpent.Serializer, out: List[str], indentlevel: int) -> None: state = { "__class__": qual_classname(obj), "race": obj.race, "gender": obj.gender, "level": obj.level, "xp": obj.xp, "hp": obj.hp, "maxhp_dice": obj.maxhp_dice, "ac": obj.ac, "attack_dice": obj.attack_dice, "alignment": obj.alignment # the other attributes are re-initialized from the races table } ser._serialize(state, out, indentlevel)
def serialize_living(self, obj: Living, ser: serpent.Serializer, out: List[str], indentlevel: int) -> None: if obj.location and obj.location is not _limbo and obj not in obj.location: raise TaleError("living {} location inconsistency".format(obj)) state = dict(vars(obj)) # remove stuff we don't want to serialize at all unserialized_attrs = {"subjective", "possessive", "objective", "teleported_from", "soul", "previous_commandline"} skipped_attrs = set() for name in list(state): if name.startswith("_"): del state[name] elif name in unserialized_attrs: del state[name] skipped_attrs.add(name) if skipped_attrs != unserialized_attrs: raise TaleError("living unserialized_attrs inconsistency") self.add_basic_properties(state, obj) # basic properties # attrs that are treated in a special way: state["race"] = obj.stats.race state["location"] = mudobj_ref(state["location"]) state["inventory"] = {mudobj_ref(thing) for thing in obj.inventory} state["following"] = mudobj_ref(state["following"]) ser._serialize(state, out, indentlevel)
def serialize_player(self, obj: Player, ser: serpent.Serializer, out: List[str], indentlevel: int) -> None: state = dict(vars(obj)) # remove stuff we don't want to serialize at all unserialized_attrs = {"subjective", "possessive", "objective", "teleported_from", "soul", "input_is_available", "transcript", "last_input_time", "previous_commandline"} skipped_attrs = set() for name in list(state): if name.startswith("_"): del state[name] elif name in unserialized_attrs: del state[name] skipped_attrs.add(name) if skipped_attrs != unserialized_attrs: raise TaleError("player unserialized_attrs inconsistency") # basic properties: self.add_basic_properties(state, obj) # attrs that are treated in a special way: state["race"] = obj.stats.race state["known_locations"] = {mudobj_ref(loc) for loc in state["known_locations"]} state["location"] = mudobj_ref(state["location"]) state["inventory"] = {mudobj_ref(thing) for thing in obj.inventory} state["following"] = mudobj_ref(state["following"]) ser._serialize(state, out, indentlevel)
def serialize_shopbehavior(self, obj: ShopBehavior, ser: serpent.Serializer, out: List[str], indentlevel: int) -> None: state = dict(vars(obj)) state["__class__"] = qual_classname(obj) state["forsale"] = {mudobj_ref(i) for i in state["forsale"]} ser._serialize(state, out, indentlevel)