def add_healthy( self, healthy: int, entity_id: UUID, scene: Scene ) -> bool: """Добоаляем жизни""" if component := scene.get_component(entity_id, ComponentUnitHealthy): self._add_healthy(component=component, healthy=healthy) return True
def display_input(self, scene: Scene, component_dialog: ComponentDialog) -> bool: """Получени ввода""" try: input_text: str = input("Введите вариант: ").strip() except UnicodeDecodeError: return False events: List[ComponentDialogEvent] for component in component_dialog.dialog_events: if component.command == input_text: system: Optional[System] = scene.get_system( component.system_type) component_input: Optional[Component] = scene.get_component( entity_id=component.entity_id, component=component.component_type) value: Any = component.value value_name: str = component.value_name kwargs: Dict[str, Any] = component.kwargs entity_id: UUID = component.entity_id event_result: bool = self._event_system( system=system, component=component_input, value=value, value_name=value_name, kwargs=kwargs, scene=scene, entity_id=entity_id) return event_result return False
def _show_display(self, scene: Scene, entity_id: UUID) -> bool: """Отрисовка диалогов""" system_display: Optional[SystemDisplay] = scene.get_system(SystemDisplay) system_input: Optional[SystemInput] = scene.get_system(SystemInput) component_dialog: Optional[ComponentDialog] = scene.get_component( entity_id=entity_id, component=ComponentDialog) if system_display is None or system_input is None or component_dialog is None: return False self.clear() system_display.display_print(scene=scene, component_dialog=component_dialog) component_dialog = scene.get_component(entity_id=entity_id, component=ComponentDialog) system_input.display_input(scene=scene, component_dialog=component_dialog) return True
def render(self, scene: Scene, render_entity_id: UUID, next_dialog: UUID) -> List[ComponentDialogEvent]: system_word: Optional[SystemWord] = scene.get_system(SystemWord) position: Optional[ComponentPosition] = scene.get_component( entity_id=render_entity_id, component=ComponentPosition) if system_word is None or position is None: return [] events: List[ComponentDialogEvent] = self._render( system_word=system_word, position=position, entity_id=render_entity_id, next_dialog=next_dialog) scene.set_resource("dialog", next_dialog) return events
def _dialog(self, scene: Scene, entity_id: UUID) -> bool: """Генерация диалогов""" if component := scene.get_component(entity_id, ComponentDialog): component: ComponentDialog component.dialog_events = self._get_dialogs(scene, component) return True
def render(self, scene: Scene, render_entity_id: UUID, next_dialog: UUID) -> List[ComponentDialogEvent]: inventory: Optional[ComponentInventory] = scene.get_component( entity_id=render_entity_id, component=ComponentInventory) if inventory is None: raise RuntimeError("Не найден компонен для рендеринга инвентаря") renders: List[ComponentDialogEvent] = list() q_event: ComponentDialogEvent = ComponentDialogEvent( command=f"q", display_info="Вернутся в меню", system_type=SystemDialog, value=None, value_name="", entity_id=render_entity_id, component_type=ComponentDialog, next_dialog=render_entity_id, info=False) if len(inventory.items) == 0: info_event: ComponentDialogEvent = ComponentDialogEvent( command=f"", display_info="В инвентаре нет предметов", system_type=type(None), value=None, value_name="", entity_id=render_entity_id, component_type=Component, next_dialog=render_entity_id, info=True) return [info_event, q_event] for index, item_uuid in enumerate(inventory.items): entity: Optional[Entity] = scene.get_entity(entity_id=item_uuid) if entity is None: continue component_item: Optional[ComponentItem] = entity.get_component( ComponentItem) if component_item is None: continue event: ComponentDialogEvent = ComponentDialogEvent( command=f"{index}", display_info=component_item.name, system_type=component_item.system_type, value=None, value_name="", entity_id=entity.get_uuid(), component_type=ComponentItem, next_dialog=next_dialog, ) renders.append(event) renders.append(q_event) scene.set_resource("dialog", render_entity_id) return renders