Trying to figure out Instances.

This commit is contained in:
2026-01-25 13:46:50 +00:00
parent 4f2b63aa47
commit f3d258cbc9
2 changed files with 78 additions and 45 deletions

76
src/duck.rs Normal file
View File

@@ -0,0 +1,76 @@
use mlua::UserData;
use mlua::Lua;
use bevy::prelude::*;
use include_dir::{include_dir, Dir};
static DATA_DIR: Dir<'_> = include_dir!("data");
/*
In lieu of the old Roblox instances.
Instances, at least for the sake of bevy's design,
are helper components that also implement a lua userdata wrapper.
I'm sure storing the Entity in the component is bad practice,
but I can't find a cleaner way of integrating with Bevy's ECS like this.
*/
trait Instance: UserData {
}
struct Script {
name: String
}
impl Instance for Script {
}
struct Context {
name: String,
lua: Lua
}
impl Instance for Context {
}
struct Part {
name: String
}
impl Instance for Part {
}
struct Folder {
name: String
}
impl Instance for Folder {
}
#[derive(Component)]
enum AnyInstance {
Context(Context),
Script(Script),
Part(Part)
}
fn script_executor() {
}
fn collision_detector() {
}
pub struct DuckPlugin;
impl Plugin for DuckPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Update,(script_executor,collision_detector));
}
}

View File

@@ -1,10 +1,7 @@
use std::sync::Mutex;
use bevy::prelude::*;
use include_dir::{include_dir, Dir};
use mlua::Lua;
static DATA_DIR: Dir<'_> = include_dir!("data");
mod duck;
use duck::DuckPlugin;
fn main() {
App::new()
@@ -14,46 +11,6 @@ fn main() {
.run();
}
trait Instance {
fn new() -> Self {
Self {}
}
fn destroy() {
}
fn clone() {
}
}
struct Part {
}
impl Instance for Part {
}
struct DuckPlugin;
impl Plugin for DuckPlugin {
fn build(&self, app: &mut App) {
commands.spawn()
}
}
// A scripting context, for threading and sandboxing scripts
#[derive(Component)]
struct DuckScriptContext {
lua: Lua
}
//
#[derive(Component)]
struct DuckScript {
context: Entity
}
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,