Skip to content

Instantly share code, notes, and snippets.

@qwe321qwe321qwe321
Last active April 18, 2024 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qwe321qwe321qwe321/bbf4b135c49372746e45246b364378c4 to your computer and use it in GitHub Desktop.
Save qwe321qwe321qwe321/bbf4b135c49372746e45246b364378c4 to your computer and use it in GitHub Desktop.
[Godot .Net] A class for Godot with Built-in Input Actions as C# constants.
public static class BuiltinInputActions
{
public static readonly StringName UIAccept = "ui_accept";
public static readonly StringName UISelect = "ui_select";
public static readonly StringName UICancel = "ui_cancel";
public static readonly StringName UIFocusNext = "ui_focus_next";
public static readonly StringName UIFocusPrev = "ui_focus_prev";
public static readonly StringName UILeft = "ui_left";
public static readonly StringName UIRight = "ui_right";
public static readonly StringName UIUp = "ui_up";
public static readonly StringName UIDown = "ui_down";
public static readonly StringName UIPageUp = "ui_page_up";
public static readonly StringName UIPageDown = "ui_page_down";
public static readonly StringName UIHome = "ui_home";
public static readonly StringName UIEnd = "ui_end";
public static readonly StringName UICut = "ui_cut";
public static readonly StringName UICopy = "ui_copy";
public static readonly StringName UIPaste = "ui_paste";
public static readonly StringName UIUndo = "ui_undo";
public static readonly StringName UIRedo = "ui_redo";
public static readonly StringName UITextCompletionQuery = "ui_text_completion_query";
public static readonly StringName UITextNewline = "ui_text_newline";
public static readonly StringName UITextNewlineBlank = "ui_text_newline_blank";
public static readonly StringName UITextNewlineAbove = "ui_text_newline_above";
public static readonly StringName UITextIndent = "ui_text_indent";
public static readonly StringName UITextDedent = "ui_text_dedent";
public static readonly StringName UITextBackspace = "ui_text_backspace";
public static readonly StringName UITextBackspaceWord = "ui_text_backspace_word";
public static readonly StringName UITextBackspaceWordMacos = "ui_text_backspace_word.macos";
public static readonly StringName UITextBackspaceAllToLeft = "ui_text_backspace_all_to_left";
public static readonly StringName UITextBackspaceAllToLeftMacos = "ui_text_backspace_all_to_left.macos";
public static readonly StringName UITextDelete = "ui_text_delete";
public static readonly StringName UITextDeleteWord = "ui_text_delete_word";
public static readonly StringName UITextDeleteWordMacos = "ui_text_delete_word.macos";
public static readonly StringName UITextDeleteAllToRight = "ui_text_delete_all_to_right";
public static readonly StringName UITextDeleteAllToRightMacos = "ui_text_delete_all_to_right.macos";
public static readonly StringName UITextCaretLeft = "ui_text_caret_left";
public static readonly StringName UITextCaretWordLeft = "ui_text_caret_word_left";
public static readonly StringName UITextCaretWordLeftMacos = "ui_text_caret_word_left.macos";
public static readonly StringName UITextCaretRight = "ui_text_caret_right";
public static readonly StringName UITextCaretWordRight = "ui_text_caret_word_right";
public static readonly StringName UITextCaretWordRightMacos = "ui_text_caret_word_right.macos";
public static readonly StringName UITextCaretUp = "ui_text_caret_up";
public static readonly StringName UITextCaretDown = "ui_text_caret_down";
public static readonly StringName UITextCaretLineStart = "ui_text_caret_line_start";
public static readonly StringName UITextCaretLineStartMacos = "ui_text_caret_line_start.macos";
public static readonly StringName UITextCaretLineEnd = "ui_text_caret_line_end";
public static readonly StringName UITextCaretLineEndMacos = "ui_text_caret_line_end.macos";
public static readonly StringName UITextCaretPageUp = "ui_text_caret_page_up";
public static readonly StringName UITextCaretPageDown = "ui_text_caret_page_down";
public static readonly StringName UITextCaretDocumentStart = "ui_text_caret_document_start";
public static readonly StringName UITextCaretDocumentStartMacos = "ui_text_caret_document_start.macos";
public static readonly StringName UITextCaretDocumentEnd = "ui_text_caret_document_end";
public static readonly StringName UITextCaretDocumentEndMacos = "ui_text_caret_document_end.macos";
public static readonly StringName UITextCaretAddBelow = "ui_text_caret_add_below";
public static readonly StringName UITextCaretAddBelowMacos = "ui_text_caret_add_below.macos";
public static readonly StringName UITextCaretAddAbove = "ui_text_caret_add_above";
public static readonly StringName UITextCaretAddAboveMacos = "ui_text_caret_add_above.macos";
public static readonly StringName UITextScrollUp = "ui_text_scroll_up";
public static readonly StringName UITextScrollUpMacos = "ui_text_scroll_up.macos";
public static readonly StringName UITextScrollDown = "ui_text_scroll_down";
public static readonly StringName UITextScrollDownMacos = "ui_text_scroll_down.macos";
public static readonly StringName UITextSelectAll = "ui_text_select_all";
public static readonly StringName UITextSelectWordUnderCaret = "ui_text_select_word_under_caret";
public static readonly StringName UITextAddSelectionForNextOccurrence = "ui_text_add_selection_for_next_occurrence";
public static readonly StringName UITextSkipSelectionForNextOccurrence = "ui_text_skip_selection_for_next_occurrence";
public static readonly StringName UITextClearCaretsAndSelection = "ui_text_clear_carets_and_selection";
public static readonly StringName UITextToggleInsertMode = "ui_text_toggle_insert_mode";
public static readonly StringName UITextSubmit = "ui_text_submit";
public static readonly StringName UIGraphDuplicate = "ui_graph_duplicate";
public static readonly StringName UIGraphDelete = "ui_graph_delete";
public static readonly StringName UIFiledialogUpOneLevel = "ui_filedialog_up_one_level";
public static readonly StringName UIFiledialogRefresh = "ui_filedialog_refresh";
public static readonly StringName UIFiledialogShowHidden = "ui_filedialog_show_hidden";
public static readonly StringName UISwapInputDirection = "ui_swap_input_direction";
}
@qwe321qwe321qwe321
Copy link
Author

