Version: 0.0.3
Slight code fixups and changed some map stuff, Also added a stat viewer for the current player in the game itself.
This commit is contained in:
parent
8496773e69
commit
21bcce37fa
12 changed files with 115 additions and 51 deletions
|
@ -1,19 +1,19 @@
|
|||
extends Node
|
||||
|
||||
var field = preload("res://scenes/menu/input-output.tscn")
|
||||
var field = preload("res://scenes/menu/inputOutput.tscn")
|
||||
var data:Dictionary
|
||||
|
||||
func loadJSON(save_path):
|
||||
if not FileAccess.file_exists(save_path):
|
||||
func loadJSON(savePath):
|
||||
if not FileAccess.file_exists(savePath):
|
||||
return false
|
||||
var file_access = FileAccess.open(save_path, FileAccess.READ)
|
||||
var json_string = file_access.get_line()
|
||||
file_access.close()
|
||||
var fileAccess = FileAccess.open(savePath, FileAccess.READ)
|
||||
var jsonString = fileAccess.get_line()
|
||||
fileAccess.close()
|
||||
|
||||
var json = JSON.new()
|
||||
var error = json.parse(json_string)
|
||||
var error = json.parse(jsonString)
|
||||
if error:
|
||||
print("JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line())
|
||||
print("JSON Parse Error: ", json.get_error_message(), " in ", jsonString, " at line ", json.get_error_line())
|
||||
return false
|
||||
|
||||
data = json.data
|
||||
|
@ -22,33 +22,31 @@ func loadJSON(save_path):
|
|||
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"))):
|
||||
var fieldInstance = field.instantiate()
|
||||
add_child(fieldInstance)
|
||||
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 = {}
|
||||
func saveJSON(savePath):
|
||||
var saveData = {}
|
||||
|
||||
for i in range(int(data.get("amount"))):
|
||||
if i > 0:
|
||||
save_data[data.get(str(i))] = get_child(i+1).text
|
||||
saveData[data.get(str(i))] = get_child(i+1).text
|
||||
|
||||
var json_string = JSON.stringify(save_data)
|
||||
var jsonString = JSON.stringify(saveData)
|
||||
|
||||
var file_access = FileAccess.open(save_path, FileAccess.WRITE)
|
||||
if not file_access:
|
||||
var fileAccess = FileAccess.open(savePath, FileAccess.WRITE)
|
||||
if not fileAccess:
|
||||
print("An error happened while saving data: ", FileAccess.get_open_error())
|
||||
return
|
||||
|
||||
file_access.store_line(json_string)
|
||||
file_access.close()
|
||||
fileAccess.store_line(jsonString)
|
||||
fileAccess.close()
|
||||
|
||||
func _on_button_pressed():
|
||||
var save_path = str("user://player_data"+get_child(1).text+".json")
|
||||
saveJSON(save_path)
|
||||
var savePath = str("user://player_data"+get_child(1).text+".json")
|
||||
saveJSON(savePath)
|
||||
|
||||
func _process(delta):
|
||||
if Input.is_action_pressed("escape"):
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
extends Node
|
||||
|
||||
var field = preload("res://scenes/menu/input-output.tscn")
|
||||
var field = preload("res://scenes/menu/inputOutput.tscn")
|
||||
var data:Dictionary
|
||||
var amount
|
||||
|
||||
func loadJSON(save_path):
|
||||
if not FileAccess.file_exists(save_path):
|
||||
func loadJSON(savePath):
|
||||
if not FileAccess.file_exists(savePath):
|
||||
return false
|
||||
var file_access = FileAccess.open(save_path, FileAccess.READ)
|
||||
var json_string = file_access.get_line()
|
||||
file_access.close()
|
||||
var fileAccess = FileAccess.open(savePath, FileAccess.READ)
|
||||
var json_string = fileAccess.get_line()
|
||||
fileAccess.close()
|
||||
|
||||
var json = JSON.new()
|
||||
var error = json.parse(json_string)
|
||||
|
@ -23,10 +23,8 @@ func loadJSON(save_path):
|
|||
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"))):
|
||||
var fieldInstance = field.instantiate()
|
||||
add_child(fieldInstance)
|
||||
get_child(i+1).position = Vector2(16,(16+i*88))
|
||||
get_child(i+1).placeholder_text = data.get(str(i))
|
||||
if i > 0:
|
||||
|
@ -34,11 +32,15 @@ func _ready():
|
|||
amount = data.get("amount")
|
||||
|
||||
func _on_button_pressed():
|
||||
var save_path = str("user://player_data"+get_child(1).text+".json")
|
||||
if loadJSON(save_path):
|
||||
var savePath = str("user://player_data"+get_child(1).text+".json")
|
||||
if loadJSON(savePath):
|
||||
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"):
|
||||
get_tree().change_scene_to_file("res://scenes/menu/main.tscn")
|
||||
|
||||
func hideGet():
|
||||
$button.visible = false
|
||||
$button.disabled = true
|
||||
|
|
|
@ -5,6 +5,7 @@ var playerIndex=0
|
|||
var objectName
|
||||
|
||||
func _ready():
|
||||
$"../characterViewer".hideGet()
|
||||
next()
|
||||
|
||||
func next():
|
||||
|
@ -15,3 +16,22 @@ func next():
|
|||
get_node(objectName).start()
|
||||
playerIndex += 1
|
||||
|
||||
func stats():
|
||||
visible = false
|
||||
$"../characterViewer".visible = true
|
||||
get_node(objectName).stop()
|
||||
$"../back".disabled = false
|
||||
$"../back".visible = true
|
||||
$"../characterViewer".get_child(1).text = str(playerIndex-1)
|
||||
$"../characterViewer".get_child(1).editable = false
|
||||
$"../characterViewer"._on_button_pressed()
|
||||
|
||||
func restart():
|
||||
visible = true
|
||||
$"../characterViewer".visible = false
|
||||
get_node(objectName).start()
|
||||
$"../back".disabled = true
|
||||
$"../back".visible = false
|
||||
|
||||
func _on_back_pressed():
|
||||
restart()
|
||||
|
|
|
@ -3,7 +3,7 @@ extends Node
|
|||
|
||||
|
||||
func _on_button_pressed():
|
||||
get_tree().change_scene_to_file("res://testing/test/map.tscn")
|
||||
get_tree().change_scene_to_file("res://scenes/map/map.tscn")
|
||||
|
||||
|
||||
func _on_button_2_pressed():
|
||||
|
|
|
@ -18,8 +18,7 @@ func _physics_process(delta):
|
|||
distanceTo += position.distance_to(toCalculate)
|
||||
print(distanceTo)
|
||||
if distanceTo > 500 and active:
|
||||
active = false
|
||||
$camera.enabled = false
|
||||
stop()
|
||||
distanceTo = 0
|
||||
get_parent().next()
|
||||
|
||||
|
@ -27,4 +26,14 @@ func _physics_process(delta):
|
|||
func start():
|
||||
$camera.enabled = true
|
||||
active = true
|
||||
$stats.disabled = false
|
||||
$stats.visible = true
|
||||
|
||||
func stop():
|
||||
$camera.enabled = false
|
||||
active = false
|
||||
$stats.disabled = true
|
||||
$stats.visible = false
|
||||
|
||||
func _on_stats_pressed():
|
||||
get_parent().stats()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue