move struct tsv parsing to struct.gd
This commit is contained in:
parent
09a63ad164
commit
6ec484b679
|
@ -126,25 +126,4 @@ func delete_save_slot(sram: File, slot_id: int):
|
||||||
sram.store_16(0)
|
sram.store_16(0)
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
var file := File.new()
|
STRUCT.parse_struct_definitions_from_tsv_filename('res://data/SNES_save.tsv', struct_types)
|
||||||
var error = file.open('res://data/SNES_save.tsv', File.READ)
|
|
||||||
if error == OK:
|
|
||||||
var current_struct: STRUCT.Struct
|
|
||||||
var line_num := 0 # Currently only used for step-through debugging
|
|
||||||
while file.get_position() < file.get_len():
|
|
||||||
var line := file.get_csv_line('\t')
|
|
||||||
line_num += 1
|
|
||||||
var size = line.size()
|
|
||||||
if size < 2:
|
|
||||||
continue
|
|
||||||
# Size is at least 2
|
|
||||||
var type := line[0]
|
|
||||||
var label := line[1]
|
|
||||||
if type == 'struct':
|
|
||||||
# New struct declaration
|
|
||||||
current_struct = STRUCT.Struct.new()
|
|
||||||
struct_types[label] = current_struct
|
|
||||||
elif type and label:
|
|
||||||
# TODO: Maybe store the trailing comments somewhere?
|
|
||||||
current_struct.members.append([label, STRUCT.get_structarraytype(type, struct_types)])
|
|
||||||
file.close()
|
|
||||||
|
|
|
@ -187,3 +187,32 @@ static func get_structarraytype(type: String, existing_structs: Dictionary):
|
||||||
print_debug('Invalid keyword used in type designator: "%s"' % k)
|
print_debug('Invalid keyword used in type designator: "%s"' % k)
|
||||||
return
|
return
|
||||||
return inner_type
|
return inner_type
|
||||||
|
|
||||||
|
static func parse_struct_definitions_from_tsv_file(tsv_file: File, existing_structs: Dictionary) -> void:
|
||||||
|
var current_struct: Struct
|
||||||
|
var line_num := 0 # Currently only used for step-through debugging
|
||||||
|
while tsv_file.get_position() < tsv_file.get_len():
|
||||||
|
var line := tsv_file.get_csv_line('\t')
|
||||||
|
line_num += 1
|
||||||
|
var size = line.size()
|
||||||
|
if size < 2:
|
||||||
|
continue
|
||||||
|
# Size is at least 2
|
||||||
|
var type := line[0]
|
||||||
|
var label := line[1]
|
||||||
|
if type == 'struct':
|
||||||
|
# New struct declaration
|
||||||
|
current_struct = Struct.new()
|
||||||
|
existing_structs[label] = current_struct
|
||||||
|
elif type and label:
|
||||||
|
# TODO: Maybe store the trailing comments somewhere?
|
||||||
|
current_struct.members.append([label, get_structarraytype(type, existing_structs)])
|
||||||
|
|
||||||
|
static func parse_struct_definitions_from_tsv_filename(filename: String, existing_structs: Dictionary) -> int:
|
||||||
|
var file := File.new()
|
||||||
|
match file.open(filename, File.READ):
|
||||||
|
OK:
|
||||||
|
parse_struct_definitions_from_tsv_file(file, existing_structs)
|
||||||
|
return OK
|
||||||
|
var error:
|
||||||
|
return error
|
||||||
|
|
Loading…
Reference in New Issue