Skip to content

Commit

Permalink
Improvement? IDK can't remember lol
Browse files Browse the repository at this point in the history
  • Loading branch information
QueenOfSquiggles committed Dec 29, 2023
1 parent bccb407 commit 0272624
Showing 1 changed file with 62 additions and 17 deletions.
79 changes: 62 additions & 17 deletions src/editor_utils.rs
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);
}
}

0 comments on commit 0272624

Please sign in to comment.