Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Started working on the beta 2 update for Dialogic 2 #1244

Merged
merged 2 commits into from
Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions addons/dialogic/Editor/CharacterEditor/CharacterEditor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -178,26 +178,25 @@ func open_portrait_folder_select() -> void:


func import_portraits_from_folder(path:String) -> void:
var dir := Directory.new()
if dir.open(path) == OK:
dir.list_dir_begin()
var file_name :String = dir.get_next()
while file_name != "":
if not dir.current_is_dir():
var file_lower = file_name.to_lower()
if '.svg' in file_lower or '.png' in file_lower:
if not '.import' in file_lower:
var final_name :String= path+ "/" + file_name
add_portrait(file_name.trim_suffix('.'+file_name.get_extension()), {'scene':"",'image':final_name, 'scale':1, 'offset':Vector2(), 'mirror':false})
file_name = dir.get_next()
else:
print("An error occurred when trying to access the path.")
var dir := DirAccess.open(path)
dir.list_dir_begin()
var file_name :String = dir.get_next()
while file_name != "":
if not dir.current_is_dir():
var file_lower = file_name.to_lower()
if '.svg' in file_lower or '.png' in file_lower:
if not '.import' in file_lower:
var final_name :String= path+ "/" + file_name
add_portrait(file_name.trim_suffix('.'+file_name.get_extension()), {'scene':"",'image':final_name, 'scale':1, 'offset':Vector2(), 'mirror':false})
file_name = dir.get_next()


func add_portrait(portrait_name:String='New portrait', portrait_data:Dictionary={'scene':"", 'image':'', 'scale':1, 'offset':Vector2(), 'mirror':false}) -> void:
var root = %PortraitTree.get_root()
add_portrait_item(portrait_name, portrait_data, root).select(0)
something_changed()


func load_portrait_tree() -> void:
%PortraitTree.clear()
var root = %PortraitTree.create_item()
Expand All @@ -208,6 +207,7 @@ func load_portrait_tree() -> void:
if root.get_child_count():
root.get_first_child().select(0)


func filter_portrait_list(filter_term:String = '') -> void:
var item : TreeItem = %PortraitTree.get_root().get_first_child()
while true:
Expand Down
3 changes: 1 addition & 2 deletions addons/dialogic/Editor/EditorView.gd
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ func _exit_tree():

func open_last_resource():
if ProjectSettings.has_setting('dialogic/editor/last_resources'):
var directory := Directory.new();
var path :String= ProjectSettings.get_setting('dialogic/editor/last_resources')[0]
if directory.file_exists(path):
if FileAccess.file_exists(path):
DialogicUtil.get_dialogic_plugin().editor_interface.inspect_object(load(path))


Expand Down
24 changes: 7 additions & 17 deletions addons/dialogic/Editor/Settings/Settings_Translations.gd
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ func _on_TransInitialize_pressed():
if %TransOrigLanguage.text.is_empty():
%TransOrigLanguage.text = ProjectSettings.get_setting('locale/fallback')
var orig_locale = %TransOrigLanguage.text.strip_edges()
var file = File.new()

if %TransFileMode.selected == 0:
file.open('res://dialogic_translation.csv', File.WRITE)
var file := FileAccess.open('res://dialogic_translation.csv', FileAccess.WRITE)
ProjectSettings.set_setting('dialogic/translation_path', 'res://dialogic_translation.csv')
file.store_csv_line(['keys', orig_locale])
else:
Expand All @@ -68,24 +67,17 @@ func _on_TransInitialize_pressed():


for timeline_path in DialogicUtil.list_resources_of_type('.dtl'):
var file := FileAccess.open(timeline_path.trim_suffix('.dtl')+'_translation.csv', FileAccess.WRITE)
if %TransFileMode.selected == 1:
file.open(timeline_path.trim_suffix('.dtl')+'_translation.csv', File.WRITE)
file.store_csv_line(['keys', orig_locale])

