├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── addons └── layerNames │ ├── LICENSE │ ├── layerNames_plugin.gd │ └── plugin.cfg └── icon.png /.gitattributes: -------------------------------------------------------------------------------- 1 | # Normalize EOL for all files that Git considers text files. 2 | * text=auto eol=lf 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Godot 4+ specific ignores 2 | .godot/ 3 | 4 | 5 | # Godot-specific ignores 6 | .import/ 7 | export.cfg 8 | export_presets.cfg 9 | 10 | # Imported translations (automatically generated from CSV files) 11 | *.translation 12 | 13 | # Mono-specific ignores 14 | .mono/ 15 | data_*/ 16 | mono_crash.*.json 17 | 18 | # Android 19 | *.aar 20 | 21 | # Mac crap 22 | .DS_Store 23 | 24 | # plugin specific 25 | addons/layerNames/layerNames.gd 26 | example/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Maurice Butler 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Godot Layer Name Enums 2 | 3 | Automatically generate user friendly lookups of project layer names. 4 | 5 | ![useage](https://github.com/user-attachments/assets/482c9bc3-ae43-4132-b716-04e4a5caa298) 6 | 7 | 8 | ## Installation 9 | 10 | Copy the `addons/layerNames` directory into your `res://addons/` directory, or install via the [Asset Library](https://godotengine.org/asset-library/asset/3372) 11 | 12 | Go to `Project` -> `Project Settings` -> `Plugins` and enable `Layer Names`. 13 | 14 | ![install](https://github.com/user-attachments/assets/382c36c1-4bdc-4599-92ef-ef6246ab9c8b) 15 | 16 | 17 | ## License 18 | 19 | Licensed under the [MIT license](LICENSE) 20 | -------------------------------------------------------------------------------- /addons/layerNames/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Maurice Butler 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /addons/layerNames/layerNames_plugin.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | extends EditorPlugin 3 | 4 | const OUTPUT_FILE := "res://addons/layerNames/layerNames.gd" 5 | const SINGLETON_NAME := "LayerNames" 6 | const SETTING_KEY_FORMAT := "layer_names/%s/layer_%s" 7 | const RENDER_LAYER_COUNT := 20 8 | const PHYSICS_LAYER_COUNT := 32 9 | const NAVIGATION_LAYER_COUNT := 32 10 | const AVOIDANCE_LAYER_COUNT := 32 11 | const INPUT_WAIT_SECONDS = 1.5 12 | 13 | const VALID_IDENTIFIER_PATTERN := "[^a-z,A-Z,0-9,_,\\s]" 14 | 15 | var previous_text := "" 16 | var wait_tickets := 0 17 | 18 | func _enter_tree() -> void: 19 | print("LayerNames plugin activated.") 20 | ProjectSettings.settings_changed.connect(_update_layer_names) 21 | if not FileAccess.file_exists(OUTPUT_FILE): 22 | _update_layer_names() 23 | 24 | func _exit_tree() -> void: 25 | ProjectSettings.settings_changed.disconnect(_update_layer_names) 26 | remove_autoload_singleton(SINGLETON_NAME) 27 | 28 | func _update_layer_names() -> void: 29 | # delay a bit using a ticket system 30 | # avoids generating a file each time a letter is typed when user modifies layer names 31 | wait_tickets += 1 32 | var wait_number = wait_tickets 33 | await get_tree().create_timer(INPUT_WAIT_SECONDS).timeout 34 | if wait_number != wait_tickets: return 35 | 36 | var render_layers_2d_enum_string : String = _create_enum_string("2d_render", RENDER_LAYER_COUNT) 37 | var physics_layers_2d_enum_string : String = _create_enum_string("2d_physics", PHYSICS_LAYER_COUNT) 38 | var navigation_layers_2d_enum_string : String = _create_enum_string("2d_navigation", NAVIGATION_LAYER_COUNT) 39 | 40 | var render_layers_3d_enum_string : String = _create_enum_string("3d_render", RENDER_LAYER_COUNT) 41 | var physics_layers_3d_enum_string : String = _create_enum_string("3d_physics", PHYSICS_LAYER_COUNT) 42 | var navigation_layers_3d_enum_string : String = _create_enum_string("3d_navigation", NAVIGATION_LAYER_COUNT) 43 | 44 | var avoidance_layers_enum_string : String = _create_enum_string("avoidance", AVOIDANCE_LAYER_COUNT) 45 | 46 | var current_text = "".join([ 47 | "extends Node\n", 48 | render_layers_2d_enum_string, 49 | physics_layers_2d_enum_string, 50 | navigation_layers_2d_enum_string, 51 | render_layers_3d_enum_string, 52 | physics_layers_3d_enum_string, 53 | navigation_layers_3d_enum_string, 54 | avoidance_layers_enum_string, 55 | ]) 56 | 57 | if current_text == previous_text: 58 | return 59 | 60 | print("Regenerating LayerNames enums") 61 | 62 | var file = FileAccess.open(OUTPUT_FILE, FileAccess.WRITE) 63 | file.store_string(current_text) 64 | file.close() 65 | previous_text = current_text 66 | 67 | add_autoload_singleton(SINGLETON_NAME, OUTPUT_FILE) 68 | 69 | func _create_enum_string(layer_type : String, max_layer_count : int) -> String: 70 | var parts := layer_type.split("_") 71 | parts.reverse() 72 | 73 | var enum_name := _sanitise(" ".join(parts)) 74 | var enum_text := ["enum ", enum_name," { \nNONE = 0,\n"] 75 | 76 | for index in max_layer_count: 77 | var layer_number := str(index + 1) 78 | var name : String = ProjectSettings.get_setting(SETTING_KEY_FORMAT % [layer_type, layer_number]) 79 | var value := 2 ** (index) 80 | var key := _sanitise(name) 81 | if !key: 82 | key = "LAYER_%s" % layer_number 83 | 84 | enum_text.push_back("%s = %s,\n" % [key, value]) 85 | 86 | enum_text.push_back("}\n\n") 87 | 88 | return "".join(enum_text) 89 | 90 | func _sanitise(input : String) -> String: 91 | var regex = RegEx.new() 92 | regex.compile(VALID_IDENTIFIER_PATTERN) 93 | 94 | var output = regex.sub(input, "", true) 95 | output = output.to_snake_case().to_upper() 96 | 97 | if output.is_valid_identifier(): 98 | return output 99 | else: 100 | return "" 101 | -------------------------------------------------------------------------------- /addons/layerNames/plugin.cfg: -------------------------------------------------------------------------------- 1 | [plugin] 2 | 3 | name="Layer Names" 4 | description="Provides user friendly lookups of project layer names." 5 | author="MauriceButler" 6 | version="1.0.0" 7 | script="layerNames_plugin.gd" 8 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MauriceButler/godot-layer-name-enums/ad7ced847e0976b56dc42508f33e0c8fbaec2aed/icon.png --------------------------------------------------------------------------------