Skip to content

Commit

Permalink
Update to latest gdext (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
TitanNano authored Nov 21, 2023
1 parent c5c697c commit 32c0f62
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 89 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ version = "0.1.0"
edition = "2021"

[workspace.dependencies]
godot = { git = "https://github.com/titannano/gdext", rev = "0f9a3e22f9cbdc31e0c575a12c69d26241a92f9f" }
godot = { git = "https://github.com/titannano/gdext", rev = "a5d17342b7b47e8af652a6a733f497c468bbd59a" }
hot-lib-reloader = "0.6.5"
itertools = "0.10.3"
abi_stable = { version = "0.11.2", default-features = false }
Expand All @@ -23,4 +23,4 @@ syn = "2.0.38"
process_path = "0.1"

godot-rust-script-derive = { path = "derive" }
tests-scripts-lib = { path = "tests-scripts-lib" }
tests-scripts-lib = { path = "tests-scripts-lib" }
4 changes: 2 additions & 2 deletions rust-script/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ impl RustScriptExtensionLayer {

let lang: Gd<RustScriptLanguage> = RustScriptLanguage::new(self.scripts_src_dir);
let res_loader = RustScriptResourceLoader::new(lang.clone());
let res_saver = Gd::new(RustScriptResourceSaver);
let res_saver = Gd::from_object(RustScriptResourceSaver);

cfg_if! {
if #[cfg(all(feature = "hot-reload", debug_assertions))] {
use godot::prelude::StringName;

let mut hot_reloader = Gd::with_base(|base| HotReloader::new((self.hot_reload_subscribe)(), self.lib_init_fn.clone(), base));
let mut hot_reloader = Gd::from_init_fn(|base| HotReloader::new((self.hot_reload_subscribe)(), self.lib_init_fn.clone(), base));

hot_reloader.call_deferred(StringName::from("register"), &[]);

Expand Down
20 changes: 9 additions & 11 deletions rust-script/src/runtime/resource_loader.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use godot::{
engine::{
file_access, FileAccess, ResourceFormatLoaderVirtual, Script,
ScriptLanguageExtensionVirtual,
},
engine::{file_access, FileAccess, IResourceFormatLoader, IScriptLanguageExtension, Script},
prelude::{
godot_api, Gd, GodotClass, GodotString, PackedStringArray, StringName, ToGodot, Variant,
godot_api, GString, Gd, GodotClass, PackedStringArray, StringName, ToGodot, Variant,
},
};

Expand All @@ -18,23 +15,24 @@ pub(super) struct RustScriptResourceLoader {

impl RustScriptResourceLoader {
pub fn new(script_lang: Gd<RustScriptLanguage>) -> Gd<Self> {
Gd::new(Self { script_lang })
Gd::from_object(Self { script_lang })
}
}

#[godot_api]
impl ResourceFormatLoaderVirtual for RustScriptResourceLoader {
impl IResourceFormatLoader for RustScriptResourceLoader {
fn handles_type(&self, type_: StringName) -> bool {
type_ == StringName::from("Script") || type_ == self.script_lang.bind().get_type().into()
}
fn get_resource_type(&self, path: GodotString) -> GodotString {

fn get_resource_type(&self, path: GString) -> GString {
let script_lang = self.script_lang.bind();
let ext_match = path
.to_string()
.ends_with(&script_lang.get_extension().to_string());

if !ext_match {
return GodotString::new();
return GString::new();
}

script_lang.get_type()
Expand All @@ -46,8 +44,8 @@ impl ResourceFormatLoaderVirtual for RustScriptResourceLoader {

fn load(
&self,
path: GodotString,
original_path: GodotString,
path: GString,
original_path: GString,
_use_sub_threads: bool,
_cache_mode: i32,
) -> Variant {
Expand Down
13 changes: 6 additions & 7 deletions rust-script/src/runtime/resource_saver.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use godot::{
engine::{
file_access, global, resource_saver::SaverFlags, FileAccess, ResourceFormatSaverVirtual,
Script,
file_access, global, resource_saver::SaverFlags, FileAccess, IResourceFormatSaver, Script,
},
obj::EngineEnum,
prelude::{godot_api, godot_print, Gd, GodotClass, GodotString, PackedStringArray, Resource},
prelude::{godot_api, godot_print, GString, Gd, GodotClass, PackedStringArray, Resource},
};

use super::rust_script::RustScript;
Expand All @@ -14,8 +13,8 @@ use super::rust_script::RustScript;
pub struct RustScriptResourceSaver;

#[godot_api]
impl ResourceFormatSaverVirtual for RustScriptResourceSaver {
fn save(&mut self, resource: Gd<Resource>, path: GodotString, flags: u32) -> global::Error {
impl IResourceFormatSaver for RustScriptResourceSaver {
fn save(&mut self, resource: Gd<Resource>, path: GString, flags: u32) -> global::Error {
let mut script: Gd<Script> = resource.cast();

godot_print!("saving rust script resource to: {}", path);
Expand All @@ -42,9 +41,9 @@ impl ResourceFormatSaverVirtual for RustScriptResourceSaver {
resource.try_cast::<RustScript>().is_some()
}
fn get_recognized_extensions(&self, _resource: Gd<Resource>) -> PackedStringArray {
PackedStringArray::from(&[GodotString::from("rs")])
PackedStringArray::from(&[GString::from("rs")])
}
fn recognize_path(&self, _resource: Gd<Resource>, _path: GodotString) -> bool {
fn recognize_path(&self, _resource: Gd<Resource>, _path: GString) -> bool {
true
}
}
53 changes: 27 additions & 26 deletions rust-script/src/runtime/rust_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use std::{ffi::c_void, ops::Deref};
use abi_stable::std_types::RBox;
use godot::{
builtin::create_script_instance,
engine::{Engine, Script, ScriptExtension, ScriptExtensionVirtual, ScriptLanguage},
engine::{Engine, IScriptExtension, Script, ScriptExtension, ScriptLanguage},
obj::UserClass,
prelude::{
godot_api, Array, Base, Dictionary, Gd, GodotClass, GodotString, Object, StringName,
godot_api, Array, Base, Dictionary, GString, Gd, GodotClass, Object, StringName,
VariantArray,
},
};
Expand All @@ -30,14 +31,14 @@ pub(super) struct RustScript {

impl RustScript {
pub fn new(class_name: String) -> Gd<Self> {
Gd::with_base(|base| Self {
Gd::from_init_fn(|base| Self {
class_name,
source_code: String::new(),
base,
})
}

pub fn class_name(&self) -> GodotString {
pub fn class_name(&self) -> GString {
self.class_name.clone().into()
}

Expand All @@ -61,7 +62,7 @@ impl RustScript {
}

#[godot_api]
impl ScriptExtensionVirtual for RustScript {
impl IScriptExtension for RustScript {
fn init(base: Base<Self::Base>) -> Self {
Self {
class_name: String::new(),
Expand All @@ -70,15 +71,15 @@ impl ScriptExtensionVirtual for RustScript {
}
}

fn get_source_code(&self) -> GodotString {
fn get_source_code(&self) -> GString {
self.source_code.clone().into()
}
fn set_source_code(&mut self, code: GodotString) {
fn set_source_code(&mut self, code: GString) {
self.source_code = code.to_string();
}

fn get_language(&self) -> Option<Gd<ScriptLanguage>> {
Some(Gd::<RustScriptLanguage>::new_default().upcast())
Some(RustScriptLanguage::alloc_gd().upcast())
}

fn can_instantiate(&self) -> bool {
Expand Down Expand Up @@ -223,24 +224,24 @@ impl ScriptExtensionVirtual for RustScript {
.unwrap_or_default();

let class_doc = Dictionary::new().apply(|dict| {
dict.set(GodotString::from("name"), self.class_name());
dict.set(GodotString::from("inherits"), self.get_instance_base_type());
dict.set(GodotString::from("brief_description"), GodotString::new());
dict.set(GodotString::from("description"), description);
dict.set(GodotString::from("tutorials"), VariantArray::new());
dict.set(GodotString::from("constructors"), VariantArray::new());
dict.set(GodotString::from("methods"), methods);
dict.set(GodotString::from("operators"), VariantArray::new());
dict.set(GodotString::from("signals"), VariantArray::new());
dict.set(GodotString::from("constants"), VariantArray::new());
dict.set(GodotString::from("enums"), VariantArray::new());
dict.set(GodotString::from("properties"), props);
dict.set(GodotString::from("theme_properties"), VariantArray::new());
dict.set(GodotString::from("annotations"), VariantArray::new());
dict.set(GodotString::from("is_deprecated"), false);
dict.set(GodotString::from("is_experimental"), false);
dict.set(GodotString::from("is_script_doc"), true);
dict.set(GodotString::from("script_path"), self.base.get_path());
dict.set(GString::from("name"), self.class_name());
dict.set(GString::from("inherits"), self.get_instance_base_type());
dict.set(GString::from("brief_description"), GString::new());
dict.set(GString::from("description"), description);
dict.set(GString::from("tutorials"), VariantArray::new());
dict.set(GString::from("constructors"), VariantArray::new());
dict.set(GString::from("methods"), methods);
dict.set(GString::from("operators"), VariantArray::new());
dict.set(GString::from("signals"), VariantArray::new());
dict.set(GString::from("constants"), VariantArray::new());
dict.set(GString::from("enums"), VariantArray::new());
dict.set(GString::from("properties"), props);
dict.set(GString::from("theme_properties"), VariantArray::new());
dict.set(GString::from("annotations"), VariantArray::new());
dict.set(GString::from("is_deprecated"), false);
dict.set(GString::from("is_experimental"), false);
dict.set(GString::from("is_script_doc"), true);
dict.set(GString::from("script_path"), self.base.get_path());
});

Array::from(&[class_doc])
Expand Down
19 changes: 10 additions & 9 deletions rust-script/src/runtime/rust_script_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ use cfg_if::cfg_if;
use godot::{
builtin::ScriptInstance,
engine::Script,
obj::UserClass,
prelude::{
godot_print,
meta::{MethodInfo, PropertyInfo},
Gd, GodotString, Object, StringName, Variant, VariantType,
GString, Gd, Object, StringName, Variant, VariantType,
},
};

Expand Down Expand Up @@ -44,7 +45,7 @@ fn script_method_list(script: &Gd<RustScript>) -> Rc<Vec<MethodInfo>> {
})
}

fn script_class_name(script: &Gd<RustScript>) -> GodotString {
fn script_class_name(script: &Gd<RustScript>) -> GString {
script.bind().class_name()
}

Expand Down Expand Up @@ -170,7 +171,7 @@ cfg_if! {
}

impl ScriptInstance for RustScriptInstance {
fn class_name(&self) -> GodotString {
fn class_name(&self) -> GString {
script_class_name(&self.script)
}

Expand Down Expand Up @@ -247,7 +248,7 @@ impl ScriptInstance for RustScriptInstance {
.unwrap_or(godot::sys::VariantType::Nil)
}

fn to_string(&self) -> GodotString {
fn to_string(&self) -> GString {
self.with_data(|data| data.to_string()).into_string().into()
}

Expand All @@ -268,7 +269,7 @@ impl ScriptInstance for RustScriptInstance {
}

fn language(&self) -> Gd<godot::engine::ScriptLanguage> {
Gd::<RustScriptLanguage>::new_default().upcast()
RustScriptLanguage::alloc_gd().upcast()
}

fn refcount_decremented(&self) -> bool {
Expand All @@ -293,7 +294,7 @@ impl RustScriptPlaceholder {
}

impl ScriptInstance for RustScriptPlaceholder {
fn class_name(&self) -> GodotString {
fn class_name(&self) -> GString {
script_class_name(&self.script)
}

Expand Down Expand Up @@ -353,8 +354,8 @@ impl ScriptInstance for RustScriptPlaceholder {
.unwrap_or(VariantType::Nil)
}

fn to_string(&self) -> GodotString {
GodotString::new()
fn to_string(&self) -> GString {
GString::new()
}

fn owner(&self) -> Gd<godot::prelude::Object> {
Expand All @@ -369,7 +370,7 @@ impl ScriptInstance for RustScriptPlaceholder {
}

fn language(&self) -> Gd<godot::engine::ScriptLanguage> {
Gd::<RustScriptLanguage>::new_default().upcast()
RustScriptLanguage::alloc_gd().upcast()
}

fn refcount_decremented(&self) -> bool {
Expand Down
Loading

0 comments on commit 32c0f62

Please sign in to comment.