From 24552b99c2a5ab07b0ed50a024a895b1c56fbc81 Mon Sep 17 00:00:00 2001 From: Patrick Clearwater Date: Sun, 10 Nov 2024 19:33:31 +1100 Subject: [PATCH] WIP - start work on EntityType properties --- Cargo.lock | 8 ++++++++ Cargo.toml | 2 +- client/ui/src/App.tsx | 10 ++++++++-- client/ui/src/LeftBar.tsx | 6 +++++- client/ui/src/RightBar.tsx | 4 +++- entities/Cargo.toml | 8 ++++++++ entities/src/lib.rs | 28 ++++++++++++++++++++++++++++ 7 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 entities/Cargo.toml create mode 100644 entities/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 4683b14..aacfff1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -576,6 +576,14 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +[[package]] +name = "entities" +version = "0.1.0" +dependencies = [ + "tsify", + "wasm-bindgen", +] + [[package]] name = "equivalent" version = "1.0.1" diff --git a/Cargo.toml b/Cargo.toml index 266e1be..b53e928 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["blocks", "cli", "client", "net-types", "physics", "server"] +members = ["blocks", "cli", "client", "entities", "net-types", "physics", "server"] resolver = "2" [workspace.dependencies] diff --git a/client/ui/src/App.tsx b/client/ui/src/App.tsx index 7cc4b7b..f5d6182 100644 --- a/client/ui/src/App.tsx +++ b/client/ui/src/App.tsx @@ -9,6 +9,7 @@ function App({ engine }: { engine: Engine }) { const initialEngineMode = EngineMode.Edit; const [currentMode, setModeState] = useState(initialEngineMode); const [blockRegistry, setBlockRegistry] = useState(); + const [selectedEntity, setSelectedEntity] = useState(false); useEffect(() => { engine.ctx_on_init(setBlockRegistry); @@ -26,8 +27,13 @@ function App({ engine }: { engine: Engine }) { return (
- - + +
); } diff --git a/client/ui/src/LeftBar.tsx b/client/ui/src/LeftBar.tsx index fead2f2..cf8be05 100644 --- a/client/ui/src/LeftBar.tsx +++ b/client/ui/src/LeftBar.tsx @@ -11,7 +11,7 @@ enum LeftBarTab { Debug, }; -export default function LeftBar({ engine, currentMode, blockRegistry }: { Engine, EngineMode, BlockRegistry }) { +export default function LeftBar({ engine, currentMode, blockRegistry, setSelectedEntity }: { Engine, EngineMode, BlockRegistry, setSelectedEntity: (bool) => void }) { const [currentTab, setCurrentTab] = useState(LeftBarTab.Debug); let theContent; if(currentTab === LeftBarTab.Blocks) { @@ -20,6 +20,10 @@ export default function LeftBar({ engine, currentMode, blockRegistry }: { Engine theContent =

What even is an entity, man?

; } else { theContent =
+
    +
  • { setSelectedEntity(true); } }>select entity
  • +
  • { setSelectedEntity(false); } }>deselect entity
  • +
{currentMode === EngineMode.Edit && }
; diff --git a/client/ui/src/RightBar.tsx b/client/ui/src/RightBar.tsx index f1deddc..2c16222 100644 --- a/client/ui/src/RightBar.tsx +++ b/client/ui/src/RightBar.tsx @@ -1,9 +1,11 @@ // The "right bar": invisible unless an entity is selected, and in that latter // case, the properties panel +import { SelectedEntity } from "../../pkg/client.js"; + // TODO: implement entities and thus this -export default function RightBar({ selectedEntity }: { selectedEntity: boolean } ) { +export default function RightBar({ selectedEntity }: { selectedEntity: SelectedEntity|undefined } ) { if(selectedEntity) { return

Siege chopper, checking in 🚁

diff --git a/entities/Cargo.toml b/entities/Cargo.toml new file mode 100644 index 0000000..2ea815a --- /dev/null +++ b/entities/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "entities" +version = "0.1.0" +edition = "2021" + +[dependencies] +wasm-bindgen.workspace = true +tsify.workspace = true diff --git a/entities/src/lib.rs b/entities/src/lib.rs new file mode 100644 index 0000000..508e075 --- /dev/null +++ b/entities/src/lib.rs @@ -0,0 +1,28 @@ +/// This crate contains data types relevant to entities +/// +/// It is designed to be used on both the server and the client + +use tsify::Tsify; + +#[derive(Tsify)] +pub struct EntityType { + /// Name appropriate for display to the user + pub name: String, + /// The properties custom to this EntityType (i.e. not including "standard" properties) + pub custom_properties: Vec +} + +#[derive(Tsify)] +pub struct EntityPropertyType { + /// Name appropriate for display to the user + pub name: String, + /// What are the valid values for this property? + pub property_kind: PropertyKind, +} + +#[derive(Tsify)] +pub enum PropertyKind { + Float, + Int, + Options(Vec), +}