Ejemplo n.º 1
0
	def _loadObjects(self):
		# get fifedit objects
		self.model = self._engine.getModel()
		self.all_action_sets = ActionSetLoader.get_sets()

		TileSetLoader.load()
		ActionSetLoader.load()
		self.animationloader = SQLiteAnimationLoader()

		self._loadGroundTiles()
		self._loadBuildings()
Ejemplo n.º 2
0
	def _get_tile_image(self, tile):
		# TODO TileLayingTool does almost the same thing, perhaps put this in a better place
		tile_sets = TileSetLoader.get_sets()

		ground_id, action_id, rotation = tile
		set_id = horizons.globals.db.get_random_tile_set(ground_id)
		return tile_sets[set_id][action_id][rotation].keys()[0]
Ejemplo n.º 3
0
	def _loadObject(cls, db):
		"""Loads the ground object from the db (animations, etc)"""
		cls._fife_objects = {}
		tile_sets = TileSetLoader.get_sets()
		tile_set_data = db("SELECT set_id FROM tile_set WHERE ground_id=?", cls.id)
		for tile_set_row in tile_set_data:
			tile_set_id = str(tile_set_row[0])
			cls_name = '%d-%s' % (cls.id, cls.shape)
			cls.log.debug('Loading ground %s', cls_name)
			fife_object = None
			try:
				fife_object = horizons.globals.fife.engine.getModel().createObject(cls_name, 'ground_' + tile_set_id)
			except RuntimeError:
				cls.log.debug('Already loaded ground %d-%s', cls.id, cls.shape)
				fife_object = horizons.globals.fife.engine.getModel().getObject(cls_name, 'ground_' + tile_set_id)
				return

			fife.ObjectVisual.create(fife_object)
			visual = fife_object.get2dGfxVisual()
			for rotation, data in tile_sets[tile_set_id][cls.shape].iteritems():
				assert len(data) == 1, 'Currently only static tiles are supported'
				img = horizons.globals.fife.animationloader.load_image(data.keys()[0], tile_set_id, cls.shape, str(rotation))
				visual.addStaticImage(rotation, img.getHandle())

			# Save the object
			cls._fife_objects[tile_set_id] = fife_object
Ejemplo n.º 4
0
    def _loadObject(cls, db):
        """Loads the ground object from the db (animations, etc)"""
        cls._objects = {}
        tile_sets = TileSetLoader.get_sets()
        tile_set_ids = db("SELECT set_id FROM tile_set WHERE ground_id=?",
                          cls.id)
        for (tile_set_id, ) in tile_set_ids:

            cls_name = '%d-%s' % (cls.id, cls.shape)
            cls.log.debug('Loading ground %s', cls_name)
            _object = None
            try:
                _object = horizons.globals.fife.engine.getModel().createObject(
                    cls_name, 'ground_' + str(tile_set_id))
            except RuntimeError:
                cls.log.debug('Already loaded ground %d-%s', cls.id, cls.shape)
                _object = horizons.globals.fife.engine.getModel().getObject(
                    cls_name, 'ground_' + str(tile_set_id))
                return

            fife.ObjectVisual.create(_object)
            visual = _object.get2dGfxVisual()

            for rotation, data in tile_sets[tile_set_id][
                    cls.shape].iteritems():
                assert len(
                    data) == 1, 'Currently only static tiles are supported'
                img = horizons.globals.fife.animationloader.load_image(
                    data.keys()[0], str(tile_set_id), str(cls.shape),
                    str(rotation))
                visual.addStaticImage(rotation, img.getHandle())

            # Save the object
            cls._objects[tile_set_id] = _object
