Skip to content

Commit

Permalink
Implement things in rust
Browse files Browse the repository at this point in the history
  • Loading branch information
RedstoneWizard08 committed Mar 21, 2023
1 parent 4cf6dc5 commit e801f51
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/src/invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface ModsIntegrity {
export interface AddInstanceArgs {
gameId: number;
name: string;
install_path: string;
installPath: string;
}

export interface InvokeFunction {
Expand Down
24 changes: 24 additions & 0 deletions common/src/instances/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@ pub struct Instance {
}

impl Instance {
pub fn blank() -> Instance {
return Instance {
id: -1,
name: "".to_string(),
game: KSPGame::KSP1,
mods: Vec::new(),
install_path: PathBuf::from(""),
description: None,
time_played: None,
};
}

pub fn new_id() -> i32 {
let mut id = Instance::load().len() as i32 - 1;
let mut instance = Some(Instance::blank());

while instance.is_some() {
id += 1;
instance = Instance::from_id(id);
}

return id;
}

pub fn defaults() -> Vec<Self> {
let v = vec![
Instance {
Expand Down
20 changes: 19 additions & 1 deletion gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,23 @@ fn set_active_instance(instance_id: i32) {
}
}

#[tauri::command]
fn add_instance(game_id: i32, name: String, install_path: String) {
let id = Instance::new_id();

let instance = Instance {
id,
name,
game: KSPGame::from_id(game_id).unwrap(),
description: None,
mods: Vec::new(),
install_path: PathBuf::from(install_path),
time_played: None,
};

instance.save();
}

pub fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
Expand All @@ -211,7 +228,8 @@ pub fn main() {
read_mod_json,
update_description,
get_active_instance,
set_active_instance
set_active_instance,
add_instance
])
.run(tauri::generate_context!())
.expect("Error while starting Wormhole!");
Expand Down

0 comments on commit e801f51

Please sign in to comment.