예제 #1
0
    def select(self, args):
        """Select an existing Zone by name
        
        Parameters
        ----------
        args : list(str)
            List of strings with subcommands

        Returns
        -------
        list(str) - the response messages string array
        """

        messages = []
        if not self.sc:
            raise Exception('No active scene. Try this:```css\n.d scene "SCENE NAME"```')
        if len(args) == 0:
            if not self.zone:
                return [
                    'No active zone or name provided\n\n',
                    self.dialog('all')
                ]
            messages.append(self.zone.get_string(self.channel))
        else:
            if len(args) == 1 and args[0].lower() == 'short':
                return [self.dialog('active_zone_short')]
            if len(args) == 1 and self.char:
                return [self.dialog('')]
            zone_name = ' '.join(args[1:])
            def canceler(cancel_args):
                if cancel_args[0].lower() in ['zone','z']:
                    return ZoneCommand(parent=self.parent, ctx=self.ctx, args=cancel_args, guild=self.guild, user=self.user, channel=self.channel).run()
                else:
                    self.parent.args = cancel_args
                    self.parent.command = self.parent.args[0]
                    return self.parent.get_messages()

            def selector(selection):
                self.zone = selection
                self.channel.set_active_zone(self.zone, self.user)
                self.user.set_active_character(self.zone)
                zone_svc.save_user(self.user)
                return [self.dialog('')]

            messages.extend(Dialog({
                'svc': zone_svc,
                'user': self.user,
                'title': 'Zone List',
                'command': 's ' + ' '.join(args),
                'type': 'select',
                'type_name': 'ZONE',
                'getter': {
                    'method': Zone.get_by_page,
                    'params': {'params': {'name__icontains': zone_name, 'scene_id': str(self.sc.id), 'guild': self.guild.name, 'archived': False}}
                },
                'formatter': lambda item, item_num, page_num, page_size: f'_ZONE #{item_num+1}_\n{item.get_short_string()}',
                'cancel': canceler,
                'select': selector
            }).open())
        return messages
    def select(self, args):
        """Select an existing Engagement by name
        
        Parameters
        ----------
        args : list(str)
            List of strings with subcommands

        Returns
        -------
        list(str) - the response messages string array
        """

        messages = []
        if len(args) == 0:
            if not self.engagement:
                return [
                    'No active engagement or name provided\n\n',
                    self.dialog('all')
                ]
            messages.append(self.engagement.get_string(self.channel))
        else:
            self.check_engagement()
            if len(args) == 1 and args[0].lower() == 'short':
                return [self.dialog('active_engagement_short')]
            if len(args) == 1 and self.char:
                return [self.dialog('')]
            engagement_name = ' '.join(args[1:])
            def canceler(cancel_args):
                if cancel_args[0].lower() in ['engagement','engage','e']:
                    return EngagementCommand(parent=self.parent, ctx=self.ctx, args=cancel_args, guild=self.guild, user=self.user, channel=self.channel).run()
                else:
                    self.parent.args = cancel_args
                    self.parent.command = self.parent.args[0]
                    return self.parent.get_messages()

            def selector(selection):
                self.engagement = selection
                self.channel.set_active_engagement(self.engagement, self.user)
                self.user.set_active_character(self.engagement)
                engagement_svc.save_user(self.user)
                return [self.dialog('')]

            messages.extend(Dialog({
                'svc': engagement_svc,
                'user': self.user,
                'title': 'Engagement List',
                'command': 's ' + ' '.join(args),
                'type': 'select',
                'type_name': 'ENGAGEMENT',
                'getter': {
                    'method': Engagement.get_by_page,
                    'params': {'params': {'name__icontains': engagement_name, 'scene_id': str(self.sc.id), 'guild': self.guild.name, 'archived': False}}
                },
                'formatter': lambda item, item_num, page_num, page_size: f'_ENGAGEMENT #{item_num+1}_\n{item.get_short_string()}',
                'cancel': canceler,
                'select': selector
            }).open())
        return messages
예제 #3
0
    def story(self, args):
        """Disaply the log story
        
        Parameters
        ----------
        args : list(str)
            List of strings with subcommands

        Returns
        -------
        list(str) - the response messages string array
        """

        messages = []
        command = 'log ' + (' '.join(args))

        def canceler(cancel_args):
            if cancel_args[0].lower() in ['log', 'redo', 'undo']:
                self.args = cancel_args
                self.command = self.args[0]
                return self.run()
            else:
                self.parent.args = cancel_args
                self.parent.command = self.parent.args[0]
                return self.parent.get_messages()

        response = Dialog({
            'svc':
            char_svc,
            'user':
            self.user,
            'title':
            'Story',
            'type':
            'view',
            'type_name':
            'Story Log',
            'command':
            command,
            'getter': {
                'method': Log.get_by_page,
                'params': {
                    'params': {
                        'user_id': str(self.user.id),
                        'category': 'Log'
                    },
                    'sort': 'created'
                }
            },
            'formatter':
            lambda log, num, page_num, page_size: log.get_string(self.user),
            'cancel':
            canceler,
            'page_size':
            10
        }).open()
        messages.extend(response)
        return messages
