Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions .github/workflows/deno.yml

This file was deleted.

27 changes: 27 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Rust

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

permissions:
contents: read

jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install stable Rust
run: |
rustup toolchain install stable --profile minimal --component clippy --component rustfmt
rustup default stable
- name: Check formatting
run: cargo fmt --all -- --check
- name: Run Clippy
run: cargo clippy --workspace --all-targets -- -D warnings
- name: Run tests
run: cargo test --workspace
Comment on lines +26 to +27
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
localstorage.json
.notes/
node_modules/
target/
build/
/world*
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: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[workspace]
members = ["rust/components"]
resolver = "2"
9 changes: 0 additions & 9 deletions deno.json

This file was deleted.

7 changes: 7 additions & 0 deletions rust/components/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "hyperfy-components"
version = "0.1.0"
edition = "2021"

[lib]
path = "src/lib.rs"
137 changes: 137 additions & 0 deletions rust/components/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
//! Pure Rust adapters for the core node component identities and shared node data.

use std::marker::PhantomData;

pub trait Component {
const KIND: &'static str;
}

#[derive(Clone, Debug, PartialEq)]
pub struct NodeTransform {
pub position: [f64; 3],
pub rotation: [f64; 4],
pub scale: [f64; 3],
}

impl Default for NodeTransform {
fn default() -> Self {
Self {
position: [0.0; 3],
rotation: [0.0, 0.0, 0.0, 1.0],
scale: [1.0; 3],
}
}
Comment on lines +10 to +23
}

#[derive(Clone, Debug, PartialEq)]
pub struct NodeWrapper<C: Component> {
pub id: String,
pub active: bool,
pub transform: NodeTransform,
component: PhantomData<C>,
}

impl<C: Component> NodeWrapper<C> {
pub fn new(id: impl Into<String>) -> Self {
Self {
id: id.into(),
active: true,
transform: NodeTransform::default(),
component: PhantomData,
}
}

pub fn kind(&self) -> &'static str {
C::KIND
}
}

macro_rules! define_components {
($($marker:ident => $wrapper:ident => $kind:literal),+ $(,)?) => {
$(
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct $marker;

impl Component for $marker {
const KIND: &'static str = $kind;
}

pub type $wrapper = NodeWrapper<$marker>;
)+

pub const COMPONENT_KINDS: &[&str] = &[$(<$marker as Component>::KIND),+];
};
}

define_components! {
Group => GroupNode => "group",
Mesh => MeshNode => "mesh",
SkinnedMesh => SkinnedMeshNode => "skinnedmesh",
Lod => LodNode => "lod",
Audio => AudioNode => "audio",
Video => VideoNode => "video",
Image => ImageNode => "image",
Snap => SnapNode => "snap",
Prim => PrimNode => "prim",
Avatar => AvatarNode => "avatar",
Action => ActionNode => "action",
Anchor => AnchorNode => "anchor",
Nametag => NametagNode => "nametag",
Particles => ParticlesNode => "particles",
Sky => SkyNode => "sky",
Ui => UiNode => "ui",
UiView => UiViewNode => "uiview",
UiText => UiTextNode => "uitext",
UiImage => UiImageNode => "uiimage",
Controller => ControllerNode => "controller",
RigidBody => RigidBodyNode => "rigidbody",
Collider => ColliderNode => "collider",
Joint => JointNode => "joint",
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn wrapper_uses_core_node_defaults_and_component_kind() {
let node = MeshNode::new("mesh-1");

assert_eq!(node.id, "mesh-1");
assert!(node.active);
assert_eq!(node.kind(), "mesh");
assert_eq!(node.transform, NodeTransform::default());
}

#[test]
fn registry_matches_all_core_node_component_kinds() {
assert_eq!(
COMPONENT_KINDS,
&[
Comment on lines +107 to +110
"group",
"mesh",
"skinnedmesh",
"lod",
"audio",
"video",
"image",
"snap",
"prim",
"avatar",
"action",
"anchor",
"nametag",
"particles",
"sky",
"ui",
"uiview",
"uitext",
"uiimage",
"controller",
"rigidbody",
"collider",
"joint",
]
);
}
}
Loading