Skip to content

Commit

Permalink
Подключил систему хешей, настроил на работу некоторые функции, измени…
Browse files Browse the repository at this point in the history
…л дизайн кнопок, и вроде все
  • Loading branch information
Kexi8BiT committed Mar 30, 2024
1 parent 6e7069f commit 21dd7b1
Show file tree
Hide file tree
Showing 19 changed files with 427 additions and 61 deletions.
Binary file modified assets/audio/finish.mp3
Binary file not shown.
9 changes: 8 additions & 1 deletion assets/games/sovadash/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"name": "SovaDash",
"color": "#ff4802",
"tags": ["Платфомер", "Популярно", "Онлайн", "2D"]
"tags": ["Платфомер", "Популярно", "Онлайн", "2D"],
"start-config": {
"command_args": "",
"exe_file": "SovaDash.exe",
"other_params": {
"enebled": false
}
}
}
9 changes: 8 additions & 1 deletion assets/games/sovadustry/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"name": "SovaDustry",
"color": "#84bed5",
"tags": ["Платфомер", "Популярно", "Онлайн", "2D", "Мультиплейер"]
"tags": ["Платфомер", "Популярно", "Онлайн", "2D", "Мультиплейер"],
"start-config": {
"command_args": "",
"exe_file": "Mindustry.exe",
"other_params": {
"enebled": false
}
}
}
9 changes: 8 additions & 1 deletion assets/games/sovamine/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"name": "SovaMine",
"color": "#7c8adb",
"tags": ["Мультиплеер", "MHost", "Онлайн", "3D"]
"tags": ["Мультиплеер", "MHost", "Онлайн", "3D"],
"start-config": {
"command_args": "",
"exe_file": "SovaMine/start.bat",
"other_params": {
"enebled": false
}
}
}
Binary file removed assets/icons/eaprsmolo.jpeg
Binary file not shown.
Binary file modified assets/icons/internet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 75 additions & 12 deletions expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,29 @@
from sound_effect import BoopSound
import json
from ui import interface_button
import shutil
import os
from hashsystem import is_directory

def copy_all_files_from_directory(from_path, to_path):
items = os.listdir(from_path)
print("Выполняется перенос файлов... [{} -> {}]".format(from_path, to_path))
for file in items:
print(f"[{from_path}/{file}] -> [{to_path}/{file}]....", end="")
shutil.copytree(f"{from_path}/{file}", f"{to_path}/{file}")
print("OK")
print("Готово!")


def get_available_drives():
return [drive for drive in string.ascii_uppercase if os.path.exists(drive + ':\\')]

def get_disk_usage(drive_letter):
def get_disk_usage(drive_letter) -> (float, float):
"""
:param drive_letter:
:return:
"""
disk_usage = psutil.disk_usage(drive_letter + ':\\')
percent_used = disk_usage.percent / 100
gb_free = disk_usage.free / (2**30) # конвертируем байты в гигабайты
Expand All @@ -28,14 +46,37 @@ def close(e):
page.overlay.remove(message)
page.update()

def on_bg_click(e):
print("on_bg_click")

def change_disk(disk):
btn.disabled = True
btn.content = ft.ProgressRing(width=20, height=20, color=ft.colors.RED_400, bgcolor=ft.colors.BLACK26)
btn.update()
dd.disabled = True
dd.update()

boop.play()
catalog = disk
catalog_to = page.client_storage.get("catalog_games")
page.client_storage.set("catalog_games", catalog)

path_to_new_games = f"{catalog}:/SovaGames"
path_to_games = f"{catalog_to}:/SovaGames"
if path_to_games == path_to_new_games:
close(disk)
return

if not is_directory(path_to_games):
os.mkdir(path_to_games)

if not is_directory(path_to_new_games):
os.mkdir(path_to_new_games)

copy_all_files_from_directory(path_to_games, path_to_new_games)
page.update()
shutil.rmtree(path_to_games)
close(disk)


def prew_change_disk(e):
boop.play()
disk = e.control.value
Expand Down Expand Up @@ -89,7 +130,22 @@ def prew_change_disk(e):


def installed_games(page: ft.Page):
catalog = page.client_storage.get("catalog_games")
path_to_games = f"{catalog}:/SovaGames"
boop = BoopSound(page)

def remove_game(game_id):
boop.play()
shutil.rmtree(f"{path_to_games}/{game_id}")
cccc.content = get_col_games()
cccc.update()

def open_in_explorer(game_id):
os.startfile(f"{path_to_games}/{game_id}")




