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:
Patrick_Pluto 2024-06-16 19:32:19 +02:00
parent 8496773e69
commit 21bcce37fa
12 changed files with 115 additions and 51 deletions

23
scenes/map/map.tscn Normal file
View file

@ -0,0 +1,23 @@
[gd_scene load_steps=3 format=3 uid="uid://mie5ckydb8k5"]
[ext_resource type="PackedScene" uid="uid://brmtkn1ddxrp1" path="res://testing/test/level.tscn" id="1_sw0jh"]
[ext_resource type="PackedScene" uid="uid://btl7r0wvecyd3" path="res://scenes/menu/view.tscn" id="2_7des0"]
[node name="map" type="Node2D"]
[node name="level" parent="." instance=ExtResource("1_sw0jh")]
[node name="characterViewer" parent="." instance=ExtResource("2_7des0")]
visible = false
[node name="back" type="Button" parent="."]
visible = false
offset_left = 512.0
offset_top = 400.0
offset_right = 638.0
offset_bottom = 435.0
scale = Vector2(2, 2)
disabled = true
text = "Back to game"
[connection signal="pressed" from="back" to="level" method="_on_back_pressed"]

View file

@ -2,7 +2,7 @@
[ext_resource type="Script" path="res://scripts/createStats.gd" id="1_xsj3b"]
[node name="character_creator" type="Control"]
[node name="characterCreator" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0

View file

@ -2,7 +2,7 @@
[ext_resource type="Script" path="res://scripts/menu.gd" id="1_xc6y7"]
[node name="main_menu" type="Control"]
[node name="mainMenu" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
@ -42,7 +42,7 @@ offset_top = 432.0
offset_right = 592.0
offset_bottom = 455.0
scale = Vector2(3, 3)
text = "Version: 0.0.2"
text = "Version: 0.0.3"
[connection signal="pressed" from="Button" to="." method="_on_button_pressed"]
[connection signal="pressed" from="Button2" to="." method="_on_button_2_pressed"]

View file

@ -2,7 +2,7 @@
[ext_resource type="Script" path="res://scripts/getStats.gd" id="1_dcehj"]
[node name="character_creator" type="Control"]
[node name="characterVsiewer" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0

View file

@ -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"):

View file

@ -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

View file

@ -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()

View file

@ -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():

View file

@ -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()

File diff suppressed because one or more lines are too long

View file

@ -17,3 +17,15 @@ shape = SubResource("RectangleShape2D_kf6qt")
[node name="camera" type="Camera2D" parent="."]
enabled = false
[node name="stats" type="Button" parent="."]
visible = false
offset_left = 112.0
offset_top = 152.0
offset_right = 238.0
offset_bottom = 187.0
scale = Vector2(2, 2)
disabled = true
text = "Stats"
[connection signal="pressed" from="stats" to="." method="_on_stats_pressed"]