forked from alborrajo/DDOn-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Common.gd
26 lines (23 loc) · 791 Bytes
/
Common.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
extends Reference
class_name Common
static func load_json_file(path):
"""Loads a JSON file from the given res path and return the loaded JSON object."""
var file = File.new()
file.open(path, file.READ)
var text = file.get_as_text()
file.close()
var result_json = JSON.parse(text)
if result_json.error != OK:
print("[load_json_file] Error loading JSON file '" + str(path) + "'.")
print("\tError: ", result_json.error)
print("\tError Line: ", result_json.error_line)
print("\tError String: ", result_json.error_string)
return null
var obj = result_json.result
return obj
static func save_json_file(path, contents):
"""Saves contents to the given path as JSON."""
var file = File.new()
file.open(path, file.WRITE)
file.store_string(JSON.print(contents))
file.close()