def protobuf_unserialize(cls, serialized): p_world = Protobuf.World() p_world.ParseFromString(serialized) return World._from_protobuf_world(p_world)
def _to_protobuf_world(self): p_world = Protobuf.World() p_world.worldengine_tag = World.worldengine_tag() p_world.worldengine_version = self.__version_hashcode__() p_world.name = self.name p_world.width = self.width p_world.height = self.height p_world.generationData.seed = self.seed p_world.generationData.n_plates = self.n_plates p_world.generationData.ocean_level = self.ocean_level p_world.generationData.step = self.step.name # Elevation self._to_protobuf_matrix(self.layers['elevation'].data, p_world.heightMapData) p_world.heightMapTh_sea = self.layers['elevation'].thresholds[0][1] p_world.heightMapTh_plain = self.layers['elevation'].thresholds[1][1] p_world.heightMapTh_hill = self.layers['elevation'].thresholds[2][1] # Plates self._to_protobuf_matrix(self.layers['plates'].data, p_world.plates) # Ocean self._to_protobuf_matrix(self.layers['ocean'].data, p_world.ocean) self._to_protobuf_matrix(self.layers['sea_depth'].data, p_world.sea_depth) if self.has_biome(): self._to_protobuf_matrix(self.layers['biome'].data, p_world.biome, biome_name_to_index) if self.has_humidity(): self._to_protobuf_matrix_with_quantiles(self.layers['humidity'], p_world.humidity) if self.has_irrigation(): self._to_protobuf_matrix(self.layers['irrigation'].data, p_world.irrigation) if self.has_permeability(): self._to_protobuf_matrix(self.layers['permeability'].data, p_world.permeabilityData) p_world.permeability_low = self.layers['permeability'].thresholds[ 0][1] p_world.permeability_med = self.layers['permeability'].thresholds[ 1][1] if self.has_watermap(): self._to_protobuf_matrix(self.layers['watermap'].data, p_world.watermapData) p_world.watermap_creek = self.layers['watermap'].thresholds[ 'creek'] p_world.watermap_river = self.layers['watermap'].thresholds[ 'river'] p_world.watermap_mainriver = self.layers['watermap'].thresholds[ 'main river'] if self.has_lakemap(): self._to_protobuf_matrix(self.layers['lake_map'].data, p_world.lakemap) if self.has_rivermap(): self._to_protobuf_matrix(self.layers['river_map'].data, p_world.rivermap) if self.has_precipitations(): self._to_protobuf_matrix(self.layers['precipitation'].data, p_world.precipitationData) p_world.precipitation_low = self.layers[ 'precipitation'].thresholds[0][1] p_world.precipitation_med = self.layers[ 'precipitation'].thresholds[1][1] if self.has_temperature(): self._to_protobuf_matrix(self.layers['temperature'].data, p_world.temperatureData) p_world.temperature_polar = self.layers['temperature'].thresholds[ 0][1] p_world.temperature_alpine = self.layers['temperature'].thresholds[ 1][1] p_world.temperature_boreal = self.layers['temperature'].thresholds[ 2][1] p_world.temperature_cool = self.layers['temperature'].thresholds[ 3][1] p_world.temperature_warm = self.layers['temperature'].thresholds[ 4][1] p_world.temperature_subtropical = self.layers[ 'temperature'].thresholds[5][1] if self.has_icecap(): self._to_protobuf_matrix(self.layers['icecap'].data, p_world.icecap) return p_world
def _to_protobuf_world(self): p_world = Protobuf.World() p_world.worldengine_tag = World.worldengine_tag() p_world.worldengine_version = self.__version_hashcode__() p_world.name = self.name p_world.width = self.width p_world.height = self.height p_world.generationData.seed = self.seed p_world.generationData.n_plates = self.n_plates p_world.generationData.ocean_level = self.ocean_level p_world.generationData.step = self.step.name # Elevation self._to_protobuf_matrix(self.elevation['data'], p_world.heightMapData) p_world.heightMapTh_sea = self.elevation['thresholds'][0][1] p_world.heightMapTh_plain = self.elevation['thresholds'][1][1] p_world.heightMapTh_hill = self.elevation['thresholds'][2][1] # Plates self._to_protobuf_matrix(self.plates, p_world.plates) # Ocean self._to_protobuf_matrix(self.ocean, p_world.ocean) self._to_protobuf_matrix(self.sea_depth, p_world.sea_depth) # Biome if hasattr(self, 'biome'): self._to_protobuf_matrix(self.biome, p_world.biome, biome_name_to_index) # Humidity if hasattr(self, 'humidity'): self._to_protobuf_matrix_with_quantiles(self.humidity, p_world.humidity) if hasattr(self, 'irrigation'): self._to_protobuf_matrix(self.irrigation, p_world.irrigation) if hasattr(self, 'permeability'): self._to_protobuf_matrix(self.permeability['data'], p_world.permeabilityData) p_world.permeability_low = self.permeability['thresholds'][0][1] p_world.permeability_med = self.permeability['thresholds'][1][1] if hasattr(self, 'watermap'): self._to_protobuf_matrix(self.watermap['data'], p_world.watermapData) p_world.watermap_creek = self.watermap['thresholds']['creek'] p_world.watermap_river = self.watermap['thresholds']['river'] p_world.watermap_mainriver = self.watermap['thresholds'][ 'main river'] if hasattr(self, 'lake_map'): self._to_protobuf_matrix(self.lake_map, p_world.lakemap) if hasattr(self, 'river_map'): self._to_protobuf_matrix(self.river_map, p_world.rivermap) if hasattr(self, 'precipitation'): self._to_protobuf_matrix(self.precipitation['data'], p_world.precipitationData) p_world.precipitation_low = self.precipitation['thresholds'][0][1] p_world.precipitation_med = self.precipitation['thresholds'][1][1] if hasattr(self, 'temperature'): self._to_protobuf_matrix(self.temperature['data'], p_world.temperatureData) p_world.temperature_polar = self.temperature['thresholds'][0][1] p_world.temperature_alpine = self.temperature['thresholds'][1][1] p_world.temperature_boreal = self.temperature['thresholds'][2][1] p_world.temperature_cool = self.temperature['thresholds'][3][1] p_world.temperature_warm = self.temperature['thresholds'][4][1] p_world.temperature_subtropical = \ self.temperature['thresholds'][5][1] if hasattr(self, 'icecap'): self._to_protobuf_matrix(self.icecap, p_world.icecap) return p_world