Skip to content

Commit bbe12cf

Browse files
Taylor C. Richbergertoasteater
authored andcommitted
Add array export hint
1 parent 9c7c8da commit bbe12cf

File tree

12 files changed

+268
-2
lines changed

12 files changed

+268
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ members = [
1515
"examples/resource",
1616
"examples/native_plugin",
1717
"examples/rpc",
18+
"examples/array_export",
1819
"impl/proc_macros"
1920
]
2021

examples/array_export/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "array_export"
3+
version = "0.1.0"
4+
authors = ["The godot-rust developers"]
5+
publish = false
6+
edition = "2018"
7+
8+
[lib]
9+
crate-type = ["cdylib"]
10+
11+
[dependencies]
12+
gdnative = { path = "../../gdnative" }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[gd_resource type="NativeScript" load_steps=2 format=2]
2+
3+
[ext_resource path="res://array_export_library.gdnlib" type="GDNativeLibrary" id=1]
4+
5+
[resource]
6+
resource_name = "ExportsArrays"
7+
class_name = "ExportsArrays"
8+
library = ExtResource( 1 )
9+
script_class_name = "ExportsArrays"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[gd_scene load_steps=2 format=2]
2+
3+
[ext_resource path="res://ExportsArrays.gdns" type="Script" id=1]
4+
5+
[node name="ExportsArrays" type="Node"]
6+
script = ExtResource( 1 )
7+
single_array = [ 133.7, 1337, "Third Element" ]
8+
single_array_range = [ -5, 1, 3, -3, 0 ]
9+
double_array = [ [ 6, "(0, 1)" ], [ "Element 1, 0", 1375.5 ] ]
10+
double_array_range = [ [ -2, 3 ], [ 4, -5 ] ]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[entry]
2+
3+
X11.64="res://../../target/debug/libarray_export.so"
4+
OSX.64="res://../../target/debug/libarray_export.dylib"
5+
Windows.64="res://../../target/debug/array_export.dll"
6+
7+
[dependencies]
8+
9+
X11.64=[ ]
10+
OSX.64=[ ]
11+
12+
[general]
13+
14+
singleton=false
15+
load_once=true
16+
symbol_prefix="godot_"
17+
reloadable=true
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[gd_resource type="Environment" load_steps=2 format=2]
2+
3+
[sub_resource type="ProceduralSky" id=1]
4+
5+
[resource]
6+
background_mode = 2
7+
background_sky = SubResource( 1 )

examples/array_export/icon.png

5.38 KB
Loading

examples/array_export/icon.png.import

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="StreamTexture"
5+
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
6+
metadata={
7+
"vram_texture": false
8+
}
9+
10+
[deps]
11+
12+
source_file="res://icon.png"
13+
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
14+
15+
[params]
16+
17+
compress/mode=0
18+
compress/lossy_quality=0.7
19+
compress/hdr_mode=0
20+
compress/bptc_ldr=0
21+
compress/normal_map=0
22+
flags/repeat=0
23+
flags/filter=true
24+
flags/mipmaps=false
25+
flags/anisotropic=false
26+
flags/srgb=2
27+
process/fix_alpha_border=true
28+
process/premult_alpha=false
29+
process/HDR_as_SRGB=false
30+
process/invert_color=false
31+
stream=false
32+
size_limit=0
33+
detect_3d=true
34+
svg/scale=1.0

examples/array_export/project.godot

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; Engine configuration file.
2+
; It's best edited using the editor UI and not directly,
3+
; since the parameters that go here are not all obvious.
4+
;
5+
; Format:
6+
; [section] ; section goes between []
7+
; param=value ; assign values to parameters
8+
9+
config_version=4
10+
11+
_global_script_classes=[ {
12+
"base": "",
13+
"class": "ExportsArrays",
14+
"language": "NativeScript",
15+
"path": "res://ExportsArrays.gdns"
16+
} ]
17+
_global_script_class_icons={
18+
"ExportsArrays": ""
19+
}
20+
21+
[application]
22+
23+
config/name="array_export"
24+
run/main_scene="res://ExportsArrays.tscn"
25+
config/icon="res://icon.png"
26+
27+
[rendering]
28+
29+
quality/driver/driver_name="GLES2"
30+
vram_compression/import_etc=true
31+
vram_compression/import_etc2=false
32+
environment/default_environment="res://default_env.tres"

examples/array_export/src/lib.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use gdnative::nativescript::init::property::hint::{ArrayHint, IntHint, RangeHint};
2+
use gdnative::prelude::*;
3+
4+
#[derive(NativeClass)]
5+
#[inherit(Node)]
6+
#[register_with(Self::register)]
7+
struct ExportsArrays;
8+
9+
#[gdnative::methods]
10+
impl ExportsArrays {
11+
fn new(_owner: &Node) -> Self {
12+
ExportsArrays
13+
}
14+
15+
fn register(builder: &ClassBuilder<Self>) {
16+
builder
17+
.add_property::<VariantArray>("single_array")
18+
.with_setter(ExportsArrays::set_single_array)
19+
.done();
20+
builder
21+
.add_property::<VariantArray>("single_array_range")
22+
.with_setter(ExportsArrays::set_single_array_range)
23+
.with_hint(ArrayHint::with_element_hint::<i64>(IntHint::Range(
24+
RangeHint::new(-5, 5),
25+
)))
26+
.done();
27+
builder
28+
.add_property::<VariantArray>("double_array")
29+
.with_setter(ExportsArrays::set_double_array)
30+
.with_hint(ArrayHint::with_element_hint::<VariantArray>(
31+
ArrayHint::new(),
32+
))
33+
.done();
34+
builder
35+
.add_property::<VariantArray>("double_array_range")
36+
.with_setter(ExportsArrays::set_double_array_range)
37+
.with_hint(ArrayHint::with_element_hint::<VariantArray>(
38+
ArrayHint::with_element_hint::<i64>(IntHint::Range(RangeHint::new(-5, 5))),
39+
))
40+
.done();
41+
}
42+
43+
fn set_single_array(&mut self, _owner: TRef<Node>, value: VariantArray) {
44+
godot_print!("Single: {:?}", value);
45+
}
46+
fn set_single_array_range(&mut self, _owner: TRef<Node>, value: VariantArray) {
47+
godot_print!("Single Range: {:?}", value);
48+
}
49+
fn set_double_array(&mut self, _owner: TRef<Node>, value: VariantArray) {
50+
godot_print!("Double: {:?}", value);
51+
}
52+
fn set_double_array_range(&mut self, _owner: TRef<Node>, value: VariantArray) {
53+
godot_print!("Double Range: {:?}", value);
54+
}
55+
}
56+
57+
fn init(handle: InitHandle) {
58+
handle.add_class::<ExportsArrays>();
59+
}
60+
61+
godot_init!(init);

0 commit comments

Comments
 (0)