Skip to content

Commit

Permalink
refactor: ♻️ it compiles (with a LOT of unfinished things)
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-rs committed Oct 19, 2023
1 parent 9258308 commit ff46311
Show file tree
Hide file tree
Showing 17 changed files with 366 additions and 392 deletions.
16 changes: 3 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@
// terms of the Steamworks API by Valve Corporation, the licensors of this
// Program grant you additional permission to convey the resulting work.

use crate::rpg;
use luminol_data::rpg;

#[derive(Default, Debug)]
pub struct Cache {}
pub struct Data {}

impl Cache {
impl Data {
/// Load all data required when opening a project.
/// Does not load config. That is expected to have been loaded beforehand.
pub fn load(&mut self) -> Result<(), String> {
todo!()
}

// TODO dependcy cycle
pub fn defaults_from_config(config: ()) -> Self {
pub fn defaults_from_config(config: &luminol_config::project::Config) -> Self {
todo!()
}

Expand Down Expand Up @@ -70,7 +70,7 @@ macro_rules! nested_ref_getter {

}

impl Cache {
impl Data {
nested_ref_getter! {
rpg::Actors, actors, State::Loaded;
rpg::Animations, animations, State::Loaded;
Expand Down
15 changes: 9 additions & 6 deletions crates/luminol-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@
use std::sync::Arc;

mod tab;
pub use tab::{Tab, Tabs};
pub use tab::{EditTabs, Tab, Tabs};

mod window;
pub use window::{Window, Windows};
pub use window::{EditWindows, Window, Windows};

pub mod modal;
pub use modal::Modal;

mod data_cache;
pub use data_cache::Data;

/// Toasts to be displayed for errors, information, etc.
mod toasts;
pub use toasts::Toasts;
Expand All @@ -42,14 +45,14 @@ pub struct UpdateState<'res, W, T> {

pub graphics: Arc<luminol_graphics::GraphicsState>,
pub filesystem: &'res mut luminol_filesystem::project::FileSystem, // FIXME: this is probably wrong
pub data: &'res mut luminol_data::data_cache::Cache, // FIXME: this is also probably wrong
pub data: &'res mut Data, // FIXME: this is also probably wrong

// TODO: look into std::any?
// we're using generics here to allow specialization on the type of window
// this is fucntionality not really used atm but maybe in the future..?
pub edit_windows: &'res mut window::EditWindows<W>,
pub edit_tabs: &'res mut tab::EditTabs<T>,
pub toasts: &'res mut toasts::Toasts,
pub edit_windows: &'res mut EditWindows<W>,
pub edit_tabs: &'res mut EditTabs<T>,
pub toasts: &'res mut Toasts,

pub project_config: &'res mut Option<luminol_config::project::Config>,
pub global_config: &'res mut luminol_config::global::Config,
Expand Down
4 changes: 2 additions & 2 deletions crates/luminol-core/src/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ where
self.clean_fn = Some(Box::new(f));
}

pub fn add_tab(&mut self, tabs: T) {
self.added.push(tabs)
pub fn add_tab(&mut self, tab: impl Into<T>) {
self.added.push(tab.into())
}

pub fn remove_tab(&mut self, tab: &T) -> bool {
Expand Down
29 changes: 13 additions & 16 deletions crates/luminol-core/src/toasts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,42 @@
// terms of the Steamworks API by Valve Corporation, the licensors of this
// Program grant you additional permission to convey the resulting work.

use egui_notify::{Toast, Toasts as ToastsInner};
use parking_lot::RwLock;

/// A toasts management struct.
#[derive(Default)]
pub struct Toasts {
inner: RwLock<ToastsInner>,
inner: egui_notify::Toasts,
}

// We wrap the toasts structs in a RefCell to maintain interior mutability.
#[allow(dead_code)]
impl Toasts {
/// Add a custom toast.
pub fn add(&self, toast: Toast) {
self.inner.write().add(toast);
pub fn add(&mut self, toast: egui_notify::Toast) {
self.inner.add(toast);
}

/// Display an info toast.
pub fn info(&self, caption: impl Into<String>) {
self.inner.write().info(caption);
pub fn info(&mut self, caption: impl Into<String>) {
self.inner.info(caption);
}

/// Display a warning toast.
pub fn warning(&self, caption: impl Into<String>) {
self.inner.write().warning(caption);
pub fn warning(&mut self, caption: impl Into<String>) {
self.inner.warning(caption);
}

/// Display an error toast.
pub fn error(&self, caption: impl Into<String>) {
self.inner.write().error(caption);
pub fn error(&mut self, caption: impl Into<String>) {
self.inner.error(caption);
}

/// Display a generic toast.
pub fn basic(&self, caption: impl Into<String>) {
self.inner.write().basic(caption);
pub fn basic(&mut self, caption: impl Into<String>) {
self.inner.basic(caption);
}

/// Display all toasts.
pub fn show(&self, ctx: &egui::Context) {
self.inner.write().show(ctx);
pub fn show(&mut self, ctx: &egui::Context) {
self.inner.show(ctx);
}
}
4 changes: 2 additions & 2 deletions crates/luminol-core/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ where
self.clean_fn = Some(Box::new(f));
}

pub fn add_window(&mut self, window: T) {
self.added.push(window)
pub fn add_window(&mut self, window: impl Into<T>) {
self.added.push(window.into())
}

pub fn remove_window(&mut self, window: &T) -> bool {
Expand Down
2 changes: 0 additions & 2 deletions crates/luminol-data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ mod rgss_structs;

mod helpers;

pub mod data_cache;

pub mod commands;

pub use helpers::*;
Expand Down
2 changes: 0 additions & 2 deletions crates/luminol-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,3 @@ reqwest = "0.11.22"
zip = { version = "0.6.6", default-features = false, features = ["deflate"] }

itertools.workspace = true

enum_dispatch = "0.3.12"
159 changes: 157 additions & 2 deletions crates/luminol-ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,161 @@
// terms of the Steamworks API by Valve Corporation, the licensors of this
// Program grant you additional permission to convey the resulting work.

mod tabs;
pub mod tabs;

mod windows;
pub mod windows;

macro_rules! tab_enum {
($visibility:vis enum $name:ident {
$( $variant:ident($variant_type:ty) ),* $(,)?
}) => {
$visibility enum $name {
$(
$variant($variant_type),
)*
}

impl luminol_core::Tab for $name {
fn name(&self) -> String {
match self {
$(
Self::$variant(v) => v.name(),
)*
}
}

fn id(&self) -> egui::Id {
match self {
$(
Self::$variant(v) => v.id(),
)*
}
}

fn show<W, T>(&mut self, ui: &mut egui::Ui, update_state: &mut luminol_core::UpdateState<'_, W, T>)
where
W: luminol_core::Window,
T: luminol_core::Tab
{
match self {
$(
Self::$variant(v) => v.show(ui, update_state),
)*
}
}

fn requires_filesystem(&self) -> bool {
match self {
$(
Self::$variant(v) => v.requires_filesystem(),
)*
}
}

fn force_close(&mut self) -> bool {
match self {
$(
Self::$variant(v) => v.force_close(),
)*
}
}
}

$(
impl From<$variant_type> for $name {
fn from(value: $variant_type) -> Self {
Self::$variant(value)
}
}
)*
};
}

macro_rules! window_enum {
($visibility:vis enum $name:ident {
$( $variant:ident($variant_type:ty) ),* $(,)?
}) => {
$visibility enum $name {
$(
$variant($variant_type),
)*
}

impl luminol_core::Window for $name {
fn show<W, T>(
&mut self,
ctx: &egui::Context,
open: &mut bool,
update_state: &mut luminol_core::UpdateState<'_, W, T>,
) where
W: luminol_core::Window,
T: luminol_core::Tab
{
match self {
$(
Self::$variant(v) => v.show(ctx, open, update_state),
)*
}
}

fn name(&self) -> String {
match self {
$(
Self::$variant(v) => v.name(),
)*
}
}

fn id(&self) -> egui::Id {
match self {
$(
Self::$variant(v) => v.id(),
)*
}
}

fn requires_filesystem(&self) -> bool {
match self {
$(
Self::$variant(v) => v.requires_filesystem(),
)*
}
}
}

$(
impl From<$variant_type> for $name {
fn from(value: $variant_type) -> Self {
Self::$variant(value)
}
}
)*
};
}

tab_enum! {
pub enum Tab {
Map(tabs::map::Tab),
Started(tabs::started::Tab)
}
}

window_enum! {
pub enum Window {
About(windows::about::Window),
Appearance(windows::appearance::Window),
CommonEvent(windows::common_event_edit::Window),
ProjectConfig(windows::config_window::Window),
Console(windows::console::Window),
EventEdit(windows::event_edit::Window),
GlobalConfig(windows::global_config_window::Window),
Items(windows::items::Window),
MapPicker(windows::map_picker::Window),
EguiInspection(windows::misc::EguiInspection),
EguiMemory(windows::misc::EguiMemory),
FilesystemDebug(windows::misc::FilesystemDebug),
NewProject(windows::new_project::Window),
ScriptEdit(windows::script_edit::Window),
SoundTest(windows::sound_test::Window)
}
}
6 changes: 3 additions & 3 deletions crates/luminol-ui/src/windows/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
// terms of the Steamworks API by Valve Corporation, the licensors of this
// Program grant you additional permission to convey the resulting work.

pub struct Console {
pub struct Window {
term: luminol_term::Terminal,
}

impl Console {
impl Window {
pub fn new(command: luminol_term::CommandBuilder) -> Result<Self, luminol_term::Error> {
Ok(Self {
term: luminol_term::Terminal::new(command)?,
})
}
}

impl luminol_core::Window for Console {
impl luminol_core::Window for Window {
fn name(&self) -> String {
self.term.title()
}
Expand Down
Loading

0 comments on commit ff46311

Please sign in to comment.