Version: 0.0.2
Second major release, minor tweaks, fully dynamic stats, now requires the official contentpack.
This commit is contained in:
parent
e5911fd155
commit
0a6ff7224a
8 changed files with 72 additions and 143 deletions
|
@ -1,15 +1,42 @@
|
|||
extends Node
|
||||
|
||||
func saveJSON():
|
||||
var save_path = str("user://player_data"+$input_id.text+".json")
|
||||
var field = preload("res://scenes/menu/input-output.tscn")
|
||||
var data:Dictionary
|
||||
|
||||
func loadJSON(save_path):
|
||||
if not FileAccess.file_exists(save_path):
|
||||
return false
|
||||
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 false
|
||||
|
||||
data = json.data
|
||||
return true
|
||||
|
||||
func _ready():
|
||||
if loadJSON("res://content/stats.json"):
|
||||
for i in range(int(data.get("amount"))):
|
||||
var field_instance = field.instantiate()
|
||||
add_child(field_instance)
|
||||
field.resource_name = str("field_"+str(i))
|
||||
for i in range(int(data.get("amount"))):
|
||||
get_child(i+1).position = Vector2(16,(16+i*88))
|
||||
get_child(i+1).placeholder_text = data.get(str(i))
|
||||
|
||||
func saveJSON(save_path):
|
||||
var save_data = {}
|
||||
|
||||
var data := {
|
||||
"name": $input_name.text,
|
||||
"hp": $input_hp.text,
|
||||
"level": $input_level.text
|
||||
}
|
||||
for i in range(int(data.get("amount"))):
|
||||
if i > 0:
|
||||
save_data[data.get(str(i))] = get_child(i+1).text
|
||||
|
||||
var json_string = JSON.stringify(data)
|
||||
var json_string = JSON.stringify(save_data)
|
||||
|
||||
var file_access = FileAccess.open(save_path, FileAccess.WRITE)
|
||||
if not file_access:
|
||||
|
@ -20,7 +47,8 @@ func saveJSON():
|
|||
file_access.close()
|
||||
|
||||
func _on_button_pressed():
|
||||
saveJSON()
|
||||
var save_path = str("user://player_data"+get_child(1).text+".json")
|
||||
saveJSON(save_path)
|
||||
|
||||
func _process(delta):
|
||||
if Input.is_action_pressed("escape"):
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
extends Node
|
||||
|
||||
func loadJSON():
|
||||
var save_path = str("user://player_data"+$input_id.text+".json")
|
||||
print(save_path)
|
||||
var field = preload("res://scenes/menu/input-output.tscn")
|
||||
var data:Dictionary
|
||||
var amount
|
||||
|
||||
func loadJSON(save_path):
|
||||
if not FileAccess.file_exists(save_path):
|
||||
return
|
||||
return false
|
||||
var file_access = FileAccess.open(save_path, FileAccess.READ)
|
||||
var json_string = file_access.get_line()
|
||||
file_access.close()
|
||||
|
@ -13,16 +15,29 @@ func loadJSON():
|
|||
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
|
||||
return false
|
||||
|
||||
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"))
|
||||
|
||||
data = json.data
|
||||
return true
|
||||
|
||||
func _ready():
|
||||
if loadJSON("res://content/stats.json"):
|
||||
for i in range(int(data.get("amount"))):
|
||||
var field_instance = field.instantiate()
|
||||
add_child(field_instance)
|
||||
field.resource_name = str("field_"+str(i))
|
||||
for i in range(int(data.get("amount"))):
|
||||
get_child(i+1).position = Vector2(16,(16+i*88))
|
||||
get_child(i+1).placeholder_text = data.get(str(i))
|
||||
if i > 0:
|
||||
get_child(i+1).editable = false
|
||||
amount = data.get("amount")
|
||||
|
||||
func _on_button_pressed():
|
||||
loadJSON()
|
||||
var save_path = str("user://player_data"+get_child(1).text+".json")
|
||||
if loadJSON(save_path):
|
||||
for i in range(int(amount)-1):
|
||||
get_child(i+2).text = data.get(str(get_child(i+2).placeholder_text))
|
||||
|
||||
func _process(delta):
|
||||
if Input.is_action_pressed("escape"):
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
extends CharacterBody2D
|
||||
|
||||
@export var speed = 200
|
||||
var toCalculate = position
|
||||
var distanceTo = 0
|
||||
var active = false
|
||||
|
||||
|
@ -15,11 +14,9 @@ func _physics_process(delta):
|
|||
if active:
|
||||
get_input()
|
||||
move_and_slide()
|
||||
distanceTo = position.distance_to(toCalculate)
|
||||
var toCalculate = position
|
||||
distanceTo += position.distance_to(toCalculate)
|
||||
if distanceTo > 500 and active:
|
||||
$Label1.visible = false
|
||||
$Label2.visible = false
|
||||
$Label3.visible = false
|
||||
active = false
|
||||
$camera.enabled = false
|
||||
get_parent().next()
|
||||
|
@ -28,28 +25,4 @@ func _physics_process(delta):
|
|||
func start():
|
||||
$camera.enabled = true
|
||||
active = true
|
||||
toCalculate = position
|
||||
$Label1.visible = true
|
||||
$Label2.visible = true
|
||||
$Label3.visible = true
|
||||
|
||||
func loadJSON(id):
|
||||
var save_path = str("user://player_data"+str(id)+".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
|
||||
$Label1.text = str("Name: "+data.get("name"))
|
||||
$Label2.text = str("HP: "+data.get("hp"))
|
||||
$Label3.text = str("Level: "+data.get("level"))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue