diff --git a/addons/dialogic/Other/DialogicClass.gd b/addons/dialogic/Other/DialogicClass.gd index 33f58545d..44ada4e54 100644 --- a/addons/dialogic/Other/DialogicClass.gd +++ b/addons/dialogic/Other/DialogicClass.gd @@ -32,47 +32,48 @@ static func prepare(): # populate the data from the resources for timeline in timeline_list: - timeline['path'] = structure['Timeline'][timeline['file']] + timeline['name'] - structure['Timeline'][timeline['file']]= timeline + timeline['path'] = structure['Timelines'][timeline['file']] + timeline['name'] + structure['Timelines'][timeline['file']]= timeline for character in character_list: - character['path'] = structure['Character'][character['file']] + character['name'] - structure['Character'][character['file']]= character + character['path'] = structure['Characters'][character['file']] + character['name'] + structure['Characters'][character['file']]= character for definition in definition_list: - definition['path'] = structure['Definition'][definition['id']] + definition['name'] - structure['Definition'][definition['id']]= definition + definition['path'] = structure['Definitions'][definition['id']] + definition['name'] + structure['Definitions'][definition['id']]= definition + definition['file'] = definition['id'] for theme in theme_list: - theme['path'] = structure['Theme'][theme['file']] + theme['name'] - structure['Theme'][theme['file']]= theme + theme['path'] = structure['Themes'][theme['file']] + theme['name'] + structure['Themes'][theme['file']]= theme # After that we put them in the order we need to make the folder paths easiest to use - for timeline in structure['Timeline'].keys(): + for timeline in structure['Timelines'].keys(): if ".json" in timeline: - timeline_folder_breakdown[structure['Timeline'][timeline]['path']] = structure['Timeline'][timeline] + timeline_folder_breakdown[structure['Timelines'][timeline]['path']] = structure['Timelines'][timeline] else: - timeline_folder_breakdown[timeline] = structure['Timeline'][timeline] + timeline_folder_breakdown[timeline] = structure['Timelines'][timeline] - for character in structure['Character'].keys(): + for character in structure['Characters'].keys(): if ".json" in character: - character_folder_breakdown[structure['Character'][character]['path']] = structure['Character'][character] + character_folder_breakdown[structure['Characters'][character]['path']] = structure['Characters'][character] else: - character_folder_breakdown[character] = structure['Character'][character] + character_folder_breakdown[character] = structure['Characters'][character] - for definition in structure['Definition'].keys(): + for definition in structure['Definitions'].keys(): if ".json" in definition: - definition_folder_breakdown[structure['Definition'][definition]['path']] = structure['Definition'][definition] + definition_folder_breakdown[structure['Definitions'][definition]['path']] = structure['Definitions'][definition] else: - definition_folder_breakdown[definition] = structure['Definition'][definition] + definition_folder_breakdown[definition] = structure['Definitions'][definition] - for theme in structure['Theme'].keys(): + for theme in structure['Themes'].keys(): if ".json" in theme: - theme_folder_breakdown[structure['Theme'][theme]['path']] = structure['Theme'][theme] + theme_folder_breakdown[structure['Themes'][theme]['path']] = structure['Themes'][theme] else: - theme_folder_breakdown[theme] = structure['Theme'][theme] + theme_folder_breakdown[theme] = structure['Themes'][theme] Engine.set_meta('dialogic_tree_loaded',true) @@ -84,10 +85,10 @@ static func prepare(): print("loaded") var flatten = {} - flatten['Timeline'] = timeline_folder_breakdown - flatten['Character'] = character_folder_breakdown - flatten['Definition'] = definition_folder_breakdown - flatten['Theme'] = theme_folder_breakdown + flatten['Timelines'] = timeline_folder_breakdown + flatten['Characters'] = character_folder_breakdown + flatten['Definitions'] = definition_folder_breakdown + flatten['Themes'] = theme_folder_breakdown DialogicResources.save_resource_folder_flat_structure(flatten) diff --git a/addons/dialogic/Other/DialogicResources.gd b/addons/dialogic/Other/DialogicResources.gd index 952bbf225..d3c9ff278 100644 --- a/addons/dialogic/Other/DialogicResources.gd +++ b/addons/dialogic/Other/DialogicResources.gd @@ -463,41 +463,46 @@ static func save_resource_folder_structure(data): static func get_resource_folder_flat_structure() -> Dictionary: # Convert the folder structure from the JSON file into a simpler one that doesn't require recursive loops var flat_structure = {} - flat_structure['Timeline'] = {} - flat_structure['Character'] = {} - flat_structure['Definition'] = {} - flat_structure['Theme'] = {} + flat_structure['Timelines'] = {} + flat_structure['Characters'] = {} + flat_structure['Definitions'] = {} + flat_structure['Themes'] = {} var json_structure = get_resource_folder_structure() - flat_structure = recursive_search("Timeline", json_structure["folders"]["Timelines"], "/", flat_structure) - flat_structure = recursive_search("Character", json_structure["folders"]["Characters"], "/", flat_structure) - flat_structure = recursive_search("Definition", json_structure["folders"]["Definitions"], "/", flat_structure) - flat_structure = recursive_search("Theme", json_structure["folders"]["Themes"], "/", flat_structure) + flat_structure = recursive_search("Timelines", json_structure["folders"]["Timelines"], "/", flat_structure) + flat_structure = recursive_search("Characters", json_structure["folders"]["Characters"], "/", flat_structure) + flat_structure = recursive_search("Definitions", json_structure["folders"]["Definitions"], "/", flat_structure) + flat_structure = recursive_search("Themes", json_structure["folders"]["Themes"], "/", flat_structure) return flat_structure static func save_resource_folder_flat_structure(flat_tree) -> Dictionary: # Convert the flat folder structure back into the nested dictionary to be able to save to JSON var nested_structure = {} - nested_structure['Timeline'] = {} - nested_structure['Character'] = {} - nested_structure['Definition'] = {} - nested_structure['Theme'] = {} + nested_structure['files'] = [] + nested_structure['folders'] = {} + nested_structure['folders']['Characters'] = {} + nested_structure['folders']['Definitions'] = {} + nested_structure['folders']['Themes'] = {} + nested_structure['folders']['Timelines'] = {} + + var structure_keys = {"Characters":"Characters", "Definitions":"Definitions", "Themes":"Themes", "Timelines":"Timelines"} set_json("res://flat.json", flat_tree) - print(flat_tree['Timeline']) - var nested = {} - nested['folders'] = {} - nested['files'] = [] - for timeline in flat_tree['Timeline'].keys(): - nested = recursive_build(timeline.right(1), flat_tree['Timeline'][timeline], nested) - + for key in structure_keys: + + var nested = {} + nested['folders'] = {} + nested['files'] = [] + for flat_key in flat_tree[key].keys(): + nested = recursive_build(flat_key.right(1), flat_tree[key][flat_key], nested) + nested_structure['folders'][key] = nested - print(nested) - set_json("res://nested.json", nested) + + set_json("res://nested.json", nested_structure) @@ -508,10 +513,10 @@ static func recursive_search(currentCheck, currentDictionary, currentFolder, str for structureFile in currentDictionary["files"]: match currentCheck: - "Timeline": structure_dictionary['Timeline'][structureFile] = currentFolder - "Character": structure_dictionary['Character'][structureFile] = currentFolder - "Definition": structure_dictionary['Definition'][structureFile] = currentFolder - "Theme": structure_dictionary['Theme'][structureFile] = currentFolder + "Timelines": structure_dictionary['Timelines'][structureFile] = currentFolder + "Characters": structure_dictionary['Characters'][structureFile] = currentFolder + "Definitions": structure_dictionary['Definitions'][structureFile] = currentFolder + "Themes": structure_dictionary['Themes'][structureFile] = currentFolder for structureFolder in currentDictionary["folders"]: recursive_search(currentCheck, currentDictionary["folders"][structureFolder], currentFolder + structureFolder + "/", structure_dictionary)