예제 #4
0
    def select(self, args):
        """Select an existing Scenario by name
        
        Parameters
        ----------
        args : list(str)
            List of strings with subcommands

        Returns
        -------
        list(str) - the response messages string array
        """

        messages = []
        if len(args) == 0:
            if not self.scenario:
                return [
                    'No active scenario or name provided\n\n',
                    self.dialog('all')
                ]
            messages.append(self.scenario.get_string())
        else:
            if len(args) == 1 and args[0].lower() == 'short':
                return [self.dialog('active_scenario_short')]
            if len(args) == 1 and self.scenario:
                return [self.dialog('')]
            scenario_name = ' '.join(args[1:])
            def canceler(cancel_args):
                if cancel_args[0].lower() in ['scenario']:
                    return ScenarioCommand(parent=self.parent, ctx=self.ctx, args=cancel_args, guild=self.guild, user=self.user, channel=self.channel).run()
                else:
                    self.parent.args = cancel_args
                    self.parent.command = self.parent.args[0]
                    return self.parent.get_messages()

            def selector(selection):
                self.scenario = selection
                self.channel.set_active_scenario(self.scenario, self.user)
                self.user.set_active_character(self.scenario.character)
                scenario_svc.save_user(self.user)
                return [self.dialog('')]

            messages.extend(Dialog({
                'svc': scenario_svc,
                'user': self.user,
                'title': 'Scenario List',
                'command': 'scenario ' + ' '.join(args),
                'type': 'select',
                'type_name': 'SCENARIO',
                'getter': {
                    'method': Scenario.get_by_page,
                    'params': {'params': {'name__icontains': scenario_name, 'channel_id': str(self.channel.id), 'guild': self.guild.name, 'archived': False}}
                },
                'formatter': lambda item, item_num, page_num, page_size: f'_SCENARIO #{item_num+1}_\n{scenario_svc.get_string(item, self.channel)}',
                'cancel': canceler,
                'select': selector
            }).open())
        return messages
    def suggestion_list(self, args):
        """Display a dialog for viewing and selecting Suggestions
        
        Parameters
        ----------
        args : list(str)
            List of strings with subcommands

        Returns
        -------
        list(str) - the response messages string array
        """

        messages = []

        def canceler(cancel_args):
            if cancel_args[0].lower() in ['suggestion', 'suggest']:
                return SuggestionCommand(parent=self.parent,
                                         ctx=self.ctx,
                                         args=cancel_args,
                                         guild=self.guild,
                                         user=self.user,
                                         channel=self.channel).run()
            else:
                self.parent.args = cancel_args
                self.parent.command = self.parent.args[0]
                return self.parent.get_messages()

        def formatter(item, item_num, page_num, page_size):
            return item.get_short_string(self.user)

        messages.extend(
            Dialog({
                'svc': suggestion_svc,
                'user': self.user,
                'title': 'Suggestion List',
                'command': 'suggestion ' + (' '.join(args)),
                'type': 'view',
                'type_name': 'SUGGESTION',
                'page_size': 1,
                'getter': {
                    'method': Suggestion.get_by_page,
                    'params': {
                        'params': {
                            'archived': False
                        }
                    }
                },
                'formatter': formatter,
                'cancel': canceler
            }).open())
        return messages
