-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
883: Property support for std collection types r=Bromeon a=ironpeak Implemented the `Export` trait for `HashMap`, `HashSet` (new) and `Vec` so that they can be exported. The PR also includes an example project using the types as properties. Co-authored-by: Hrafn Orri Hrafnkelsson <HrafnOrri@BitCrow.net> Co-authored-by: Jan Haller <bromeon@gmail.com>
- Loading branch information
Showing
22 changed files
with
351 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
examples/array-export/Cargo.toml → examples/builder-export/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
examples/array-export/ExportsArrays.gdns → examples/builder-export/ExportsArrays.gdns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[entry] | ||
|
||
X11.64="res://../../target/debug/libbuilder_export.so" | ||
OSX.64="res://../../target/debug/libbuilder_export.dylib" | ||
Windows.64="res://../../target/debug/builder_export.dll" | ||
|
||
[dependencies] | ||
|
||
X11.64=[ ] | ||
OSX.64=[ ] | ||
|
||
[general] | ||
|
||
singleton=false | ||
load_once=true | ||
symbol_prefix="godot_" | ||
reloadable=true |
File renamed without changes.
File renamed without changes
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "property-export" | ||
version = "0.1.0" | ||
authors = ["The godot-rust developers"] | ||
edition = "2021" | ||
rust-version = "1.56" | ||
license = "MIT" | ||
publish = false | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
gdnative = { path = "../../gdnative" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
extends Node | ||
|
||
func _ready(): | ||
var rust = get_node("../PropertyExport") | ||
|
||
print("\n-----------------------------------------------------------------") | ||
print("Print from GDScript (note the lexicographically ordered map/set):") | ||
print(" Vec (name):"); | ||
for name in rust.name_vec: | ||
print(" * %s" % name) | ||
|
||
print("\n HashMap (string -> color):") | ||
for string in rust.color_map: | ||
var color = rust.color_map[string] | ||
print(" * %s -> #%s" % [string, color.to_html(false)]); | ||
|
||
print("\n HashSet (ID):") | ||
for id in rust.id_set: | ||
print(" * %s" % id) | ||
|
||
# The program has printed the contents and fulfilled its purpose, quit | ||
get_tree().quit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[gd_scene load_steps=4 format=2] | ||
|
||
[ext_resource path="res://property_export_library.gdnlib" type="GDNativeLibrary" id=1] | ||
[ext_resource path="res://GDScriptPrinter.gd" type="Script" id=2] | ||
|
||
[sub_resource type="NativeScript" id=1] | ||
resource_name = "PropertyExport" | ||
class_name = "PropertyExport" | ||
library = ExtResource( 1 ) | ||
|
||
[node name="Node" type="Node"] | ||
|
||
[node name="PropertyExport" type="Node" parent="."] | ||
script = SubResource( 1 ) | ||
name_vec = [ "Godot", "Godette", "Go ." ] | ||
color_map = { | ||
"blue": Color( 0.184314, 0.160784, 0.8, 1 ), | ||
"green": Color( 0.0941176, 0.447059, 0.192157, 1 ), | ||
"teal": Color( 0.0941176, 0.423529, 0.564706, 1 ) | ||
} | ||
id_set = [ 21, 77, 8, 90 ] | ||
|
||
[node name="GDScriptPrinter" type="Node" parent="."] | ||
script = ExtResource( 2 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[gd_resource type="Environment" load_steps=2 format=2] | ||
|
||
[sub_resource type="ProceduralSky" id=1] | ||
sky_top_color = Color( 0.0470588, 0.454902, 0.976471, 1 ) | ||
sky_horizon_color = Color( 0.556863, 0.823529, 0.909804, 1 ) | ||
sky_curve = 0.25 | ||
ground_bottom_color = Color( 0.101961, 0.145098, 0.188235, 1 ) | ||
ground_horizon_color = Color( 0.482353, 0.788235, 0.952941, 1 ) | ||
ground_curve = 0.01 | ||
sun_energy = 16.0 | ||
|
||
[resource] | ||
background_mode = 2 | ||
background_sky = SubResource( 1 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
; Engine configuration file. | ||
; It's best edited using the editor UI and not directly, | ||
; since the parameters that go here are not all obvious. | ||
; | ||
; Format: | ||
; [section] ; section goes between [] | ||
; param=value ; assign values to parameters | ||
|
||
config_version=4 | ||
|
||
_global_script_classes=[ ] | ||
_global_script_class_icons={ | ||
} | ||
|
||
[application] | ||
|
||
config/name="Godot Rust - Property Export" | ||
run/main_scene="res://Main.tscn" | ||
|
||
[rendering] | ||
|
||
environment/default_environment="res://default_env.tres" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[entry] | ||
|
||
X11.64="res://../../target/debug/libproperty_export.so" | ||
OSX.64="res://../../target/debug/libproperty_export.dylib" | ||
Windows.64="res://../../target/debug/property_export.dll" | ||
|
||
[dependencies] | ||
|
||
X11.64=[ ] | ||
OSX.64=[ ] | ||
|
||
[general] | ||
|
||
singleton=false | ||
load_once=true | ||
symbol_prefix="godot_" | ||
reloadable=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use gdnative::prelude::*; | ||
|
||
use std::collections::{HashMap, HashSet}; | ||
|
||
#[derive(NativeClass, Default)] | ||
#[inherit(Node)] | ||
pub struct PropertyExport { | ||
#[property] | ||
name_vec: Vec<String>, | ||
|
||
#[property] | ||
color_map: HashMap<GodotString, Color>, | ||
|
||
#[property] | ||
id_set: HashSet<i64>, | ||
} | ||
|
||
#[methods] | ||
impl PropertyExport { | ||
fn new(_base: &Node) -> Self { | ||
Self::default() | ||
} | ||
|
||
#[export] | ||
fn _ready(&self, _base: &Node) { | ||
godot_print!("------------------------------------------------------------------"); | ||
godot_print!("Print from Rust (note the unordered map/set):"); | ||
godot_print!(" Vec (name):"); | ||
for name in &self.name_vec { | ||
godot_print!(" * {}", name); | ||
} | ||
|
||
godot_print!("\n HashMap (string -> color):"); | ||
for (string, color) in &self.color_map { | ||
godot_print!(" * {} -> #{}", string, color.to_html(false)); | ||
} | ||
|
||
godot_print!("\n HashSet (ID):"); | ||
for id in &self.id_set { | ||
godot_print!(" * {}", id); | ||
} | ||
} | ||
} | ||
|
||
fn init(handle: InitHandle) { | ||
handle.add_class::<PropertyExport>(); | ||
} | ||
|
||
godot_init!(init); |
Oops, something went wrong.