Ejemplo n.º 5
0
	def _loadObject(cls, db):
		"""Loads the ground object from the db (animations, etc)"""
		cls._fife_objects = {}
		tile_sets = TileSetLoader.get_sets()
		model = horizons.globals.fife.engine.getModel()
		load_image = horizons.globals.fife.animationloader.load_image
		tile_set_data = db("SELECT set_id FROM tile_set WHERE ground_id=?", cls.id)
		for tile_set_row in tile_set_data:
			tile_set_id = str(tile_set_row[0])
			cls_name = '{:d}-{}'.format(cls.id, cls.shape)
			cls.log.debug('Loading ground %s', cls_name)
			fife_object = None
			try:
				fife_object = model.createObject(cls_name, 'ground_' + tile_set_id)
			except fife.NameClash:
				cls.log.debug('Already loaded ground %d-%s', cls.id, cls.shape)
				fife_object = model.getObject(cls_name, 'ground_' + tile_set_id)
				return

			fife.ObjectVisual.create(fife_object)
			visual = fife_object.get2dGfxVisual()
			for rotation, data in tile_sets[tile_set_id][cls.shape].items():
				if not data:
					raise KeyError('No data found for tile set `{}` in rotation `{}`. '
						'Most likely the shape `{}` is missing.'
						.format(tile_set_id, rotation, cls.shape))
				if len(data) > 1:
					raise ValueError('Currently only static tiles are supported. '
						'Found this data for tile set `{}` in rotation `{}`: '
						'{}'.format(tile_set_id, rotation, data))
				img = load_image(list(data.keys())[0], tile_set_id, cls.shape, str(rotation))
				visual.addStaticImage(rotation, img.getHandle())

			# Save the object
			cls._fife_objects[tile_set_id] = fife_object
Ejemplo n.º 6
0
	def _loadObject(cls, db):
		"""Loads the ground object from the db (animations, etc)"""
		cls._fife_objects = {}
		tile_sets = TileSetLoader.get_sets()
		model = horizons.globals.fife.engine.getModel()
		load_image = horizons.globals.fife.animationloader.load_image
		tile_set_data = db("SELECT set_id FROM tile_set WHERE ground_id=?", cls.id)
		for tile_set_row in tile_set_data:
			tile_set_id = str(tile_set_row[0])
			cls_name = '%d-%s' % (cls.id, cls.shape)
			cls.log.debug('Loading ground %s', cls_name)
			fife_object = None
			try:
				fife_object = model.createObject(cls_name, 'ground_' + tile_set_id)
			except RuntimeError:
				cls.log.debug('Already loaded ground %d-%s', cls.id, cls.shape)
				fife_object = model.getObject(cls_name, 'ground_' + tile_set_id)
				return

			fife.ObjectVisual.create(fife_object)
			visual = fife_object.get2dGfxVisual()
			for rotation, data in tile_sets[tile_set_id][cls.shape].iteritems():
				if not data:
					raise KeyError('No data found for tile set `%s` in rotation `%s`. '
						'Most likely the shape `%s` is missing.' %
						(tile_set_id, rotation, cls.shape))
				if len(data) > 1:
					raise ValueError('Currently only static tiles are supported. '
						'Found this data for tile set `%s` in rotation `%s`: '
						'%s' % (tile_set_id, rotation, data))
				img = load_image(data.keys()[0], tile_set_id, cls.shape, str(rotation))
				visual.addStaticImage(rotation, img.getHandle())

			# Save the object
			cls._fife_objects[tile_set_id] = fife_object
Ejemplo n.º 7
0
    def _get_tile_image(self, tile):
        # TODO TileLayingTool does almost the same thing, perhaps put this in a better place
        tile_sets = TileSetLoader.get_sets()

        ground_id, action_id, rotation = tile
        set_id = horizons.globals.db.get_random_tile_set(ground_id)
        return list(tile_sets[set_id][action_id][rotation].keys())[0]
Ejemplo n.º 8
0
 def _init_sets(self):
     self.sets = []
     self.sets.append(
         ImageSetManager(TileSetLoader.get_sets(),
                         PATHS.TILE_SETS_JSON_FILE))
     self.sets.append(
         ImageSetManager(ActionSetLoader.get_sets(),
                         PATHS.ACTION_SETS_JSON_FILE))
Ejemplo n.º 9
0
	def load_grounds(cls, db, load_now=False):
		cls.log.debug("Entities: loading grounds")
		if hasattr(cls, "grounds"):
			cls.log.debug("Entities: grounds already loaded")
			return

		from horizons.world.ground import GroundClass
		tile_sets = TileSetLoader.get_sets()
		cls.grounds = _EntitiesLazyDict()
		for (ground_id,) in db("SELECT ground_id FROM tile_set"):
			tile_set_id = db("SELECT set_id FROM tile_set WHERE ground_id=?", ground_id)[0][0]
			for shape in tile_sets[tile_set_id].iterkeys():
				cls_name = '%d-%s' % (ground_id, shape)
				cls.grounds.create_on_access(cls_name, Callback(GroundClass, db, ground_id, shape))
				if load_now:
					cls.grounds[cls_name]
		cls.grounds['-1-special'] = GroundClass(db, -1, 'special')