var tml:DialogicTimeline = load(timeline_path)
for event in tml.get_events():
#if event.
if event.can_be_translated():
file.store_csv_line([event.add_translation_id(), event.get_original_translation_text()])

ResourceSaver.save(tml, timeline_path)

if %TransFileMode.selected == 1:
file.close()

if %TransFileMode.selected == 0:
file.close()


ProjectSettings.set_setting('dialogic/translation_enabled', true)
ProjectSettings.save()
Expand All @@ -96,26 +88,24 @@ func _on_TransRemove_pressed():

func erase_translations():
ProjectSettings.set_setting('dialogic/translation_enabled', false)
var file = File.new()
var dir = Directory.new()
var trans_files = Array(ProjectSettings.get_setting('locale/translations'))
var trans_path = DialogicUtil.get_project_setting('dialogic/translation_path', '')
if trans_path.ends_with('.csv'):
for x_file in DialogicUtil.listdir(trans_path.get_base_dir()):
if x_file.ends_with('.translation'):
trans_files.erase(trans_path.get_base_dir().path_join(x_file))
dir.remove(trans_path.get_base_dir().path_join(x_file))
dir.remove(DialogicUtil.get_project_setting('dialogic/translation_path', ''))
DirAccess.remove_absolute(trans_path.get_base_dir().path_join(x_file))
DirAccess.remove_absolute(DialogicUtil.get_project_setting('dialogic/translation_path', ''))

ProjectSettings.set_setting('dialogic/translation_path', null)

for timeline_path in DialogicUtil.list_resources_of_type('.dtl'):
if trans_path == '':
dir.remove(timeline_path.trim_suffix('.dtl')+'_translation.csv')
DirAccess.remove_absolute(timeline_path.trim_suffix('.dtl')+'_translation.csv')
for x_file in DialogicUtil.listdir(timeline_path.get_base_dir()):
if x_file.ends_with('.translation'):
trans_files.erase(timeline_path.get_base_dir().path_join(x_file))
dir.remove(timeline_path.get_base_dir().path_join(x_file))
DirAccess.remove_absolute(timeline_path.get_base_dir().path_join(x_file))

var tml:DialogicTimeline = load(timeline_path)
for event in tml.get_events():
Expand Down
32 changes: 16 additions & 16 deletions addons/dialogic/Editor/VisualEditor/VisualEditor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,14 @@ func _on_event_block_gui_input(event, item: Node):
var to_position = moving_piece.get_index()
if move_start_position != to_position:
TimelineUndoRedo.create_action("[D] Moved event (type '"+moving_piece.resource.to_string()+"').")
TimelineUndoRedo.add_do_method(self, "move_block_to_index", move_start_position, to_position)
TimelineUndoRedo.add_undo_method(self, "move_block_to_index", to_position, move_start_position)
TimelineUndoRedo.add_do_method(move_block_to_index.call(move_start_position, to_position))
TimelineUndoRedo.add_undo_method(move_block_to_index.call(to_position, move_start_position))

# in case a something like a choice or condition was moved BELOW it's end node the end_node is moved as well!!!
if moving_piece.resource.can_contain_events:
if moving_piece.end_node.get_index() < to_position:
TimelineUndoRedo.add_do_method(self, "move_block_to_index", moving_piece.end_node.get_index(), to_position)
TimelineUndoRedo.add_undo_method(self, "move_block_to_index", to_position+1, moving_piece.end_node.get_index())
TimelineUndoRedo.add_do_method(move_block_to_index.call(moving_piece.end_node.get_index(), to_position))
TimelineUndoRedo.add_undo_method(move_block_to_index.call(to_position+1, moving_piece.end_node.get_index()))