예제 #6
0
    def story(self, args):
        """Disaply the Zone story
        
        Parameters
        ----------
        args : list(str)
            List of strings with subcommands

        Returns
        -------
        list(str) - the response messages string array
        """

        messages =[]
        if not self.sc:
            raise Exception('No active scene. Try this:```css\n.d scene "SCENE NAME"```')
        command = 'zone ' + (' '.join(args))
        def canceler(cancel_args):
            if cancel_args[0].lower() in ['zone','s']:
                self.args = cancel_args
                self.command = self.args[0]
                return self.run()
            else:
                self.parent.args = cancel_args
                self.parent.command = self.parent.args[0]
                return self.parent.get_messages()
        response = Dialog({
            'svc': zone_svc,
            'user': self.user,
            'title': 'Story',
            'type': 'view',
            'type_name': 'Story Log',
            'command': command,
            'getter': {
                'method': Log.get_by_page,
                'params': {
                    'params': {'parent_id': str(self.sc.id)},
                    'sort': 'created'
                },
                'parent_method': Zone.get_by_page,
                'parent_params': {
                    'params': {'category__in': ['Character','Aspect','Stunt']},
                    'sort': 'created'
                }
            },
            'formatter': lambda log, num, page_num, page_size: log.get_string(self.user), # if log.category == 'Log' else log.get_string()
            'cancel': canceler,
            'page_size': 10
        }).open()
        messages.extend(response)
        return messages
    def story(self, args):
        """Disaply the Engagement story
        
        Parameters
        ----------
        args : list(str)
            List of strings with subcommands

        Returns
        -------
        list(str) - the response messages string array
        """

        messages =[]
        self.check_engagement()
        command = 'engagement ' + (' '.join(args))
        def canceler(cancel_args):
            if cancel_args[0].lower() in ['engagement','engage','e']:
                self.args = cancel_args
                self.command = self.args[0]
                return self.run()
            else:
                self.parent.args = cancel_args
                self.parent.command = self.parent.args[0]
                return self.parent.get_messages()
        response = Dialog({
            'svc': engagement_svc,
            'user': self.user,
            'title': 'Story',
            'type': 'view',
            'type_name': 'Story Log',
            'command': command,
            'getter': {
                'method': Log.get_by_page,
                'params': {
                    'params': {'parent_id': str(self.sc.id)},
                    'sort': 'created'
                },
                'parent_method': Engagement.get_by_page,
                'parent_params': {
                    'params': {'category__in': ['Character','Aspect','Stunt']},
                    'sort': 'created'
                }
            },
            'formatter': lambda log, num, page_num, page_size: log.get_string(self.user), # if log.category == 'Log' else log.get_string()
            'cancel': canceler,
            'page_size': 10
        }).open()
        messages.extend(response)
        return messages
예제 #8
0
    def undo_list(self, args):
        """Display a dialog for viewing and selecting Changes to undo
        
        Parameters
        ----------
        args : list(str)
            List of strings with subcommands

        Returns
        -------
        list(str) - the response messages string array
        """

        messages = []
        command = 'undo ' + (' '.join(args))

        def canceler(cancel_args):
            if cancel_args[0].lower() in ['log', 'redo', 'undo']:
                self.args = cancel_args
                self.command = self.args[0]
                return self.run()
            else:
                self.parent.args = cancel_args
                self.parent.command = self.parent.args[0]
                return self.parent.get_messages()

        response = Dialog({
            'svc': char_svc,
            'user': self.user,
            'title': 'Undo List',
            'type': 'view',
            'type_name': 'Undo History',
            'command': command,
            'getter': {
                'method': Log.get_by_page,
                'params': {
                    'params': {
                        'user_id': str(self.user.id),
                        'category__ne': 'Log'
                    }
                }
            },
            'formatter': lambda undo, num, page_num, page_size:
            f'_Undo #{num+1}_\n{undo.get_string()}',
            'cancel': canceler
        }).open()
        messages.extend(response)
        return messages
예제 #9
0
    def __init__(self):
        super(daySelect, self).__init__()
        self.ui = Dialog()
        self.ui.setupUi(self)
        self.settings = Settings()
        self.class_repo = self.settings.class_path
        repo_children = [
            str(x.name) for x in self.class_repo.expanduser().iterdir()
        ]
        for item in repo_children:
            self.ui.daySelect.addItem(item)

        self.ui.fullTime.setDisabled(True)

        self.ui.buttonBox.clicked.connect(self.onSelect)
        self.exec_()
예제 #10
0
    def story(self, args):
        """Disaply the Scene story
        
        Parameters
        ----------
        args : list(str)
            List of strings with subcommands

        Returns
        -------
        list(str) - the response messages string array
        """

        messages =[]
        command = 'scene ' + (' '.join(args))
        def canceler(cancel_args):
            if cancel_args[0].lower() in ['scene','s']:
                return SceneCommand(parent=self.parent, ctx=self.ctx, args=cancel_args, guild=self.guild, user=self.user, channel=self.channel).run()
            else:
                self.parent.args = cancel_args
                self.parent.command = self.parent.args[0]
                return self.parent.get_messages()
        response = Dialog({
            'svc': scene_svc,
            'user': self.user,
            'title': 'Story',
            'type': 'view',
            'type_name': 'Story Log',
            'command': command,
            'getter': {
                'method': Log.get_by_page,
                'params': {
                    'params': {'parent_id': str(self.sc.id), 'data__note__exists': True},
                    'sort': 'created'
                },
                'parent_method': Scene.get_by_page,
                'parent_params': {
                    'params': {'category__in': ['Character','Aspect','Stunt']},
                    'sort': 'created'
                }
            },
            'formatter': lambda log, num, page_num, page_size: log.get_string(self.user), # if log.category == 'Log' else log.get_string()
            'cancel': canceler,
            'page_size': 10
        }).open()
        messages.extend(response)
        return messages
