Commit a2989022 authored by Yankovskiy Georgiy's avatar Yankovskiy Georgiy

Commits 918563db, a19804a8 refactor (part 2 of 2)

parent e96ebca9
...@@ -131,8 +131,4 @@ pyvenv.cfg ...@@ -131,8 +131,4 @@ pyvenv.cfg
venv venv
pip-selfcheck.json pip-selfcheck.json
# End of https://www.toptal.com/developers/gitignore/api/pycharm,venv # End of https://www.toptal.com/developers/gitignore/api/pycharm,venv
\ No newline at end of file
### Extra
.agent-data
\ No newline at end of file
...@@ -17,18 +17,12 @@ from ingame.models.GameEntry import GameEntry ...@@ -17,18 +17,12 @@ from ingame.models.GameEntry import GameEntry
from ingame.models.GameAgent import GameAgent from ingame.models.GameAgent import GameAgent
from PySide6.QtCore import Property, Signal, Slot, QObject, Qt from PySide6.QtCore import Property, Signal, Slot, QObject, Qt
class GameShortcut:
def __init__(self, filename, product_name, icon):
self.filename = filename
self.product_name = product_name
self.icon = icon
class App(QtCore.QObject): class App(QtCore.QObject):
app_name = "ingame" app_name = "ingame"
app_author = "foss" app_author = "foss"
game_list_details_retrieving_progress = Signal(float, name="gameListDetailsRetrievingProgress")
game_started = Signal(bool, name="gameStarted") game_started = Signal(bool, name="gameStarted")
game_ended = Signal(bool, name="gameEnded") game_ended = Signal(bool, name="gameEnded")
data_found = Signal(dict, name="gotGameData") data_found = Signal(dict, name="gotGameData")
...@@ -108,13 +102,19 @@ class App(QtCore.QObject): ...@@ -108,13 +102,19 @@ class App(QtCore.QObject):
print('An error occurred', e) print('An error occurred', e)
pass pass
# TODO: refactor! # TODO: fix: progress=1.0 not emitted if details already cached/downloaded
def retrieve_games_details(self): def retrieve_games_details(self):
def retrieve_games_details_thread(t): def retrieve_games_details_thread(t):
t.game_list_details_retrieving_progress.emit(0.0)
all_count: int = len(self.games_model.games_list)
game_entry: GameEntry game_entry: GameEntry
i: int = 0
for game_entry in self.games_model.games_list: for game_entry in self.games_model.games_list:
game_description = t.agent.retrieve_game_description(game_entry.name) game_description = t.agent.retrieve_game_description(game_entry.name)
game_entry.icon = game_description['image_location_path'] or game_entry.icon game_entry.icon = game_description['image_location_path'] or game_entry.icon
t.game_list_details_retrieving_progress.emit(float(i) / all_count)
i += 1
t.game_list_details_retrieving_progress.emit(1.0)
thread = threading.Thread(target=retrieve_games_details_thread, args=(self,)) thread = threading.Thread(target=retrieve_games_details_thread, args=(self,))
thread.start() thread.start()
...@@ -130,12 +130,12 @@ class App(QtCore.QObject): ...@@ -130,12 +130,12 @@ class App(QtCore.QObject):
@Slot(str, result=dict) @Slot(str, result=dict)
def get_game_data(self, game_name): def get_game_data(self, game_name):
def search_thread(t, name): def get_game_data_thread(t, name):
search_result = t.agent.retrieve_game_description(name) search_result = t.agent.retrieve_game_description(name)
t.data_found.emit(search_result) t.data_found.emit(search_result)
return return
thread = threading.Thread(target=search_thread, args=(self, game_name)) thread = threading.Thread(target=get_game_data_thread, args=(self, game_name))
thread.start() thread.start()
@Slot(str) @Slot(str)
......
...@@ -4,6 +4,7 @@ import requests ...@@ -4,6 +4,7 @@ import requests
from steam_web_api import Steam from steam_web_api import Steam
from steamgrid import SteamGridDB from steamgrid import SteamGridDB
from ingame.models.GameDescription import GameDescription from ingame.models.GameDescription import GameDescription
import time
class GameAgent: class GameAgent:
...@@ -15,7 +16,7 @@ class GameAgent: ...@@ -15,7 +16,7 @@ class GameAgent:
def __init__(self, config_path, cache_path): def __init__(self, config_path, cache_path):
super().__init__() super().__init__()
# TODO: move API tokens to GUI settings tab / environmental variables # TODO: move API tokens to GUI settings tab / environmental variables
self.steam_grid_db_client = SteamGridDB('66827eabea66de47d036777ed2be87b2') self.steam_grid_db_client = SteamGridDB("66827eabea66de47d036777ed2be87b2")
self.steam_client = Steam("SOME_KEY_HERE_I_GUESS") self.steam_client = Steam("SOME_KEY_HERE_I_GUESS")
self.config_path = config_path self.config_path = config_path
...@@ -32,15 +33,19 @@ class GameAgent: ...@@ -32,15 +33,19 @@ class GameAgent:
''' USAGE ''' ''' USAGE '''
def retrieve_game_description(self, game_name): def retrieve_game_description(self, game_name):
if game_name not in self.data: if game_name not in self.data:
# TODO: checkup for failed requests # TODO: checkup for failed requests
search_results = self.steam_client.apps.search_games(game_name) search_results = self.steam_client.apps.search_games(game_name)
self.add_game_description(search_results, game_name) self.__add_game_description(search_results, game_name)
game_description = self.data[game_name] game_description = self.data[game_name]
return game_description.as_dict() return game_description.as_dict()
def steam_grid_db_retrieve_image(self, game_name): ''' DATABASE '''
def __steam_grid_db_retrieve_image(self, game_name):
try: try:
save_path = f"{self.steam_grid_db_images_path}/{game_name}.png" save_path = f"{self.steam_grid_db_images_path}/{game_name}.png"
if os.path.exists(save_path): if os.path.exists(save_path):
...@@ -49,6 +54,7 @@ class GameAgent: ...@@ -49,6 +54,7 @@ class GameAgent:
# TODO: checkup for failed requests # TODO: checkup for failed requests
result = self.steam_grid_db_client.search_game(game_name) result = self.steam_grid_db_client.search_game(game_name)
grids = self.steam_grid_db_client.get_grids_by_gameid(list([result[0].id])) grids = self.steam_grid_db_client.get_grids_by_gameid(list([result[0].id]))
# TODO: too slow, replace loop o(n) with o(1) if possible # TODO: too slow, replace loop o(n) with o(1) if possible
for grid in grids: for grid in grids:
if grid.height == 900 and grid.width == 600: if grid.height == 900 and grid.width == 600:
...@@ -62,10 +68,10 @@ class GameAgent: ...@@ -62,10 +68,10 @@ class GameAgent:
except: except:
return '' return ''
''' DATABASE ''' def __add_game_description(self, search_results, game_name):
def add_game_description(self, search_results, game_name):
game_description = GameDescription() game_description = GameDescription()
game_description.locked = True
self.data[game_name] = game_description
# Steam game info # Steam game info
if search_results['apps']: if search_results['apps']:
...@@ -90,9 +96,8 @@ class GameAgent: ...@@ -90,9 +96,8 @@ class GameAgent:
game_description.languages = app_data['supported_languages'] game_description.languages = app_data['supported_languages']
# Steam Grid DB image retrieving # Steam Grid DB image retrieving
game_description.image_location_path = self.steam_grid_db_retrieve_image(game_name) game_description.image_location_path = self.__steam_grid_db_retrieve_image(game_name)
game_description.locked = False
self.data[game_name] = game_description
self.save_db() self.save_db()
def save_db(self): def save_db(self):
......
...@@ -3,6 +3,7 @@ from dataclasses import dataclass ...@@ -3,6 +3,7 @@ from dataclasses import dataclass
@dataclass @dataclass
class GameDescription: class GameDescription:
locked: bool = False
title: str = 'Информация не найдена!' title: str = 'Информация не найдена!'
desc: str = 'Информация не найдена!' desc: str = 'Информация не найдена!'
languages: str = 'Информация не найдена!' languages: str = 'Информация не найдена!'
......
...@@ -293,6 +293,7 @@ Rectangle { ...@@ -293,6 +293,7 @@ Rectangle {
// Повторитель // Повторитель
Repeater { Repeater {
id: gamesGridRepeater
model: core_app.games model: core_app.games
// Карточка игры // Карточка игры
Game { Game {
...@@ -346,6 +347,7 @@ Rectangle { ...@@ -346,6 +347,7 @@ Rectangle {
// LOGIC // LOGIC
property int focusedItems: 0; property int focusedItems: 0;
property int focusedTabs: 0; property int focusedTabs: 0;
...@@ -393,28 +395,33 @@ Rectangle { ...@@ -393,28 +395,33 @@ Rectangle {
// c[tabs.focusedItems].clicked(); // c[tabs.focusedItems].clicked();
} }
function onGamepadClickedLB(done){ /* SIGNALS */
if(window.scene !== S.homeScene) return;
function onGamepadClickedLB(args){
tabs.applyTabsFocus(-1) tabs.applyTabsFocus(-1)
} }
function onGamepadClickedRB(done){ function onGamepadClickedRB(args){
if(window.scene !== S.homeScene) return;
tabs.applyTabsFocus(1) tabs.applyTabsFocus(1)
} }
function onGamepadAxisLeft(done){ function onGamepadAxisLeft(args){
if(window.scene !== S.homeScene) return;
tabs.applyItemsFocus(-1) tabs.applyItemsFocus(-1)
} }
function onGamepadAxisRight(done){ function onGamepadAxisRight(args){
if(window.scene !== S.homeScene) return;
tabs.applyItemsFocus(1) tabs.applyItemsFocus(1)
} }
function onGamepadClickedApply(done){ function onGamepadClickedApply(args){
if(window.scene !== S.homeScene) return; if(window.scene !== S.homeScene) return;
// console.log("onGamepadClickedApply");
let c = gamesGrid.children; let c = gamesGrid.children;
c[tabs.focusedItems].press(); c[tabs.focusedItems].press();
} }
function onGameListDetailsRetrievingProgress(args) {
let progress = args[0];
console.log(progress);
if(progress === 1.0){
gamesGridRepeater.model = [];
gamesGridRepeater.model = core_app.games;
}
}
} }
......
...@@ -14,7 +14,7 @@ Window { ...@@ -14,7 +14,7 @@ Window {
} }
FontLoader { FontLoader {
id: globalFont; id: globalFont;
source: "./fonts/OpenSans-VariableFont_wdth.ttf" source: "./fonts/OpenSans-VariableFont.ttf"
} }
...@@ -50,6 +50,9 @@ Window { ...@@ -50,6 +50,9 @@ Window {
function onGamepadClickedBack(done){ function onGamepadClickedBack(done){
window._trigger("onGamepadClickedBack", done); window._trigger("onGamepadClickedBack", done);
} }
function onGameListDetailsRetrievingProgress(progress){
homeScene.onGameListDetailsRetrievingProgress([progress]);
}
} }
function _trigger(_method, ...args){ function _trigger(_method, ...args){
......
...@@ -42,20 +42,23 @@ Rectangle { ...@@ -42,20 +42,23 @@ Rectangle {
anchors.rightMargin: 0 anchors.rightMargin: 0
} }
function onGamepadClickedLB(done){ function onGamepadClickedLB(args){
tabs.onGamepadClickedLB(done) tabs.onGamepadClickedLB(args)
} }
function onGamepadClickedRB(done){ function onGamepadClickedRB(args){
tabs.onGamepadClickedRB(done) tabs.onGamepadClickedRB(args)
} }
function onGamepadAxisLeft(done){ function onGamepadAxisLeft(args){
tabs.onGamepadAxisLeft(done) tabs.onGamepadAxisLeft(args)
} }
function onGamepadAxisRight(done){ function onGamepadAxisRight(args){
tabs.onGamepadAxisRight(done) tabs.onGamepadAxisRight(args)
} }
function onGamepadClickedApply(done){ function onGamepadClickedApply(args){
tabs.onGamepadClickedApply(done) tabs.onGamepadClickedApply(args)
}
function onGameListDetailsRetrievingProgress(args){
tabs.onGameListDetailsRetrievingProgress(args)
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment