Skip to content

Commit

Permalink
Use EditorSettings instead of ProjectSettings. Closes #19
Browse files Browse the repository at this point in the history
  • Loading branch information
nklbdev committed Oct 30, 2023
1 parent 7f7377d commit 278b226
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 79 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

**Importality - is an add-on for [Godot](https://godotengine.org) engine for importing graphics and animations from popular formats.**

### ATTENTION!
In version 0.3.0, the plugin settings were moved from the ProjectSettings to the EditorSettings! This may come as a surprise and may break some of your configured processes! But this will allow you to avoid publishing your local settings along with the project file to the Git repository, and will make CI/DC easier.

## 📜 Table of contents

- [Introduction](#introduction)
Expand Down
3 changes: 3 additions & 0 deletions README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

**Importality - это дополнение (addon) для движка [Godot](https://godotengine.org) для импорта графики и анимации из популярных форматов.**

### ВНИМАНИЕ!
В версии 0.3.0 настройки плагина были перенесены из настроек проекта (ProjectSettings) в настройки редактора (EditorSettings)! Это может стать неожиданностью и может сломать некоторые ваши настроенные процессы! Но это позволит вам не публиковать ваши локальные настройки вместе с файлом проекта в репозиторий Git, и облегчит CI/CD.

## 📜 Содержание

- [Вступление](#вступление)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ extends "standalone_image_format_loader_extension.gd"

const _Common = preload("common.gd")

static var command_building_rules_for_custom_image_loader_project_setting: _ProjectSetting = _ProjectSetting.new(
static var command_building_rules_for_custom_image_loader_setting: _Setting = _Setting.new(
"command_building_rules_for_custom_image_loader", PackedStringArray(), TYPE_PACKED_STRING_ARRAY, PROPERTY_HINT_NONE)

func _get_recognized_extensions() -> PackedStringArray:
var rules_by_extensions_result: _ProjectSetting.GettingValueResult = command_building_rules_for_custom_image_loader_project_setting.get_value()
var rules_by_extensions_result: _Setting.GettingValueResult = command_building_rules_for_custom_image_loader_setting.get_value()
if rules_by_extensions_result.error:
push_error("Failed to get command building rules for custom image loader project setting")
push_error("Failed to get command building rules for custom image loader setting")
return PackedStringArray()
var extensions: PackedStringArray
for rule_string in rules_by_extensions_result.value:
Expand All @@ -24,8 +24,8 @@ func _get_recognized_extensions() -> PackedStringArray:
extensions.push_back(extension)
return extensions

func get_project_settings() -> Array[_ProjectSetting]:
return [command_building_rules_for_custom_image_loader_project_setting]
func get_settings() -> Array[_Setting]:
return [command_building_rules_for_custom_image_loader_setting]

static var regex_middle_spaces: RegEx = RegEx.create_from_string("(?<=\\S)\\s(?>=\\S)")
static func normalize_string(source: String) -> String:
Expand Down Expand Up @@ -58,14 +58,14 @@ func _load_image(
scale: float
) -> Error:

var temp_dir_path_result: _ProjectSetting.GettingValueResult = _Common.common_temporary_files_directory_path_project_setting.get_value()
var temp_dir_path_result: _Setting.GettingValueResult = _Common.common_temporary_files_directory_path_setting.get_value()
if temp_dir_path_result.error:
push_error("Failed to get Temporary Files Directory Path to export image from source file: %s" % [temp_dir_path_result])
return ERR_UNCONFIGURED

var rules_by_extensions_result: _ProjectSetting.GettingValueResult = command_building_rules_for_custom_image_loader_project_setting.get_value()
var rules_by_extensions_result: _Setting.GettingValueResult = command_building_rules_for_custom_image_loader_setting.get_value()
if rules_by_extensions_result.error:
push_error("Failed to get command building rules for custom image loader project setting")
push_error("Failed to get command building rules for custom image loader setting")
return ERR_UNCONFIGURED

var command_templates_by_extensions: Dictionary
Expand Down
4 changes: 2 additions & 2 deletions addons/nklbdev.importality/common.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@tool

const _ProjectSetting = preload("project_setting.gd")
const _Setting = preload("setting.gd")

const SPRITE_SHEET_LAYOUTS_NAMES: PackedStringArray = [
"Packed",
Expand Down Expand Up @@ -91,7 +91,7 @@ class AnimationLibraryInfo:
static func get_vector2i(dict: Dictionary, x_key: String, y_key: String) -> Vector2i:
return Vector2i(int(dict[x_key]), int(dict[y_key]))

static var common_temporary_files_directory_path_project_setting: _ProjectSetting = _ProjectSetting.new(
static var common_temporary_files_directory_path_setting: _Setting = _Setting.new(
"temporary_files_directory_path", "", TYPE_STRING, PROPERTY_HINT_GLOBAL_DIR,
"", true, func(v: String): return v.is_empty())

Expand Down
13 changes: 8 additions & 5 deletions addons/nklbdev.importality/editor_plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ var __editor_import_plugins: Array[EditorImportPlugin]
var __image_format_loader_extensions: Array[ImageFormatLoaderExtension]

func _enter_tree() -> void:
var editor_file_system: EditorFileSystem = get_editor_interface().get_resource_filesystem()
var editor_interface: EditorInterface = get_editor_interface()
var editor_file_system: EditorFileSystem = editor_interface.get_resource_filesystem()
var editor_settings: EditorSettings = editor_interface.get_editor_settings()

var exporters: Array[ExporterBase]
for Exporter in EXPORTERS_SCRIPTS:
var exporter: ExporterBase = Exporter.new(editor_file_system)
for setting in exporter.get_project_settings():
setting.register()
for setting in exporter.get_settings():
setting.register(editor_settings)
exporters.push_back(exporter)
var image_format_loader_extension: ImageFormatLoaderExtension = \
exporter.get_image_format_loader_extension()
Expand All @@ -59,8 +62,8 @@ func _enter_tree() -> void:
for Extension in STANDALONE_IMAGE_FORMAT_LOADER_EXTENSIONS:
var image_format_loader_extension: StandaloneImageFormatLoaderExtension = \
Extension.new() as StandaloneImageFormatLoaderExtension
for setting in image_format_loader_extension.get_project_settings():
setting.register()
for setting in image_format_loader_extension.get_settings():
setting.register(editor_settings)
__image_format_loader_extensions.push_back(image_format_loader_extension)
image_format_loader_extension.add_format_loader()

Expand Down
12 changes: 6 additions & 6 deletions addons/nklbdev.importality/export/_.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extends RefCounted
const _Result = preload("../result.gd").Class
const _Common = preload("../common.gd")
const _Options = preload("../options.gd")
const _ProjectSetting = preload("../project_setting.gd")
const _Setting = preload("../setting.gd")
const _DirAccessExtensions = preload("../dir_access_ext.gd")

const _SpriteSheetBuilderBase = preload("../sprite_sheet_builder/_.gd")
Expand Down Expand Up @@ -41,7 +41,7 @@ class ExportResult:

var __name: String
var __recognized_extensions: PackedStringArray
var __project_settings: Array[_ProjectSetting] = [_Common.common_temporary_files_directory_path_project_setting]
var __settings: Array[_Setting] = [_Common.common_temporary_files_directory_path_setting]
var __options: Array[Dictionary] = [
_Options.create_option(_Options.EDGES_ARTIFACTS_AVOIDANCE_METHOD, _Common.EdgesArtifactsAvoidanceMethod.NONE,
PROPERTY_HINT_ENUM, ",".join(_Common.EDGES_ARTIFACTS_AVOIDANCE_METHODS_NAMES),
Expand Down Expand Up @@ -76,13 +76,13 @@ func _init(
name: String,
recognized_extensions: PackedStringArray,
options: Array[Dictionary],
project_settings: Array[_ProjectSetting],
settings: Array[_Setting],
image_format_loader_extension: ImageFormatLoaderExtension = null
) -> void:
__name = name
__recognized_extensions = recognized_extensions
__options.append_array(options)
__project_settings.append_array(project_settings)
__settings.append_array(settings)
__image_format_loader_extension = image_format_loader_extension

func get_recognized_extensions() -> PackedStringArray:
Expand All @@ -94,8 +94,8 @@ func get_options() -> Array[Dictionary]:
func get_name() -> String:
return __name

func get_project_settings() -> Array[_ProjectSetting]:
return __project_settings
func get_settings() -> Array[_Setting]:
return __settings

func get_image_format_loader_extension() -> ImageFormatLoaderExtension:
return __image_format_loader_extension
Expand Down
44 changes: 22 additions & 22 deletions addons/nklbdev.importality/export/aseprite.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@ const __aseprite_sheet_types_by_sprite_sheet_layout: PackedStringArray = \
const __aseprite_animation_directions: PackedStringArray = \
[ "forward", "reverse", "pingpong", "pingpong_reverse" ]

var __os_command_project_setting: _ProjectSetting = _ProjectSetting.new(
var __os_command_setting: _Setting = _Setting.new(
"aseprite_or_libre_sprite_command", "", TYPE_STRING, PROPERTY_HINT_NONE,
"", true, func(v: String): return v.is_empty())

var __os_command_arguments_project_setting: _ProjectSetting = _ProjectSetting.new(
var __os_command_arguments_setting: _Setting = _Setting.new(
"aseprite_or_libre_sprite_command_arguments", PackedStringArray(), TYPE_PACKED_STRING_ARRAY, PROPERTY_HINT_NONE,
"", true, func(v: PackedStringArray): return false)

func _init(editor_file_system: EditorFileSystem) -> void:
var recognized_extensions: PackedStringArray = ["ase", "aseprite"]
super("Aseprite", recognized_extensions, [],
[__os_command_project_setting, __os_command_arguments_project_setting],
[__os_command_setting, __os_command_arguments_setting],
CustomImageFormatLoaderExtension.new(
recognized_extensions,
__os_command_project_setting,
__os_command_arguments_project_setting,
_Common.common_temporary_files_directory_path_project_setting))
__os_command_setting,
__os_command_arguments_setting,
_Common.common_temporary_files_directory_path_setting))

func _export(res_source_file_path: String, options: Dictionary) -> ExportResult:
var result: ExportResult = ExportResult.new()
var err: Error

var os_command_result: _ProjectSetting.GettingValueResult = __os_command_project_setting.get_value()
var os_command_result: _Setting.GettingValueResult = __os_command_setting.get_value()
if os_command_result.error:
result.fail(ERR_UNCONFIGURED, "Failed to get Aseprite Command to export spritesheet", os_command_result)
return result

var os_command_arguments_result: _ProjectSetting.GettingValueResult = __os_command_arguments_project_setting.get_value()
var os_command_arguments_result: _Setting.GettingValueResult = __os_command_arguments_setting.get_value()
if os_command_arguments_result.error:
result.fail(ERR_UNCONFIGURED, "Failed to get Aseprite Command Arguments to export spritesheet", os_command_arguments_result)
return result

var temp_dir_path_result: _ProjectSetting.GettingValueResult = _Common.common_temporary_files_directory_path_project_setting.get_value()
var temp_dir_path_result: _Setting.GettingValueResult = _Common.common_temporary_files_directory_path_setting.get_value()
if temp_dir_path_result.error:
result.fail(ERR_UNCONFIGURED, "Failed to get Temporary Files Directory Path to export spritesheet", temp_dir_path_result)
return result
Expand Down Expand Up @@ -197,20 +197,20 @@ class CustomImageFormatLoaderExtension:
extends ImageFormatLoaderExtension

var __recognized_extensions: PackedStringArray
var __os_command_project_setting: _ProjectSetting
var __os_command_arguments_project_setting: _ProjectSetting
var __common_temporary_files_directory_path_project_setting: _ProjectSetting
var __os_command_setting: _Setting
var __os_command_arguments_setting: _Setting
var __common_temporary_files_directory_path_setting: _Setting

func _init(recognized_extensions: PackedStringArray,
os_command_project_setting: _ProjectSetting,
os_command_arguments_project_setting: _ProjectSetting,
common_temporary_files_directory_path_project_setting: _ProjectSetting
os_command_setting: _Setting,
os_command_arguments_setting: _Setting,
common_temporary_files_directory_path_setting: _Setting
) -> void:
__recognized_extensions = recognized_extensions
__os_command_project_setting = os_command_project_setting
__os_command_arguments_project_setting = os_command_arguments_project_setting
__common_temporary_files_directory_path_project_setting = \
common_temporary_files_directory_path_project_setting
__os_command_setting = os_command_setting
__os_command_arguments_setting = os_command_arguments_setting
__common_temporary_files_directory_path_setting = \
common_temporary_files_directory_path_setting

func _get_recognized_extensions() -> PackedStringArray:
return __recognized_extensions
Expand All @@ -219,17 +219,17 @@ class CustomImageFormatLoaderExtension:
var global_source_file_path: String = file_access.get_path_absolute()
var err: Error

var os_command_result: _ProjectSetting.GettingValueResult = __os_command_project_setting.get_value()
var os_command_result: _Setting.GettingValueResult = __os_command_setting.get_value()
if os_command_result.error:
push_error(os_command_result.error_description)
return os_command_result.error

var os_command_arguments_result: _ProjectSetting.GettingValueResult = __os_command_arguments_project_setting.get_value()
var os_command_arguments_result: _Setting.GettingValueResult = __os_command_arguments_setting.get_value()
if os_command_arguments_result.error:
push_error(os_command_arguments_result.error_description)
return os_command_arguments_result.error

var temp_dir_path_result: _ProjectSetting.GettingValueResult = _Common.common_temporary_files_directory_path_project_setting.get_value()
var temp_dir_path_result: _Setting.GettingValueResult = _Common.common_temporary_files_directory_path_setting.get_value()
if temp_dir_path_result.error:
push_error("Failed to get Temporary Files Directory Path to export spritesheet")
return temp_dir_path_result.error
Expand Down
14 changes: 7 additions & 7 deletions addons/nklbdev.importality/export/krita.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ extends "_.gd"

const _XML = preload("../xml.gd")

var __os_command_project_setting: _ProjectSetting = _ProjectSetting.new(
var __os_command_setting: _Setting = _Setting.new(
"krita_command", "", TYPE_STRING, PROPERTY_HINT_NONE,
"", true, func(v: String): return v.is_empty())

var __os_command_arguments_project_setting: _ProjectSetting = _ProjectSetting.new(
var __os_command_arguments_setting: _Setting = _Setting.new(
"krita_command_arguments", PackedStringArray(), TYPE_PACKED_STRING_ARRAY, PROPERTY_HINT_NONE,
"", true, func(v: PackedStringArray): return false)

func _init(editor_file_system: EditorFileSystem) -> void:
var recognized_extensions: PackedStringArray = ["kra", "krita"]
super("Krita", recognized_extensions, [], [
__os_command_project_setting,
__os_command_arguments_project_setting,
__os_command_setting,
__os_command_arguments_setting,
], CustomImageFormatLoaderExtension.new(recognized_extensions))

func __validate_image_name(image_name: String) -> _Result:
Expand All @@ -37,17 +37,17 @@ func _export(res_source_file_path: String, options: Dictionary) -> ExportResult:
var result: ExportResult = ExportResult.new()
var err: Error

var os_command_result: _ProjectSetting.GettingValueResult = __os_command_project_setting.get_value()
var os_command_result: _Setting.GettingValueResult = __os_command_setting.get_value()
if os_command_result.error:
result.fail(ERR_UNCONFIGURED, "Failed to get Krita Command to export spritesheet", os_command_result)
return result

var os_command_arguments_result: _ProjectSetting.GettingValueResult = __os_command_arguments_project_setting.get_value()
var os_command_arguments_result: _Setting.GettingValueResult = __os_command_arguments_setting.get_value()
if os_command_arguments_result.error:
result.fail(ERR_UNCONFIGURED, "Failed to get Krita Command Arguments to export spritesheet", os_command_arguments_result)
return result

var temp_dir_path_result: _ProjectSetting.GettingValueResult = _Common.common_temporary_files_directory_path_project_setting.get_value()
var temp_dir_path_result: _Setting.GettingValueResult = _Common.common_temporary_files_directory_path_setting.get_value()
if temp_dir_path_result.error:
result.fail(ERR_UNCONFIGURED, "Failed to get Temporary Files Directory Path to export spritesheet", temp_dir_path_result)
return result
Expand Down
Loading

0 comments on commit 278b226

Please sign in to comment.