# move it back so the DO action works. (Kinda stupid but whatever)
move_block_to_index(to_position, move_start_position)
Expand Down Expand Up @@ -411,8 +411,8 @@ func _input(event):
if (len(selected_items) != 0):
var events_indexed = get_events_indexed(selected_items)
TimelineUndoRedo.create_action("[D] Deleting "+str(len(selected_items))+" event(s).")
TimelineUndoRedo.add_do_method(self, "delete_events_indexed", events_indexed)
TimelineUndoRedo.add_undo_method(self, "add_events_indexed", events_indexed)
TimelineUndoRedo.add_do_method(delete_events_indexed.call(events_indexed))
TimelineUndoRedo.add_undo_method(add_events_indexed.call(events_indexed))
TimelineUndoRedo.commit_action()
get_viewport().set_input_as_handled()

Expand Down Expand Up @@ -456,17 +456,17 @@ func _input(event):
paste_position = %Timeline.get_child_count()-1
if events_list:
TimelineUndoRedo.create_action("[D] Pasting "+str(len(events_list))+" event(s).")
TimelineUndoRedo.add_do_method(self, "add_events_at_index", events_list, paste_position)
TimelineUndoRedo.add_undo_method(self, "remove_events_at_index", paste_position+1, len(events_list))
TimelineUndoRedo.add_do_method(add_events_at_index.call(events_list, paste_position))
TimelineUndoRedo.add_undo_method(remove_events_at_index.call(paste_position+1, len(events_list)))
TimelineUndoRedo.commit_action()
get_viewport().set_input_as_handled()

# CTRL X
if is_event_pressed(event, KEY_X, false, false, true):
var events_indexed = get_events_indexed(selected_items)
TimelineUndoRedo.create_action("[D] Cut "+str(len(selected_items))+" event(s).")
TimelineUndoRedo.add_do_method(self, "cut_events_indexed", events_indexed)
TimelineUndoRedo.add_undo_method(self, "add_events_indexed", events_indexed)
TimelineUndoRedo.add_do_method(cut_events_indexed.call(events_indexed))
TimelineUndoRedo.add_undo_method(add_events_indexed.call(events_indexed))
TimelineUndoRedo.commit_action()
get_viewport().set_input_as_handled()

Expand All @@ -476,8 +476,8 @@ func _input(event):
var events = get_events_indexed(selected_items).values()
var at_index = selected_items[-1].get_index()
TimelineUndoRedo.create_action("[D] Duplicate "+str(len(events))+" event(s).")
TimelineUndoRedo.add_do_method(self, "add_events_at_index", events, at_index)
TimelineUndoRedo.add_undo_method(self, "remove_events_at_index", at_index, len(events))
TimelineUndoRedo.add_do_method(add_events_at_index.call(events, at_index))
TimelineUndoRedo.add_undo_method(remove_events_at_index.call(at_index, len(events)))
TimelineUndoRedo.commit_action()
get_viewport().set_input_as_handled()

Expand Down Expand Up @@ -753,13 +753,13 @@ func _add_event_button_pressed(event_script):

if event_script.can_contain_events:
TimelineUndoRedo.create_action("[D] Add event.")
TimelineUndoRedo.add_do_method(self, "add_event_with_end_branch", event_script.duplicate(), at_index, true, true)
TimelineUndoRedo.add_undo_method(self, "remove_events_at_index", at_index, 2)
TimelineUndoRedo.add_do_method(add_event_with_end_branch.call(event_script.duplicate(), at_index, true, true))
TimelineUndoRedo.add_undo_method(remove_events_at_index.call(at_index, 2))
TimelineUndoRedo.commit_action()
else:
TimelineUndoRedo.create_action("[D] Add event.")
TimelineUndoRedo.add_do_method(self, "add_event_node", event_script.duplicate(), at_index, true, true)
TimelineUndoRedo.add_undo_method(self, "remove_events_at_index", at_index, 1)
TimelineUndoRedo.add_do_method(add_event_node.call(event_script.duplicate(), at_index, true, true))
TimelineUndoRedo.add_undo_method(remove_events_at_index.call(at_index, 1))
TimelineUndoRedo.commit_action()
something_changed()
scroll_to_piece(at_index)
Expand Down
59 changes: 21 additions & 38 deletions addons/dialogic/Events/Converter/Settings_Converter.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,19 @@ func refresh():

