예제 #1
0
def create_map():
    """
	Create a map with a square island (20x20) at position (20, 20) and return the path
	to the database file.
	"""

    tiles = []
    for x, y in Rect.init_from_topleft_and_size(0, 0, 20, 20).tuple_iter():
        if (0 < x < 20) and (0 < y < 20):
            ground = GROUND.DEFAULT_LAND
        else:
            # Add coastline at the borders.
            ground = GROUND.SHALLOW_WATER
        tiles.append([0, 20 + x, 20 + y] + list(ground))

    fd, map_file = tempfile.mkstemp()
    os.close(fd)

    db = DbReader(map_file)
    with open('content/map-template.sql') as map_template:
        db.execute_script(map_template.read())

    db('BEGIN')
    db.execute_many("INSERT INTO ground VALUES(?, ?, ?, ?, ?, ?)", tiles)
    db('COMMIT')
    db.close()
    return map_file
예제 #2
0
    def save_map(self, path, prefix):
        map_file = os.path.join(path, prefix + '.sqlite')
        if os.path.exists(map_file):
            os.unlink(map_file)  # the process relies on having an empty file

        db = DbReader(map_file)
        with open('content/map-template.sql') as map_template:
            db.execute_script(map_template.read())

        save_successful = True
        try:
            db('BEGIN')
            for island_id, coords_list in self._iter_islands():
                for x, y in coords_list:
                    tile = self.world.full_map[(x, y)]
                    db('INSERT INTO ground VALUES(?, ?, ?, ?, ?, ?)',
                       island_id, x, y, tile.id, tile.shape, tile.rotation)
            db('COMMIT')
        except sqlite3.Error as e:
            self.log.debug('Error: {error}'.format(error=e.args[0]))
            save_successful = False
        finally:
            db.close()

        return save_successful
예제 #3
0
def create_map():
	"""
	Create a map with a square island (20x20) at position (20, 20) and return the path
	to the database file.
	"""

	tiles = []
	for x, y in Rect.init_from_topleft_and_size(0, 0, 20, 20).tuple_iter():
		if (0 < x < 20) and (0 < y < 20):
			ground = GROUND.DEFAULT_LAND
		else:
			# Add coastline at the borders.
			ground = GROUND.SHALLOW_WATER
		tiles.append([0, 20 + x, 20 + y] + list(ground))

	fd, map_file = tempfile.mkstemp()
	os.close(fd)

	db = DbReader(map_file)
	with open('content/map-template.sql') as map_template:
		db.execute_script(map_template.read())

	db('BEGIN')
	db.execute_many("INSERT INTO ground VALUES(?, ?, ?, ?, ?, ?)", tiles)
	db('COMMIT')
	db.close()
	return map_file
예제 #4
0
	def save_map(self, path, prefix):
		map_file = os.path.join(path, prefix + '.sqlite')
		if os.path.exists(map_file):
			os.unlink(map_file) # the process relies on having an empty file

		db = DbReader(map_file)
		with open('content/map-template.sql') as map_template:
			db.execute_script(map_template.read())

		db('BEGIN')
		for island_id, coords_list in self._iter_islands():
			for x, y in coords_list:
				tile = self.world.full_map[(x, y)]
				db('INSERT INTO ground VALUES(?, ?, ?, ?, ?, ?)', island_id, x, y, tile.id, tile.shape, tile.rotation + 45)
		db('COMMIT')
		db.close()