def get_game_object(game_id):
with open(f"assets/games/{game_id}/config.json", "r", encoding="utf-8") as f:
config = json.load(f)
Expand All @@ -105,14 +161,27 @@ def get_game_object(game_id):
]
)
),
ft.Container(ft.Row([ft.IconButton(icon=ft.icons.RESTART_ALT, icon_color=ft.colors.WHITE, style=ft.ButtonStyle(bgcolor=ft.colors.GREEN, shape=ft.RoundedRectangleBorder(radius=15))), ft.IconButton(ft.icons.FOLDER, icon_color=ft.colors.WHITE, style=ft.ButtonStyle(bgcolor=ft.colors.AMBER_900, shape=ft.RoundedRectangleBorder(radius=15))), ft.IconButton(ft.icons.DELETE_FOREVER, icon_color=ft.colors.WHITE, style=ft.ButtonStyle(bgcolor=ft.colors.RED_700, shape=ft.RoundedRectangleBorder(radius=15)))]))
ft.Container(ft.Row([
ft.IconButton(ft.icons.RESTART_ALT, icon_color=ft.colors.WHITE, style=ft.ButtonStyle(bgcolor=ft.colors.GREEN, shape=ft.RoundedRectangleBorder(radius=15))),
ft.IconButton(ft.icons.FOLDER, on_click=lambda _: open_in_explorer(game_id), icon_color=ft.colors.WHITE, style=ft.ButtonStyle(bgcolor=ft.colors.AMBER_900, shape=ft.RoundedRectangleBorder(radius=15))),
ft.IconButton(ft.icons.DELETE_FOREVER, on_click=lambda _: remove_game(game_id), icon_color=ft.colors.WHITE, style=ft.ButtonStyle(bgcolor=ft.colors.RED_700, shape=ft.RoundedRectangleBorder(radius=15)))]))

], alignment=ft.MainAxisAlignment.SPACE_BETWEEN
)
)
return object

files = os.listdir(f"assets/games")

def get_col_games():
files = os.listdir(path_to_games)
if len(files) == 0:
return ft.Container(ft.Text("У вас нет игорь :(", size=15, color="#555555"), alignment=ft.alignment.center)
print(files)
return ft.Column([
get_game_object(file) for file in files
], spacing=50, scroll=ft.ScrollMode.HIDDEN)

cccc = ft.Container(get_col_games(),height=400,border_radius=20)
def close(e):
boop.play()
page.overlay.remove(content)
Expand All @@ -121,13 +190,7 @@ def close(e):
ft.Container(
ft.Container(
ft.Column([
ft.Container(
ft.Column([
get_game_object(file) for file in files
], spacing=50, scroll=ft.ScrollMode.HIDDEN),
height=400,
border_radius=20
),
cccc,
ft.Container(
ft.ElevatedButton("Назад", on_click=close, **interface_button, width=150),
alignment=ft.alignment.center
Expand Down
47 changes: 44 additions & 3 deletions game_run_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
from ui import interface_button, interface_switch
from internets import get_updates
import time
from install_game import install_game
import os
import subprocess
from modals import qwqwqwq


class GamesPage:
def __init__(self, id, web = False, config_start: {} = None, page: ft.Page = None, content_page = None):
self.content_page = content_page
Expand All @@ -13,12 +19,18 @@ def __init__(self, id, web = False, config_start: {} = None, page: ft.Page = Non
self.path = f"assets/games/{self.id}"
with open(f"{self.path}/description.txt", "r", encoding='utf-8') as f:
self.description = f.read()

self.path_to_game_folder = f"{page.client_storage.get('catalog_games')}:/SovaGames/{self.id}"
if not os.path.exists(self.path_to_game_folder):
self.start_button = ft.ElevatedButton("Установить", **interface_button, on_click=self.install)
else:
self.start_button = ft.ElevatedButton("Запустить", **interface_button, on_click=self.start)
self.boop = BoopSound(page)
self.page = page
self.icon = ft.Image(f"{self.path}/icon.png")
self.config = json.load(open(f"{self.path}/config.json", "r", encoding='utf-8'))
news = ft.Column([], scroll=ft.ScrollMode.HIDDEN, expand=True)
nes_col = get_updates(game_id=self.id)
nes_col = get_updates(game_id=self.id, base_url=self.page.client_storage.get("cdn_url"))
for new in nes_col:
content_new = ft.Container(
ft.Column([
Expand Down Expand Up @@ -73,9 +85,38 @@ def __init__(self, id, web = False, config_start: {} = None, page: ft.Page = Non
ft.Container(ft.Text(self.config["name"], size=30, weight=ft.FontWeight.BOLD, color=ft.colors.WHITE)),
tags,
], horizontal_alignment=ft.CrossAxisAlignment.CENTER),width=280, height=550),
ft.Container(ft.ElevatedButton("Играть", **interface_button), width=280, margin=ft.margin.only(bottom=10))
ft.Container(self.start_button, width=280, margin=ft.margin.only(bottom=10))
], horizontal_alignment=ft.CrossAxisAlignment.CENTER, alignment=ft.MainAxisAlignment.SPACE_BETWEEN), height=630, width=300, bgcolor=ft.colors.BLACK26, border_radius=15, margin=ft.margin.only(top=10))
], vertical_alignment=ft.CrossAxisAlignment.START), opacity=0, animate_opacity=ft.Animation(300, ft.AnimationCurve.EASE_IN_OUT),)
], vertical_alignment=ft.CrossAxisAlignment.START), opacity=0, animate_opacity=ft.Animation(300, ft.AnimationCurve.EASE_IN_OUT))


