New profiles system + auto version label
This commit is contained in:
parent
94ee27472c
commit
6ffa6e643b
7 changed files with 128 additions and 49 deletions
|
|
@ -10,11 +10,12 @@ const DEFAULT_WEAPON = preload("res://scenes/weapons/presets/SingleLaserMk1.tscn
|
|||
|
||||
const gameversion = "Ictar 1.1"
|
||||
|
||||
## Creates new profile or resaves it if it exists
|
||||
static var profile : Profile = Profile.new()
|
||||
|
||||
## Creates a new profile if it doesn't exist
|
||||
static func profile_create(profile_name : String) -> void:
|
||||
var path = "user://"+profile_name+".cosmic"
|
||||
if FileAccess.file_exists(path):
|
||||
profile_save(profile_name, "menu")
|
||||
return
|
||||
var profile_meta = {
|
||||
'hash' : {},
|
||||
|
|
@ -51,8 +52,8 @@ static func profile_save_from_meta(profile_meta : Dictionary) -> void:
|
|||
var profile_meta_keys = profile_meta['meta'].keys()
|
||||
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")
|
||||
var file = FileAccess.open(path, FileAccess.WRITE)
|
||||
file.store_string(json_string)
|
||||
|
||||
## Returns profile meta of profile if it exists
|
||||
|
|
@ -63,8 +64,6 @@ static func profile_load(profile_name : String) -> Dictionary:
|
|||
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])
|
||||
return profile_meta
|
||||
|
||||
## Deletes profile file if it exists
|
||||
|
|
@ -74,8 +73,8 @@ static func profile_delete(profile_name : String) -> void:
|
|||
var dir = DirAccess.open("user://")
|
||||
dir.remove(path)
|
||||
|
||||
## Compares existing hash and calculated hash of file and if they are not equal resaves file with legit = false.
|
||||
static func profile_legit_check(profile_meta : Dictionary) -> void:
|
||||
## Compares existing hash and calculated hash of file and if they are not equal resaves file with legit = false. Either way it returns profile meta.
|
||||
static func profile_legit_check(profile_meta : Dictionary) -> Dictionary:
|
||||
var old_hash = []
|
||||
var new_hash = []
|
||||
var profile_meta_keys = profile_meta['meta'].keys()
|
||||
|
|
@ -85,9 +84,10 @@ static func profile_legit_check(profile_meta : Dictionary) -> void:
|
|||
old_hash.sort()
|
||||
new_hash.sort()
|
||||
if old_hash == new_hash and profile_meta['meta']['legit']:
|
||||
return
|
||||
return profile_meta
|
||||
profile_meta['meta']['legit'] = false
|
||||
profile_save_from_meta(profile_meta)
|
||||
return profile_meta
|
||||
|
||||
## Returns copy of loaded item resource in directory if it exists or DEFAULT_ITEM instead.
|
||||
static func get_item(id : String) -> Item:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue