forked from interstellar_development/freettrpg
e5911fd155
First major release, refined the creator, added stats to the main game, added a menu to view stats.
29 lines
843 B
GDScript
29 lines
843 B
GDScript
extends Node
|
|
|
|
func loadJSON():
|
|
var save_path = str("user://player_data"+$input_id.text+".json")
|
|
print(save_path)
|
|
if not FileAccess.file_exists(save_path):
|
|
return
|
|
var file_access = FileAccess.open(save_path, FileAccess.READ)
|
|
var json_string = file_access.get_line()
|
|
file_access.close()
|
|
|
|
var json = JSON.new()
|
|
var error = json.parse(json_string)
|
|
if error:
|
|
print("JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line())
|
|
return
|
|
|
|
var data:Dictionary = json.data
|
|
$output_name.text = str("Name: "+data.get("name"))
|
|
$output_hp.text = str("HP: "+data.get("hp"))
|
|
$output_level.text = str("Level: "+data.get("level"))
|
|
|
|
|
|
func _on_button_pressed():
|
|
loadJSON()
|
|
|
|
func _process(delta):
|
|
if Input.is_action_pressed("escape"):
|
|
get_tree().change_scene_to_file("res://scenes/menu/main.tscn")
|