This commit is contained in:
parent
114409322d
commit
f5f80e156a
2
.cargo/config.toml
Normal file
2
.cargo/config.toml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[profile.dev.package."*"]
|
||||||
|
opt-level = 2
|
25
.gitea/workflows/build.yaml
Normal file
25
.gitea/workflows/build.yaml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
name: Build
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Build:
|
||||||
|
env:
|
||||||
|
RUNNER_TOOL_CACHE: /toolcache
|
||||||
|
container: rust:alpine
|
||||||
|
steps:
|
||||||
|
- name: Install node
|
||||||
|
run: apk add nodejs gcc libc-dev pkgconf libx11-dev alsa-lib-dev eudev-dev tar openssl-dev
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Restore cache
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cargo/bin/
|
||||||
|
~/.cargo/registry/index/
|
||||||
|
~/.cargo/registry/cache/
|
||||||
|
~/.cargo/git/db/
|
||||||
|
target/
|
||||||
|
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
- name: Build
|
||||||
|
run: cargo build --release
|
50
.github/workflows/docs.yml
vendored
50
.github/workflows/docs.yml
vendored
@ -1,50 +0,0 @@
|
|||||||
name: Docs
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [master]
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
pages: write
|
|
||||||
id-token: write
|
|
||||||
concurrency:
|
|
||||||
group: deploy
|
|
||||||
cancel-in-progress: false
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
name: Build
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- name: Install Dependencies
|
|
||||||
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
|
|
||||||
- name: Setup Rust
|
|
||||||
uses: dtolnay/rust-toolchain@stable
|
|
||||||
- name: Configure cache
|
|
||||||
uses: Swatinem/rust-cache@v2
|
|
||||||
- name: Setup pages
|
|
||||||
id: pages
|
|
||||||
uses: actions/configure-pages@v4
|
|
||||||
- name: Clean docs folder
|
|
||||||
run: cargo clean --doc
|
|
||||||
- name: Build docs
|
|
||||||
run: cargo doc --no-deps
|
|
||||||
- name: Add redirect
|
|
||||||
run: echo '<meta http-equiv="refresh" content="0;url=bevy_dirworld/index.html">' > target/doc/index.html
|
|
||||||
- name: Remove lock file
|
|
||||||
run: rm target/doc/.lock
|
|
||||||
- name: Upload artifact
|
|
||||||
uses: actions/upload-pages-artifact@v3
|
|
||||||
with:
|
|
||||||
path: target/doc
|
|
||||||
deploy:
|
|
||||||
name: Deploy
|
|
||||||
environment:
|
|
||||||
name: github-pages
|
|
||||||
url: ${{ steps.deployment.outputs.page_url }}
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: build
|
|
||||||
steps:
|
|
||||||
- name: Deploy to GitHub Pages
|
|
||||||
id: deployment
|
|
||||||
uses: actions/deploy-pages@v4
|
|
24
.github/workflows/rust.yml
vendored
24
.github/workflows/rust.yml
vendored
@ -1,24 +0,0 @@
|
|||||||
name: Rust
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ "master" ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ "master" ]
|
|
||||||
|
|
||||||
env:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Install Dependencies
|
|
||||||
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
|
|
||||||
- name: Build
|
|
||||||
run: cargo build --verbose
|
|
||||||
- name: Run tests
|
|
||||||
run: cargo test --verbose
|
|
7132
Cargo.lock
generated
Normal file
7132
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "bevy_dirworld"
|
name = "bevy_dirworld"
|
||||||
version = "0.4.0"
|
version = "0.4.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
@ -16,7 +16,7 @@ notify-debouncer-full = "0.5"
|
|||||||
md5 = "0.7"
|
md5 = "0.7"
|
||||||
aes = "0.8"
|
aes = "0.8"
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
hex-literal = "0.4"
|
hex-literal = "1.0"
|
||||||
uuid = "1.11"
|
uuid = "1.11"
|
||||||
lazy_static = "1.5"
|
lazy_static = "1.5"
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ version = "0.2"
|
|||||||
features = ["serialize"]
|
features = ["serialize"]
|
||||||
|
|
||||||
[dependencies.occule]
|
[dependencies.occule]
|
||||||
git = "https://git.soaos.dev/occule"
|
git = "https://git.soaos.dev/soaos/occule"
|
||||||
tag = "v0.3.1"
|
tag = "v0.3.1"
|
||||||
|
|
||||||
[dependencies.yarnspinner]
|
[dependencies.yarnspinner]
|
||||||
@ -43,7 +43,7 @@ version = "0.9"
|
|||||||
features = ["lua54", "bevy_bindings"]
|
features = ["lua54", "bevy_bindings"]
|
||||||
|
|
||||||
[dependencies.bevy_basic_interaction]
|
[dependencies.bevy_basic_interaction]
|
||||||
git = "https://git.soaos.dev/bevy_basic_interaction"
|
git = "https://git.soaos.dev/soaos/bevy_basic_interaction"
|
||||||
tag = "v0.2.0"
|
tag = "v0.2.0"
|
||||||
|
|
||||||
[dependencies.strum]
|
[dependencies.strum]
|
||||||
|
@ -6,10 +6,12 @@ use bevy::prelude::*;
|
|||||||
#[derive(Debug, Event, Deref, DerefMut, Clone)]
|
#[derive(Debug, Event, Deref, DerefMut, Clone)]
|
||||||
pub struct DirworldLeaveRoom(pub PathBuf);
|
pub struct DirworldLeaveRoom(pub PathBuf);
|
||||||
|
|
||||||
/// Event called when entering a room
|
/// Event called when entering a room, but before loading and spawning entities.
|
||||||
#[derive(Debug, Event, Clone)]
|
#[derive(Debug, Event, Clone)]
|
||||||
pub struct DirworldEnterRoom {
|
pub struct DirworldEnterRoom {
|
||||||
|
/// Room entered
|
||||||
pub exited: PathBuf,
|
pub exited: PathBuf,
|
||||||
|
/// Room exited from
|
||||||
pub entered: PathBuf,
|
pub entered: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,9 +19,12 @@ pub struct DirworldEnterRoom {
|
|||||||
#[derive(Debug, Event, Deref, DerefMut, Clone)]
|
#[derive(Debug, Event, Deref, DerefMut, Clone)]
|
||||||
pub struct DirworldChangeRoot(pub PathBuf);
|
pub struct DirworldChangeRoot(pub PathBuf);
|
||||||
|
|
||||||
|
/// Event called once navigation between rooms is complete (all entities loaded and spawned).
|
||||||
#[derive(Debug, Event, Clone)]
|
#[derive(Debug, Event, Clone)]
|
||||||
pub struct DirworldNavigationComplete {
|
pub struct DirworldNavigationComplete {
|
||||||
|
/// Room entered
|
||||||
pub from: PathBuf,
|
pub from: PathBuf,
|
||||||
|
/// Room exited
|
||||||
pub to: PathBuf,
|
pub to: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,16 +6,18 @@ use std::{ffi::OsStr, path::PathBuf};
|
|||||||
|
|
||||||
use actor::ActorPlugin;
|
use actor::ActorPlugin;
|
||||||
use bevy::{ecs::system::IntoObserverSystem, prelude::*};
|
use bevy::{ecs::system::IntoObserverSystem, prelude::*};
|
||||||
use bevy_mod_scripting::core::ScriptingPlugin;
|
|
||||||
use bevy_mod_scripting::lua::LuaScriptingPlugin;
|
use bevy_mod_scripting::lua::LuaScriptingPlugin;
|
||||||
use cache::DirworldCache;
|
use cache::DirworldCache;
|
||||||
use events::{DirworldChangeRoot, DirworldEnterRoom, DirworldLeaveRoom, DirworldNavigationComplete, DirworldSpawn};
|
use events::{
|
||||||
|
DirworldChangeRoot, DirworldEnterRoom, DirworldLeaveRoom, DirworldNavigationComplete,
|
||||||
|
DirworldSpawn,
|
||||||
|
};
|
||||||
use occule::Codec;
|
use occule::Codec;
|
||||||
use preload::{DirworldPreload, DirworldPreloadPlugin};
|
use preload::{DirworldPreload, DirworldPreloadPlugin};
|
||||||
use resources::{DirworldLastDir, EntryType};
|
|
||||||
use resources::{
|
use resources::{
|
||||||
DirworldCodecs, DirworldCurrentDir, DirworldObservers, DirworldRootDir, DirworldTasks,
|
DirworldCodecs, DirworldCurrentDir, DirworldObservers, DirworldRootDir, DirworldTasks,
|
||||||
};
|
};
|
||||||
|
use resources::{DirworldLastDir, EntryType};
|
||||||
pub use watcher::DirworldWatcherEvent;
|
pub use watcher::DirworldWatcherEvent;
|
||||||
pub use watcher::DirworldWatcherSet;
|
pub use watcher::DirworldWatcherSet;
|
||||||
|
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
// TODO: remove
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
@ -50,7 +53,8 @@ pub fn register(world: &mut World) {
|
|||||||
|
|
||||||
fn translate(ctx: FunctionCallContext, entity: Val<Entity>, translation: Val<Vec3>) {
|
fn translate(ctx: FunctionCallContext, entity: Val<Entity>, translation: Val<Vec3>) {
|
||||||
let world = ctx.world().unwrap();
|
let world = ctx.world().unwrap();
|
||||||
world.with_global_access(|world| {
|
// TODO: Handle
|
||||||
|
let _ = world.with_global_access(|world| {
|
||||||
if let Some(mut transform) = world.entity_mut(*entity).get_mut::<Transform>() {
|
if let Some(mut transform) = world.entity_mut(*entity).get_mut::<Transform>() {
|
||||||
transform.translation += *translation;
|
transform.translation += *translation;
|
||||||
}
|
}
|
||||||
@ -59,7 +63,7 @@ fn translate(ctx: FunctionCallContext, entity: Val<Entity>, translation: Val<Vec
|
|||||||
|
|
||||||
fn rotate(ctx: FunctionCallContext, entity: Val<Entity>, axis: Val<Vec3>, angle: f32) {
|
fn rotate(ctx: FunctionCallContext, entity: Val<Entity>, axis: Val<Vec3>, angle: f32) {
|
||||||
let world = ctx.world().unwrap();
|
let world = ctx.world().unwrap();
|
||||||
world.with_global_access(|world| {
|
let _ = world.with_global_access(|world| {
|
||||||
if let Some(mut transform) = world.entity_mut(*entity).get_mut::<Transform>() {
|
if let Some(mut transform) = world.entity_mut(*entity).get_mut::<Transform>() {
|
||||||
transform.rotation *= Quat::from_axis_angle(*axis, angle);
|
transform.rotation *= Quat::from_axis_angle(*axis, angle);
|
||||||
}
|
}
|
||||||
@ -69,7 +73,7 @@ fn rotate(ctx: FunctionCallContext, entity: Val<Entity>, axis: Val<Vec3>, angle:
|
|||||||
fn get_dirworld_id(ctx: FunctionCallContext, entity: Val<Entity>) -> Result<String, InteropError> {
|
fn get_dirworld_id(ctx: FunctionCallContext, entity: Val<Entity>) -> Result<String, InteropError> {
|
||||||
let world = ctx.world()?;
|
let world = ctx.world()?;
|
||||||
let mut result = Ok(Default::default());
|
let mut result = Ok(Default::default());
|
||||||
world.with_global_access(|world| {
|
let _ = world.with_global_access(|world| {
|
||||||
result = if let Some(dirworld_entity) = world.entity(*entity).get::<DirworldEntity>() {
|
result = if let Some(dirworld_entity) = world.entity(*entity).get::<DirworldEntity>() {
|
||||||
Ok(dirworld_entity
|
Ok(dirworld_entity
|
||||||
.payload
|
.payload
|
||||||
@ -88,7 +92,7 @@ fn get_dirworld_id(ctx: FunctionCallContext, entity: Val<Entity>) -> Result<Stri
|
|||||||
fn condition_true(ctx: FunctionCallContext) -> Result<bool, InteropError> {
|
fn condition_true(ctx: FunctionCallContext) -> Result<bool, InteropError> {
|
||||||
let world = ctx.world()?;
|
let world = ctx.world()?;
|
||||||
let mut result = Ok(Default::default());
|
let mut result = Ok(Default::default());
|
||||||
world.with_global_access(|world| {
|
let _ = world.with_global_access(|world| {
|
||||||
result = Ok(Condition::True.evaluate(world));
|
result = Ok(Condition::True.evaluate(world));
|
||||||
});
|
});
|
||||||
result
|
result
|
||||||
@ -109,7 +113,7 @@ fn condition_ancestor_of(
|
|||||||
};
|
};
|
||||||
let world = ctx.world()?;
|
let world = ctx.world()?;
|
||||||
let mut result = Ok(Default::default());
|
let mut result = Ok(Default::default());
|
||||||
world.with_global_access(|world| {
|
let _ = world.with_global_access(|world| {
|
||||||
result = Ok(Condition::AncestorOf {
|
result = Ok(Condition::AncestorOf {
|
||||||
ancestor,
|
ancestor,
|
||||||
descendant,
|
descendant,
|
||||||
@ -134,7 +138,7 @@ fn condition_descendant_of(
|
|||||||
};
|
};
|
||||||
let world = ctx.world()?;
|
let world = ctx.world()?;
|
||||||
let mut result = Ok(Default::default());
|
let mut result = Ok(Default::default());
|
||||||
world.with_global_access(|world| {
|
let _ = world.with_global_access(|world| {
|
||||||
result = Ok(Condition::DescendantOf {
|
result = Ok(Condition::DescendantOf {
|
||||||
ancestor,
|
ancestor,
|
||||||
descendant,
|
descendant,
|
||||||
@ -159,7 +163,7 @@ fn condition_parent_of(
|
|||||||
};
|
};
|
||||||
let world = ctx.world()?;
|
let world = ctx.world()?;
|
||||||
let mut result = Ok(Default::default());
|
let mut result = Ok(Default::default());
|
||||||
world.with_global_access(|world| {
|
let _ = world.with_global_access(|world| {
|
||||||
result = Ok(Condition::ParentOf { parent, child }.evaluate(world));
|
result = Ok(Condition::ParentOf { parent, child }.evaluate(world));
|
||||||
});
|
});
|
||||||
result
|
result
|
||||||
@ -180,7 +184,7 @@ fn condition_child_of(
|
|||||||
};
|
};
|
||||||
let world = ctx.world()?;
|
let world = ctx.world()?;
|
||||||
let mut result = Ok(Default::default());
|
let mut result = Ok(Default::default());
|
||||||
world.with_global_access(|world| {
|
let _ = world.with_global_access(|world| {
|
||||||
result = Ok(Condition::ChildOf { parent, child }.evaluate(world));
|
result = Ok(Condition::ChildOf { parent, child }.evaluate(world));
|
||||||
});
|
});
|
||||||
result
|
result
|
||||||
@ -196,7 +200,7 @@ fn condition_in_room(
|
|||||||
};
|
};
|
||||||
let world = ctx.world()?;
|
let world = ctx.world()?;
|
||||||
let mut result = Ok(Default::default());
|
let mut result = Ok(Default::default());
|
||||||
world.with_global_access(|world| {
|
let _ = world.with_global_access(|world| {
|
||||||
result = Ok(Condition::InRoom(room).evaluate(world));
|
result = Ok(Condition::InRoom(room).evaluate(world));
|
||||||
});
|
});
|
||||||
result
|
result
|
||||||
@ -212,7 +216,7 @@ fn condition_object_in_room(
|
|||||||
};
|
};
|
||||||
let world = ctx.world()?;
|
let world = ctx.world()?;
|
||||||
let mut result = Ok(Default::default());
|
let mut result = Ok(Default::default());
|
||||||
world.with_global_access(|world| {
|
let _ = world.with_global_access(|world| {
|
||||||
result = Ok(Condition::ObjectInRoom(object).evaluate(world));
|
result = Ok(Condition::ObjectInRoom(object).evaluate(world));
|
||||||
});
|
});
|
||||||
result
|
result
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
use avian3d::prelude::{Physics, PhysicsTime};
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use notify::{
|
use notify::{
|
||||||
event::{MetadataKind, ModifyKind, RenameMode},
|
event::{MetadataKind, ModifyKind, RenameMode},
|
||||||
@ -10,7 +11,7 @@ use crate::{
|
|||||||
cache::DirworldCache,
|
cache::DirworldCache,
|
||||||
components::{DirworldEntity, Persist},
|
components::{DirworldEntity, Persist},
|
||||||
events::{
|
events::{
|
||||||
DirworldChangeRoot, DirworldEnterRoom, DirworldLeaveRoom, DirworldNavigationComplete,
|
DirworldChangeRoot, DirworldEnterRoom, DirworldLeaveRoom,
|
||||||
},
|
},
|
||||||
preload::{load_entity, DirworldPreloadBegin, PreloadState, RoomAssets},
|
preload::{load_entity, DirworldPreloadBegin, PreloadState, RoomAssets},
|
||||||
resources::{
|
resources::{
|
||||||
@ -48,7 +49,11 @@ pub fn navigate_to_room(
|
|||||||
mut next_preload_state: ResMut<NextState<PreloadState>>,
|
mut next_preload_state: ResMut<NextState<PreloadState>>,
|
||||||
mut room_assets: ResMut<RoomAssets>,
|
mut room_assets: ResMut<RoomAssets>,
|
||||||
mut dirworld_tasks: ResMut<DirworldTasks>,
|
mut dirworld_tasks: ResMut<DirworldTasks>,
|
||||||
|
persitent_entities: Query<&DirworldEntity, With<Persist>>,
|
||||||
|
mut time: ResMut<Time<Physics>>,
|
||||||
) {
|
) {
|
||||||
|
time.pause();
|
||||||
|
dirworld_tasks.insert("Loading Room".into(), None);
|
||||||
let DirworldEnterRoom {
|
let DirworldEnterRoom {
|
||||||
exited: old_path,
|
exited: old_path,
|
||||||
entered: path,
|
entered: path,
|
||||||
@ -89,7 +94,6 @@ pub fn navigate_to_room(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
dirworld_tasks.insert("Loading Room".into(), None);
|
|
||||||
for entry in entries {
|
for entry in entries {
|
||||||
load_entity(
|
load_entity(
|
||||||
&entry,
|
&entry,
|
||||||
@ -99,6 +103,8 @@ pub fn navigate_to_room(
|
|||||||
&mut commands,
|
&mut commands,
|
||||||
&mut next_preload_state,
|
&mut next_preload_state,
|
||||||
&mut room_assets,
|
&mut room_assets,
|
||||||
|
&root_dir,
|
||||||
|
&persitent_entities,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
preload_event_writer.send(DirworldPreloadBegin { old_path: old_path.clone(), path: path.clone() });
|
preload_event_writer.send(DirworldPreloadBegin { old_path: old_path.clone(), path: path.clone() });
|
||||||
@ -115,6 +121,8 @@ pub fn handle_changes(
|
|||||||
mut event_writer: EventWriter<DirworldWatcherEvent>,
|
mut event_writer: EventWriter<DirworldWatcherEvent>,
|
||||||
mut next_preload_state: ResMut<NextState<PreloadState>>,
|
mut next_preload_state: ResMut<NextState<PreloadState>>,
|
||||||
mut room_assets: ResMut<RoomAssets>,
|
mut room_assets: ResMut<RoomAssets>,
|
||||||
|
persitent_entities: Query<&DirworldEntity, With<Persist>>,
|
||||||
|
root_dir: Res<DirworldRootDir>,
|
||||||
) {
|
) {
|
||||||
let event = &trigger.event().0;
|
let event = &trigger.event().0;
|
||||||
info!("Watcher Event: {event:?}");
|
info!("Watcher Event: {event:?}");
|
||||||
@ -134,6 +142,8 @@ pub fn handle_changes(
|
|||||||
&mut commands,
|
&mut commands,
|
||||||
&mut next_preload_state,
|
&mut next_preload_state,
|
||||||
&mut room_assets,
|
&mut room_assets,
|
||||||
|
&root_dir,
|
||||||
|
&persitent_entities,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,6 +157,8 @@ pub fn handle_changes(
|
|||||||
&mut commands,
|
&mut commands,
|
||||||
&mut next_preload_state,
|
&mut next_preload_state,
|
||||||
&mut room_assets,
|
&mut room_assets,
|
||||||
|
&root_dir,
|
||||||
|
&persitent_entities,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
EventKind::Modify(ModifyKind::Metadata(MetadataKind::Any)) => {
|
EventKind::Modify(ModifyKind::Metadata(MetadataKind::Any)) => {
|
||||||
@ -159,6 +171,8 @@ pub fn handle_changes(
|
|||||||
&mut commands,
|
&mut commands,
|
||||||
&mut next_preload_state,
|
&mut next_preload_state,
|
||||||
&mut room_assets,
|
&mut room_assets,
|
||||||
|
&root_dir,
|
||||||
|
&persitent_entities,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -12,8 +12,11 @@ pub struct DirworldPreload {
|
|||||||
pub data: Option<Vec<u8>>,
|
pub data: Option<Vec<u8>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Event triggered once preloading begins in a room
|
||||||
#[derive(Debug, Event, Clone)]
|
#[derive(Debug, Event, Clone)]
|
||||||
pub struct DirworldPreloadBegin {
|
pub struct DirworldPreloadBegin {
|
||||||
|
/// Path of old room
|
||||||
pub old_path: PathBuf,
|
pub old_path: PathBuf,
|
||||||
|
/// Path of loading room
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
use crate::cache::DirworldCache;
|
use crate::cache::DirworldCache;
|
||||||
|
use crate::components::Persist;
|
||||||
|
use crate::resources::DirworldRootDir;
|
||||||
use crate::{
|
use crate::{
|
||||||
components::DirworldEntity,
|
components::DirworldEntity,
|
||||||
resources::{DirworldCodecs, DirworldObservers, EntryType},
|
resources::{DirworldCodecs, DirworldObservers, EntryType},
|
||||||
@ -6,6 +8,7 @@ use crate::{
|
|||||||
Extensions,
|
Extensions,
|
||||||
};
|
};
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
use std::path::Path;
|
||||||
use std::{collections::HashMap, path::PathBuf};
|
use std::{collections::HashMap, path::PathBuf};
|
||||||
|
|
||||||
mod systems;
|
mod systems;
|
||||||
@ -13,6 +16,7 @@ mod systems;
|
|||||||
mod resources;
|
mod resources;
|
||||||
pub use resources::*;
|
pub use resources::*;
|
||||||
|
|
||||||
|
/// Preload-related events
|
||||||
pub mod events;
|
pub mod events;
|
||||||
pub use events::*;
|
pub use events::*;
|
||||||
|
|
||||||
@ -59,8 +63,18 @@ pub fn load_entity(
|
|||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
preload_state: &mut NextState<PreloadState>,
|
preload_state: &mut NextState<PreloadState>,
|
||||||
room_assets: &mut RoomAssets,
|
room_assets: &mut RoomAssets,
|
||||||
|
root_dir: &DirworldRootDir,
|
||||||
|
persistent_entities: &Query<&DirworldEntity, With<Persist>>,
|
||||||
) {
|
) {
|
||||||
info!("Entity: {entry:?}");
|
info!("Entity: {entry:?}");
|
||||||
|
if persistent_entities.iter().find(|e| e.path == *entry).is_some() {
|
||||||
|
info!("Entity is persistent, skipping...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if Some(entry.canonicalize().unwrap()) == root_dir.0.as_ref().and_then(|d| d.parent().map(Path::to_path_buf)) {
|
||||||
|
info!("Entity is root directory, skipping...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
let (mut payload, data) = extract_entity_payload(&entry, &codecs);
|
let (mut payload, data) = extract_entity_payload(&entry, &codecs);
|
||||||
payload = payload.map(|p| cache.get_entity_cache(&entry).unwrap_or(p));
|
payload = payload.map(|p| cache.get_entity_cache(&entry).unwrap_or(p));
|
||||||
let entry_type = if entry.is_dir() {
|
let entry_type = if entry.is_dir() {
|
||||||
|
@ -6,8 +6,11 @@ use bevy::prelude::*;
|
|||||||
#[derive(Resource, Default, Debug, Deref, DerefMut)]
|
#[derive(Resource, Default, Debug, Deref, DerefMut)]
|
||||||
pub struct RoomAssets(pub HashMap<PathBuf, HashMap<String, UntypedHandle>>);
|
pub struct RoomAssets(pub HashMap<PathBuf, HashMap<String, UntypedHandle>>);
|
||||||
|
|
||||||
|
/// Paths used while preloading entities
|
||||||
#[derive(Resource, Clone)]
|
#[derive(Resource, Clone)]
|
||||||
pub struct PreloadPaths {
|
pub struct PreloadPaths {
|
||||||
|
/// Path of old room
|
||||||
pub src: PathBuf,
|
pub src: PathBuf,
|
||||||
|
/// Path of current room
|
||||||
pub dst: PathBuf,
|
pub dst: PathBuf,
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
|
use avian3d::prelude::{Physics, PhysicsTime};
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
components::DirworldEntity,
|
components::{DirworldEntity, Persist},
|
||||||
events::{DirworldNavigationComplete, DirworldSpawn},
|
events::{DirworldNavigationComplete, DirworldSpawn},
|
||||||
resources::{DirworldObservers, DirworldTasks, EntryType},
|
resources::{DirworldObservers, DirworldTasks, EntryType},
|
||||||
Extensions,
|
Extensions,
|
||||||
@ -41,10 +42,11 @@ pub fn handle_preload(
|
|||||||
|
|
||||||
pub fn handle_spawn(
|
pub fn handle_spawn(
|
||||||
preload_paths: Res<PreloadPaths>,
|
preload_paths: Res<PreloadPaths>,
|
||||||
dirworld_entity_query: Query<(Entity, &DirworldEntity)>,
|
dirworld_entity_query: Query<(Entity, &DirworldEntity), Without<Persist>>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
observers: Res<DirworldObservers>,
|
observers: Res<DirworldObservers>,
|
||||||
mut event_writer: EventWriter<DirworldNavigationComplete>,
|
mut event_writer: EventWriter<DirworldNavigationComplete>,
|
||||||
|
mut time: ResMut<Time<Physics>>,
|
||||||
) {
|
) {
|
||||||
info!("Spawning");
|
info!("Spawning");
|
||||||
for (entity, DirworldEntity { path, .. }) in dirworld_entity_query.iter() {
|
for (entity, DirworldEntity { path, .. }) in dirworld_entity_query.iter() {
|
||||||
@ -58,6 +60,7 @@ pub fn handle_spawn(
|
|||||||
commands.trigger_targets(DirworldSpawn(entity), observer.clone());
|
commands.trigger_targets(DirworldSpawn(entity), observer.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
time.unpause();
|
||||||
event_writer.send(DirworldNavigationComplete {
|
event_writer.send(DirworldNavigationComplete {
|
||||||
from: preload_paths.src.clone(),
|
from: preload_paths.src.clone(),
|
||||||
to: preload_paths.dst.clone(),
|
to: preload_paths.dst.clone(),
|
||||||
|
@ -19,6 +19,7 @@ pub struct DirworldCurrentDir {
|
|||||||
pub payload: Option<DirworldEntityPayload>,
|
pub payload: Option<DirworldEntityPayload>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Last room player was in
|
||||||
#[derive(Resource, Deref, DerefMut, Default, Debug)]
|
#[derive(Resource, Deref, DerefMut, Default, Debug)]
|
||||||
pub struct DirworldLastDir(pub PathBuf);
|
pub struct DirworldLastDir(pub PathBuf);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user