예제 #11
0
    def channel_list(self, args):
        """
        
        Parameters
        ----------
        args : list(str)
            List of strings with subcommands
        """

        messages = []
        def canceler(cancel_args):
            if cancel_args[0].lower() in ['chan']:
                return ChannelCommand(parent=self.parent, ctx=self.ctx, args=cancel_args, guild=self.guild, user=self.user, channel=self.channel).run()
            else:
                self.parent.args = cancel_args
                self.parent.command = self.parent.args[0]
                return self.parent.get_messages()

        def selector(selection):
            self.channel = selection
            return self.chan(self.args)

        def formatter(item, item_num, page_num, page_size):
            return f'_CHANNAL #{((page_num-1)*page_size)+item_num+1}_\n{item.get_short_string(self.user)}'

        messages.extend(Dialog({
            'svc': channel_svc,
            'user': self.user,
            'title': 'Channel List',
            'command': 'chan ' + (' '.join(args)),
            'type': 'select',
            'type_name': 'CHANNEL',
            'getter': {
                'method': Channel.get_by_page,
                'params': {'params': {'guild': self.guild.name, 'archived': False}}
            },
            'formatter': formatter,
            'cancel': canceler,
            'select': selector
        }).open())
        return messages
예제 #12
0
    def zone_list(self, args):
        """Display a dialog for viewing and selecting Zones
        
        Parameters
        ----------
        args : list(str)
            List of strings with subcommands

        Returns
        -------
        list(str) - the response messages string array
        """

        messages = []
        if not self.sc:
            raise Exception('No active scene. Try this:```css\n.d scene "SCENE NAME"```')
        def canceler(cancel_args):
            if cancel_args[0].lower() in ['zone']:
                return ZoneCommand(parent=self.parent, ctx=self.ctx, args=cancel_args, guild=self.guild, user=self.user, channel=self.channel).run()
            else:
                self.parent.args = cancel_args
                self.parent.command = self.parent.args[0]
                return self.parent.get_messages()

        messages.extend(Dialog({
            'svc': zone_svc,
            'user': self.user,
            'title': 'Zone List',
            'command': 'zone ' + (' '.join(args)),
            'type': 'view',
            'type_name': 'ZONE',
            'getter': {
                'method': Zone().get_by_scene,
                'params': {'scene': self.sc, 'archived': False}
            },
            'formatter': lambda item, item_num, page_num, page_size: f'{item.get_short_string(self.channel)}',
            'cancel': canceler
        }).open())
        return messages
예제 #13
0
    def engagement_list(self, args):
        """Display a dialog for viewing and selecting Engagements
        
        Parameters
        ----------
        args : list(str)
            List of strings with subcommands

        Returns
        -------
        list(str) - the response messages string array
        """

        messages = []
        self.check_engagement()
        def canceler(cancel_args):
            if cancel_args[0].lower() in ['engagement']:
                return EngagementCommand(parent=self.parent, ctx=self.ctx, args=cancel_args, guild=self.guild, user=self.user, channel=self.channel).run()
            else:
                self.parent.args = cancel_args
                self.parent.command = self.parent.args[0]
                return self.parent.get_messages()

        messages.extend(Dialog({
            'svc': engagement_svc,
            'user': self.user,
            'title': 'Engagement List',
            'command': 'engagement ' + (' '.join(args)),
            'type': 'view',
            'type_name': 'ENGAGEMENT',
            'getter': {
                'method': Engagement().get_by_scene,
                'params': {'scene': self.sc, 'archived': False}
            },
            'formatter': lambda item, item_num, page_num, page_size: f'{item.get_short_string(self.channel)}',
            'cancel': canceler
        }).open())
        return messages
