def load(self, policy_data): effects_to_load = dict() for effect in self._civic_policy_effects: effects_to_load[type(effect).guid64] = effect if policy_data is not None: if policy_data.policy_id == self.guid64: if policy_data.custom_data: policy_msg = GameplaySaveData_pb2.PersistableCivicPolicyStreetPolicyData( ) policy_msg.ParseFromString(policy_data.custom_data) self._enacted = policy_msg.enacted for effect_data in policy_msg.effect_data: effect = effects_to_load.get(effect_data.policy_id) if effect is not None: effect.set_load_state_from_msg( effect_data.custom_data) else: self._enacted = True
def save(self, provider_data): effect_states = [] for effect in self._civic_policy_effects: effect_custom_data = effect.get_save_state_msg() if effect_custom_data is not None: effect_states.append((type(effect).guid64, effect_custom_data)) if not effect_states: super().save(provider_data) return policy_msg = GameplaySaveData_pb2.PersistableCivicPolicyStreetPolicyData( ) policy_msg.enacted = self.enacted for (effect_id, effect_custom_data) in effect_states: with ProtocolBufferRollback(policy_msg.effect_data) as effect_data: effect_data.policy_id = effect_id effect_data.custom_data = effect_custom_data with ProtocolBufferRollback(provider_data.policy_data) as policy_data: policy_data.policy_id = self.guid64 policy_data.custom_data = policy_msg.SerializeToString()