예제 #5
0
    def save_map(self, path, prefix):
        map_file = os.path.join(path, prefix + '.sqlite')
        if os.path.exists(map_file):
            os.unlink(map_file)  # the process relies on having an empty file

        db = DbReader(map_file)
        with open('content/map-template.sql') as map_template:
            db.execute_script(map_template.read())

        db('BEGIN')
        for island_id, coords_list in self._iter_islands():
            for x, y in coords_list:
                tile = self.world.full_map[(x, y)]
                db('INSERT INTO ground VALUES(?, ?, ?, ?, ?, ?)', island_id, x,
                   y, tile.id, tile.shape, tile.rotation + 45)
        db('COMMIT')
        db.close()
    def check_files(cls):
        """Check that the required atlas files exist."""
        paths = [
            'content' + os.sep + 'actionsets.json',
            'content' + os.sep + 'atlas.sql',
            'content' + os.sep + 'tilesets.json',
        ]
        for path in paths:
            if not os.path.exists(path):
                return False

        # verify that the combined images exist
        db = DbReader(':memory:')
        db.execute_script(open('content' + os.sep + 'atlas.sql').read())
        for db_row in db("SELECT atlas_path FROM atlas"):
            if not os.path.exists(db_row[0]):
                return False
        return True
    def check_files(cls):
        """Check that the required atlas files exist."""
        paths = [
            "content" + os.sep + "actionsets.json",
            "content" + os.sep + "atlas.sql",
            "content" + os.sep + "tilesets.json",
        ]
        for path in paths:
            if not os.path.exists(path):
                return False

                # verify that the combined images exist
        db = DbReader(":memory:")
        db.execute_script(open("content" + os.sep + "atlas.sql").read())
        for db_row in db("SELECT atlas_path FROM atlas"):
            if not os.path.exists(db_row[0]):
                return False
        return True
예제 #8
0
	def check_files(cls):
		"""Check that the required atlas files exist."""
		paths = [
			'content' + os.sep + 'actionsets.json',
			'content' + os.sep + 'atlas.sql',
			'content' + os.sep + 'tilesets.json',
		]
		for path in paths:
			if not os.path.exists(path):
				return False

		# verify that the combined images exist
		db = DbReader(':memory:')
		with open('content' + os.sep + 'atlas.sql') as f:
			db.execute_script(f.read())
		for db_row in db("SELECT atlas_path FROM atlas"):
			if not os.path.exists(db_row[0]):
				return False
		return True
예제 #9
0
	def check_files(cls):
		"""Check that the required atlas files exist."""
		paths = [
			PATHS.ACTION_SETS_JSON_FILE,
			PATHS.ATLAS_DB_PATH,
			PATHS.TILE_SETS_JSON_FILE,
		]
		for path in paths:
			if not os.path.exists(path):
				return False

		# verify that the combined images exist
		db = DbReader(':memory:')
		with open(PATHS.ATLAS_DB_PATH) as f:
			db.execute_script(f.read())
		for db_row in db("SELECT atlas_path FROM atlas"):
			if not os.path.exists(db_row[0]):
				return False
		return True
	def save_map(self, path, prefix):
		map_file = os.path.join(path, prefix + '.sqlite')
		if os.path.exists(map_file):
			os.unlink(map_file) # the process relies on having an empty file

		db = DbReader(map_file)
		with open('content/map-template.sql') as map_template:
			db.execute_script(map_template.read())

		save_successful = True
		try:
			db('BEGIN')
			for island_id, coords_list in self._iter_islands():
				for x, y in coords_list:
					tile = self.world.full_map[(x, y)]
					db('INSERT INTO ground VALUES(?, ?, ?, ?, ?, ?)', island_id, x, y, tile.id, tile.shape, tile.rotation + 45)
			db('COMMIT')
		except sqlite3.Error as e:
			self.log.debug('Error: {error}'.format(error=e.args[0]))
			save_successful = False
		finally:
			db.close()

		return save_successful
