You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							58 lines
						
					
					
						
							1.2 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							58 lines
						
					
					
						
							1.2 KiB
						
					
					
				| extends Node | |
| 
 | |
| const FILE_PATH = "user://local_storage" | |
| 
 | |
| 
 | |
| func _ready(): | |
| 	TranslationServer.set_locale(read_value("locale","en")) | |
| 
 | |
| 
 | |
| func read_content(): | |
| 	var f = File.new() | |
| 	var err = f.open(FILE_PATH, File.READ) | |
| 	var content = {} | |
| 	if err == OK: | |
| 		content = parse_json(f.get_as_text()) | |
| 		f.close() | |
| 	if content == null: | |
| 		content = {} | |
| 	return content | |
| 
 | |
| 
 | |
| func write_content(content:Dictionary): | |
| 	var f = File.new() | |
| 	var err = f.open(FILE_PATH, File.WRITE) | |
| 	#var err = f.open_encrypted_with_pass(FILE_PATH, File.WRITE, OS.get_unique_id()) | |
| 	f.store_string(to_json(content)) | |
| 	f.close() | |
| 
 | |
| 
 | |
| func write_value(key:String, value): | |
| 	var content = read_content() | |
| 	content[key] = value | |
| 	write_content(content) | |
| 
 | |
| 
 | |
| func read_value(key:String, default = null): | |
| 	var content = read_content() | |
| 	if content.has(key) && content.get(key) != null: | |
| 		return content.get(key) | |
| 	else: | |
| 		return default | |
| 
 | |
| 
 | |
| func delete_value(key:String): | |
| 	var content = read_content() | |
| 	content.erase(key) | |
| 	write_content(content) | |
| 
 | |
| 
 | |
| func write_values(new_content:Dictionary): | |
| 	var content = read_content() | |
| 	for key in new_content: | |
| 		content[key] = new_content[key] | |
| 	write_content(content) | |
| 
 | |
| 
 | |
| func read_values(): | |
| 	return read_content() |