Export to S-expressions

main
~erin 2023-04-28 21:34:02 -04:00
parent 5004b71b84
commit aa336e60d4
Signed by: erin
GPG Key ID: 9A8E308CEFA37A47
8 changed files with 1158 additions and 342 deletions

253
Cargo.lock generated
View File

@ -319,6 +319,18 @@ dependencies = [
"syn 2.0.15",
]
[[package]]
name = "atk-sys"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11ad703eb64dc058024f0e57ccfa069e15a413b98dbd50a1a950e743b7f11148"
dependencies = [
"glib-sys",
"gobject-sys",
"libc",
"system-deps",
]
[[package]]
name = "atomic-waker"
version = "1.1.1"
@ -498,6 +510,16 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be"
[[package]]
name = "cairo-sys-rs"
version = "0.16.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c48f4af05fabdcfa9658178e1326efa061853f040ce7d72e33af6885196f421"
dependencies = [
"libc",
"system-deps",
]
[[package]]
name = "calloop"
version = "0.10.5"
@ -526,6 +548,16 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
[[package]]
name = "cfg-expr"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8790cf1286da485c72cf5fc7aeba308438800036ec67d89425924c4807268c9"
dependencies = [
"smallvec",
"target-lexicon",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -1085,7 +1117,9 @@ dependencies = [
"eframe",
"egui",
"fake",
"rfd",
"serde",
"serde-lexpr",
"tracing-subscriber",
"tracing-wasm",
"uuid",
@ -1156,6 +1190,36 @@ dependencies = [
"byteorder",
]
[[package]]
name = "gdk-pixbuf-sys"
version = "0.16.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3092cf797a5f1210479ea38070d9ae8a5b8e9f8f1be9f32f4643c529c7d70016"
dependencies = [
"gio-sys",
"glib-sys",
"gobject-sys",
"libc",
"system-deps",
]
[[package]]
name = "gdk-sys"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d76354f97a913e55b984759a997b693aa7dc71068c9e98bcce51aa167a0a5c5a"
dependencies = [
"cairo-sys-rs",
"gdk-pixbuf-sys",
"gio-sys",
"glib-sys",
"gobject-sys",
"libc",
"pango-sys",
"pkg-config",
"system-deps",
]
[[package]]
name = "generic-array"
version = "0.14.7"
@ -1195,6 +1259,29 @@ version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4"
[[package]]
name = "gio-sys"
version = "0.16.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9b693b8e39d042a95547fc258a7b07349b1f0b48f4b2fa3108ba3c51c0b5229"
dependencies = [
"glib-sys",
"gobject-sys",
"libc",
"system-deps",
"winapi",
]
[[package]]
name = "glib-sys"
version = "0.16.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c61a4f46316d06bfa33a7ac22df6f0524c8be58e3db2d9ca99ccb1f357b62a65"
dependencies = [
"libc",
"system-deps",
]
[[package]]
name = "glow"
version = "0.12.1"
@ -1207,6 +1294,17 @@ dependencies = [
"web-sys",
]
[[package]]
name = "gobject-sys"
version = "0.16.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3520bb9c07ae2a12c7f2fbb24d4efc11231c8146a86956413fb1a79bb760a0f1"
dependencies = [
"glib-sys",
"libc",
"system-deps",
]
[[package]]
name = "gpu-alloc"
version = "0.5.3"
@ -1259,6 +1357,24 @@ dependencies = [
"bitflags",
]
[[package]]
name = "gtk-sys"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89b5f8946685d5fe44497007786600c2f368ff6b1e61a16251c89f72a97520a3"
dependencies = [
"atk-sys",
"cairo-sys-rs",
"gdk-pixbuf-sys",
"gdk-sys",
"gio-sys",
"glib-sys",
"gobject-sys",
"libc",
"pango-sys",
"system-deps",
]
[[package]]
name = "hashbrown"
version = "0.12.3"
@ -1283,6 +1399,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "hermit-abi"
version = "0.3.1"
@ -1368,6 +1490,12 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "itoa"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6"
[[package]]
name = "jni"
version = "0.21.1"
@ -1425,6 +1553,27 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lexpr"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a84de6a9df442363b08f5dbf0cd5b92edc70097b89c4ce4bfea4679fe48bc67"
dependencies = [
"itoa",
"lexpr-macros",
"ryu",
]
[[package]]
name = "lexpr-macros"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36b5cb8bb985c81a8ac1a0f8b5c4865214f574ddd64397ef7a99c236e21f35bb"
dependencies = [
"proc-macro2",
"quote",
]
[[package]]
name = "libc"
version = "0.2.142"
@ -1835,6 +1984,18 @@ dependencies = [
"ttf-parser",
]
[[package]]
name = "pango-sys"
version = "0.16.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e134909a9a293e04d2cc31928aa95679c5e4df954d0b85483159bd20d8f047f"
dependencies = [
"glib-sys",
"gobject-sys",
"libc",
"system-deps",
]
[[package]]
name = "parking"
version = "2.1.0"
@ -2063,6 +2224,31 @@ version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1382d1f0a252c4bf97dc20d979a2fdd05b024acd7c2ed0f7595d7817666a157"
[[package]]
name = "rfd"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cb2988ec50c9bcdb0c012b89643a6094a35a785a37897211ee62e1639342f7b"
dependencies = [
"async-io",
"block",
"dispatch",
"futures-util",
"glib-sys",
"gobject-sys",
"gtk-sys",
"js-sys",
"log",
"objc",
"objc-foundation",
"objc_id",
"raw-window-handle",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"windows 0.44.0",
]
[[package]]
name = "ron"
version = "0.8.0"
@ -2100,6 +2286,12 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "ryu"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
[[package]]
name = "same-file"
version = "1.0.6"
@ -2149,6 +2341,16 @@ dependencies = [
"serde_derive",
]
[[package]]
name = "serde-lexpr"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb4cda13396159f59e7946118cdac0beadeecfb7cf76b197f4147e546f4ead6f"
dependencies = [
"lexpr",
"serde",
]
[[package]]
name = "serde-xml-rs"
version = "0.4.1"
@ -2183,6 +2385,15 @@ dependencies = [
"syn 2.0.15",
]
[[package]]
name = "serde_spanned"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0efd8caf556a6cebd3b285caf480045fcc1ac04f6bd786b09a6f11af30c4fcf4"
dependencies = [
"serde",
]
[[package]]
name = "sha1"
version = "0.10.5"
@ -2322,6 +2533,25 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "system-deps"
version = "6.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0fe581ad25d11420b873cf9aedaca0419c2b411487b134d4d21065f3d092055"
dependencies = [
"cfg-expr",
"heck",
"pkg-config",
"toml",
"version-compare",
]
[[package]]
name = "target-lexicon"
version = "0.12.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd1ba337640d60c3e96bc6f0638a939b9c9a7f2c316a1598c279828b3d1dc8c5"
[[package]]
name = "tempfile"
version = "3.5.0"
@ -2425,11 +2655,26 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "toml"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b403acf6f2bb0859c93c7f0d967cb4a75a7ac552100f9322faf64dc047669b21"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
]
[[package]]
name = "toml_datetime"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
@ -2438,6 +2683,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "239410c8609e8125456927e6707163a3b1fdb40561e4b803bc041f466ccfdc13"
dependencies = [
"indexmap",
"serde",
"serde_spanned",
"toml_datetime",
"winnow",
]
@ -2609,6 +2856,12 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "version-compare"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "579a42fc0b8e0c63b76519a339be31bed574929511fa53c1a3acae26eb258f29"
[[package]]
name = "version_check"
version = "0.9.4"

View File

@ -24,6 +24,8 @@ chrono = { version = "0.4", features = ["serde"] }
chrono-humanize = "0.2.2"
uuid = { version = "1.3.1", features = ["v4", "fast-rng", "js", "serde"] }
fake = "2.5"
serde-lexpr = "0.1.3"
rfd = "0.11"
# native:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]

1141
dist/fplanner.js vendored

File diff suppressed because it is too large Load Diff

BIN
dist/fplanner_bg.wasm vendored

Binary file not shown.

View File

@ -1,10 +1,13 @@
pub mod components;
pub mod draw;
mod structure;
use serde_lexpr::{from_str, print::*, to_string_custom};
use chrono::prelude::Utc;
use chrono_humanize::HumanTime;
use fake::{Fake, Faker};
use std::collections::HashMap;
use std::path::PathBuf;
use uuid::Uuid;
/// We derive Deserialize/Serialize so we can persist app state on shutdown.
@ -20,6 +23,7 @@ pub struct PlannerApp {
view_layers: Vec<structure::Layer>,
new_index: usize,
new_label: String,
save_path: Option<PathBuf>,
current_project: structure::Project,
}
@ -33,6 +37,7 @@ impl Default for PlannerApp {
update_view: true,
new_index: 0,
new_label: String::default(),
save_path: None,
current_project: structure::Project::default(),
}
}
@ -69,6 +74,7 @@ impl eframe::App for PlannerApp {
update_view,
new_index,
new_label,
save_path,
current_project,
} = self;
@ -82,12 +88,32 @@ impl eframe::App for PlannerApp {
// The top panel is often a good place for a menu bar:
egui::menu::bar(ui, |ui| {
ui.menu_button("File", |ui| {
if ui.button("Save As").clicked() {
let options = Options::default();
let sexpr = to_string_custom(
&current_project,
options
.with_keyword_syntax(KeywordSyntax::ColonPrefix)
.with_nil_syntax(NilSyntax::Token)
.with_bool_syntax(BoolSyntax::Token)
.with_vector_syntax(VectorSyntax::Octothorpe),
)
.unwrap();
if let Some(path) = rfd::FileDialog::new()
.add_filter("plan", &["splan"])
.set_file_name("untitled.splan")
.set_title("Save Plan")
.save_file()
{
println!("{}", &path.display().to_string());
std::fs::write(path.display().to_string(), sexpr).unwrap();
*save_path = Some(path.to_owned());
}
}
if ui.button("Quit").clicked() {
_frame.close();
}
if ui.button("Save").clicked() {
eprintln!("Unimplemented!");
}
});
});
});
@ -167,18 +193,20 @@ impl eframe::App for PlannerApp {
});
ui.add(egui::Slider::new(new_index, 0..=10).text("Z-Index"));
if ui.button("Create").clicked() {
let id = Uuid::new_v4();
let new_layer = structure::Layer {
zindex: new_index.clone(),
label: new_label.clone(),
visible: true,
components: HashMap::from([(
Uuid::new_v4(),
id.clone(),
components::Component {
id: Uuid::new_v4(),
id: id.clone(),
label: Faker.fake::<String>(),
description: Faker.fake::<String>(),
c_type: components::ComponentType::Door,
material: components::Material::Metal,
shapes: vec![],
},
)]),
};

View File

@ -1,3 +1,4 @@
use super::draw::Shape;
use uuid::Uuid;
#[derive(serde::Deserialize, serde::Serialize, PartialEq)]
@ -36,6 +37,7 @@ pub struct Component {
pub description: String,
pub c_type: ComponentType,
pub material: Material,
pub shapes: Vec<Shape>,
}
impl Default for Component {
@ -46,6 +48,7 @@ impl Default for Component {
description: String::default(),
c_type: ComponentType::Furniture,
material: Material::Wood,
shapes: vec![],
}
}
}

