Skip to content

Commit

Permalink
feat: overwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
rfuzzo committed Apr 14, 2023
1 parent 06dd77c commit 93caca7
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 12 deletions.
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
# Tes3edit-rs

A small egui-rust ui to quickly edit plugins for The Elder Scrolls III: Morrowind.
A small egui-rust ui to quickly edit plugins for The Elder Scrolls III: Morrowind.

PRs welcome! Feature requests welcome: <https://github.com/rfuzzo/tes3edit/issues>

## Features

- Drag and drop any esp into the editor to open it
- Open multiple esps at the same time
- In-place editing
- Save as patch feature: only save edited records to a new plugin
- Search records by ID

## TODOs

- [Critical] New record creation
- [Critical] New plugin creation
- [Critical] Omwaddon support
- [Enhancement] Better search function
- [Enhancement] Dump esp to json/yaml
- [Enhancement] Load json/yaml
- [Epic] Compare plugins

## Getting started

### App

...

- download the latest release from github: <https://github.com/rfuzzo/tes3edit>
- open `tes3edit.exe`

### Web

...
> Unstable! Not feature complete!
- open <https://rfuzzo.github.io/tes3edit/>
- edit esps there

## Screenshots

...
![Editor View](/assets/Screenshot%202023-04-14%20154959.png)

![Drag and drop](/assets/Screenshot%202023-04-14%20155030.png)
Binary file added assets/Screenshot 2023-04-14 154959.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Screenshot 2023-04-14 155030.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub struct TemplateApp {
/// The last directory used in the file picker
pub light_mode: bool,

pub overwrite: bool,

// runtime
#[serde(skip)]
pub current_plugin_id: String,
Expand Down Expand Up @@ -60,6 +62,7 @@ impl Default for TemplateApp {
recent_plugins: vec![],
last_directory: "/".into(),
light_mode: false,
overwrite: false,
current_plugin_id: "".into(),
plugins: HashMap::default(),
search_text: "".into(),
Expand Down Expand Up @@ -200,6 +203,8 @@ impl TemplateApp {
}
}

const VERSION: &str = env!("CARGO_PKG_VERSION");

impl eframe::App for TemplateApp {
/// Called by the frame work to save state before shutdown.
fn save(&mut self, storage: &mut dyn eframe::Storage) {
Expand Down Expand Up @@ -237,6 +242,14 @@ impl eframe::App for TemplateApp {
status_edited = format!("Edited Records: {}", data.edited_records.len());
}
ui.label(status_edited);

// VERSION
ui.with_layout(egui::Layout::right_to_left(egui::Align::RIGHT), |ui| {
ui.label(VERSION);
ui.label("Version: ");
ui.separator();
ui.hyperlink("https://github.com/rfuzzo/tes3edit");
});
});
});

Expand Down
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,17 @@ pub fn save_all(
edited_records: &HashMap<String, TES3Object>,
plugin_path: &Path,
toasts: &mut Toasts,
overwrite: &bool,
) {
let mut plugin = Plugin {
objects: get_records(records, edited_records),
};
// save
let output_path = plugin_path.with_extension("new.esp");
let mut output_path = plugin_path.to_path_buf();
if !overwrite {
output_path = plugin_path.with_extension("new.esp");
}

match plugin.save_path(output_path) {
Ok(_) => {
toasts
Expand Down
15 changes: 10 additions & 5 deletions src/views/menu_bar_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl TemplateApp {
&plugin_data.edited_records,
&path,
&mut self.toasts,
&self.overwrite,
);
self.last_directory = path;
}
Expand Down Expand Up @@ -119,10 +120,9 @@ impl TemplateApp {
ui.separator();

#[cfg(not(target_arch = "wasm32"))]
if ui.button("Save All").clicked() {
// get current plugin
if ui.button("Save Patch").clicked() {
if let Some((key, data)) = self.plugins.get_key_value(&self.current_plugin_id) {
crate::save_all(
crate::save_patch(
&data.records,
&data.edited_records,
Path::new(key),
Expand All @@ -132,17 +132,22 @@ impl TemplateApp {
}

#[cfg(not(target_arch = "wasm32"))]
if ui.button("Save Patch").clicked() {
if ui.button("Save All").clicked() {
// get current plugin
if let Some((key, data)) = self.plugins.get_key_value(&self.current_plugin_id) {
crate::save_patch(
crate::save_all(
&data.records,
&data.edited_records,
Path::new(key),
&mut self.toasts,
&self.overwrite,
);
}
}

#[cfg(not(target_arch = "wasm32"))]
ui.checkbox(&mut self.overwrite, "Overwrite");

// theme button on right
ui.with_layout(egui::Layout::right_to_left(egui::Align::RIGHT), |ui| {
global_dark_light_mode_switch(ui, &mut self.light_mode);
Expand Down
7 changes: 6 additions & 1 deletion src/views/records_list_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ impl TemplateApp {
// logic
let mut record_ids_to_delete = vec![];

// add button // todo move?
// if ui.button("Add record").clicked() {
// // get type and id
// }

// the record list
egui::ScrollArea::vertical().show(ui, |ui| {
// order by tags
Expand Down Expand Up @@ -175,7 +180,7 @@ impl TemplateApp {
}
}

/// super dumb but I can't be bothered to mess around with enums
/// todo super dumb but I can't be bothered to mess around with enums now
fn get_all_tags() -> Vec<String> {
let v = vec![
"TES3", "GMST", "GLOB", "CLAS", "FACT", "RACE", "SOUN", "SNDG", "SKIL", "MGEF", "SCPT",
Expand Down

0 comments on commit 93caca7

Please sign in to comment.