Done refactoring
This commit is contained in:
parent
3a136ff215
commit
2176e9d798
88 changed files with 821 additions and 880 deletions
62
scripts/game.gd
Normal file
62
scripts/game.gd
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue