|
4 | 4 | import os |
5 | 5 | import json |
6 | 6 | import sys |
| 7 | +import shutil |
| 8 | + |
| 9 | +from PyQt5.QtWidgets import QPushButton, QMessageBox |
| 10 | + |
7 | 11 | # Adiciona a pasta minigames ao sys.path |
8 | 12 | #sys.path.append(os.path.join(os.path.dirname(__file__), 'minigames')) |
9 | 13 | from PyQt5.QtWidgets import ( |
@@ -45,6 +49,45 @@ def load_minigames(): |
45 | 49 |
|
46 | 50 | return minigames |
47 | 51 |
|
| 52 | + |
| 53 | +def copiar_pastas_padrao(): |
| 54 | + # Caminhos das pastas padrão |
| 55 | + minigames_default_path = os.path.join(os.path.dirname(__file__), "minigames") |
| 56 | + minigames_config_default_path = os.path.join(os.path.dirname(__file__), "minigames_config") |
| 57 | + |
| 58 | + # Caminhos das pastas de usuário |
| 59 | + minigames_user_path = os.path.expanduser("~/.pet_game/minigames") |
| 60 | + minigames_config_user_path = os.path.expanduser("~/.pet_game/minigames_config") |
| 61 | + |
| 62 | + # Copiar pasta minigames |
| 63 | + if os.path.exists(minigames_default_path): |
| 64 | + if not os.path.exists(minigames_user_path): |
| 65 | + os.makedirs(minigames_user_path) |
| 66 | + for arquivo in os.listdir(minigames_default_path): |
| 67 | + origem = os.path.join(minigames_default_path, arquivo) |
| 68 | + destino = os.path.join(minigames_user_path, arquivo) |
| 69 | + if not os.path.exists(destino): # Evita sobrescrever arquivos já existentes |
| 70 | + shutil.copy(origem, destino) |
| 71 | + |
| 72 | + # Copiar pasta minigames_config |
| 73 | + if os.path.exists(minigames_config_default_path): |
| 74 | + if not os.path.exists(minigames_config_user_path): |
| 75 | + os.makedirs(minigames_config_user_path) |
| 76 | + for arquivo in os.listdir(minigames_config_default_path): |
| 77 | + origem = os.path.join(minigames_config_default_path, arquivo) |
| 78 | + destino = os.path.join(minigames_config_user_path, arquivo) |
| 79 | + if not os.path.exists(destino): # Evita sobrescrever arquivos já existentes |
| 80 | + shutil.copy(origem, destino) |
| 81 | + |
| 82 | + # Mensagem de confirmação para o usuário |
| 83 | + QMessageBox.information(None, "Pasta Copiada", "Os minigames e configurações padrão foram copiados com sucesso para a pasta de usuário!") |
| 84 | + |
| 85 | +# Exemplo de como adicionar o botão à interface |
| 86 | +def adicionar_botao_copiar_pastas(layout): |
| 87 | + botao_copiar = QPushButton("Copiar Minigames e Configurações") |
| 88 | + botao_copiar.clicked.connect(copiar_pastas_padrao) |
| 89 | + layout.addWidget(botao_copiar) |
| 90 | + |
48 | 91 | class PetGameModule(QDialog): |
49 | 92 | def __init__(self, parent=None): |
50 | 93 | super().__init__(parent) |
@@ -200,6 +243,13 @@ def init_ui(self): |
200 | 243 | self.init_games_tab() |
201 | 244 | self.init_pomodoro_tab() |
202 | 245 | self.init_shop_tab() |
| 246 | + |
| 247 | + # Adiciona o botão para copiar minigames padrão |
| 248 | + config_tab = QWidget() |
| 249 | + config_layout = QVBoxLayout(config_tab) |
| 250 | + adicionar_botao_copiar_pastas(config_layout) # Chama a função correta que adiciona o botão |
| 251 | + |
| 252 | + self.tabs.addTab(config_tab, "Configurações") |
203 | 253 |
|
204 | 254 | layout.addWidget(self.tabs) |
205 | 255 |
|
@@ -484,7 +534,8 @@ def update_pomodoro_timer(self): |
484 | 534 | #self.hat_selector.addItems(["Selecionar chapéu"] + self.unlocked_hats) |
485 | 535 | #self.hat_selector.setCurrentText("Selecionar chapéu" if not self.equipped_hat else self.equipped_hat) |
486 | 536 |
|
487 | | - |
| 537 | + |
| 538 | + |
488 | 539 | def start_status_timer(self): |
489 | 540 | self.status_timer = QTimer(self) |
490 | 541 | self.status_timer.timeout.connect(self.decrease_status) |
|
0 commit comments