Trying to figure out Instances.
This commit is contained in:
76
src/duck.rs
Normal file
76
src/duck.rs
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
47
src/main.rs
47
src/main.rs
@@ -1,10 +1,7 @@
|
|||||||
use std::sync::Mutex;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
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() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
@@ -14,46 +11,6 @@ fn main() {
|
|||||||
.run();
|
.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(
|
fn setup(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
|
|||||||
Reference in New Issue
Block a user