Skip to content

Commit

Permalink
download checks
Browse files Browse the repository at this point in the history
closes #13
  • Loading branch information
rfuzzo committed Mar 9, 2024
1 parent 115b496 commit eaf03db
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 271 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ openmw-cfg = "0.5" # move to featur
reqwest = { version = "0.11", features = ["blocking", "json"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

seahash = "4.1"

[package]
name = "plox"
Expand All @@ -43,6 +43,7 @@ rust-ini = { workspace = true }
log = { workspace = true }
env_logger = { workspace = true }
regex = { workspace = true }
seahash = { workspace = true }
openmw-cfg = { workspace = true } # move to feature flag

[dev-dependencies]
Expand Down
89 changes: 82 additions & 7 deletions gui/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
use plox::parser::Parser;
use std::env;

use log::error;
use plox::{
detect_game, download_latest_rules, gather_mods, get_default_rules_dir,
parser::{self, Parser},
sorter::{new_stable_sorter, Sorter},
};

/// We derive Deserialize/Serialize so we can persist app state on shutdown.
#[derive(serde::Deserialize, serde::Serialize)]
#[serde(default)] // if we add new fields, give them default values when deserializing old state
pub struct TemplateApp {
// Example stuff:
label: String,

#[serde(skip)] // This how you opt-out of serialization of a field
#[serde(skip)]
parser: Option<Parser>,

#[serde(skip)]
sorter: Sorter,

#[serde(skip)]
mods: Vec<String>,

#[serde(skip)]
new_order: Vec<String>,
}

impl Default for TemplateApp {
fn default() -> Self {
Self {
// Example stuff:
label: "Hello World!".to_owned(),
parser: None,
sorter: new_stable_sorter(),
mods: vec![],
new_order: vec![],
}
}
}
Expand Down Expand Up @@ -49,6 +63,53 @@ impl eframe::App for TemplateApp {
// Put your widgets into a `SidePanel`, `TopBottomPanel`, `CentralPanel`, `Window` or `Area`.
// For inspiration and more examples, go to https://emilk.github.io/egui

// first setup
let mut render_warning_only = false;
if self.parser.is_none() {
// init parser
if let Some(game) = detect_game() {
// TODO this blocks UI and sorts everything
// TODO run a terminal?
let root = env::current_dir().expect("No current working dir");

// rules
let rules_dir = get_default_rules_dir(game);
download_latest_rules(game, &rules_dir);

// mods
self.mods = gather_mods(&root, game);

// parser
let mut parser = parser::get_parser(game);
if let Err(e) = parser.init(rules_dir) {
error!("Parser init failed: {}", e);
// TODO do something, render some warning only
render_warning_only = true;
}

// evaluate
parser.evaluate_plugins(&self.mods);

// sort
match self.sorter.topo_sort(&self.mods, &parser.order_rules) {
Ok(new) => {
self.new_order = new;
}
Err(e) => {
error!("error sorting: {e:?}");
// TODO do something, render some warning only
render_warning_only = true;
}
}

self.parser = Some(parser);
} else {
error!("No game detected");
// TODO do something, render some warning only
render_warning_only = true;
}
}

egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
// The top panel is often a good place for a menu bar:

Expand All @@ -72,6 +133,20 @@ impl eframe::App for TemplateApp {
// The central panel the region left after adding TopPanel's and SidePanel's
ui.heading("PLOX");

if render_warning_only {
// TODO some warning
ui.label("WARNING");

ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| {
powered_by_egui_and_eframe(ui);
egui::warn_if_debug_build(ui);
});

return;
}

// TODO main UI

ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| {
powered_by_egui_and_eframe(ui);
egui::warn_if_debug_build(ui);
Expand Down
Loading

0 comments on commit eaf03db

Please sign in to comment.