ChocolateBird/scripts/loaders/common.gd

39 lines
1.1 KiB
GDScript3
Raw Normal View History

2023-07-28 15:57:21 +09:30
extends Node
2023-07-31 23:33:05 +09:30
static func load_json(filename: String) -> Dictionary:
2023-07-28 15:57:21 +09:30
var file := File.new()
var error := file.open(filename, File.READ)
if error == OK:
var result = JSON.parse(file.get_as_text())
if result.error == OK:
return result.result
else:
print_debug(result.error_string)
print_debug(result.error_line)
return {}
2023-07-31 23:33:05 +09:30
static func load_tsv(filename: String, delimiter: String = '\t') -> Dictionary:
var file := File.new()
var error := file.open(filename, File.READ)
if error == OK:
var headers := file.get_csv_line(delimiter)
var n := headers.size()
var output = {}
while file.get_position() < file.get_len():
var line := file.get_csv_line(delimiter)
var entry := {}
for i in range(1, n):
if line.size() > i:
var token := line[i]
entry[headers[i]] = token
if token.begins_with('0x'):
var hex := token.hex_to_int()
if hex > 0:
entry[headers[i]] = hex
output[line[0]] = entry
return output
print_debug(error)
return {}
var SNES_PSX_addresses := load_tsv('res://data/SNES_PSX_addresses.tsv')