예제 #14
0
def main(world: World, mapfile: str = "skyrim_map.jpg") -> int:

    global mapsurface, scale, screen, mapgroup, bottom_button_group

    pygame.init()
    pygame.display.set_caption("MapGen {}".format(current_version))
    screen = pygame.display.set_mode(resolution)

    # Log.d(type(screen));
    # main map initialization
    mapgroup = pygame.sprite.Group()
    mapsurface = Map(mapfile, 0, 0, 0)
    mapsurface.add(mapgroup)

    # button blocks drawing

    menu_blocks_group = pygame.sprite.Group()
    right_menu_block = MenuBlock(800, 0, 200, 800)
    bottom_menu_block = MenuBlock(0, 800, 1000, 100)
    menu_blocks_group.add(right_menu_block)
    menu_blocks_group.add(bottom_menu_block)

    # Log.expects(menu_blocks_group.has(right_menu_block), True)
    # Log.expects(menu_blocks_group.has(bottom_menu_block), True)
    # Log.expects(mapgroup.has(mapsurface), True)

    right_button_group = pygame.sprite.Group()
    add_province_button = Button(x=825,
                                 y=25,
                                 w=150,
                                 h=75,
                                 text="Add Province",
                                 mode=1)
    delete_province_button = Button(x=825,
                                    y=125,
                                    w=150,
                                    h=75,
                                    text="Delete Province",
                                    mode=0)
    add_state_button = Button(x=825,
                              y=225,
                              w=150,
                              h=75,
                              text="Add State",
                              mode=2)
    edit_graph_button = Button(x=825,
                               y=325,
                               w=150,
                               h=75,
                               text="Edit Graph",
                               mode=3)
    edit_parameter_button = Button(x=825,
                                   y=425,
                                   w=150,
                                   h=75,
                                   text="Edit Parameter",
                                   mode=4)
    political_coordinates_button = Button(x=825,
                                          y=525,
                                          w=150,
                                          h=75,
                                          text="Political Coords",
                                          mode=5)
    diplomacy_coordinates_button = Button(x=825,
                                          y=625,
                                          w=150,
                                          h=75,
                                          text="Diplomacy Coords",
                                          mode=6)
    compile_script_button = Button(x=825,
                                   y=725,
                                   w=150,
                                   h=75,
                                   text="Compile Script",
                                   mode=0)

    right_button_group.add(add_province_button)
    right_button_group.add(delete_province_button)
    right_button_group.add(add_state_button)
    right_button_group.add(edit_graph_button)
    right_button_group.add(edit_parameter_button)
    right_button_group.add(political_coordinates_button)
    right_button_group.add(diplomacy_coordinates_button)
    right_button_group.add(compile_script_button)

    bottom_button_group = pygame.sprite.Group()

    # ================== ДОБАВЛЯТЬ КНОПКУ ДЛЯ ПАРАМЕТРОВ ===================
    political_parameter_button = Button(x=10,
                                        y=805,
                                        w=180,
                                        h=40,
                                        text="Political",
                                        mode=POLITICAL_MODE)
    population_parameter_button = Button(x=10,
                                         y=855,
                                         w=180,
                                         h=40,
                                         text="Population",
                                         mode=POPULATION_MODE)
    production_parameter_button = Button(x=210,
                                         y=805,
                                         w=180,
                                         h=40,
                                         text="Production",
                                         mode=PRODUCTION_MODE)
    education_parameter_button = Button(x=210,
                                        y=855,
                                        w=180,
                                        h=40,
                                        text="Education",
                                        mode=EDUCATION_MODE)
    army_parameter_button = Button(x=410,
                                   y=805,
                                   w=180,
                                   h=40,
                                   text="Army",
                                   mode=ARMY_MODE)
    natural_resources_button = Button(x=410,
                                      y=855,
                                      w=180,
                                      h=40,
                                      text="Natural Resources",
                                      mode=NATURAL_RESOURCES_MODE)
    separatism_button = Button(x=610,
                               y=805,
                               w=180,
                               h=40,
                               text="Separatism",
                               mode=SEPARATISM_MODE)
    climate_button = Button(x=610,
                            y=855,
                            w=180,
                            h=40,
                            text="Climate auspiciousness",
                            mode=CLIMATE_MODE)
    sea_button = Button(x=810,
                        y=805,
                        w=180,
                        h=40,
                        text='Water Provinces',
                        mode=SEA_MODE)
    defensive_ability_button = Button(x=810,
                                      y=855,
                                      w=180,
                                      h=40,
                                      text="Defensive ability",
                                      mode=DEFENSIVE_ABILITY_MODE)
    # ============== ЗАСОВЫВАТЬ КНОПКУ В СВОЮ ГРУППУ ======================
    bottom_button_group.add(political_parameter_button)
    bottom_button_group.add(population_parameter_button)
    bottom_button_group.add(production_parameter_button)
    bottom_button_group.add(education_parameter_button)
    bottom_button_group.add(army_parameter_button)
    bottom_button_group.add(natural_resources_button)
    bottom_button_group.add(separatism_button)
    bottom_button_group.add(climate_button)
    bottom_button_group.add(sea_button)
    bottom_button_group.add(defensive_ability_button)

    scale = 0  # масштаб карты. транслятор масштаб : размер карты в mapsurface.scale_dict
    pressed = False
    capital_pressed = -1
    mode = 0
    last_coords = None
    current_added_province = None
    text_showing: bool = True
    icon_showing: bool = True
    parameter_mode: int = POLITICAL_MODE

    chosen_state: State = None
    # Log.d(parameter_mode);
    """
		Mode 0: 	is the mode with political map showing and nothinhg else
		Mode 1: 	mode when user adds province drawing polygons
		Mode 2: 	mode when user color provinces into countries
		Mode 3: 	mode when user draw a graph
		Mode 4:		mode when user is editing a province parameters
		Mode 5:		mode when user edit political coordinates
		Mode 6: 	mode when user edit diplomacy coordinates
	"""

    # main screen cycle
    while True:
        frameEventsList = pygame.event.get()

        # обработка вспомогательных модов работы

        for event in frameEventsList:
            if event.type == pygame.KEYDOWN:
                try:
                    if event.key in map(ord, list('тТnN')):
                        text_showing = not text_showing
                        # Log.d('got it');
                        continue
                    elif event.key in map(ord, list('iIшШ')):
                        icon_showing = not icon_showing

                except Exception:
                    pass

        screen.fill((228, 228, 228))
        # Log.expects(myrange(0, 2).contains(mode), True);

        if myrange(0, 4).contains(mode):
            pressed, last_coords = MapMovementAndZoom(frameEventsList, pressed,
                                                      last_coords)
            mapgroup.draw(screen)
            if myrange(0, 3).contains(mode):
                world.draw_all(screen, mapsurface, mode=parameter_mode)
            if mode == 3: world.draw_graph(screen, mapsurface)
            if mode == 4: world.draw_borders(screen, mapsurface)
        """
		В отдельный этап вынесены эвенты со сменой режима работы"
		"""

        if mode == 0:  # mode enter

            try:
                new_mode: int = check_buttons(frameEventsList,
                                              right_button_group, mode)
                if mode != new_mode:
                    mode = new_mode
                    raise ModeChangeProcedure
            except ModeChangeProcedure:
                if mode == 1:
                    province_name = Dialog().get(
                        message="Введите название провинции")
                    current_added_province = Province()
                    current_added_province.set_id(world.get_new_province_id())
                    current_added_province.set_name(province_name)
                    # Log.d(current_added_province.get_name());
                    world.addProvince(current_added_province)
                elif mode == 2:
                    state_name = Dialog().get(
                        message="Введите название страны")
                    current_added_state = State()
                    current_added_state.set_id(world.get_new_state_id())
                    current_added_state.set_name(state_name)
                    current_added_state.add_self_to_group(state_icons_group)
                    world.addState(current_added_state)

                elif myrange(3, 6).contains(mode):
                    pass
                continue

        if myrange(1, 6).contains(mode):  # mode exit
            try:
                new_mode: int = check_buttons(frameEventsList,
                                              right_button_group, mode)
                if mode != new_mode:
                    old_mode = mode
                    mode = new_mode
                    raise ModeChangeProcedure
            except ModeChangeProcedure:
                if mode == 0:
                    if old_mode == 1:
                        current_added_province = None
                        if len(world.list_of_capitals) != len(
                                world.list_of_province):
                            world.list_of_province.pop()
                            # Log.d(len(world.list_of_capitals), len(world.list_of_province));

                    elif old_mode == 2:
                        current_added_state = None
                    elif old_mode == 3:
                        pass

        if mode == 1:
            provinceGeometryEdit(frameEventsList, current_added_province,
                                 mapsurface)
        elif mode == 2:
            addStateMode(frameEventsList, current_added_state, mapsurface)

        elif mode == 3:
            capital_pressed = graphEditMode(frameEventsList, screen,
                                            mapsurface, world, capital_pressed)

        elif mode == 4:

            parameter_mode = editParameterMode(frameEventsList, screen,
                                               mapsurface, world,
                                               parameter_mode)
            # Log.d(parameter_mode);
            world.draw_parameter(screen, mapsurface, parameter_mode)

        elif mode == 5:
            chosen_state = editPoliticalCoords(frameEventsList, screen, world,
                                               chosen_state)
        elif mode == 6:
            chosen_state = editDiplomacyCoords(frameEventsList, screen, world,
                                               chosen_state)

        menu_blocks_group.draw(screen)
        # блоки меню отрисовываются при любом режиме работы программы
        right_button_group.draw(screen)
        # кнопки отрисовываются при любом режиме работы программы.
        bottom_button_group.draw(screen)
        # if icon_showing: world.icon_draw(screen, mapsurface);
        pygame.display.flip()

    return 0
