Skip to content

Commit 68fd6a1

Browse files
authored
Rust files shouldn't be exported #64 (#69)
Rust source code should not be included in the exported resources. Resolves #64
1 parent 94edf15 commit 68fd6a1

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

rust-script/src/runtime/editor.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
*/
6+
7+
use godot::{
8+
builtin::{GString, PackedStringArray},
9+
classes::{
10+
EditorExportPlugin, EditorPlugin, IEditorExportPlugin, IEditorPlugin, Node, Resource,
11+
},
12+
obj::{Base, Gd, NewGd, WithBaseField},
13+
prelude::{godot_api, GodotClass},
14+
};
15+
16+
#[derive(GodotClass)]
17+
#[class(base = EditorPlugin, tool )]
18+
pub struct RustScriptEditorPlugin {
19+
base: Base<EditorPlugin>,
20+
export_plugin: Gd<RustScriptExportPlugin>,
21+
}
22+
23+
#[godot_api]
24+
impl IEditorPlugin for RustScriptEditorPlugin {
25+
fn init(base: Base<Self::Base>) -> Self {
26+
Self {
27+
base,
28+
export_plugin: RustScriptExportPlugin::new_gd(),
29+
}
30+
}
31+
fn enter_tree(&mut self) {
32+
let export_plugin = self.export_plugin.clone();
33+
34+
self.base_mut().add_export_plugin(&export_plugin);
35+
}
36+
37+
fn exit_tree(&mut self) {
38+
let export_plugin = self.export_plugin.clone();
39+
40+
self.base_mut().remove_export_plugin(&export_plugin);
41+
}
42+
}
43+
44+
#[derive(GodotClass)]
45+
#[class(base = EditorExportPlugin, tool, init)]
46+
struct RustScriptExportPlugin {
47+
base: Base<EditorExportPlugin>,
48+
}
49+
50+
#[godot_api]
51+
impl IEditorExportPlugin for RustScriptExportPlugin {
52+
#[expect(unused_variables)]
53+
fn customize_resource(
54+
&mut self,
55+
resource: godot::prelude::Gd<Resource>,
56+
path: godot::prelude::GString,
57+
) -> Option<godot::prelude::Gd<Resource>> {
58+
None
59+
}
60+
61+
#[expect(unused_variables)]
62+
fn customize_scene(
63+
&mut self,
64+
scene: godot::prelude::Gd<Node>,
65+
path: godot::prelude::GString,
66+
) -> Option<godot::prelude::Gd<Node>> {
67+
None
68+
}
69+
70+
fn get_customization_configuration_hash(&self) -> u64 {
71+
0
72+
}
73+
74+
fn get_name(&self) -> godot::prelude::GString {
75+
GString::from("RustScriptExportPlugin")
76+
}
77+
78+
fn export_file(&mut self, path: GString, _type_: GString, _features: PackedStringArray) {
79+
if !path.ends_with(".rs") {
80+
return;
81+
}
82+
83+
self.base_mut().skip();
84+
}
85+
}

rust-script/src/runtime/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
mod call_context;
88
mod downgrade_self;
9+
mod editor;
910
mod metadata;
1011
mod resource_loader;
1112
mod resource_saver;

0 commit comments

Comments
 (0)