10
src/app/draw.rs Normal file
View File

@ -0,0 +1,10 @@
#[derive(serde::Deserialize, serde::Serialize, PartialEq, Clone)]
pub struct Position(f64, f64, f64);
#[derive(serde::Deserialize, serde::Serialize, PartialEq, Clone)]
pub enum Shape {
Circle(Position, f64), // Centre, Radius
Rectangle(Position, Position), // Top-left, Bottom-right
Triangle(Position, Position, Position), // 3 points
Line(Position, Position), // 2 points
}

53
untitled.splan Normal file
View File

@ -0,0 +1,53 @@
(
(id . "5d932ba0-8912-4e53-95b7-5152bab827ac")
(name . "Meow")
(created . "2023-04-29T00:28:43.560471889Z")
(modified "2023-04-29T00:30:40.945891620Z")
(license . CNPL)
(layers
(0
(zindex . 0)
(label . "Meow")
(visible . #t)
(components
("bbf8f70a-60c1-4859-924b-c360b897dc6c"
(id . "73e48d43-2ec4-4397-8289-54ddc87f9886")
(label . "sWzh9LGiSKrlQsRWoK") (description . "Bq59shWXHCKhTH1")
(c_type . Door)
(material . Metal)
(shapes)
)
)
)
(2
(zindex . 2)
(label . ":O")
(visible . #t)
(components
("92e47d24-d69f-4b14-9d25-badb1ebe5f98"
(id . "7e82f1b1-5c88-4edd-805f-19f98e34c244")
(label . "s8so6MS711zAODf")
(description . "7tCDffx2dFFzIrT")
(c_type . Door)
(material . Metal)
(shapes)
)
)
)
(3
(zindex . 3)
(label . "Hello")
(visible . #t)
(components
("4774cddf-fba6-4008-a212-d1aff8b22cf9"
(id . "7d03467b-79bf-4e1f-8970-5be62c444842")
(label . "zEkXt7uOVBSb")
(description . "hi9js3X8dWaWZ")
(c_type . Door)
(material . Metal)
(shapes)
)
)
)
)
)