def install(self, e):
install_game(self.page, self.id)


def start(self, e):
self.page.overlay.append(qwqwqwq)
self.page.update()
self.start_button.disabled = True
self.start_button.update()
currrect = os.getcwd()
os.chdir(self.path_to_game_folder)
to_exe = self.config["start-config"]["exe_file"]
path = f"{self.path_to_game_folder}/{to_exe}"
process = subprocess.Popen(path)
return_code = process.wait() # Ждем, пока приложение будет закрыто
print(f"Приложение \"{self.id}\" закрыто. Код завершения: {return_code}")
os.chdir(currrect)
self.start_button.disabled = False
self.start_button.update()
if return_code != 0:
self.error(return_code)

self.page.overlay.remove(qwqwqwq)
self.page.update()

def error(self, error):
print("Вывести ошибку")
def set_page(self, e):
self.content_page.content = self.content
self.content_page.update()
Expand Down
31 changes: 16 additions & 15 deletions games_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from sound_effect import BoopSound
from game_run_page import GamesPage
import time
import os
class Game_object(ft.UserControl):
id: str = None
web_content: bool = True
Expand All @@ -29,7 +30,7 @@ def __init__(self, id: str, web_content: bool = False, page: ft.Page = None, con
self.GAME_PAGE = GamesPage(id, web_content, None, page, content_page=content)

def on_object_hover(self, e):
e.control.content.shadow.blur_radius = 10 if e.data == "true" else 50
e.control.content.scale = 0.98 if e.data == "true" else 1
e.control.update()

def go_to_page(self, e):
Expand Down Expand Up @@ -85,14 +86,14 @@ def build(self):
animate_scale=ft.Animation(300, ft.AnimationCurve.EASE_IN_OUT),
animate_offset=ft.Animation(200, ft.AnimationCurve.EASE_OUT),
animate=ft.Animation(100, ft.AnimationCurve.EASE_IN_OUT),
shadow=ft.BoxShadow(
spread_radius=0,
blur_radius=50,
color=config["color"],
offset=ft.Offset(0, 0),
blur_style=ft.ShadowBlurStyle.NORMAL,

)
# shadow=ft.BoxShadow(
# spread_radius=0,
# blur_radius=50,
# color=config["color"],
# offset=ft.Offset(0, 0),
# blur_style=ft.ShadowBlurStyle.NORMAL,
#
# )

)

Expand Down Expand Up @@ -122,16 +123,16 @@ def get_games_page(page, content):
ft.Container(width=800, height=1, bgcolor="#5c5e60"),
])
),
Game_object(id="sovacraft", web_content=False, page=page, content=content),
Game_object(id="sovadash", web_content=False, page=page, content=content),
Game_object(id="sovadastry", web_content=False, page=page, content=content),
# Game_object(id="sovamine", web_content=False, page=page, content=content),
# Game_object(id="sovadash", web_content=False, page=page, content=content),
# Game_object(id="sovadustry", web_content=False, page=page, content=content),

],
] + [Game_object(id=game, web_content=False, page=page, content=content) for game in os.listdir("assets/games")],
alignment=ft.MainAxisAlignment.START,
spacing=10,
scroll=ft.ScrollMode.ALWAYS,
scroll=ft.ScrollMode.HIDDEN,
),

height=page.window_height - 120,
height=page.window_height - 100,
)
return games
16 changes: 5 additions & 11 deletions home_page.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import flet as ft
from ui import interface_button
import requests
from internets import get_updates
from internets import get_updates, get_author
md1 = """
# Добро пожаловать в SovaLauncher!
SovaLauncher - фанатская переделка оригинального SovaLaucher, в отличии от оригинала этот лаунчер имеет множество забавных фич и дополнений
Expand All @@ -25,10 +22,8 @@
def get_main_page_home(page: ft.Page):
base_url = page.client_storage.get("cdn_url")
def open_devs(e):
req = requests.get(base_url + "/info/devloper")
if req.status_code == 200:
req = req.json()
dev = req["devloper"]
dev = get_author(page.client_storage.get("cdn_url"))
if dev:
dialog = ft.AlertDialog(
modal=False,
title=ft.Text("Разработчики"),
Expand All @@ -52,12 +47,10 @@ def open_devs(e):
dialog.open = True
page.update()

else:
page.error(req.status_code)

def update_history(e):
news = ft.Column([], scroll=ft.ScrollMode.HIDDEN, expand=True)
nes_col = get_updates(game_id="sovalauncher")
nes_col = get_updates(game_id="sovalauncher", base_url=page.client_storage.get("cdn_url"))
for new in nes_col:
content_new = ft.Container(
ft.Column([
Expand Down Expand Up @@ -93,6 +86,7 @@ def supp(e):
content = ft.Container(
ft.Column(
[
ft.Text("Добро пожаловать в SovaLauncher", size=50, weight=ft.FontWeight.BOLD),
ft.Markdown(
md1,
selectable=True,
Expand Down
Loading

0 comments on commit 21dd7b1

Please sign in to comment.