Created
September 24, 2015 20:59
-
-
Save jackmakesthings/765adba3bcecaede76bf to your computer and use it in GitHub Desktop.
Godot currently has a bug that prevents altering dictionaries made via json_parse; this is one user's workaround. Might come in handy considering I'm using json as my godot project's data format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Workaround proposed by Hammer Bro again : | |
const DICTIONARY_TYPE = typeof({}) | |
# Recreate the structure of a dictionary, maintaining references to all leaf-level values. | |
func copy_dictionary(dictionary): | |
var output = {} | |
for key in dictionary.keys(): | |
var value = dictionary[key] | |
if typeof(value) == DICTIONARY_TYPE: | |
output[key] = copy_dictionary(value) | |
else: | |
output[key] = value | |
return output | |
# So that in previous code, one need to call : | |
json_dictionary.parse_json('{"outer_key" : {"inner_key" : "value"}}') | |
json_dictionary = copy_dictionary(json_dictionary) | |
# Basically, this workaround copies the content of the dictionary obtained by parse_json() into a new dictionary structure. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment