Exemple #1
0
    def load(self, file_name):
        """

        :param file_name:
        """
        # TODO what if file name does not exist or is not a valid scenario file
        self.scenario = Scenario.from_file(file_name)
        self.changed.emit()
Exemple #2
0
    def create(self, properties):
        """
        Create new scenario (from the create new scenario dialog).

        :param properties:
        """
        self.scenario = Scenario()
        self.scenario[constants.ScenarioProperty.TITLE] = properties[constants.ScenarioProperty.TITLE]
        self.scenario.create_empty_map(properties[constants.ScenarioProperty.MAP_COLUMNS],
            properties[constants.ScenarioProperty.MAP_ROWS])

        # standard rules
        self.scenario[constants.ScenarioProperty.RULES] = 'standard.rules'
        # self.scenario.load_rules()
        # TODO rules as extra?
        rule_file = constants.extend(constants.SCENARIO_RULESET_FOLDER, self.scenario[constants.ScenarioProperty.RULES])
        self.scenario._rules = utils.read_as_yaml(rule_file)

        # emit that everything has changed
        self.changed.emit()
Exemple #3
0
class EditorScenario(QtCore.QObject):
    """
    Wrap around the Scenario file to get notified of recreations
    """

    #: signal, scenario has changed completely
    changed = QtCore.pyqtSignal()

    def __init__(self):
        super().__init__()
        self.scenario = None

    def load(self, file_name):
        """

        :param file_name:
        """
        # TODO what if file name does not exist or is not a valid scenario file
        self.scenario = Scenario.from_file(file_name)
        self.changed.emit()

    def create(self, properties):
        """
        Create new scenario (from the create new scenario dialog).

        :param properties:
        """
        self.scenario = Scenario()
        self.scenario[constants.ScenarioProperty.TITLE] = properties[constants.ScenarioProperty.TITLE]
        self.scenario.create_empty_map(properties[constants.ScenarioProperty.MAP_COLUMNS],
            properties[constants.ScenarioProperty.MAP_ROWS])

        # standard rules
        self.scenario[constants.ScenarioProperty.RULES] = 'standard.rules'
        # self.scenario.load_rules()
        # TODO rules as extra?
        rule_file = constants.extend(constants.SCENARIO_RULESET_FOLDER, self.scenario[constants.ScenarioProperty.RULES])
        self.scenario._rules = utils.read_as_yaml(rule_file)

        # emit that everything has changed
        self.changed.emit()
def scenario_preview(scenario_file_name):
    """
    A client got a message on the constants.C.SCENARIO_PREVIEW channel. In the message should be a scenario file name
    (key = 'scenario'). Assemble a preview and send it back.
    """
    t0 = time.clock()

    # TODO existing? can be loaded?
    scenario = Scenario.from_file(scenario_file_name)
    print('reading the file took {}s'.format(time.clock() - t0))

    preview = {'scenario': scenario_file_name}

    # some scenario properties should be copied
    scenario_copy_keys = [
        constants.ScenarioProperty.MAP_COLUMNS,
        constants.ScenarioProperty.MAP_ROWS, constants.ScenarioProperty.TITLE,
        constants.ScenarioProperty.DESCRIPTION
    ]
    for key in scenario_copy_keys:
        preview[key] = scenario[key]

    # some nations properties should be copied
    nations = {}
    nation_copy_keys = [
        constants.NationProperty.COLOR, constants.NationProperty.NAME,
        constants.NationProperty.DESCRIPTION
    ]
    for nation in scenario.nations():
        nations[nation] = {}
        for key in nation_copy_keys:
            nations[nation][key] = scenario.nation_property(nation, key)
    preview['nations'] = nations

    # assemble a nations map (-1 means no nation)
    columns = scenario[constants.ScenarioProperty.MAP_COLUMNS]
    rows = scenario[constants.ScenarioProperty.MAP_ROWS]
    nations_map = [-1] * (columns * rows)
    for nation_id in scenario.nations():
        provinces = scenario.provinces_of_nation(nation_id)
        for province in provinces:
            tiles = scenario.province_property(
                province, constants.ProvinceProperty.TILES)
            for column, row in tiles:
                nations_map[row * columns + column] = nation_id
    preview['map'] = nations_map

    print('generating preview took {}s'.format(time.clock() - t0))

    return preview
