Skip to content

Commit

Permalink
Update gdext (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
TitanNano committed Jun 24, 2024
1 parent 821b21a commit da275fb
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 81 deletions.
35 changes: 13 additions & 22 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,8 +10,8 @@ version = "0.1.0"
edition = "2021"

[workspace.dependencies]
godot = { git = "https://github.com/godot-rust/gdext", rev = "22fd33d4d5213a3fe5db9a58547888cebe35c647" }
godot-cell = { git = "https://github.com/godot-rust/gdext", rev = "22fd33d4d5213a3fe5db9a58547888cebe35c647" }
godot = { git = "https://github.com/godot-rust/gdext", rev = "4c8ea83fc3452485f7b33f2411c136a248457334", features = ["experimental-threads"] }
godot-cell = { git = "https://github.com/godot-rust/gdext", rev = "4c8ea83fc3452485f7b33f2411c136a248457334" }
itertools = "0.10.3"
rand = "0.8.5"
darling = { version = "0.20.3" }
Expand Down
79 changes: 40 additions & 39 deletions rust-script/src/runtime/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl ToDictionary for PropertyInfo {

dict.set("name", self.property_name.clone());
dict.set("class_name", self.class_name.to_string_name());
dict.set("type", self.variant_type as i32);
dict.set("type", self.variant_type.ord());
dict.set("hint", self.hint.ord());
dict.set("hint_string", self.hint_string.clone());
dict.set("usage", self.usage.ord());
Expand Down Expand Up @@ -53,44 +53,45 @@ fn variant_type_to_str(var_type: VariantType) -> &'static str {
use VariantType as V;

match var_type {
V::Nil => "void",
V::Bool => "Bool",
V::Int => "Int",
V::Float => "Float",
V::String => "String",
V::Vector2 => "Vector2",
V::Vector2i => "Vector2i",
V::Rect2 => "Rect2",
V::Rect2i => "Rect2i",
V::Vector3 => "Vector3",
V::Vector3i => "Vector3i",
V::Transform2D => "Transform2D",
V::Vector4 => "Vector4",
V::Vector4i => "Vector4i",
V::Plane => "Plane",
V::Quaternion => "Quaternion",
V::Aabb => "Aabb",
V::Basis => "Basis",
V::Transform3D => "Transform3D",
V::Projection => "Projection",
V::Color => "Color",
V::StringName => "StringName",
V::NodePath => "NodePath",
V::Rid => "Rid",
V::Object => "Object",
V::Callable => "Callable",
V::Signal => "Signal",
V::Dictionary => "Dictionary",
V::Array => "Array",
V::PackedByteArray => "PackedByteArray",
V::PackedInt32Array => "PackedInt32Array",
V::PackedInt64Array => "PackedInt64Array",
V::PackedColorArray => "PackedColorArray",
V::PackedStringArray => "PackedStringArray",
V::PackedVector3Array => "PackedVector3Array",
V::PackedVector2Array => "PackedVector2Array",
V::PackedFloat64Array => "PackedFloat64Array",
V::PackedFloat32Array => "PackedFloat32Array",
V::NIL => "void",
V::BOOL => "Bool",
V::INT => "Int",
V::FLOAT => "Float",
V::STRING => "String",
V::VECTOR2 => "Vector2",
V::VECTOR2I => "Vector2i",
V::RECT2 => "Rect2",
V::RECT2I => "Rect2i",
V::VECTOR3 => "Vector3",
V::VECTOR3I => "Vector3i",
V::TRANSFORM2D => "Transform2D",
V::VECTOR4 => "Vector4",
V::VECTOR4I => "Vector4i",
V::PLANE => "Plane",
V::QUATERNION => "Quaternion",
V::AABB => "Aabb",
V::BASIS => "Basis",
V::TRANSFORM3D => "Transform3D",
V::PROJECTION => "Projection",
V::COLOR => "Color",
V::STRING_NAME => "StringName",
V::NODE_PATH => "NodePath",
V::RID => "Rid",
V::OBJECT => "Object",
V::CALLABLE => "Callable",
V::SIGNAL => "Signal",
V::DICTIONARY => "Dictionary",
V::ARRAY => "Array",
V::PACKED_BYTE_ARRAY => "PackedByteArray",
V::PACKED_INT32_ARRAY => "PackedInt32Array",
V::PACKED_INT64_ARRAY => "PackedInt64Array",
V::PACKED_COLOR_ARRAY => "PackedColorArray",
V::PACKED_STRING_ARRAY => "PackedStringArray",
V::PACKED_VECTOR3_ARRAY => "PackedVector3Array",
V::PACKED_VECTOR2_ARRAY => "PackedVector2Array",
V::PACKED_FLOAT64_ARRAY => "PackedFloat64Array",
V::PACKED_FLOAT32_ARRAY => "PackedFloat32Array",
_ => "UNKNOWN",
}
}

Expand Down
5 changes: 2 additions & 3 deletions rust-script/src/runtime/resource_saver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

use godot::global;
use godot::{
engine::{
file_access, global, resource_saver::SaverFlags, FileAccess, IResourceFormatSaver, Script,
},
engine::{file_access, resource_saver::SaverFlags, FileAccess, IResourceFormatSaver, Script},
obj::EngineBitfield,
prelude::{godot_api, godot_print, GString, Gd, GodotClass, PackedStringArray, Resource},
};
Expand Down
20 changes: 10 additions & 10 deletions rust-script/src/runtime/rust_script_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
*/

use core::panic;
use std::{collections::HashMap, fmt::Debug, ops::DerefMut, pin::Pin};
use std::{collections::HashMap, fmt::Debug, ops::DerefMut};

use godot::{
builtin::meta::{MethodInfo, PropertyInfo},
engine::{Script, ScriptInstance, SiMut},
prelude::{GString, Gd, Object, StringName, Variant, VariantType},
};
use godot_cell::GdCell;
use godot_cell::blocking::GdCell;

use crate::script_registry::GodotScriptObject;

Expand Down Expand Up @@ -51,7 +51,7 @@ fn script_property_list(script: &Gd<RustScript>) -> Box<[PropertyInfo]> {
}

pub struct Context<'a> {
cell: Pin<&'a GdCell<Box<dyn GodotScriptObject>>>,
cell: &'a GdCell<Box<dyn GodotScriptObject>>,
data_ptr: *mut Box<dyn GodotScriptObject>,
}

Expand All @@ -63,7 +63,7 @@ impl<'a> Debug for Context<'a> {

impl<'a> Context<'a> {
unsafe fn new(
cell: Pin<&'a GdCell<Box<dyn GodotScriptObject>>>,
cell: &'a GdCell<Box<dyn GodotScriptObject>>,
data_ptr: *mut Box<dyn GodotScriptObject>,
) -> Self {
Self { cell, data_ptr }
Expand Down Expand Up @@ -100,7 +100,7 @@ impl<'a> Context<'a> {
}

pub(super) struct RustScriptInstance {
data: Pin<Box<GdCell<Box<dyn GodotScriptObject>>>>,
data: GdCell<Box<dyn GodotScriptObject>>,

script: Gd<RustScript>,
generic_script: Gd<Script>,
Expand Down Expand Up @@ -132,14 +132,14 @@ impl ScriptInstance for RustScriptInstance {
}

fn set_property(this: SiMut<Self>, name: StringName, value: &Variant) -> bool {
let cell_ref = this.data.as_ref();
let cell_ref = &this.data;
let mut mut_data = cell_ref.borrow_mut().unwrap();

mut_data.set(name, value.to_owned())
}

fn get_property(&self, name: StringName) -> Option<Variant> {
let guard = self.data.as_ref().borrow().unwrap();
let guard = self.data.borrow().unwrap();

guard.get(name)
}
Expand All @@ -157,7 +157,7 @@ impl ScriptInstance for RustScriptInstance {
method: StringName,
args: &[&Variant],
) -> Result<Variant, godot::sys::GDExtensionCallErrorType> {
let cell = this.data.as_ref();
let cell = &this.data;
let mut data_guard = cell.borrow_mut().unwrap();
let data = data_guard.deref_mut();
let data_ptr = data as *mut _;
Expand Down Expand Up @@ -186,7 +186,7 @@ impl ScriptInstance for RustScriptInstance {
.iter()
.find(|prop| prop.property_name == name)
.map(|prop| prop.variant_type)
.unwrap_or(godot::sys::VariantType::Nil)
.unwrap_or(godot::sys::VariantType::NIL)
}

fn to_string(&self) -> GString {
Expand Down Expand Up @@ -306,7 +306,7 @@ impl ScriptInstance for RustScriptPlaceholder {
.iter()
.find(|prop| prop.property_name == name)
.map(|prop| prop.variant_type)
.unwrap_or(VariantType::Nil)
.unwrap_or(VariantType::NIL)
}

fn to_string(&self) -> GString {
Expand Down
8 changes: 4 additions & 4 deletions rust-script/src/runtime/rust_script_language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ impl IScriptLanguageExtension for RustScriptLanguage {
) -> Dictionary {
let mut validation = Dictionary::new();

validation.insert("valid", "true");
validation.insert("errors", VariantArray::new());
validation.insert("functions", VariantArray::new());
validation.insert("warnings", VariantArray::new());
validation.set("valid", "true");
validation.set("errors", VariantArray::new());
validation.set("functions", VariantArray::new());
validation.set("warnings", VariantArray::new());

validation
}
Expand Down
2 changes: 1 addition & 1 deletion rust-script/src/script_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl From<&RustScriptSignalInfo> for MethodInfo {
method_name: value.name.into(),
class_name: ClassName::none(),
return_type: PropertyInfo {
variant_type: VariantType::Nil,
variant_type: VariantType::NIL,
class_name: ClassName::none(),
property_name: StringName::default(),
hint: PropertyHint::NONE,
Expand Down

0 comments on commit da275fb

Please sign in to comment.