62 lines
2.1 KiB
GDScript
62 lines
2.1 KiB
GDScript
extends Node
|
|
|
|
class_name Game
|
|
|
|
static var gameversion = "Ictar 1.1"
|
|
|
|
static func profile_create(profile_name):
|
|
var path = "user://"+profile_name+".cosmic"
|
|
if not FileAccess.file_exists(path):
|
|
var profile_meta = {
|
|
'hash' : {},
|
|
'meta' : {
|
|
'created_in_version' : gameversion,
|
|
'creation_date' : Time.get_datetime_string_from_system(),
|
|
'last_version' : gameversion,
|
|
'last_updated' : Time.get_datetime_string_from_system(),
|
|
'profile_name' : profile_name,
|
|
'legit' : true
|
|
}
|
|
}
|
|
var profile_meta_keys = profile_meta['meta'].keys()
|
|
for i in range(len(profile_meta_keys)):
|
|
if profile_meta_keys[i][0] == "_":
|
|
profile_meta_keys.remove_at(i)
|
|
for i in range(len(profile_meta_keys)):
|
|
profile_meta['hash'][i] = str(profile_meta['meta'][profile_meta_keys[i]]).sha256_buffer().hex_encode()
|
|
var file = FileAccess.open(path, FileAccess.WRITE)
|
|
var json_string = JSON.stringify(profile_meta, "\t")
|
|
file.store_string(json_string)
|
|
else:
|
|
profile_save(profile_name, "menu")
|
|
|
|
static func profile_save(profile_name, _gamestate):
|
|
var path = "user://"+profile_name+".cosmic"
|
|
if not FileAccess.file_exists(path):
|
|
profile_create(profile_name)
|
|
return
|
|
var profile_meta = profile_load(profile_name)
|
|
profile_meta['meta']['lastversion'] = gameversion
|
|
profile_meta['meta']['lastupdated'] = Time.get_datetime_string_from_system()
|
|
var profile_meta_keys = profile_meta['meta'].keys()
|
|
for i in range(len(profile_meta_keys)):
|
|
if profile_meta_keys[i][0] == "_":
|
|
profile_meta_keys.remove_at(i)
|
|
for i in range(len(profile_meta_keys)):
|
|
profile_meta['hash'][i] = str(profile_meta['meta'][profile_meta_keys[i]]).sha256_buffer().hex_encode()
|
|
var file = FileAccess.open(path, FileAccess.WRITE)
|
|
var json_string = JSON.stringify(profile_meta, "\t")
|
|
file.store_string(json_string)
|
|
|
|
|
|
static func profile_load(profile_name):
|
|
var path = "user://"+profile_name+".cosmic"
|
|
if not FileAccess.file_exists(path):
|
|
return
|
|
var file = FileAccess.open(path, FileAccess.READ)
|
|
var string = file.get_as_text()
|
|
var profile_meta = JSON.parse_string(string)
|
|
for meta in profile_meta:
|
|
print(meta, ": ", profile_meta[meta])
|
|
print(profile_meta[meta].keys())
|
|
return profile_meta
|