예제 #11
0
    def save_map(self, path, prefix, players_recommended):
        map_file = os.path.join(path, prefix + '.sqlite')
        if os.path.exists(map_file):
            os.unlink(map_file)  # the process relies on having an empty file

        db = DbReader(map_file)
        with open('content/map-template.sql') as map_template:
            db.execute_script(map_template.read())

        save_successful = True
        try:
            db('BEGIN')
            for island_id, coords_list in self._iter_islands():
                for x, y in coords_list:
                    tile = self.world.full_map[(x, y)]
                    db('INSERT INTO ground VALUES(?, ?, ?, ?, ?, ?)',
                       island_id, x, y, tile.id, tile.shape, tile.rotation)
            #test code to implement number of players recommended
            name = "players_recommended"
            if type(players_recommended) == int:
                value = players_recommended
            elif type(players_recommended) == str:
                value = int(players_recommended)
            elif type(players_recommended) == float:
                value = int(float(players_recommended))
            else:
                value = ""
            db('INSERT INTO properties VALUES(?,?)', name, value)
            db('COMMIT')
        except sqlite3.Error as e:
            self.log.debug('Error: {error}'.format(error=e.args[0]))
            save_successful = False
        finally:
            db.close()

        return save_successful
예제 #12
0
	def __init__(self, game_identifier, is_map, options=None):
		is_random_map = False
		if is_map:
			self.upgrader = None
			handle, self._temp_path = tempfile.mkstemp()
			os.close(handle)
			super(SavegameAccessor, self).__init__(dbfile=self._temp_path)
			with open('content/savegame_template.sql') as savegame_template:
				self.execute_script(savegame_template.read())

			if isinstance(game_identifier, list):
				is_random_map = True
				random_island_sequence = game_identifier
			else:
				self._map_path = game_identifier
		else:
			self.upgrader = SavegameUpgrader(game_identifier)
			self._temp_path = None
			game_identifier = self.upgrader.get_path()
			super(SavegameAccessor, self).__init__(dbfile=game_identifier)

			map_name_data = self('SELECT value FROM metadata WHERE name = ?', 'map_name')
			if not map_name_data:
				is_random_map = True
				random_island_sequence = self('SELECT value FROM metadata WHERE name = ?', 'random_island_sequence')[0][0].split(' ')
			else:
				map_name = map_name_data[0][0]
				if map_name.startswith('USER_MAPS_DIR:'):
					self._map_path = PATHS.USER_MAPS_DIR + map_name[len('USER_MAPS_DIR:'):]
				elif os.path.isabs(map_name):
					self._map_path = map_name
				else:
					self._map_path = SavegameManager.get_filename_from_map_name(map_name)

		if is_random_map:
			handle, self._temp_path2 = tempfile.mkstemp()
			os.close(handle)
			random_map_db = DbReader(self._temp_path2)
			with open('content/map-template.sql') as map_template:
				random_map_db.execute_script(map_template.read())
			for island_id, island_string in enumerate(random_island_sequence):
				create_random_island(random_map_db, island_id, island_string)
			random_map_db.close()
			self._map_path = self._temp_path2

			self('INSERT INTO metadata VALUES(?, ?)', 'random_island_sequence',
				' '.join(random_island_sequence))

		if options is not None:
			if options.map_padding is not None:
				self("INSERT INTO map_properties VALUES(?, ?)", 'padding', options.map_padding)

		self('ATTACH ? AS map_file', self._map_path)
		if is_random_map:
			self.map_name = random_island_sequence
		elif os.path.isabs(self._map_path):
			self.map_name = self._map_path
		else:
			self.map_name = SavegameManager.get_savegamename_from_filename(self._map_path)

		map_padding = self("SELECT value FROM map_properties WHERE name = 'padding'")
		self.map_padding = int(map_padding[0][0]) if map_padding else MAP.PADDING

		self._load_building()
		self._load_settlement()
		self._load_concrete_object()
		self._load_production()
		self._load_storage()
		self._load_wildanimal()
		self._load_unit()
		self._load_building_collector()
		self._load_production_line()
		self._load_unit_path()
		self._load_storage_global_limit()
		self._load_health()
		self._load_fish_data()
		self._hash = None
