From 2efb3aff04e8dea2aa33689d3187e8f8c4e80dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thea=20Sch=C3=B6bl?= Date: Wed, 10 May 2023 17:04:31 +0200 Subject: [PATCH] mhk3 --- rust/mhgd/Cargo.toml | 13 +++++++++++++ rust/mhgd/src/lib.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 rust/mhgd/Cargo.toml create mode 100644 rust/mhgd/src/lib.rs diff --git a/rust/mhgd/Cargo.toml b/rust/mhgd/Cargo.toml new file mode 100644 index 0000000..64559d7 --- /dev/null +++ b/rust/mhgd/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "mhgd" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +godot = { git = "https://github.com/godot-rust/gdext", branch = "master" } +lightwave-3d = "1.0.0" +itertools = "0.10.5" +starforcelib = { path = "../starforcelib" } +springylib = { path = "../springylib" } diff --git a/rust/mhgd/src/lib.rs b/rust/mhgd/src/lib.rs new file mode 100644 index 0000000..d00f7b9 --- /dev/null +++ b/rust/mhgd/src/lib.rs @@ -0,0 +1,40 @@ +use crate::sproing::datafile::DatafileLoader; +use ::godot::engine::class_macros::auto_register_classes; +use ::godot::engine::{ResourceFormatLoaderVirtual, ResourceLoader}; +use ::godot::init::{gdextension, ExtensionLayer}; +use ::godot::prelude::{ExtensionLibrary, Gd, InitHandle, InitLevel, Share}; + +pub mod sproing; +pub mod lightwave_object; + +struct Main {} + +#[gdextension] +unsafe impl ExtensionLibrary for Main { + fn load_library(handle: &mut InitHandle) -> bool { + handle.register_layer(InitLevel::Editor, ResourceLoaderLayer { datafile: None }); + true + } +} + +struct ResourceLoaderLayer { + pub datafile: Option>, +} + +impl ExtensionLayer for ResourceLoaderLayer { + fn initialize(&mut self) { + auto_register_classes(); + + self.datafile = Some(Gd::::with_base(DatafileLoader::init)); + + ResourceLoader::singleton() + .add_resource_format_loader(self.datafile.as_ref().unwrap().share().upcast(), true); + } + + fn deinitialize(&mut self) { + if let Some(datafile) = &self.datafile { + ResourceLoader::singleton().remove_resource_format_loader(datafile.share().upcast()); + self.datafile = None; + } + } +}