def event(self, scene: Scene, system_event: System, event_type: str, entity_id: UUID, component: Component, value: Any, value_name: str, kwargs: Dict[str, Any]) -> None: player_uuid: UUID = scene.get_resource("player") player: Entity = scene.get_entity(entity_id=player_uuid) component_inventory: Optional[ ComponentInventory] = player.get_component(ComponentInventory) if component_inventory is None: raise RuntimeError( "Не найден компонент инветаря при использование зелья") if isinstance(value, bool) and value: self.enable_potion(scene=scene, item_entity_id=entity_id, component_inventory=component_inventory, component_potion=component, player=player) scene.set_resource("dialog", component_inventory.entity_items)
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