예제 #13
0
    def __init__(self, game_identifier, is_map, options=None):
        is_random_map = False
        if is_map:
            self.upgrader = None
            handle, self._temp_path = tempfile.mkstemp()
            os.close(handle)
            super().__init__(dbfile=self._temp_path)
            with open('content/savegame_template.sql') as savegame_template:
                self.execute_script(savegame_template.read())

            if isinstance(game_identifier, list):
                is_random_map = True
                random_island_sequence = game_identifier
            else:
                self._map_path = game_identifier
        else:
            self.upgrader = SavegameUpgrader(game_identifier)
            self._temp_path = None
            game_identifier = self.upgrader.get_path()
            super().__init__(dbfile=game_identifier)

            map_name_data = self('SELECT value FROM metadata WHERE name = ?',
                                 'map_name')
            if not map_name_data:
                is_random_map = True
                random_island_sequence = self(
                    'SELECT value FROM metadata WHERE name = ?',
                    'random_island_sequence')[0][0].split(' ')
            else:
                map_name = map_name_data[0][0]
                if map_name.startswith('USER_MAPS_DIR:'):
                    self._map_path = PATHS.USER_MAPS_DIR + map_name[
                        len('USER_MAPS_DIR:'):]
                elif os.path.isabs(map_name):
                    self._map_path = map_name
                else:
                    self._map_path = SavegameManager.get_filename_from_map_name(
                        map_name)

        if is_random_map:
            handle, self._temp_path2 = tempfile.mkstemp()
            os.close(handle)
            random_map_db = DbReader(self._temp_path2)
            with open('content/map-template.sql') as map_template:
                random_map_db.execute_script(map_template.read())
            for island_id, island_string in enumerate(random_island_sequence):
                create_random_island(random_map_db, island_id, island_string)
            random_map_db.close()
            self._map_path = self._temp_path2

            self('INSERT INTO metadata VALUES(?, ?)', 'random_island_sequence',
                 ' '.join(random_island_sequence))

        if options is not None:
            if options.map_padding is not None:
                self("INSERT INTO map_properties VALUES(?, ?)", 'padding',
                     options.map_padding)

        if not os.path.exists(self._map_path):
            raise MapFileNotFound("Map file " + str(self._map_path) +
                                  " not found!")

        self('ATTACH ? AS map_file', self._map_path)
        if is_random_map:
            self.map_name = random_island_sequence
        elif os.path.isabs(self._map_path):
            self.map_name = self._map_path
        else:
            self.map_name = SavegameManager.get_savegamename_from_filename(
                self._map_path)

        map_padding = self(
            "SELECT value FROM map_properties WHERE name = 'padding'")
        self.map_padding = int(
            map_padding[0][0]) if map_padding else MAP.PADDING

        self._load_building()
        self._load_settlement()
        self._load_concrete_object()
        self._load_production()
        self._load_storage()
        self._load_wildanimal()
        self._load_unit()
        self._load_building_collector()
        self._load_production_line()
        self._load_unit_path()
        self._load_storage_global_limit()
        self._load_health()
        self._load_fish_data()
        self._hash = None