Source

_builtin_action_display_names[] in godot/core/input/input_map.cpp

static const _BuiltinActionDisplayName _builtin_action_display_names[] = {
	/* clang-format off */
    { "ui_accept",                                     TTRC("Accept") },
    { "ui_select",                                     TTRC("Select") },
    { "ui_cancel",                                     TTRC("Cancel") },
    { "ui_focus_next",                                 TTRC("Focus Next") },
    { "ui_focus_prev",                                 TTRC("Focus Prev") },
    { "ui_left",                                       TTRC("Left") },
    { "ui_right",                                      TTRC("Right") },
    { "ui_up",                                         TTRC("Up") },
    { "ui_down",                                       TTRC("Down") },
    { "ui_page_up",                                    TTRC("Page Up") },
    { "ui_page_down",                                  TTRC("Page Down") },
    { "ui_home",                                       TTRC("Home") },
    { "ui_end",                                        TTRC("End") },
    { "ui_cut",                                        TTRC("Cut") },
    { "ui_copy",                                       TTRC("Copy") },
    { "ui_paste",                                      TTRC("Paste") },
    { "ui_undo",                                       TTRC("Undo") },
    { "ui_redo",                                       TTRC("Redo") },
    { "ui_text_completion_query",                      TTRC("Completion Query") },
    { "ui_text_newline",                               TTRC("New Line") },
    { "ui_text_newline_blank",                         TTRC("New Blank Line") },
    { "ui_text_newline_above",                         TTRC("New Line Above") },
    { "ui_text_indent",                                TTRC("Indent") },
    { "ui_text_dedent",                                TTRC("Dedent") },
    { "ui_text_backspace",                             TTRC("Backspace") },
    { "ui_text_backspace_word",                        TTRC("Backspace Word") },
    { "ui_text_backspace_word.macos",                  TTRC("Backspace Word") },
    { "ui_text_backspace_all_to_left",                 TTRC("Backspace all to Left") },
    { "ui_text_backspace_all_to_left.macos",           TTRC("Backspace all to Left") },
    { "ui_text_delete",                                TTRC("Delete") },
    { "ui_text_delete_word",                           TTRC("Delete Word") },
    { "ui_text_delete_word.macos",                     TTRC("Delete Word") },
    { "ui_text_delete_all_to_right",                   TTRC("Delete all to Right") },
    { "ui_text_delete_all_to_right.macos",             TTRC("Delete all to Right") },
    { "ui_text_caret_left",                            TTRC("Caret Left") },
    { "ui_text_caret_word_left",                       TTRC("Caret Word Left") },
    { "ui_text_caret_word_left.macos",                 TTRC("Caret Word Left") },
    { "ui_text_caret_right",                           TTRC("Caret Right") },
    { "ui_text_caret_word_right",                      TTRC("Caret Word Right") },
    { "ui_text_caret_word_right.macos",                TTRC("Caret Word Right") },
    { "ui_text_caret_up",                              TTRC("Caret Up") },
    { "ui_text_caret_down",                            TTRC("Caret Down") },
    { "ui_text_caret_line_start",                      TTRC("Caret Line Start") },
    { "ui_text_caret_line_start.macos",                TTRC("Caret Line Start") },
    { "ui_text_caret_line_end",                        TTRC("Caret Line End") },
    { "ui_text_caret_line_end.macos",                  TTRC("Caret Line End") },
    { "ui_text_caret_page_up",                         TTRC("Caret Page Up") },
    { "ui_text_caret_page_down",                       TTRC("Caret Page Down") },
    { "ui_text_caret_document_start",                  TTRC("Caret Document Start") },
    { "ui_text_caret_document_start.macos",            TTRC("Caret Document Start") },
    { "ui_text_caret_document_end",                    TTRC("Caret Document End") },
    { "ui_text_caret_document_end.macos",              TTRC("Caret Document End") },
    { "ui_text_caret_add_below",                       TTRC("Caret Add Below") },
    { "ui_text_caret_add_below.macos",                 TTRC("Caret Add Below") },
    { "ui_text_caret_add_above",                       TTRC("Caret Add Above") },
    { "ui_text_caret_add_above.macos",                 TTRC("Caret Add Above") },
    { "ui_text_scroll_up",                             TTRC("Scroll Up") },
    { "ui_text_scroll_up.macos",                       TTRC("Scroll Up") },
    { "ui_text_scroll_down",                           TTRC("Scroll Down") },
    { "ui_text_scroll_down.macos",                     TTRC("Scroll Down") },
    { "ui_text_select_all",                            TTRC("Select All") },
    { "ui_text_select_word_under_caret",               TTRC("Select Word Under Caret") },
    { "ui_text_add_selection_for_next_occurrence",     TTRC("Add Selection for Next Occurrence") },
    { "ui_text_skip_selection_for_next_occurrence",    TTRC("Skip Selection for Next Occurrence") },
    { "ui_text_clear_carets_and_selection",            TTRC("Clear Carets and Selection") },
    { "ui_text_toggle_insert_mode",                    TTRC("Toggle Insert Mode") },
    { "ui_text_submit",                                TTRC("Submit Text") },
    { "ui_graph_duplicate",                            TTRC("Duplicate Nodes") },
    { "ui_graph_delete",                               TTRC("Delete Nodes") },
    { "ui_filedialog_up_one_level",                    TTRC("Go Up One Level") },
    { "ui_filedialog_refresh",                         TTRC("Refresh") },
    { "ui_filedialog_show_hidden",                     TTRC("Show Hidden") },
    { "ui_swap_input_direction ",                      TTRC("Swap Input Direction") },
    { "",                                              ""}
	/* clang-format on */
};

Parser.py

import re

# Open the input file and read its contents
with open('input.c', 'r') as file:
    data = file.read()

# Use a regular expression to find all action names
action_names = re.findall(r'{ "(.*?)",', data)

# Open the output file and write the action names in the desired format
with open('output.cs', 'w') as file:
    file.write('public static class BuiltinInputActions \n{\n')
    for name in action_names:
        if name:  # Ignore empty names
            name = name.strip()  # Trim the name
            # Convert the action name to PascalCase
            pascal_case_name = ''.join(word if word.upper() == word else word.title() for word in name.split('_'))
            # Replace 'ui' with 'UI'
            pascal_case_name = pascal_case_name.replace('Ui', 'UI')
            # Remove '.' character
            pascal_case_name = pascal_case_name.replace('.', '')
            # Write the action name to the output file
            file.write(f'\tpublic static readonly StringName {pascal_case_name} = "{name}";\n')
    file.write('}\n')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment