Commit 41c7628f authored by ADav's avatar ADav

GameAgent 13.05

parent 9a49b9d1
......@@ -12,6 +12,7 @@ from desktop_parser import DesktopFile
from ingame.models.Gamepad import Gamepad
from ingame.models.GamesModel import Game, GamesModel
from ingame.models.GameAgent import GameAgent
from PySide6.QtCore import Property, Signal, Slot, QObject, Qt
......@@ -47,6 +48,8 @@ class App(QtCore.QObject):
self.gamepad.l_clicked = lambda: self.gamepad_axis_left.emit(True)
self.gamepad.r_clicked = lambda: self.gamepad_axis_right.emit(True)
self.agent = GameAgent()
self.setup()
def setup(self):
......@@ -107,13 +110,20 @@ class App(QtCore.QObject):
# event.accept() # let the window close
# else:
# event.ignore()
self.agent.clean_data()
### SLOTS ###
@Slot(str)
def get_game_data(self, game_name):
print(game_name)
# self.agent.search_game("Risk of rain 2") # оригинальной osu в стиме нет =) Плейсхолдер
self.agent.search_game(game_name)
# self.agent.search_game("asdjfiawefhawijefh")
@Slot(str)
def start_game(self, exec):
self.game_started.emit(True)
def run_in_thread(t, _exec):
t.running_game_process = subprocess.Popen(
_exec,
......
import os
import pickle
from steam_web_api import Steam
# TODO:
# -Определиться, используется ли люстресс. Если да, вместо этого будет обращение к нему. Если нет,
# продумать "рыбу" более логично.
# -Починить отображение системных требований (точнее, разобраться, что именно возвращает API
# -Додумать форматированные данные, что именно мы видим на странице игры?
class GameAgent:
tempgame = "Risk of rain 2"
datapath = "./ingame/agentdata"
all_data = dict()
scenario = 0
def __init__(self):
super().__init__()
agent_key = "SOME_KEY_HERE_I_GUESS"
self.steam_process = Steam(agent_key)
self.get_all_data()
def add_game_info(self, data, name):
if not data['apps']:
self.all_data[name] = 0
else:
gameid = data['apps'][0]['id']
data = self.steam_process.apps.get_app_details(gameid)
self.all_data[name] = data[str(gameid[0])]['data']
with open(self.datapath, "wb+") as datafile:
pickle.dump(self.all_data, datafile)
self.get_all_data()
def search_game(self, Gamename):
self.get_all_data()
if Gamename in self.all_data:
print("ITS HERE!")
else:
search_results = self.steam_process.apps.search_games(Gamename)
self.add_game_info(search_results, Gamename)
self.format_game_data(self.all_data[Gamename])
def get_all_data(self):
try:
with open(self.datapath, "rb") as datafile:
self.all_data = pickle.load(datafile)
except FileNotFoundError:
self.all_data = dict()
def format_game_data(self, gamedata):
if gamedata != 0:
formated_data = dict()
formated_data['title'] = gamedata['name']
formated_data['desc'] = gamedata['short_description']
formated_data['languages'] = gamedata['supported_languages']
formated_data['reqs'] = gamedata['linux_requirements']
for key, value in formated_data.items():
print("{0}: {1}".format(key, value))
else:
print("Игра не распозана!")
def clean_data(self):
self.all_data = dict()
with open(self.datapath, "wb") as datafile:
pickle.dump(self.all_data, datafile)
print("data cleaned")
\ No newline at end of file
......@@ -23,6 +23,8 @@ C.Button {
gameInfoScene.icon = game.gameIcon;
gameInfoScene.exec = game.gameExec;
window.scene = SceneConstants.gameInfoScene;
if(core_app === undefined) return;
core_app.get_game_data(gameTitle);
}
}
......
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