Skip to content

Commit 3cf3a93

Browse files
committed
Update examples (single exported class, different element types, no icon)
1 parent 5204ec9 commit 3cf3a93

File tree

6 files changed

+35
-125
lines changed

6 files changed

+35
-125
lines changed

examples/property-export/Main.tscn

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,20 @@
1-
[gd_scene load_steps=5 format=2]
1+
[gd_scene load_steps=3 format=2]
22

33
[ext_resource path="res://property_export_library.gdnlib" type="GDNativeLibrary" id=1]
44

55
[sub_resource type="NativeScript" id=1]
6-
resource_name = "ExampleHashMapProperty"
7-
class_name = "ExampleHashMapProperty"
8-
library = ExtResource( 1 )
9-
10-
[sub_resource type="NativeScript" id=2]
11-
resource_name = "ExampleHashSetProperty"
12-
class_name = "ExampleHashSetProperty"
13-
library = ExtResource( 1 )
14-
15-
[sub_resource type="NativeScript" id=3]
16-
resource_name = "ExampleVecProperty"
17-
class_name = "ExampleVecProperty"
6+
resource_name = "PropertyExport"
7+
class_name = "PropertyExport"
188
library = ExtResource( 1 )
199

2010
[node name="Node" type="Node"]
2111

22-
[node name="HashMap" type="Node" parent="."]
12+
[node name="PropertyExport" type="Node" parent="."]
2313
script = SubResource( 1 )
24-
players = {
25-
0: "Player0",
26-
1: "Player1"
14+
name_vec = [ "Godot", "Godette", "Go ." ]
15+
color_map = {
16+
"blue": Color( 0.184314, 0.160784, 0.8, 1 ),
17+
"green": Color( 0.0941176, 0.447059, 0.192157, 1 ),
18+
"teal": Color( 0.0941176, 0.423529, 0.564706, 1 )
2719
}
28-
29-
[node name="HashSet" type="Node" parent="."]
30-
script = SubResource( 2 )
31-
players = [ "Player0", "Player0", "Player1" ]
32-
33-
[node name="Vec" type="Node" parent="."]
34-
script = SubResource( 3 )
35-
players = [ "Player0", "Player1" ]
20+
id_set = [ 21, 77, 8, 90 ]

examples/property-export/icon.png

-3.42 KB
Binary file not shown.

examples/property-export/icon.png.import

Lines changed: 0 additions & 35 deletions
This file was deleted.

examples/property-export/project.godot

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ _global_script_class_icons={
1616

1717
config/name="Godot Rust - Property Export"
1818
run/main_scene="res://Main.tscn"
19-
config/icon="res://icon.png"
2019

2120
[rendering]
2221

examples/property-export/src/lib.rs

Lines changed: 24 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,51 @@
1-
use gdnative::api::*;
21
use gdnative::prelude::*;
32

43
use std::collections::{HashMap, HashSet};
54

6-
// HashMap
75
#[derive(NativeClass, Default)]
86
#[inherit(Node)]
9-
pub struct ExampleHashMapProperty {
7+
pub struct PropertyExport {
108
#[property]
11-
players: HashMap<i64, String>,
12-
}
13-
14-
impl ExampleHashMapProperty {
15-
fn new(_owner: &Node) -> Self {
16-
Self::default()
17-
}
18-
}
9+
name_vec: Vec<String>,
1910

20-
#[methods]
21-
impl ExampleHashMapProperty {
22-
#[export]
23-
fn _ready(&self, _owner: &Node) {
24-
godot_print!("HashMap:");
25-
for (id, name) in &self.players {
26-
godot_print!("Hello, {} - {}!", id, name);
27-
}
28-
}
29-
}
11+
#[property]
12+
color_map: HashMap<GodotString, Color>,
3013

31-
// HashSet
32-
#[derive(NativeClass, Default)]
33-
#[inherit(Node)]
34-
pub struct ExampleHashSetProperty {
3514
#[property]
36-
players: HashSet<String>,
15+
id_set: HashSet<i64>,
3716
}
3817

39-
impl ExampleHashSetProperty {
40-
fn new(_owner: &Node) -> Self {
18+
#[methods]
19+
impl PropertyExport {
20+
fn new(_base: &Node) -> Self {
4121
Self::default()
4222
}
43-
}
4423

45-
#[methods]
46-
impl ExampleHashSetProperty {
4724
#[export]
48-
fn _ready(&self, _owner: &Node) {
49-
godot_print!("HashSet:");
50-
for name in &self.players {
51-
godot_print!("Hello, {}!", name);
25+
fn _ready(&self, base: &Node) {
26+
godot_print!("Vec (name):");
27+
for name in &self.name_vec {
28+
godot_print!("* {}", name);
5229
}
53-
}
54-
}
55-
56-
// Vec
57-
#[derive(NativeClass, Default)]
58-
#[inherit(Node)]
59-
pub struct ExampleVecProperty {
60-
#[property]
61-
players: Vec<String>,
62-
}
6330

64-
impl ExampleVecProperty {
65-
fn new(_owner: &Node) -> Self {
66-
Self::default()
67-
}
68-
}
31+
godot_print!("\nHashMap (string -> color):");
32+
for (string, color) in &self.color_map {
33+
godot_print!("* {} -> #{}", string, color.to_html(false));
34+
}
6935

70-
#[methods]
71-
impl ExampleVecProperty {
72-
#[export]
73-
fn _ready(&self, _owner: &Node) {
74-
godot_print!("Vec:");
75-
for name in &self.players {
76-
godot_print!("Hello, {}!", name);
36+
godot_print!("\nHashSet (ID):");
37+
for id in &self.id_set {
38+
godot_print!("* {}", id);
7739
}
40+
41+
// The program has printed the contents and fulfilled its purpose, quit
42+
let scene_tree = base.get_tree().unwrap();
43+
unsafe { scene_tree.assume_safe() }.quit(0);
7844
}
7945
}
8046

81-
// Function that registers all exposed classes to Godot
8247
fn init(handle: InitHandle) {
83-
// Register the new `HelloWorld` type we just declared.
84-
handle.add_class::<ExampleHashMapProperty>();
85-
handle.add_class::<ExampleHashSetProperty>();
86-
handle.add_class::<ExampleVecProperty>();
48+
handle.add_class::<PropertyExport>();
8749
}
8850

89-
// Macro that creates the entry-points of the dynamic library.
9051
godot_init!(init);

gdnative-core/src/core_types/variant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1643,7 +1643,7 @@ impl<T: ToVariant> ToVariant for HashSet<T> {
16431643
}
16441644
}
16451645

1646-
impl<T: Eq + std::hash::Hash + FromVariant> FromVariant for HashSet<T> {
1646+
impl<T: FromVariant + Eq + Hash> FromVariant for HashSet<T> {
16471647
#[inline]
16481648
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError> {
16491649
let arr = VariantArray::from_variant(variant)?;

0 commit comments

Comments
 (0)