예제 #15
0
    def new_engagement(self, args):
        """Create a new Engagement by name
        
        Parameters
        ----------
        args : list(str)
            List of strings with subcommands

        Returns
        -------
        list(str) - the response messages string array
        """

        messages = []
        self.check_engagement()
        if len(args) == 0:
            if not self.engagement:
                return [
                    'No active engagement or name provided\n\n',
                    self.dialog('all')
                ]
            messages.append(self.engagement.get_string(self.channel))
        else:
            if len(args) == 1 and args[0].lower() == 'short':
                return [self.dialog('active_engagement_short')]
            engagement_type = args[0]
            if engagement_type == 'rename':
                engagement_name = ' '.join(args[1:])
                if not self.engagement:
                    return [
                        'No active engagement or name provided\n\n',
                        self.dialog('all')
                    ]
                else:
                    engagement = Engagement().find(self.guild.name, str(self.channel.id), str(self.sc.id), engagement_name)
                    if engagement:
                        return [f'Cannot rename to _{engagement_name}_. Engagement already exists']
                    else:
                        self.engagement.name = engagement_name
                        engagement_svc.save(self.engagement, self.user)
                        messages.append(self.dialog(''))
            else:
                if engagement_type.lower() not in ['conflict','contest','challenge']:
                    raise Exception('No engagement type (CONFLICT, CONTEST, CHALLENGE)')
                if len(args) > 1:
                    engagement_name = ' '.join(args[1:])
                else:
                    engagement_name = f'{engagement_type.title()} at {T.to(T.now())}'
                def canceler(cancel_args):
                    if cancel_args[0].lower() in ['engagement','engage','e']:
                        return EngagementCommand(parent=self.parent, ctx=self.ctx, args=cancel_args, guild=self.guild, user=self.user, channel=self.channel).run()
                    else:
                        self.parent.args = cancel_args
                        self.parent.command = self.parent.args[0]
                        return self.parent.get_messages()

                def selector(selection):
                    self.engagement = selection
                    self.channel.set_active_engagement(self.engagement, self.user)
                    self.user.set_active_character(self.engagement.character)
                    engagement_svc.save_user(self.user)
                    return [self.dialog('')]

                def creator(**params):
                    item = Engagement().get_or_create(**params)
                    if self.scenario:
                        scenes = scenario_svc.get_scenes(self.scenario)
                        characters = scenario_svc.get_characters(scenes)
                        item.characters = [str(c.id) for c in characters]
                    item.type_name = engagement_type.title()
                    engagement_svc.save(item, self.user)
                    return item

                messages.extend(Dialog({
                    'svc': engagement_svc,
                    'user': self.user,
                    'title': 'Engagement List',
                    'command': 'new engagement ' + ' '.join(args),
                    'type': 'select',
                    'type_name': 'ENGAGEMENT',
                    'getter': {
                        'method': Engagement.get_by_page,
                        'params': {'params': {'name__icontains': engagement_name, 'scene_id': str(self.sc.id), 'guild': self.guild.name, 'archived': False}}
                    },
                    'formatter': lambda item, item_num, page_num, page_size: f'_ENGAGEMENT #{item_num+1}_\n{item.get_short_string()}',
                    'cancel': canceler,
                    'select': selector,
                    'confirm': {
                        'method': creator,
                        'params': {'user': self.user, 'name': engagement_name, 'scene': self.sc, 'channel': self.channel, 'guild': self.guild.name}
                    }
                }).open())
        return messages
예제 #16
0
    def new_session(self, args):
        """Create a new Session by name
        
        Parameters
        ----------
        args : list(str)
            List of strings with subcommands

        Returns
        -------
        list(str) - the response messages string array
        """

        messages = []
        if len(args) == 0:
            if not self.session:
                return [
                    'No active session or name provided\n\n',
                    self.dialog('all')
                ]
            messages.append(self.session.get_string(self.channel, self.user))
        else:
            if len(args) == 1 and args[0].lower() == 'short':
                return [self.dialog('active_session_short')]
            session_name = ' '.join(args)
            if len(args) > 1 and args[1] == 'rename':
                session_name = ' '.join(args[2:])
                if not self.session:
                    return [
                        'No active session or name provided\n\n',
                        self.dialog('all')
                    ]
                else:
                    session = Session().find(self.guild.name,
                                             str(self.channel.id),
                                             session_name)
                    if session:
                        return [
                            f'Cannot rename to _{session_name}_. Session already exists'
                        ]
                    else:
                        self.session.name = session_name
                        session_svc.save(self.session, self.user)
                        messages.append(self.dialog(''))
            else:

                def canceler(cancel_args):
                    if cancel_args[0].lower() in ['session', 's']:
                        return SessionCommand(parent=self.parent,
                                              ctx=self.ctx,
                                              args=cancel_args,
                                              guild=self.guild,
                                              user=self.user,
                                              channel=self.channel).run()
                    else:
                        self.parent.args = cancel_args
                        self.parent.command = self.parent.args[0]
                        return self.parent.get_messages()

                def selector(selection):
                    self.session = selection
                    self.channel.set_active_session(self.session, self.user)
                    return [self.dialog('')]

                def creator(**params):
                    item = Session().get_or_create(**params)
                    return item

                messages.extend(
                    Dialog({
                        'svc':
                        session_svc,
                        'user':
                        self.user,
                        'title':
                        'Session List',
                        'command':
                        'new session ' + ' '.join(args),
                        'type':
                        'select',
                        'type_name':
                        'SESSION',
                        'getter': {
                            'method': Session.get_by_page,
                            'params': {
                                'params': {
                                    'name__icontains': session_name,
                                    'channel_id': str(self.channel.id),
                                    'guild': self.guild.name,
                                    'archived': False
                                }
                            }
                        },
                        'formatter':
                        lambda item, item_num, page_num, page_size:
                        f'_SESSION #{item_num+1}_\n{item.get_short_string()}',
                        'cancel':
                        canceler,
                        'select':
                        selector,
                        'confirm': {
                            'method': creator,
                            'params': {
                                'user': self.user,
                                'name': session_name,
                                'channel': self.channel,
                                'guild': self.guild.name
                            }
                        }
                    }).open())
        return messages