Ejemplo n.º 10
0
	def load_grounds(cls, db, load_now=False):
		cls.log.debug("Entities: loading grounds")
		if hasattr(cls, "grounds"):
			cls.log.debug("Entities: grounds already loaded")
			return

		from horizons.world.ground import GroundClass
		tile_sets = TileSetLoader.get_sets()
		cls.grounds = _EntitiesLazyDict()
		for (ground_id,) in db("SELECT ground_id FROM tile_set"):
			tile_set_id = db("SELECT set_id FROM tile_set WHERE ground_id=?", ground_id)[0][0]
			for shape in tile_sets[tile_set_id].iterkeys():
				cls_name = '%d-%s' % (ground_id, shape)
				cls.grounds.create_on_access(cls_name, Callback(GroundClass, db, ground_id, shape))
				if load_now:
					cls.grounds[cls_name]
		cls.grounds['-1-special'] = GroundClass(db, -1, 'special')
Ejemplo n.º 11
0
    def _set_cursor_image(self):
        """Replace the cursor with an image of the selected tile."""
        # FIXME the water tile is too big to use as cursor
        if self._tile_details[0] == 0:
            return

        tile = tuple(self._tile_details)
        image = TileLayingTool.tile_images.get(tile)
        if not image:
            tile_sets = TileSetLoader.get_sets()

            ground_id, action_id, rotation = tile
            set_id = horizons.globals.db.get_random_tile_set(ground_id)
            filename = tile_sets[set_id][action_id][rotation].keys()[0]

            image = horizons.globals.fife.imagemanager.load(filename)
            TileLayingTool.tile_images[tile] = image

        horizons.globals.fife.cursor.set(image)
Ejemplo n.º 12
0
	def _loadGroundTiles(self):
		print("loading UH ground tiles...")
		tile_sets = TileSetLoader.get_sets()

		for tile_set_id in tile_sets:
			tile_set = tile_sets[tile_set_id]
			object = self.model.createObject(str(tile_set_id), util.GROUND_NAMESPACE)
			fife.ObjectVisual.create(object)

			# load animations
			for action_id in tile_sets[tile_set_id].iterkeys():
				action = object.createAction(action_id+"_"+str(tile_set_id))
				fife.ActionVisual.create(action)
				for rotation in tile_sets[tile_set_id][action_id].iterkeys():
					anim = self.animationloader.loadResource( \
						str(tile_set_id)+"+"+str(action_id)+"+"+ \
						str(rotation) + ':shift:center+0,bottom+8')
					action.get2dGfxVisual().addAnimation(int(rotation), anim)
					action.setDuration(anim.getDuration())
Ejemplo n.º 13
0
	def _set_cursor_image(self):
		"""Replace the cursor with an image of the selected tile."""
		# FIXME the water tile is too big to use as cursor
		if self._tile_details[0] == 0:
			return

		tile = tuple(self._tile_details)
		image = TileLayingTool.tile_images.get(tile)
		if not image:
			tile_sets = TileSetLoader.get_sets()

			ground_id, action_id, rotation = tile
			set_id = horizons.globals.db.get_random_tile_set(ground_id)
			filename = tile_sets[set_id][action_id][rotation].keys()[0]

			image = horizons.globals.fife.imagemanager.load(filename)
			TileLayingTool.tile_images[tile] = image

		horizons.globals.fife.cursor.set(image)
