-
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.
- Loading branch information
1 parent
bccb407
commit 0272624
Showing
1 changed file
with
62 additions
and
17 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,23 +1,68 @@ | ||
use godot::engine::{EditorCommandPalette, EditorPlugin, IEditorPlugin, PopupMenu}; | ||
use godot::prelude::*; | ||
|
||
use crate::game_globals::CoreGlobals; | ||
use crate::serialization::SquigglesSerialized; | ||
|
||
pub fn register_editor_elements() {} | ||
|
||
pub fn unregister_editor_elements() {} | ||
|
||
pub fn register_editor_elements() { | ||
// let Some(mut cmd) = EditorInterface::singleton().get_command_palette() else { | ||
// return; | ||
// }; | ||
// cmd.add_command( | ||
// "Force Core Globals to Serialize".to_godot(), | ||
// "squiggles_core_serialize".to_godot(), | ||
// Callable::from_fn("name", |_args: &[&Variant]| { | ||
// CoreGlobals::singleton() | ||
// .bind() | ||
// .get_config() | ||
// .bind_mut() | ||
// .serialize(); | ||
// Ok(Variant::nil()) | ||
// }), | ||
// ); | ||
#[derive(GodotClass)] | ||
#[class(tool, editor_plugin, init, base=EditorPlugin)] | ||
struct SquigglesCoreEditorUtils { | ||
tool_items: Option<Gd<PopupMenu>>, | ||
#[base] | ||
base: Base<EditorPlugin>, | ||
} | ||
|
||
pub fn unregister_editor_elements() {} | ||
#[godot_api] | ||
impl IEditorPlugin for SquigglesCoreEditorUtils { | ||
fn enter_tree(&mut self) { | ||
let menu = PopupMenu::new_alloc(); | ||
self.base | ||
.add_tool_submenu_item("Squiggles Core".to_godot(), menu.clone()); | ||
self.tool_items = Some(menu); | ||
let Some(editor) = self.base.get_editor_interface() else { | ||
return; | ||
}; | ||
let Some(mut cmd) = editor.get_command_palette() else { | ||
return; | ||
}; | ||
self.register_tool_item( | ||
"force_globals_serialize", | ||
"Forces the core globals to serialize their data to the user dir. Clears the missing file warnings.", | ||
Callable::from_fn("name", |_args: &[&Variant]| { | ||
CoreGlobals::singleton() | ||
.bind() | ||
.get_config() | ||
.bind_mut() | ||
.serialize(); | ||
Ok(Variant::nil()) | ||
}), | ||
&mut cmd, | ||
); | ||
} | ||
|
||
fn exit_tree(&mut self) {} | ||
} | ||
|
||
impl SquigglesCoreEditorUtils { | ||
/// registers a callable command in both the tools dropdown pane of the editor and the command palette for quick access | ||
fn register_tool_item( | ||
&mut self, | ||
name: &str, | ||
description: &str, | ||
func: Callable, | ||
command_palette: &mut Gd<EditorCommandPalette>, | ||
) { | ||
let fname = ("squiggles_core/".to_string() + name).to_godot(); | ||
if let Some(mut menu_items) = self.tool_items.clone() { | ||
menu_items.add_item(name.to_godot()); | ||
let index = menu_items.get_item_count() - 1; | ||
menu_items.set_item_tooltip(index, description.to_godot()) | ||
} | ||
self.base.add_tool_menu_item(fname.clone(), func.clone()); | ||
command_palette.add_command(name.to_godot(), fname, func); | ||
} | ||
} |