module Lapis::EditorScriptCreation

Defined in:

libgodot/editor_script_creation.cr

Constant Summary

BUTTON_ID_OPEN_CRYSTAL_SCRIPT_BASE = 99000_i64
COMMON_BASE_TYPES = ["Node", "Node2D", "Node3D", "CharacterBody3D", "CharacterBody2D", "Control", "Camera3D", "Area3D", "Area2D", "RigidBody3D", "RigidBody2D", "Resource", "RefCounted"]
ID_CRYSTAL_SCRIPT = 889901_i64
ID_SCENE_ATTACH = 889902_i64
ID_SCENE_DETACH_CONVERT = 889903_i64
TEMPLATES = ["Standard Node (_ready & _process)", "Physics Movement (CharacterBody)", "Tool Script (@[Tool] In-Editor Execution)", "Empty Class"]

Class Method Summary

Class Method Detail

def self.adapt_script_create_dialog_path(scd : Node) : Void #

Adapts the file path inside a native ScriptCreateDialog to ensure a clean .cr extension when Crystal is selected


def self.cleanup : Void #

def self.cleanup_on_shutdown : Void #

def self.convert_crystal_node_to_parent(node : Node, parent_type : String, ed_iface : EditorInterface) : Void #

def self.ensure_cr_extension(path : String) : String #

Normalizes a path to end with exactly one .cr extension, stripping duplicate dots or other extensions


def self.find_all_children(parent : Node, type_name : String) : Array(Node) #

Recursively discovers all child nodes matching the specified Godot class name


def self.find_scene_tree_dock(base_ctrl : Control) : Node | Nil #

def self.fix_script_create_dialog(scd : Node) : Void #

Repairs a Godot native ScriptCreateDialog's language menu:

  • Updates index 1 (CrystalLanguage) text to "Crystal" and sets official Crystal icon
  • Prunes any out-of-bounds surplus items (count must never exceed ScriptServer language count)
  • Ensures valid selection index so it never shows broken red icon or empty fields
  • Sets up live path adaptation when language is switched

def self.generate_template_code(class_name : String, base_type : String, tmpl_idx : Int64) : String #

def self.get_create_dialog_selected_type(cd : Node) : String #

Retrieves the selected type from a Godot CreateDialog by inspecting its Tree control


def self.get_script_button_icon(ed_iface : EditorInterface) : Texture2D | Nil #

def self.get_selected_node(ed_iface : EditorInterface) : Node | Nil #

Retrieves the currently selected Node in the Godot Editor


def self.hook_create_new_submenu(fs_dock : Node, sub_node : Node) : Void #

Hooks dynamically created "Create New" submenus in FileSystemDock


def self.open_crystal_script_info(ed_iface : EditorInterface, info : ScriptLocationInfo) : Void #

Opens the given Crystal script in Godot's ScriptEditor at the specified 1-based line number and switches to the Script tab


def self.register_script_button_info(info : ScriptLocationInfo) : Int64 #

def self.setup(ed_iface : EditorInterface, base_ctrl : Control) : Void #

Sets up all editor integration entry points: toolbar button, FileSystem dock menus, SceneTree menus, and ScriptCreateDialog interception


def self.setup_filesystem_dock_menus(ed_iface : EditorInterface) : Void #
  1. FileSystem Dock Context Menu & Create New Menu

def self.setup_scene_tree_dock_menus(ed_iface : EditorInterface, base_ctrl : Control) : Void #
  1. SceneTree Dock Node Context Menu ("Attach/New Crystal Script...") & Detach Script Protection

def self.setup_script_create_dialog_interception(ed_iface : EditorInterface, base_ctrl : Control) : Void #

Intercepts Godot's built-in ScriptCreateDialog whenever CrystalScript is selected in "Create New Resource" (FileSystem Dock -> Create New -> Resource -> CrystalScript) and repairs native ScriptCreateDialog instances so they never show broken red icons.


def self.setup_toolbar_button(ed_iface : EditorInterface, base_ctrl : Control) : Void #
  1. Top Toolbar "+ Script" Button

def self.show_detach_convert_dialog(node : Node, parent_type : String, ed_iface : EditorInterface, base_ctrl : Control) : Void #

def self.show_dialog(initial_path : String = "", default_name : String = "", default_base : String = "") : Void #
  1. Interactive Dialog Presentation

def self.sync_scene_tree_script_buttons(ed_iface : EditorInterface, base_ctrl : Control) : Void #

Synchronizes "Open Script" icon buttons next to custom Crystal nodes and resources in the SceneTreeDock


def self.sync_tree_item_buttons_recursive(item : Godot::Object, scene_root : Godot::Node, rel_path : String, script_icon : Godot::Texture2D) : Void #

def self.to_snake_case(str : String) : String #

Converts CamelCase to snake_case for clean Crystal file naming