Skip to content

Commit

Permalink
Improve editor configuration by splitting it in two files
Browse files Browse the repository at this point in the history
  • Loading branch information
ephread committed May 19, 2019
1 parent efe0639 commit 0545a1f
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/.gutconfig.json export-ignore
/.inkgd_compiler.gd export-ignore
/CHANGELOG.md export-ignore
/CONTRIBUTING.md export-ignore
/default_env.tres export-ignore
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
export.cfg
export_presets.cfg

# Mono-specific ignores
.mono/
# inkgd ignores

.inkgd_compiler.cfg
4 changes: 4 additions & 0 deletions .inkgd_ink.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[inkgd]

source_file_path="res://examples/ink/the_intercept.ink"
target_file_path="res://examples/ink/the_intercept.ink.json"
1 change: 0 additions & 1 deletion addons/inkgd/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
*.import
inkgd.cfg
56 changes: 39 additions & 17 deletions addons/inkgd/editor/configuration.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

extends Object

const _ROOT_DIR = "res://addons/inkgd/"
const _EDITOR_ROOT_DIR = _ROOT_DIR + "editor/"
const _ROOT_DIR = "res://"

const _COMPILER_CONFIG = _ROOT_DIR + ".inkgd_compiler.cfg"
const _INK_CONFIG = _ROOT_DIR + ".inkgd_ink.cfg"

# ############################################################################ #
# Properties
Expand All @@ -22,7 +24,8 @@ var target_file_path: String = ""
# Private Properties
# ############################################################################ #

var _config_file = ConfigFile.new()
var _compiler_config_file = ConfigFile.new()
var _ink_config_file = ConfigFile.new()

# ############################################################################ #
# Overrides
Expand All @@ -36,30 +39,49 @@ func _init():
# ############################################################################ #

func retrieve():
var config_path = _EDITOR_ROOT_DIR + "inkgd.cfg"
retrieve_inklecate()
retrieve_ink()

func persist():
persist_inklecate()
persist_ink()

var err = _config_file.load(config_path)
func retrieve_inklecate():
var err = _compiler_config_file.load(_COMPILER_CONFIG)
if err != OK:
# Assuming it doesn't exist.
mono_path = ""
inklecate_path = ""
return


mono_path = _compiler_config_file.get_value("inkgd", "mono_path", "")
inklecate_path = _compiler_config_file.get_value("inkgd", "inklecate_path", "")

func retrieve_ink():
var err = _ink_config_file.load(_INK_CONFIG)
if err != OK:
# Assuming it doesn't exist.
source_file_path = ""
target_file_path = ""
return

source_file_path = _ink_config_file.get_value("inkgd", "source_file_path", "")
target_file_path = _ink_config_file.get_value("inkgd", "target_file_path", "")

mono_path = _config_file.get_value("ink", "mono_path", "")
inklecate_path = _config_file.get_value("ink", "inklecate_path", "")
source_file_path = _config_file.get_value("ink", "source_file_path", "")
target_file_path = _config_file.get_value("ink", "target_file_path", "")

func persist():
_config_file.set_value("ink", "mono_path", mono_path)
_config_file.set_value("ink", "inklecate_path", inklecate_path)
_config_file.set_value("ink", "source_file_path", source_file_path)
_config_file.set_value("ink", "target_file_path", target_file_path)
func persist_inklecate():
_compiler_config_file.set_value("inkgd", "mono_path", mono_path)
_compiler_config_file.set_value("inkgd", "inklecate_path", inklecate_path)

var err = _compiler_config_file.save(_COMPILER_CONFIG)
if err != OK:
printerr("Could not save: " + _COMPILER_CONFIG)

func persist_ink():
_ink_config_file.set_value("inkgd", "source_file_path", source_file_path)
_ink_config_file.set_value("inkgd", "target_file_path", target_file_path)

var config_path = _EDITOR_ROOT_DIR + "inkgd.cfg"
var err = _config_file.save(config_path)
var err = _ink_config_file.save(_INK_CONFIG)
if err != OK:
printerr("Could not save: " + config_path)
printerr("Could not save: " + _INK_CONFIG)
24 changes: 13 additions & 11 deletions addons/inkgd/editor/ink_dock.gd
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,20 @@ func _file_dialog_hide():
InkFileDialog.disconnect("file_selected", self, "_executable_selected")

func _mono_selected(path: String):
configuration.mono_path = path
update_save_and_cleanup(path, MonoLineEdit, "_mono_selected")
configuration.mono_path = ProjectSettings.globalize_path(path)
update_save_and_cleanup(configuration.mono_path, MonoLineEdit, "_mono_selected")

func _source_file_selected(path: String):
configuration.source_file_path = path
update_save_and_cleanup(path, SourceFileLineEdit, "_source_file_selected")
configuration.source_file_path = ProjectSettings.localize_path(path)
update_save_and_cleanup(configuration.source_file_path, SourceFileLineEdit, "_source_file_selected")

func _target_file_selected(path: String):
configuration.target_file_path = path
update_save_and_cleanup(path, TargetFileLineEdit, "_target_file_selected")
configuration.target_file_path = ProjectSettings.localize_path(path)
update_save_and_cleanup(configuration.target_file_path, TargetFileLineEdit, "_target_file_selected")

func _executable_selected(path: String):
configuration.inklecate_path = path
update_save_and_cleanup(path, ExecutableLineEdit, "_executable_selected")
configuration.inklecate_path = ProjectSettings.globalize_path(path)
update_save_and_cleanup(configuration.inklecate_path, ExecutableLineEdit, "_executable_selected")

func _configuration_focus_exited():
configuration.mono_path = MonoLineEdit.text
Expand Down Expand Up @@ -178,9 +178,11 @@ func _build_button_pressed():
if is_windows:
OS.execute(configuration.inklecate_path, [], true, output)
else:
OS.execute(configuration.mono_path, [configuration.inklecate_path, '-o',
configuration.target_file_path, configuration.source_file_path], true, output)

OS.execute(configuration.mono_path, [
configuration.inklecate_path, '-o',
ProjectSettings.globalize_path(configuration.target_file_path),
ProjectSettings.globalize_path(configuration.source_file_path)
], true, output)

# Outputing a BOM is inklecate's way of saying that everything went through.
# This is fragile. There might be a better option to express the BOM.
Expand Down
2 changes: 1 addition & 1 deletion examples/ink/the_intercept.ink.json

Large diffs are not rendered by default.

0 comments on commit 0545a1f

Please sign in to comment.