Skip to content

Commit e7d419f

Browse files
committed
Add export plugin and editor plugin
1 parent a5bf652 commit e7d419f

File tree

9 files changed

+173
-1
lines changed

9 files changed

+173
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Godot 4+ specific ignores
22
.godot/
3+
**/bin/**
4+
!**/bin/.gdignore
35

46
# Temporary directories
57
node_modules/

godot/default/bin/.gdignore

Whitespace-only changes.

godot/default/export_presets.cfg

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
[preset.0]
2+
3+
name="Windows Desktop"
4+
platform="Windows Desktop"
5+
runnable=true
6+
advanced_options=false
7+
dedicated_server=false
8+
custom_features=""
9+
export_filter="all_resources"
10+
include_filter=""
11+
exclude_filter=""
12+
export_path="bin/fluent-translation.exe"
13+
encryption_include_filters=""
14+
encryption_exclude_filters=""
15+
encrypt_pck=false
16+
encrypt_directory=false
17+
script_export_mode=2
18+
19+
[preset.0.options]
20+
21+
custom_template/debug=""
22+
custom_template/release=""
23+
debug/export_console_wrapper=1
24+
binary_format/embed_pck=false
25+
texture_format/s3tc_bptc=true
26+
texture_format/etc2_astc=false
27+
binary_format/architecture="x86_64"
28+
codesign/enable=false
29+
codesign/timestamp=true
30+
codesign/timestamp_server_url=""
31+
codesign/digest_algorithm=1
32+
codesign/description=""
33+
codesign/custom_options=PackedStringArray()
34+
application/modify_resources=true
35+
application/icon=""
36+
application/console_wrapper_icon=""
37+
application/icon_interpolation=4
38+
application/file_version=""
39+
application/product_version=""
40+
application/company_name=""
41+
application/product_name=""
42+
application/file_description=""
43+
application/copyright=""
44+
application/trademarks=""
45+
application/export_angle=0
46+
application/export_d3d12=0
47+
application/d3d12_agility_sdk_multiarch=true
48+
ssh_remote_deploy/enabled=false
49+
ssh_remote_deploy/host="user@host_ip"
50+
ssh_remote_deploy/port="22"
51+
ssh_remote_deploy/extra_args_ssh=""
52+
ssh_remote_deploy/extra_args_scp=""
53+
ssh_remote_deploy/run_script="Expand-Archive -LiteralPath '{temp_dir}\\{archive_name}' -DestinationPath '{temp_dir}'
54+
$action = New-ScheduledTaskAction -Execute '{temp_dir}\\{exe_name}' -Argument '{cmd_args}'
55+
$trigger = New-ScheduledTaskTrigger -Once -At 00:00
56+
$settings = New-ScheduledTaskSettingsSet
57+
$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings
58+
Register-ScheduledTask godot_remote_debug -InputObject $task -Force:$true
59+
Start-ScheduledTask -TaskName godot_remote_debug
60+
while (Get-ScheduledTask -TaskName godot_remote_debug | ? State -eq running) { Start-Sleep -Milliseconds 100 }
61+
Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue"
62+
ssh_remote_deploy/cleanup_script="Stop-ScheduledTask -TaskName godot_remote_debug -ErrorAction:SilentlyContinue
63+
Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue
64+
Remove-Item -Recurse -Force '{temp_dir}'"
65+
fluent/strip_comments=true

