Skip to content

Commit

Permalink
Custom Games fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LegItMate committed Apr 14, 2024
1 parent 7878717 commit e8a7db2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
51 changes: 38 additions & 13 deletions src-tauri/src/launchers/custom_games.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@ use crate::{
},
CONFIG_DIR,
};
use serde::{Serialize, Deserialize};

#[derive(Debug, Serialize, Deserialize)]
struct GameData {
banner_path: String,
executable: String,
location: String,
display_name: String,
game_id: String,
launch_id: String,
size: i64,
launch_command: String,
launcher_name: String,
args: Vec<String>,
#[serde(default)]
lastlaunch: i64,
#[serde(default)]
launches: i32,
#[serde(default)]
favourite: bool,
}

pub async fn get_installed_games() -> Vec<GameObject> {
let games_data = read_file(format!(
"{}/cache/games/data.json",
Expand All @@ -22,18 +44,21 @@ pub async fn get_installed_games() -> Vec<GameObject> {

#[tauri::command]
pub async fn add_custom_game(location: String, display_name: String) {
let mut obj: GameObject = GameObject::new(
"".to_string(),
"".to_string(),
"".to_string(),
display_name,
"CustomGame".to_string(),
"".to_string(),
0,
"".to_string(),
"CustomGame".to_string(),
vec![],
);
let mut obj: GameData = GameData {
banner_path: "".to_string(),
executable: "".to_string(),
location: "".to_string(),
display_name: display_name,
game_id: "CustomGame".to_string(),
launch_id: "".to_string(),
size: 0,
launch_command: "".to_string(),
launcher_name: "CustomGame".to_string(),
args: vec![],
lastlaunch: 0,
launches: 0,
favourite: false,
};
obj.executable = location
.split("\\")
.collect::<Vec<_>>()
Expand Down Expand Up @@ -73,7 +98,7 @@ pub async fn add_custom_game(location: String, display_name: String) {
bannername
);
}
let mut games_data: Vec<GameObject> = serde_json::from_str(
let mut games_data: Vec<GameData> = serde_json::from_str(
&read_file(format!(
"{}/cache/games/data.json",
CONFIG_DIR.lock().unwrap()
Expand Down
4 changes: 2 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ export default {
);
data = data.filter(
(a) =>
a.DisplayName !=
document.getElementById("removeGame").parentNode.parentNode
a.display_name !=
document.getElementById("removeGame").parentNode
.firstChild.innerHTML
);
await invoke("write_file", {
Expand Down
2 changes: 1 addition & 1 deletion src/components/AllGames.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default {
newGameLocation
) {
await invoke("add_custom_game", {
location: newGameLocation.split("\\").slice(0, -1).join("\\"),
location: newGameLocation,
displayName: document.getElementById("inputGameName").value,
});
loadGames("allGamesList");
Expand Down
4 changes: 2 additions & 2 deletions src/components/find-games.vue
Original file line number Diff line number Diff line change
Expand Up @@ -504,15 +504,15 @@ export default {
let data = await storage.getGamesData();
data = data
.filter((x) => typeof x.launches === "number")
.filter((x) => typeof x.launches === "number" && x.launches != 0)
.sort((a, b) => b.launches - a.launches)
.slice(0, 5);
return data;
} else if (listID === "recentGamesList") {
let data = await storage.getGamesData();
data = data
.filter((x) => typeof x.launches === "number")
.filter((x) => typeof x.launches === "number" && x.launches != 0)
.sort((a, b) => b.launches - a.launches);
return data;
} else if (listID === "allGamesList") {
Expand Down

0 comments on commit e8a7db2

Please sign in to comment.