-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from RedMser/export-plugin-cleanup
Add Editor and Export plugin
- Loading branch information
Showing
20 changed files
with
232 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# Godot 4+ specific ignores | ||
.godot/ | ||
**/bin/** | ||
!**/bin/.gdignore | ||
|
||
# Temporary directories | ||
node_modules/ | ||
|
Empty file.
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,65 @@ | ||
[preset.0] | ||
|
||
name="Windows Desktop" | ||
platform="Windows Desktop" | ||
runnable=true | ||
advanced_options=false | ||
dedicated_server=false | ||
custom_features="" | ||
export_filter="all_resources" | ||
include_filter="" | ||
exclude_filter="" | ||
export_path="bin/fluent-translation.exe" | ||
encryption_include_filters="" | ||
encryption_exclude_filters="" | ||
encrypt_pck=false | ||
encrypt_directory=false | ||
script_export_mode=2 | ||
|
||
[preset.0.options] | ||
|
||
custom_template/debug="" | ||
custom_template/release="" | ||
debug/export_console_wrapper=1 | ||
binary_format/embed_pck=false | ||
texture_format/s3tc_bptc=true | ||
texture_format/etc2_astc=false | ||
binary_format/architecture="x86_64" | ||
codesign/enable=false | ||
codesign/timestamp=true | ||
codesign/timestamp_server_url="" | ||
codesign/digest_algorithm=1 | ||
codesign/description="" | ||
codesign/custom_options=PackedStringArray() | ||
application/modify_resources=true | ||
application/icon="" | ||
application/console_wrapper_icon="" | ||
application/icon_interpolation=4 | ||
application/file_version="" | ||
application/product_version="" | ||
application/company_name="" | ||
application/product_name="" | ||
application/file_description="" | ||
application/copyright="" | ||
application/trademarks="" | ||
application/export_angle=0 | ||
application/export_d3d12=0 | ||
application/d3d12_agility_sdk_multiarch=true | ||
ssh_remote_deploy/enabled=false | ||
ssh_remote_deploy/host="user@host_ip" | ||
ssh_remote_deploy/port="22" | ||
ssh_remote_deploy/extra_args_ssh="" | ||
ssh_remote_deploy/extra_args_scp="" | ||
ssh_remote_deploy/run_script="Expand-Archive -LiteralPath '{temp_dir}\\{archive_name}' -DestinationPath '{temp_dir}' | ||
$action = New-ScheduledTaskAction -Execute '{temp_dir}\\{exe_name}' -Argument '{cmd_args}' | ||
$trigger = New-ScheduledTaskTrigger -Once -At 00:00 | ||
$settings = New-ScheduledTaskSettingsSet | ||
$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings | ||
Register-ScheduledTask godot_remote_debug -InputObject $task -Force:$true | ||
Start-ScheduledTask -TaskName godot_remote_debug | ||
while (Get-ScheduledTask -TaskName godot_remote_debug | ? State -eq running) { Start-Sleep -Milliseconds 100 } | ||
Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue" | ||
ssh_remote_deploy/cleanup_script="Stop-ScheduledTask -TaskName godot_remote_debug -ErrorAction:SilentlyContinue | ||
Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue | ||
Remove-Item -Recurse -Force '{temp_dir}'" | ||
fluent/strip_comments=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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[env] | ||
GODOT4_BIN = { value = "../build/godot.windows.editor.x86_64.console.exe", relative = true } | ||
GODOT4_BIN = { value = "../build/godot.windows.editor.x86_64.exe", relative = true } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use godot::{classes::{EditorPlugin, IEditorPlugin}, prelude::*}; | ||
|
||
use super::FluentExportPlugin; | ||
|
||
#[derive(GodotClass)] | ||
#[class(tool, editor_plugin, init, base=EditorPlugin)] | ||
pub struct FluentEditorPlugin { | ||
export_plugin: Option<Gd<FluentExportPlugin>>, | ||
base: Base<EditorPlugin>, | ||
} | ||
|
||
#[godot_api] | ||
impl IEditorPlugin for FluentEditorPlugin { | ||
fn enter_tree(&mut self) { | ||
let export_plugin = FluentExportPlugin::new_gd(); | ||
self.export_plugin = Some(export_plugin.clone()); | ||
self.base_mut().add_export_plugin(export_plugin); | ||
} | ||
|
||
fn exit_tree(&mut self) { | ||
let export_plugin = self.export_plugin.take(); | ||
self.base_mut().remove_export_plugin(export_plugin); | ||
self.export_plugin = None; | ||
} | ||
} |
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,47 @@ | ||
use godot::{classes::{EditorExportPlatform, EditorExportPlugin, IEditorExportPlugin}, prelude::*}; | ||
use constcat::concat as constcat; | ||
|
||
use super::strip_comments; | ||
|
||
const EXPORT_OPTION_PREFIX: &str = "fluent/"; | ||
const EXPORT_OPTION_STRIP_COMMENTS: &str = constcat!(EXPORT_OPTION_PREFIX, "strip_comments"); | ||
|
||
#[derive(GodotClass)] | ||
#[class(base=EditorExportPlugin)] | ||
pub struct FluentExportPlugin { | ||
base: Base<EditorExportPlugin>, | ||
} | ||
|
||
#[godot_api] | ||
impl IEditorExportPlugin for FluentExportPlugin { | ||
fn init(base: Base<EditorExportPlugin>) -> Self { | ||
Self { | ||
base, | ||
} | ||
} | ||
|
||
fn get_export_options(&self, _platform: Gd<EditorExportPlatform>) -> Array<Dictionary> { | ||
array![dict! { | ||
"option": dict! { | ||
"name": GString::from(EXPORT_OPTION_STRIP_COMMENTS), | ||
"type": VariantType::BOOL, | ||
}, | ||
"default_value": Variant::from(true), | ||
}] | ||
} | ||
|
||
fn export_file(&mut self, path: GString, _type: GString, _features: PackedStringArray) { | ||
if !path.to_string().to_lowercase().ends_with("ftl") { | ||
return; | ||
} | ||
|
||
if self.base().get_option(StringName::from(EXPORT_OPTION_STRIP_COMMENTS)).booleanize() { | ||
// Strip comments from file | ||
let contents = strip_comments(path.clone()); | ||
let binary = PackedByteArray::from_iter(contents.bytes()); | ||
|
||
self.base_mut().skip(); | ||
self.base_mut().add_file(path, binary, false); | ||
} | ||
} | ||
} |
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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use godot::prelude::*; | ||
use fluent_syntax::{ast, parser::parse, serializer::serialize}; | ||
use godot::classes::FileAccess; | ||
|
||
pub fn strip_comments(path: GString) -> String { | ||
let contents = FileAccess::get_file_as_string(path.clone()); | ||
let ftl = parse(contents.to_string()); | ||
let mut ftl = match ftl { | ||
Ok(ftl) => ftl, | ||
Err((ftl, err)) => { | ||
godot_warn!("Error parsing {}: {:?}", path, err); | ||
ftl | ||
}, | ||
}; | ||
|
||
ftl.body.retain(|ast| { | ||
match ast { | ||
ast::Entry::Comment(_) | ast::Entry::GroupComment(_) | ast::Entry::ResourceComment(_) => false, | ||
_ => true, | ||
} | ||
}); | ||
|
||
let contents = serialize(&ftl); | ||
contents | ||
} |
Oops, something went wrong.