Ejemplo n.º 14
0
	def _loadObject(cls, db):
		"""Loads the ground object from the db (animations, etc)"""
		cls._fife_objects = {}
		tile_sets = TileSetLoader.get_sets()
		model = horizons.globals.fife.engine.getModel()
		load_image = horizons.globals.fife.animationloader.load_image
		tile_set_data = db("SELECT set_id FROM tile_set WHERE ground_id=?", cls.id)
		for tile_set_row in tile_set_data:
			tile_set_id = str(tile_set_row[0])
			cls_name = '{:d}-{}'.format(cls.id, cls.shape)
			cls.log.debug('Loading ground %s', cls_name)
			fife_object = None
			try:
				fife_object = model.createObject(cls_name, 'ground_' + tile_set_id)
			except fife.NameClash:
				cls.log.debug('Already loaded ground %d-%s', cls.id, cls.shape)
				fife_object = model.getObject(cls_name, 'ground_' + tile_set_id)
				return

			fife.ObjectVisual.create(fife_object)
			visual = fife_object.get2dGfxVisual()
			for rotation, data in tile_sets[tile_set_id][cls.shape].items():
				if not data:
					raise KeyError('No data found for tile set `{}` in rotation `{}`. '
						'Most likely the shape `{}` is missing.'
						.format(tile_set_id, rotation, cls.shape))
				if len(data) > 1:
					raise ValueError('Currently only static tiles are supported. '
						'Found this data for tile set `{}` in rotation `{}`: '
						'{}'.format(tile_set_id, rotation, data))
				img = load_image(list(data.keys())[0], tile_set_id, cls.shape, str(rotation))
				# make the drawing origin correspond with the center of the groundpart of the image
				# (instead of the center of the image)
				img.setYShift(int(img.getWidth() / 4 - img.getHeight() / 2))
				visual.addStaticImage(rotation, img.getHandle())

			# Save the object
			cls._fife_objects[tile_set_id] = fife_object
Ejemplo n.º 15
0
	def _loadObject(cls, db):
		""" Loads the ground object from the db (animations, etc)
		"""
		cls.log.debug('Loading ground %s', cls.id)
		try:
			cls._object = horizons.globals.fife.engine.getModel().createObject(str(cls.id), 'ground')
		except RuntimeError:
			cls.log.debug('Already loaded ground %s', cls.id)
			cls._object = horizons.globals.fife.engine.getModel().getObject(str(cls.id), 'ground')
			return

		fife.ObjectVisual.create(cls._object)

		tile_sets = TileSetLoader.get_sets()
		for (tile_set_id,) in db("SELECT set_id FROM tile_set WHERE ground_id=?", cls.id):
			for action_id in tile_sets[tile_set_id].iterkeys():
				action = cls._object.createAction(action_id+"_"+str(tile_set_id))
				fife.ActionVisual.create(action)
				for rotation in tile_sets[tile_set_id][action_id].iterkeys():
					anim = horizons.globals.fife.animationloader.loadResource(
						str(tile_set_id)+"+"+str(action_id)+"+"+
						str(rotation) + ':shift:center+0,bottom+8')
					action.get2dGfxVisual().addAnimation(int(rotation), anim)
					action.setDuration(anim.getDuration())
Ejemplo n.º 16
0
					not_found = not_found + 1
					continue

				# Instead of only float value we need to hold a 'bit' more infos in all_action_sets dictionary
				animval = all_action_sets[tileset_id][action_id][rotation][file]
				del all_action_sets[tileset_id][action_id][rotation][file]
				all_action_sets[tileset_id][action_id][rotation][file_new] = [animval, \
					atlases[entry.source], entry.xpos, entry.ypos, entry.width, entry.height]

# Dump it into JSON file
import json
with open(os.path.join("development", "atlas", "actionsets.json"), mode="wb") as fjson:
	json.dump(all_action_sets, fjson, indent=1)

# Same stuff with tilesets
all_tile_sets = TileSetLoader.get_sets()
for tileset_id in all_tile_sets:
	for action_id in all_tile_sets[tileset_id]:
		for rotation in sorted(all_tile_sets[tileset_id][action_id]):
			for file in sorted(all_tile_sets[tileset_id][action_id][rotation]):

				file_new = file.replace('\\', '/')

				try:
					entry = mapping[file_new]
				except KeyError:
					print "Warning: {0} not found".format(file)
					not_found = not_found + 1
					continue

				animval = all_tile_sets[tileset_id][action_id][rotation][file]
Ejemplo n.º 17
0
	def _init_sets(self):
		self.sets = []
		self.sets.append(ImageSetManager(TileSetLoader.get_sets(), PATHS.TILE_SETS_JSON_FILE))
		self.sets.append(ImageSetManager(ActionSetLoader.get_sets(), PATHS.ACTION_SETS_JSON_FILE))