예제 #14
0
    def __init__(self, game_identifier, is_map):
        is_random_map = False
        if is_map:
            self.upgrader = None
            handle, self._temp_path = tempfile.mkstemp()
            os.close(handle)
            super(SavegameAccessor, self).__init__(dbfile=self._temp_path)
            with open("content/savegame_template.sql") as savegame_template:
                self.execute_script(savegame_template.read())

            if isinstance(game_identifier, list):
                is_random_map = True
                random_island_sequence = game_identifier
            else:
                self._map_path = game_identifier
        else:
            self.upgrader = SavegameUpgrader(game_identifier)
            self._temp_path = None
            game_identifier = self.upgrader.get_path()
            super(SavegameAccessor, self).__init__(dbfile=game_identifier)

            map_name_data = self("SELECT value FROM metadata WHERE name = ?", "map_name")
            if not map_name_data:
                is_random_map = True
                random_island_sequence = self("SELECT value FROM metadata WHERE name = ?", "random_island_sequence")[0][
                    0
                ].split(" ")
            else:
                map_name = map_name_data[0][0]
                if os.path.isabs(map_name):
                    self._map_path = map_name
                else:
                    self._map_path = SavegameManager.get_filename_from_map_name(map_name)

        if is_random_map:
            handle, self._temp_path2 = tempfile.mkstemp()
            os.close(handle)
            random_map_db = DbReader(self._temp_path2)
            with open("content/map-template.sql") as map_template:
                random_map_db.execute_script(map_template.read())
            for island_id, island_string in enumerate(random_island_sequence):
                create_random_island(random_map_db, island_id, island_string)
            random_map_db.close()
            self._map_path = self._temp_path2

            self("INSERT INTO metadata VALUES(?, ?)", "random_island_sequence", " ".join(random_island_sequence))

        self("ATTACH ? AS map_file", self._map_path)
        if is_random_map:
            self.map_name = random_island_sequence
        elif os.path.isabs(self._map_path):
            self.map_name = self._map_path
        else:
            self.map_name = SavegameManager.get_savegamename_from_filename(self._map_path)

        self._load_building()
        self._load_settlement()
        self._load_concrete_object()
        self._load_production()
        self._load_storage()
        self._load_wildanimal()
        self._load_unit()
        self._load_building_collector()
        self._load_production_line()
        self._load_unit_path()
        self._load_storage_global_limit()
        self._load_health()
        self._load_fish_data()
        self._hash = None
예제 #15
0
    def __init__(self, game_identifier, is_map):
        is_random_map = False
        if is_map:
            self.upgrader = None
            handle, self._temp_path = tempfile.mkstemp()
            os.close(handle)
            super(SavegameAccessor, self).__init__(dbfile=self._temp_path)
            with open('content/savegame_template.sql') as savegame_template:
                self.execute_script(savegame_template.read())

            if isinstance(game_identifier, list):
                is_random_map = True
                random_island_sequence = game_identifier
            else:
                self._map_path = game_identifier
        else:
            self.upgrader = SavegameUpgrader(game_identifier)
            self._temp_path = None
            game_identifier = self.upgrader.get_path()
            super(SavegameAccessor, self).__init__(dbfile=game_identifier)

            map_name_data = self('SELECT value FROM metadata WHERE name = ?',
                                 'map_name')
            if not map_name_data:
                is_random_map = True
                random_island_sequence = self(
                    'SELECT value FROM metadata WHERE name = ?',
                    'random_island_sequence')[0][0].split(' ')
            else:
                map_name = map_name_data[0][0]
                if os.path.isabs(map_name):
                    self._map_path = map_name
                else:
                    self._map_path = SavegameManager.get_filename_from_map_name(
                        map_name)

        if is_random_map:
            handle, self._temp_path2 = tempfile.mkstemp()
            os.close(handle)
            random_map_db = DbReader(self._temp_path2)
            with open('content/map-template.sql') as map_template:
                random_map_db.execute_script(map_template.read())
            for island_id, island_string in enumerate(random_island_sequence):
                create_random_island(random_map_db, island_id, island_string)
            random_map_db.close()
            self._map_path = self._temp_path2

            self('INSERT INTO metadata VALUES(?, ?)', 'random_island_sequence',
                 ' '.join(random_island_sequence))

        self('ATTACH ? AS map_file', self._map_path)
        if is_random_map:
            self.map_name = random_island_sequence
        elif os.path.isabs(self._map_path):
            self.map_name = self._map_path
        else:
            self.map_name = SavegameManager.get_savegamename_from_filename(
                self._map_path)

        self._load_building()
        self._load_settlement()
        self._load_concrete_object()
        self._load_production()
        self._load_storage()
        self._load_wildanimal()
        self._load_unit()
        self._load_building_collector()
        self._load_production_line()
        self._load_unit_path()
        self._load_storage_global_limit()
        self._load_health()
        self._load_fish_data()
        self._hash = None