From 76ec44d4e6df866cc68cb820815bb9b73e91d7a1 Mon Sep 17 00:00:00 2001 From: zxq5 Date: Tue, 15 Jul 2025 00:40:12 +0100 Subject: [PATCH] added notes, improved other features and removed most bugs --- Cargo.lock | 13 + Cargo.toml | 2 + .../ee0fa255-9a71-44b1-9556-e7b3157f1f77.json | 1 + .../1da3111e-717a-4452-8209-98c5443fc31a.json | 13 + .../67e29043-9aa8-4dd9-807c-cc7385eb6847.json | 16 + .../d1b10e0c-f6b4-4b9d-a96e-cb51213f0243.json | 22 + project/objects/zxq5.json | 28 -- .../a24b3ab7-2572-4af4-8457-df26937fd773.json | 37 ++ .../c96f5e87-7517-44cc-a5ab-42ffd537801d.json | 25 ++ project/templates/character.json | 48 -- src/error.rs | 22 + src/explorer.rs | 159 +++++++ src/main.rs | 163 ++----- src/main_editor.rs | 1 - src/note.rs | 109 +++++ src/object.rs | 169 +++----- src/scene.rs | 27 ++ src/template.rs | 410 ++++++++++-------- 18 files changed, 777 insertions(+), 488 deletions(-) create mode 100644 project/notes/ee0fa255-9a71-44b1-9556-e7b3157f1f77.json create mode 100644 project/objects/1da3111e-717a-4452-8209-98c5443fc31a.json create mode 100644 project/objects/67e29043-9aa8-4dd9-807c-cc7385eb6847.json create mode 100644 project/objects/d1b10e0c-f6b4-4b9d-a96e-cb51213f0243.json delete mode 100644 project/objects/zxq5.json create mode 100644 project/templates/a24b3ab7-2572-4af4-8457-df26937fd773.json create mode 100644 project/templates/c96f5e87-7517-44cc-a5ab-42ffd537801d.json delete mode 100644 project/templates/character.json create mode 100644 src/error.rs create mode 100644 src/explorer.rs create mode 100644 src/note.rs create mode 100644 src/scene.rs diff --git a/Cargo.lock b/Cargo.lock index 2c38be1..2a93bc6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3267,6 +3267,8 @@ dependencies = [ "serde", "serde_json", "thiserror 2.0.12", + "uuid", + "walkdir", ] [[package]] @@ -3611,6 +3613,17 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" +[[package]] +name = "uuid" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cf4199d1e5d15ddd86a694e4d0dffa9c323ce759fea589f00fef9d81cc1931d" +dependencies = [ + "getrandom 0.3.3", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "v_frame" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index ea783f5..d67336c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,3 +20,5 @@ serde_json = "1.0.140" chrono = { version = "0.4.41", features = ["serde"] } thiserror = "2.0.12" egui_commonmark = { version = "0.20.0", features = ["embedded_image"] } +walkdir = "2.5.0" +uuid = { version = "1.17.0", features = ["v4"] } diff --git a/project/notes/ee0fa255-9a71-44b1-9556-e7b3157f1f77.json b/project/notes/ee0fa255-9a71-44b1-9556-e7b3157f1f77.json new file mode 100644 index 0000000..cd0118f --- /dev/null +++ b/project/notes/ee0fa255-9a71-44b1-9556-e7b3157f1f77.json @@ -0,0 +1 @@ +{"name":"Note","content":"this is the note! gfjh gfdhgj fgfjhghfd iughuifghuifghuifghuifghuifdg"} \ No newline at end of file diff --git a/project/objects/1da3111e-717a-4452-8209-98c5443fc31a.json b/project/objects/1da3111e-717a-4452-8209-98c5443fc31a.json new file mode 100644 index 0000000..88a8990 --- /dev/null +++ b/project/objects/1da3111e-717a-4452-8209-98c5443fc31a.json @@ -0,0 +1,13 @@ +{ + "id": "1da3111e-717a-4452-8209-98c5443fc31a", + "template_id": "c96f5e87-7517-44cc-a5ab-42ffd537801d", + "name": "sword", + "fields": { + "description": { + "value": "idk, it probably looks cool" + }, + "durability": { + "value": "13.1" + } + } +} \ No newline at end of file diff --git a/project/objects/67e29043-9aa8-4dd9-807c-cc7385eb6847.json b/project/objects/67e29043-9aa8-4dd9-807c-cc7385eb6847.json new file mode 100644 index 0000000..d23a7e2 --- /dev/null +++ b/project/objects/67e29043-9aa8-4dd9-807c-cc7385eb6847.json @@ -0,0 +1,16 @@ +{ + "id": "67e29043-9aa8-4dd9-807c-cc7385eb6847", + "template_id": "c96f5e87-7517-44cc-a5ab-42ffd537801d", + "name": "sword", + "fields": { + "durability": { + "value": "8.6" + }, + "Icon": { + "value": "/home/zxq5/Projects/Minecraft/Packs/ZXQ5 projects/ZXQ5 x/ZXQ5 x-512/ZXQ5 x Release/classic.pack.png" + }, + "description": { + "value": "idk" + } + } +} \ No newline at end of file diff --git a/project/objects/d1b10e0c-f6b4-4b9d-a96e-cb51213f0243.json b/project/objects/d1b10e0c-f6b4-4b9d-a96e-cb51213f0243.json new file mode 100644 index 0000000..7b96f6a --- /dev/null +++ b/project/objects/d1b10e0c-f6b4-4b9d-a96e-cb51213f0243.json @@ -0,0 +1,22 @@ +{ + "id": "d1b10e0c-f6b4-4b9d-a96e-cb51213f0243", + "template_id": "a24b3ab7-2572-4af4-8457-df26937fd773", + "name": "zxq5", + "fields": { + "Appearance": { + "value": "taller than panic" + }, + "Date of Birth": { + "value": "2025-07-15" + }, + "Portrait / Image": { + "value": "/home/zxq5/Pictures/logos and pfps/YT profile picture background.png" + }, + "Age": { + "value": "19" + }, + "Personality": { + "value": "coder" + } + } +} \ No newline at end of file diff --git a/project/objects/zxq5.json b/project/objects/zxq5.json deleted file mode 100644 index 39b12b4..0000000 --- a/project/objects/zxq5.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "template_name": "Character", - "template_path": "templates/character.json", - "name": "zxq5", - "fields": { - "Age": { - "value": "19" - }, - "Birth Date": { - "value": "2025-07-11" - }, - "Name": { - "value": "zxq5" - }, - "Backstory": { - "value": "zxq5" - }, - "Profile Picture": { - "value": "/home/zxq5/Pictures/logos and pfps/YT profile picture.png" - }, - "Personality": { - "value": "zxq5" - }, - "Appearance": { - "value": "zxq5" - } - } -} \ No newline at end of file diff --git a/project/templates/a24b3ab7-2572-4af4-8457-df26937fd773.json b/project/templates/a24b3ab7-2572-4af4-8457-df26937fd773.json new file mode 100644 index 0000000..74366b9 --- /dev/null +++ b/project/templates/a24b3ab7-2572-4af4-8457-df26937fd773.json @@ -0,0 +1,37 @@ +{ + "name": "Character", + "id": "a24b3ab7-2572-4af4-8457-df26937fd773", + "description": "character", + "fields": [ + { + "name": "Portrait / Image", + "field_type": "Image", + "required": true, + "description": "image of character" + }, + { + "name": "Date of Birth", + "field_type": "Date", + "required": false, + "description": "date of birth" + }, + { + "name": "Age", + "field_type": "Number", + "required": false, + "description": "age" + }, + { + "name": "Appearance", + "field_type": "MultiLine", + "required": false, + "description": "character's appearance" + }, + { + "name": "Personality", + "field_type": "MultiLine", + "required": false, + "description": "character's personality" + } + ] +} \ No newline at end of file diff --git a/project/templates/c96f5e87-7517-44cc-a5ab-42ffd537801d.json b/project/templates/c96f5e87-7517-44cc-a5ab-42ffd537801d.json new file mode 100644 index 0000000..ebcd7bf --- /dev/null +++ b/project/templates/c96f5e87-7517-44cc-a5ab-42ffd537801d.json @@ -0,0 +1,25 @@ +{ + "name": "Item", + "id": "c96f5e87-7517-44cc-a5ab-42ffd537801d", + "description": "an in-game item", + "fields": [ + { + "name": "durability", + "field_type": "Number", + "required": false, + "description": "the item's durability" + }, + { + "name": "description", + "field_type": "MultiLine", + "required": true, + "description": "the item's description" + }, + { + "name": "Icon", + "field_type": "Image", + "required": false, + "description": "yes" + } + ] +} \ No newline at end of file diff --git a/project/templates/character.json b/project/templates/character.json deleted file mode 100644 index 6c88655..0000000 --- a/project/templates/character.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "Character", - "description": "character template!", - "fields": [ - { - "name": "Profile Picture", - "field_type": "Image", - "required": false, - "description": "Path to character's profile picture" - }, - { - "name": "Name", - "field_type": "SingleLine", - "required": true, - "description": "The full name of the character" - }, - { - "name": "Age", - "field_type": "Number", - "required": false, - "description": "Character's age in years" - }, - { - "name": "Birth Date", - "field_type": "Date", - "required": false, - "description": "Date of birth (YYYY-MM-DD)" - }, - { - "name": "Appearance", - "field_type": "MultiLine", - "required": false, - "description": "Physical description of the character" - }, - { - "name": "Personality", - "field_type": "MultiLine", - "required": false, - "description": "Personality traits and behavior" - }, - { - "name": "Backstory", - "field_type": "MultiLine", - "required": false, - "description": "Character's history and background" - } - ] -} diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..441e43c --- /dev/null +++ b/src/error.rs @@ -0,0 +1,22 @@ +pub struct Error { + message: String, + visible: bool, +} + +impl Error { + pub fn new(message: String) -> Self { + Self { + message, + visible: true, + } + } + + pub fn show(&mut self, ui: &mut egui::Ui) { + egui::Window::new("Error") + .open(&mut self.visible) + .fixed_size([200.0, 100.0]) + .show(ui.ctx(), |ui| { + ui.label(self.message.clone()); + }); + } +} diff --git a/src/explorer.rs b/src/explorer.rs new file mode 100644 index 0000000..95c3fe3 --- /dev/null +++ b/src/explorer.rs @@ -0,0 +1,159 @@ +use egui::RichText; + +use crate::{ + PROJECT_FOLDER, RightPanelContent, + note::Note, + object::ObjectInstance, + template::{FieldType, Template}, +}; + +pub struct Explorer {} + +impl Explorer { + pub fn new() -> Self { + Self {} + } + + pub fn ui(&mut self, to_load: &mut Option, ui: &mut egui::Ui) { + let (templates, objects) = match Self::load_templates() { + Ok((templates, objects)) => (templates, objects), + Err(e) => { + eprintln!("Failed to load project: {e}"); + ui.label(RichText::new("Failed to load project").color(egui::Color32::RED)); + return; + } + }; + + ui.vertical(|ui| { + egui::collapsing_header::CollapsingState::load_with_default_open( + ui.ctx(), + ui.make_persistent_id("templates"), + true, + ) + .show_header(ui, |ui| { + ui.horizontal(|ui| { + ui.label("Templates"); + if ui.button("+").clicked() { + *to_load = Some(RightPanelContent::Template { + template: Box::new(Template::default()), + new_field_name: Default::default(), + new_field_type: FieldType::SingleLine, + new_field_required: false, + new_field_description: Default::default(), + }); + } + }); + }) + .body(|ui| { + for template in &templates { + let id = ui.make_persistent_id(template.name.clone()); + egui::collapsing_header::CollapsingState::load_with_default_open( + ui.ctx(), + id, + true, + ) + .show_header(ui, |ui| { + // load the template + if ui.selectable_label(false, template.name.clone()).clicked() { + *to_load = Some(RightPanelContent::template(Some(template.clone()))); + } + + // create a new object based on this template + if ui.button("+").clicked() { + *to_load = Some(RightPanelContent::Object { + object: Box::new(ObjectInstance::new(template)), + }); + } + }) + .body(|ui| { + for object in &objects { + if object.template_id == template.id { + ui.horizontal(|ui| { + ui.add_space(10.0); + + // load the object + if ui.selectable_label(false, &object.name).clicked() { + *to_load = Some(RightPanelContent::Object { + object: Box::new(object.clone()), + }); + } + }); + } + } + }); + } + }); + + let notes = Self::load_notes().unwrap(); + + egui::collapsing_header::CollapsingState::load_with_default_open( + ui.ctx(), + ui.make_persistent_id("notes"), + true, + ) + .show_header(ui, |ui| { + ui.horizontal(|ui| { + ui.label("Notes"); + if ui.button("+").clicked() { + *to_load = Some(RightPanelContent::Note { + note: Box::new(Note::default()), + }); + } + }); + }) + .body(|ui| { + for note in ¬es { + ui.horizontal(|ui| { + ui.add_space(10.0); + + // load the note + if ui.selectable_label(false, ¬e.name).clicked() { + *to_load = Some(RightPanelContent::Note { + note: Box::new(note.clone()), + }); + } + }); + } + }); + + egui::CollapsingHeader::new("Projects").show(ui, |ui| {}); + }); + } + + fn load_templates() -> std::io::Result<(Vec