godot/default/test.en.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
# this is a comment
2+
## another comment
13
-term = email
4+
### third kind of comment
25
HELLO =
36
{ $unreadEmails ->
47
[one] You have one unread { -term }.

rust/.cargo/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[env]
2-
GODOT4_BIN = { value = "../build/godot.windows.editor.x86_64.console.exe", relative = true }
2+
GODOT4_BIN = { value = "../build/godot.windows.editor.x86_64.exe", relative = true }

rust/src/fluent/editor_plugin.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use godot::{classes::{EditorPlugin, IEditorPlugin}, prelude::*};
2+
3+
use super::FluentExportPlugin;
4+
5+
#[derive(GodotClass)]
6+
#[class(tool, editor_plugin, init, base=EditorPlugin)]
7+
pub struct FluentEditorPlugin {
8+
export_plugin: Option<Gd<FluentExportPlugin>>,
9+
base: Base<EditorPlugin>,
10+
}
11+
12+
#[godot_api]
13+
impl IEditorPlugin for FluentEditorPlugin {
14+
fn enter_tree(&mut self) {
15+
let export_plugin = FluentExportPlugin::new_gd();
16+
self.export_plugin = Some(export_plugin.clone());
17+
self.base_mut().add_export_plugin(export_plugin);
18+
}
19+
20+
fn exit_tree(&mut self) {
21+
let export_plugin = self.export_plugin.take();
22+
self.base_mut().remove_export_plugin(export_plugin);
23+
self.export_plugin = None;
24+
}
25+
}

rust/src/fluent/export_plugin.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use godot::{classes::{EditorExportPlatform, EditorExportPlugin, IEditorExportPlugin}, prelude::*};
2+
use constcat::concat as constcat;
3+
4+
use super::strip_comments;
5+
6+
const EXPORT_OPTION_PREFIX: &str = "fluent/";
7+
const EXPORT_OPTION_STRIP_COMMENTS: &str = constcat!(EXPORT_OPTION_PREFIX, "strip_comments");
8+
9+
#[derive(GodotClass)]
10+
#[class(base=EditorExportPlugin)]
11+
pub struct FluentExportPlugin {
12+
base: Base<EditorExportPlugin>,
13+
}
14+
15+
#[godot_api]
16+
impl IEditorExportPlugin for FluentExportPlugin {
17+
fn init(base: Base<EditorExportPlugin>) -> Self {
18+
Self {
19+
base,
20+
}
21+
}
22+
23+
fn get_export_options(&self, _platform: Gd<EditorExportPlatform>) -> Array<Dictionary> {
24+
array![dict! {
25+
"option": dict! {
26+
"name": GString::from(EXPORT_OPTION_STRIP_COMMENTS),
27+
"type": VariantType::BOOL,
28+
},
29+
"default_value": Variant::from(true),
30+
}]
31+
}
32+
33+
fn export_file(&mut self, path: GString, _type: GString, _features: PackedStringArray) {
34+
if !path.to_string().to_lowercase().ends_with("ftl") {
35+
return;
36+
}
37+
38+
if self.base().get_option(StringName::from(EXPORT_OPTION_STRIP_COMMENTS)).booleanize() {
39+
// Strip comments from file
40+
let contents = strip_comments(path.clone());
41+
let binary = PackedByteArray::from_iter(contents.bytes());
42+
43+
self.base_mut().skip();
44+
self.base_mut().add_file(path, binary, false);
45+
}
46+
}
47+
}

rust/src/fluent/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ mod importer;
1010
pub use self::importer::*;
1111
mod translation;
1212
pub use self::translation::*;
13+
mod export_plugin;
14+
pub use self::export_plugin::*;
15+
mod strip_comments;
16+
pub use self::strip_comments::*;
1317
pub mod locale;
1418
#[allow(dead_code)]
1519
pub mod project_settings;
20+
mod editor_plugin;

rust/src/fluent/strip_comments.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use godot::prelude::*;
2+
use fluent_syntax::{ast, parser::parse, serializer::serialize};
3+
use godot::classes::FileAccess;
4+
5+
pub fn strip_comments(path: GString) -> String {
6+
let contents = FileAccess::get_file_as_string(path.clone());
7+
let ftl = parse(contents.to_string());
8+
let mut ftl = match ftl {
9+
Ok(ftl) => ftl,
10+
Err((ftl, err)) => {
11+
godot_warn!("Error parsing {}: {:?}", path, err);
12+
ftl
13+
},
14+
};
15+
16+
ftl.body.retain(|ast| {
17+
match ast {
18+
ast::Entry::Comment(_) | ast::Entry::GroupComment(_) | ast::Entry::ResourceComment(_) => false,
19+
_ => true,
20+
}
21+
});
22+
23+
let contents = serialize(&ftl);
24+
contents
25+
}

0 commit comments

Comments
 (0)