예제 #17
0
    def new_scene(self, args):
        """Create a new Scene by name
        
        Parameters
        ----------
        args : list(str)
            List of strings with subcommands

        Returns
        -------
        list(str) - the response messages string array
        """

        messages = []
        if not self.scenario:
            raise Exception('No active scenario. Try this:```css\n.d new scenario "SCENARIO NAME"```')
        if len(args) == 0:
            if not self.sc:
                return [
                    'No active scene or name provided\n\n',
                    self.dialog('all')
                ]
            messages.append(self.sc.get_string(self.channel, self.user))
        else:
            if len(args) == 1 and args[0].lower() == 'short':
                return [self.dialog('active_scene_short')]
            scene_name = ' '.join(args)
            if len(args) > 1 and args[1] == 'rename':
                scene_name = ' '.join(args[2:])
                if not self.sc:
                    return [
                        'No active scene or name provided\n\n',
                        self.dialog('all')
                    ]
                else:
                    scene = Scene().find(self.guild.name, str(self.channel.id), str(self.scenario.id), scene_name)
                    if scene:
                        return [f'Cannot rename to _{scene_name}_. Scene already exists']
                    else:
                        self.sc.name = scene_name
                        scene_svc.save(self.sc, self.user)
                        messages.append(self.dialog(''))
            else:
                def canceler(cancel_args):
                    if cancel_args[0].lower() in ['scene','s']:
                        return SceneCommand(parent=self.parent, ctx=self.ctx, args=cancel_args, guild=self.guild, user=self.user, channel=self.channel).run()
                    else:
                        self.parent.args = cancel_args
                        self.parent.command = self.parent.args[0]
                        return self.parent.get_messages()

                def selector(selection):
                    self.sc = selection
                    self.channel.set_active_scene(self.sc, self.user)
                    return [self.dialog('')]

                def creator(**params):
                    item = Scene().get_or_create(**params)
                    scenes = scenario_svc.get_scenes(self.scenario)
                    characters = scenario_svc.get_characters(scenes)
                    item.characters = [str(c.id) for c in characters]
                    scene_svc.save(item, self.user)
                    return item

                messages.extend(Dialog({
                    'svc': scene_svc,
                    'user': self.user,
                    'title': 'Scene List',
                    'command': 'new scene ' + ' '.join(args),
                    'type': 'select',
                    'type_name': 'SCENE',
                    'getter': {
                        'method': Scene.get_by_page,
                        'params': {'params': {'name__icontains': scene_name, 'scenario_id': str(self.scenario.id), 'guild': self.guild.name, 'archived': False}}
                    },
                    'formatter': lambda item, item_num, page_num, page_size: f'_SCENE #{item_num+1}_\n{item.get_short_string()}',
                    'cancel': canceler,
                    'select': selector,
                    'confirm': {
                        'method': creator,
                        'params': {'user': self.user, 'name': scene_name, 'scenario': self.scenario, 'channel': self.channel, 'guild': self.guild.name}
                    }
                }).open())
        return messages
예제 #18
0
            chosen_state = editPoliticalCoords(frameEventsList, screen, world,
                                               chosen_state)
        elif mode == 6:
            chosen_state = editDiplomacyCoords(frameEventsList, screen, world,
                                               chosen_state)

        menu_blocks_group.draw(screen)
        # блоки меню отрисовываются при любом режиме работы программы
        right_button_group.draw(screen)
        # кнопки отрисовываются при любом режиме работы программы.
        bottom_button_group.draw(screen)
        # if icon_showing: world.icon_draw(screen, mapsurface);
        pygame.display.flip()

    return 0


if __name__ == '__main__':

    # консольная конфигурация мира типа введите название

    # Расскоментировать для включения диалогового окна

    # name = Dialog().get(message = "Введите имя карты")
    mapfile = Dialog().get_file()
    try:
        world = World(name=name)
    except Exception:
        world = World()

    main(world, mapfile=mapfile)