.
This commit is contained in:
7
Cargo.lock
generated
7
Cargo.lock
generated
@@ -309,6 +309,7 @@ dependencies = [
|
|||||||
"bevy",
|
"bevy",
|
||||||
"include_dir",
|
"include_dir",
|
||||||
"mlua",
|
"mlua",
|
||||||
|
"nameof",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2933,6 +2934,12 @@ dependencies = [
|
|||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nameof"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ae5794a00611c89e072a2d8bd5164c410a96181f1f7f40676c94293d44af1401"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ndk"
|
name = "ndk"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ edition = "2024"
|
|||||||
bevy = { version = "0.16", features = ["file_watcher"] }
|
bevy = { version = "0.16", features = ["file_watcher"] }
|
||||||
include_dir = "0.7.4"
|
include_dir = "0.7.4"
|
||||||
mlua = { version = "0.11.5", features = ["luau","luau-jit","luau-vector4","serde","send"] }
|
mlua = { version = "0.11.5", features = ["luau","luau-jit","luau-vector4","serde","send"] }
|
||||||
|
nameof = "1.3.0"
|
||||||
|
|
||||||
[profile.dev.package."*"]
|
[profile.dev.package."*"]
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
|
|||||||
186
src/duck.rs
186
src/duck.rs
@@ -1,76 +1,166 @@
|
|||||||
use mlua::UserData;
|
use mlua::UserData;
|
||||||
use mlua::Lua;
|
use mlua::Lua;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
use mlua::UserDataFields;
|
||||||
|
use mlua::UserDataMethods;
|
||||||
|
use nameof::name_of_type;
|
||||||
|
use std::ops::Deref;
|
||||||
|
use std::ops::DerefMut;
|
||||||
|
|
||||||
use include_dir::{include_dir, Dir};
|
use include_dir::{include_dir, Dir};
|
||||||
|
|
||||||
static DATA_DIR: Dir<'_> = include_dir!("data");
|
static DATA_DIR: Dir<'_> = include_dir!("data");
|
||||||
|
|
||||||
/*
|
struct BevyContext<'a> {
|
||||||
In lieu of the old Roblox instances.
|
commands: Commands<'a, 'a>
|
||||||
Instances, at least for the sake of bevy's design,
|
}
|
||||||
are helper components that also implement a lua userdata wrapper.
|
impl<'a> BevyContext<'a> {
|
||||||
|
fn from_raw(commands: Commands<'a,'a>) -> Self {
|
||||||
I'm sure storing the Entity in the component is bad practice,
|
BevyContext { commands: commands }
|
||||||
but I can't find a cleaner way of integrating with Bevy's ECS like this.
|
}
|
||||||
*/
|
/*fn get_instance<T>(&self, entity: Entity) -> &T {
|
||||||
|
self.commands.entity(entity).
|
||||||
trait Instance: UserData {
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Script {
|
// Id for this object to the server
|
||||||
name: String
|
struct Netlink {
|
||||||
}
|
|
||||||
|
|
||||||
impl Instance for Script {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
trait Class {
|
||||||
struct Context {
|
// Class name for filtering
|
||||||
name: String,
|
fn class_name() -> String { name_of_type!(Self).into() }
|
||||||
lua: Lua
|
// Create a default object
|
||||||
}
|
fn new_entity<'a>(context: &BevyContext) -> (EntityCommands<'a>, Self);
|
||||||
|
// fn clone(&self) -> Self;
|
||||||
impl Instance for Context {
|
fn add_fields<T, F: UserDataFields<T>>(_fields: &mut F) {}
|
||||||
|
fn add_methods<T, F: UserDataMethods<T>>(_methods: &mut F) {}
|
||||||
}
|
|
||||||
|
|
||||||
struct Part {
|
|
||||||
name: String
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Instance for Part {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Folder {
|
|
||||||
name: String
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Instance for Folder {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct Instance<S: Class> {
|
||||||
|
name: String,
|
||||||
|
class: S,
|
||||||
|
entity: Entity,
|
||||||
|
netlink: Netlink
|
||||||
|
}
|
||||||
|
impl<S: Class> UserData for Instance<S> {
|
||||||
|
fn add_fields<F: UserDataFields<Self>>(fields: &mut F) {
|
||||||
|
S::add_fields::<Self,F>(fields);
|
||||||
|
}
|
||||||
|
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||||
|
S::add_methods::<Self,M>(methods);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<S: Class> Instance<S> {
|
||||||
|
fn new(context: &BevyContext) -> Self {
|
||||||
|
let (entity,sub) = S::new_entity(context);
|
||||||
|
Instance {
|
||||||
|
name: S::class_name(),
|
||||||
|
class: sub,
|
||||||
|
entity: entity.id(),
|
||||||
|
netlink: Netlink {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Constructor;
|
||||||
|
|
||||||
|
impl UserData for Constructor {
|
||||||
|
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||||
|
methods.add_method("part", |lua, this, ()| {
|
||||||
|
let part = IPart::new()
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Resource)]
|
||||||
|
struct ScriptContext {
|
||||||
|
lua: Lua
|
||||||
|
}
|
||||||
|
impl Class for ScriptContext {
|
||||||
|
fn new_entity(context: &BevyContext) -> (EntityCommands<'_>,Self) {
|
||||||
|
( context.commands.spawn_empty(), ScriptContext::new() )
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl ScriptContext {
|
||||||
|
fn new() -> Self {
|
||||||
|
let lua = Lua::new();
|
||||||
|
lua.sandbox(true);
|
||||||
|
let globals = lua.globals();
|
||||||
|
globals.set("new",Constructor);
|
||||||
|
ScriptContext { lua: lua }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Script {
|
||||||
|
context: Entity
|
||||||
|
}
|
||||||
|
impl Class for Script {
|
||||||
|
fn new_entity(context: &BevyContext) -> (Entity, Self) {
|
||||||
|
( context.)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attachment
|
||||||
|
struct Node;
|
||||||
|
impl Class for Node {}
|
||||||
|
|
||||||
|
struct Part {
|
||||||
|
|
||||||
|
}
|
||||||
|
impl Class for Part {
|
||||||
|
fn new_entity(context: &BevyContext) -> Self {
|
||||||
|
commands.spawn()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl UserData for Part {}
|
||||||
|
|
||||||
|
struct Located<S: Class> {
|
||||||
|
class: S
|
||||||
|
}
|
||||||
|
impl<S: Class> UserData for Located<S> {
|
||||||
|
fn add_fields<F: UserDataFields<Self>>(fields: &mut F) {
|
||||||
|
S::add_fields(fields);
|
||||||
|
}
|
||||||
|
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||||
|
S::add_methods(methods);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<S: Class> Class for Located<S> {
|
||||||
|
fn new_entity(context: &BevyContext) -> Self {
|
||||||
|
let (entity,sub) = S::new_entity(context);
|
||||||
|
Located { class: S::new_entity(context), }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type IAttachment = Instance<Located<Node>>;
|
||||||
|
type IModel = Instance<Located<Node>>;
|
||||||
|
type IPart = Instance<Located<Part>>;
|
||||||
|
type IContext = Instance<ScriptContext>;
|
||||||
|
type IScript = Instance<Script>;
|
||||||
|
type IFolder = Instance<Node>;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
enum AnyInstance {
|
enum AnyInstance {
|
||||||
Context(Context),
|
Attachment(IAttachment),
|
||||||
Script(Script),
|
Context(IContext),
|
||||||
Part(Part)
|
Folder(IFolder),
|
||||||
|
Script(IScript),
|
||||||
|
Model(IModel),
|
||||||
|
Part(IPart)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn script_executor() {
|
fn script_executor() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collision_detector() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct DuckPlugin;
|
pub struct DuckPlugin;
|
||||||
|
|
||||||
impl Plugin for DuckPlugin {
|
impl Plugin for DuckPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(Update,(script_executor,collision_detector));
|
app.add_systems(Update,(script_executor));
|
||||||
|
app.insert_resource(ScriptContext::new_entity())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user