From 16c1574e400d73198713336e18975ff37ab78290 Mon Sep 17 00:00:00 2001 From: Silas Bartha Date: Fri, 11 Oct 2024 16:02:07 -0400 Subject: Way too many changes (0.2) --- src/resources.rs | 93 +++++++++++++------------------------------------------- 1 file changed, 21 insertions(+), 72 deletions(-) (limited to 'src/resources.rs') diff --git a/src/resources.rs b/src/resources.rs index c145960..c9f7b40 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -1,80 +1,29 @@ -use std::{ - fs, - path::{Path, PathBuf}, -}; +use std::{collections::BTreeMap, path::PathBuf}; -use anyhow::{Context, Result}; -use bevy::prelude::*; +use bevy::{ecs::world::CommandQueue, prelude::*, tasks::Task}; +use multi_key_map::MultiKeyMap; +use occule::Codec; -use crate::events::DirworldNavigationEvent; +/// Root directory of the world +#[derive(Resource, Deref, DerefMut, Default)] +pub struct DirworldRootDir(pub Option); -/// Configuration for Dirworld. -#[derive(Resource)] -pub struct DirworldConfig { - root: PathBuf, -} - -impl DirworldConfig { - /// Construct a new dirworld config with the given root path. Will panic if the provided path - /// cannot be canonicalized. - // TODO: Don't panic? lol - pub fn new(root: PathBuf) -> Self { - Self { - root: fs::canonicalize(root).expect("Failed to canonicalize path!"), - } - } - - /// - pub fn root(&self) -> &PathBuf { - &self.root - } -} +/// Current directory of the world +#[derive(Resource, Deref, DerefMut, Default)] +pub struct DirworldCurrentDir(pub Option); -/// Contains the dirworld state. -#[derive(Resource)] -pub struct Dirworld { - /// Current active directory. - pub path: PathBuf, +/// Running background tasks +#[derive(Default, Resource, Deref, DerefMut)] +pub struct DirworldTasks(pub BTreeMap>>); - /// Entities local to the current room. - pub tracked_entities: Vec, -} +#[derive(Debug, Default, Resource, Deref, DerefMut)] +pub(crate) struct DirworldObservers(pub MultiKeyMap); -impl FromWorld for Dirworld { - fn from_world(world: &mut World) -> Self { - let config = world.remove_resource::().unwrap(); - world.send_event(DirworldNavigationEvent::EnteredRoom { - path: config.root().clone(), - }); - let result = Self { - path: config.root().clone(), - tracked_entities: vec![], - }; - world.insert_resource(config); - result - } -} +#[derive(Default, Resource, Deref, DerefMut)] +pub(crate) struct DirworldCodecs(pub MultiKeyMap>); -impl Dirworld { - /// Move into a new room. - // TODO: Clear tracked entities? - // TODO: Make into command extension trait? - pub fn navigate_to( - &mut self, - path: PathBuf, - event_writer: &mut EventWriter, - ) -> Result<()> { - event_writer.send(DirworldNavigationEvent::LeftRoom { - path: self.path.clone(), - }); - self.path = Path::new(&self.path) - .join(path) - .to_str() - .context("Path not valid UTF-8")? - .into(); - event_writer.send(DirworldNavigationEvent::EnteredRoom { - path: self.path.clone(), - }); - Ok(()) - } +#[derive(Debug, PartialEq, Eq, Hash)] +pub enum EntryType { + File(Option), + Folder, } -- cgit v1.2.3