func _on_verify_pressed():

var file = File.new()

%OutputLog.text = ""

if file.file_exists("res://dialogic/settings.cfg"):
if FileAccess.file_exists("res://dialogic/settings.cfg"):
%OutputLog.text += "[√] Dialogic 1.x data [color=green]found![/color]\r\n"

if file.file_exists("res://dialogic/definitions.json"):
if FileAccess.file_exists("res://dialogic/definitions.json"):
%OutputLog.text += "[√] Dialogic 1.x definitions [color=green]found![/color]\r\n"
else:
%OutputLog.text += "[X] Dialogic 1.x definitions [color=red]not found![/color]\r\n"
%OutputLog.text += "Please copy the res://dialogic folder from your Dialogic 1.x project into this project and try again.\r\n"
return

if file.file_exists("res://dialogic/settings.cfg"):
if FileAccess.file_exists("res://dialogic/settings.cfg"):
%OutputLog.text += "[√] Dialogic 1.x settings [color=green]found![/color]\r\n"
else:
%OutputLog.text += "[X] Dialogic 1.x settings [color=red]not found![/color]\r\n"
Expand All @@ -49,7 +47,7 @@ func _on_verify_pressed():
%OutputLog.text += "\r\n"

%OutputLog.text += "Verifying data:\r\n"
file.open("res://dialogic/folder_structure.json",File.READ)
var file := FileAccess.open("res://dialogic/folder_structure.json", FileAccess.READ)
var fileContent = file.get_as_text()
var json_object = JSON.new()

Expand Down Expand Up @@ -99,7 +97,7 @@ func _on_verify_pressed():
%OutputLog.text += "[color=yellow]There may be an issue, please check in Dialogic 1.x to make sure that is correct![/color]\r\n"


file.open("res://dialogic/definitions.json",File.READ)
file = FileAccess.open("res://dialogic/definitions.json",FileAccess.READ)
fileContent = file.get_as_text()
json_object = JSON.new()

Expand Down Expand Up @@ -163,15 +161,13 @@ func _on_verify_pressed():
%OutputLog.text += "Initial integrity check completed!\r\n"


var directory = Directory.new()
var directoryCheck = directory.dir_exists(conversionRootFolder)

if directoryCheck:
if DirAccess.dir_exists_absolute(conversionRootFolder):
%OutputLog.text += "[color=yellow]Conversion folder already exists, coverting will overwrite existing files.[/color]\r\n"
else:
%OutputLog.text += conversionRootFolder
%OutputLog.text += "Folders are being created in " + conversionRootFolder + ". Converted files will be located there.\r\n"
directory.open("res://")
var directory = DirAccess.open("res://")
directory.make_dir(conversionRootFolder)
directory.open(conversionRootFolder)
directory.make_dir("characters")
Expand All @@ -188,8 +184,7 @@ func _on_verify_pressed():

func list_files_in_directory(path):
var files = []
var dir = Directory.new()
dir.open(path)
var dir = DirAccess.open(path)
dir.list_dir_begin()

while true:
Expand Down Expand Up @@ -244,8 +239,7 @@ func convertTimelines():
var folderPath = timelineFolderBreakdown[item]
%OutputLog.text += "Timeline " + folderPath + item +": "
var jsonData = {}
var file = File.new()
file.open("res://dialogic/timelines/" + item,File.READ)
var file := FileAccess.open("res://dialogic/timelines/" + item, FileAccess.READ)
var fileContent = file.get_as_text()
var json_object = JSON.new()

