Beispiel #1
0
	def _buildGroundTilesLayerArray(self):
		"""Builds a tuple representation of all the ground tiles"""
		# A representation of all the tiles, syntax is tiles(x, y, instance of groundtile)
		tiles = {}

		# Builds an x,y representation of all groundtiles
		ground_layer = self._map.getLayer(util.GROUND_LAYER_NAME)
		instances = ground_layer.getInstances()
		self.x_minimum = 0
		self.x_maximum = 0
		self.y_minimum = 0
		self.y_maximum = 0
		for instance in instances:
			type = util.getGroundTileId(instance.getObject().getId())
			(position, rotation) = self._extractPositionRotationFromInstance(instance)
			x = int(position.x)
			y = int(position.y)
			tiles[(x, y)] = ("island_0", instance)
			if x < self.x_minimum:
				self.x_minimum = x
			elif x > self.x_maximum:
				self.x_maximum = x
			if y > self.y_maximum:
				self.y_maximum = y
			elif y < self.y_minimum:
				self.y_minimum = y
		return tiles
Beispiel #2
0
	def _saveIsland(self, name, relative_island_filepath, tiles):
		"""Writes an SQL file for an island"""
		island_filepath = os.path.join(util.getUHPath(), relative_island_filepath)
		print "Saving island " + island_filepath
		if os.path.exists(island_filepath):
			os.remove(island_filepath)
		island_db = self._create_island_db(island_filepath)
		island_db("BEGIN IMMEDIATE TRANSACTION")

		for instance in tiles:
			type = util.getGroundTileId(instance.getObject().getId())
			# TODO (MMB) "default action id = 0"
			action_id = instance.getObject().getActionIds()[0]
			if instance.getCurrentAction() != None:
				action_id = instance.getCurrentAction().getId()
			# TODO (MMB) a bit of a hack to only get the name without a possible _ts_curved etc. suffix
			action_id = re.sub("_ts.*", "", action_id)
			(position, rotation) = self._extractPositionRotationFromInstance(instance)
			island_db("INSERT INTO ground VALUES (?, ?, ?, ?, ?)", position.x, position.y, type, action_id, rotation)
		island_db("COMMIT TRANSACTION");

		pass