def scenario_preview(scenario_file_name):
    """
    A client got a message on the constants.C.SCENARIO_PREVIEW channel. In the message should be a scenario file name
    (key = 'scenario'). Assemble a preview and send it back.
    """
    t0 = time.clock()

    # TODO existing? can be loaded?
    scenario = Scenario.from_file(scenario_file_name)
    logger.info('reading of the file took {}s'.format(time.clock() - t0))

    preview = {'scenario': scenario_file_name}

    # some scenario properties should be copied
    scenario_copy_keys = [constants.ScenarioProperty.MAP_COLUMNS,
                          constants.ScenarioProperty.MAP_ROWS,
                          constants.ScenarioProperty.TITLE,
                          constants.ScenarioProperty.DESCRIPTION]
    for key in scenario_copy_keys:
        preview[key] = scenario[key]

    # some nations properties should be copied
    nations = {}
    nation_copy_keys = [constants.NationProperty.COLOR,
                        constants.NationProperty.NAME,
                        constants.NationProperty.DESCRIPTION]
    for nation in scenario.nations():
        nations[nation] = {}
        for key in nation_copy_keys:
            nations[nation][key] = scenario.nation_property(nation, key)
    preview['nations'] = nations

    # assemble a nations map (-1 means no nation)
    columns = scenario[constants.ScenarioProperty.MAP_COLUMNS]
    rows = scenario[constants.ScenarioProperty.MAP_ROWS]
    nations_map = [-1] * (columns * rows)
    for nation_id in scenario.nations():
        provinces = scenario.provinces_of_nation(nation_id)
        for province in provinces:
            tiles = scenario.province_property(province, constants.ProvinceProperty.TILES)
            for column, row in tiles:
                nations_map[row * columns + column] = nation_id
    preview['map'] = nations_map

    logger.info('generating preview took {}s'.format(time.clock() - t0))

    return preview
Exemple #6
0
if __name__ == '__main__':

    # add source directory to path if needed
    source_directory = os.path.realpath(
        os.path.join(os.path.abspath(os.path.dirname(__file__)),
                     os.path.pardir, os.path.pardir, 'source'))
    if source_directory not in sys.path:
        sys.path.insert(0, source_directory)

    from imperialism_remake.base import constants
    from imperialism_remake.server.scenario import Scenario

    # load scenario
    scenario = Scenario.from_file(
        constants.extend(constants.CORE_SCENARIO_FOLDER,
                         'Europe1814.scenario'))

    # nation map
    columns = scenario[constants.ScenarioProperty.MAP_COLUMNS]
    rows = scenario[constants.ScenarioProperty.MAP_ROWS]
    map = [0] * (columns * rows)
    for nation in scenario.nations():
        provinces = scenario.provinces_of_nation(nation)
        for province in provinces:
            tiles = scenario.province_property(province, 'tiles')
            for column, row in tiles:
                map[row * columns + column] = nation

    # get outlines
    for nation in scenario.nations():
import os, sys

from PyQt5 import QtWidgets

if __name__ == '__main__':

    # add source directory to path if needed
    source_directory = os.path.realpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), os.path.pardir, os.path.pardir, 'source'))
    if source_directory not in sys.path:
        sys.path.insert(0, source_directory)

    from imperialism_remake.base import constants
    from imperialism_remake.server.scenario import Scenario

    # load scenario
    scenario = Scenario.from_file(constants.extend(constants.CORE_SCENARIO_FOLDER, 'Europe1814.scenario'))

    # nation map
    columns = scenario[constants.ScenarioProperty.MAP_COLUMNS]
    rows = scenario[constants.ScenarioProperty.MAP_ROWS]
    map = [0] * (columns * rows)
    for nation in scenario.nations():
        provinces = scenario.provinces_of_nation(nation)
        for province in provinces:
            tiles = scenario.province_property(province, 'tiles')
            for column, row in tiles:
                map[row * columns + column] = nation

    # get outlines
    for nation in scenario.nations():
        visited = [False] * (columns * rows)