Expand All @@ -256,10 +250,9 @@ func convertTimelines():
var fileName = contents["metadata"]["name"]
%OutputLog.text += "Name: " + fileName + ", " + str(contents["events"].size()) + " timeline events"

var directory = Directory.new()
var directoryCheck = directory.dir_exists(conversionRootFolder + "/timelines" + folderPath)
if !directoryCheck:
directory.open(conversionRootFolder + "/timelines")

if not DirAccess.dir_exists_absolute(conversionRootFolder + "/timelines" + folderPath):
var directory = DirAccess.open(conversionRootFolder + "/timelines")

var progresiveDirectory = ""
for pathItem in folderPath.split('/'):
Expand All @@ -274,7 +267,8 @@ func convertTimelines():
folderPath = folderPath.left(-1)
# we will save it as an intermediary file first, then on second pass cleanup make it the .dtl
var newFilePath = conversionRootFolder + "/timelines" + folderPath + "/" + fileName + ".cnv"
file.open(newFilePath,File.WRITE)

file = FileAccess.open(newFilePath, FileAccess.WRITE)

# update the new location so we know where second pass items are

Expand Down Expand Up @@ -663,7 +657,6 @@ func convertTimelines():
file.store_string(eventLine)

file.store_string("\r\n\r\n")
file.close()



Expand All @@ -677,11 +670,8 @@ func convertTimelines():
for item in timelineFolderBreakdown:
%OutputLog.text += "Verifying file: " + timelineFolderBreakdown[item] + "\r\n"

var oldFile = File.new()
oldFile.open(timelineFolderBreakdown[item] ,File.READ)

var newFile = File.new()
newFile.open(timelineFolderBreakdown[item].replace(".cnv", ".dtl") ,File.WRITE)
var oldFile = FileAccess.open(timelineFolderBreakdown[item], FileAccess.READ)
var newFile = FileAccess.open(timelineFolderBreakdown[item].replace(".cnv", ".dtl"), FileAccess.WRITE)

var regex = RegEx.new()
regex.compile('(<.*?>)')
Expand Down Expand Up @@ -725,14 +715,10 @@ func convertTimelines():
newFile.store_string(line)
else:
newFile.store_string(line)


oldFile.close()
newFile.close()

var dir = Directory.new()
var fileDirectory = timelineFolderBreakdown[item].replace(timelineFolderBreakdown[item].split("/")[-1], "")
dir.open(fileDirectory)
var dir = DirAccess.open(fileDirectory)
dir.remove(timelineFolderBreakdown[item])

%OutputLog.text += "Completed conversion of file: " + timelineFolderBreakdown[item].replace(".cnv", ".dtl") + "\r\n"
Expand All @@ -748,8 +734,7 @@ func convertCharacters():
var folderPath = characterFolderBreakdown[item]
%OutputLog.text += "Character " + folderPath + item +": "
var jsonData = {}
var file = File.new()
file.open("res://dialogic/characters/" + item,File.READ)
var file := FileAccess.open("res://dialogic/characters/" + item, FileAccess.READ)
var fileContent = file.get_as_text()
var json_object = JSON.new()

Expand All @@ -766,10 +751,9 @@ func convertCharacters():



var directory = Directory.new()
var directoryCheck = directory.dir_exists(conversionRootFolder + "/characters" + folderPath)
if !directoryCheck:
directory.open(conversionRootFolder + "/characters")

if not DirAccess.dir_exists_absolute(conversionRootFolder + "/characters" + folderPath):
var directory = DirAccess.open(conversionRootFolder + "/characters")

var progresiveDirectory = ""
for pathItem in folderPath.split('/'):
Expand Down Expand Up @@ -854,7 +838,6 @@ func convertCharacters():
else:
%OutputLog.text += "[color=red]There was a problem parsing this file![/color]\r\n"

file.close()
# Second pass, shorten all of the paths, so they match the character dictionary in Dialogic itself

# Temporarily need an array to be able to sort
Expand Down
Loading