Add Save & Load Game Data
This commit is contained in:
parent
d9a43b64da
commit
a85c69313b
13 changed files with 173 additions and 7 deletions
BIN
assets/icons/locked.png
Normal file
BIN
assets/icons/locked.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
34
assets/icons/locked.png.import
Normal file
34
assets/icons/locked.png.import
Normal file
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://dcd26ajdxnv5s"
|
||||
path="res://.godot/imported/locked.png-0e485415f5c3174bad8abf5ae073d9e6.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/icons/locked.png"
|
||||
dest_files=["res://.godot/imported/locked.png-0e485415f5c3174bad8abf5ae073d9e6.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
|
@ -1,6 +1,7 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://cwf2fhvjfq7xg"]
|
||||
[gd_scene load_steps=3 format=3 uid="uid://cwf2fhvjfq7xg"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/ui/select_stage.gd" id="1_t86bq"]
|
||||
[ext_resource type="Texture2D" uid="uid://dcd26ajdxnv5s" path="res://assets/icons/locked.png" id="2_ppj84"]
|
||||
|
||||
[node name="SelectStage" type="Control"]
|
||||
layout_mode = 3
|
||||
|
@ -62,6 +63,12 @@ theme_override_constants/margin_top = 10
|
|||
theme_override_constants/margin_right = 10
|
||||
theme_override_constants/margin_bottom = 10
|
||||
|
||||
[node name="Locked" type="TextureRect" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer"]
|
||||
layout_mode = 2
|
||||
texture = ExtResource("2_ppj84")
|
||||
expand_mode = 2
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="Stage 1" type="Button" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer"]
|
||||
layout_mode = 2
|
||||
text = "1"
|
||||
|
@ -74,6 +81,12 @@ theme_override_constants/margin_top = 10
|
|||
theme_override_constants/margin_right = 10
|
||||
theme_override_constants/margin_bottom = 10
|
||||
|
||||
[node name="Locked" type="TextureRect" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer2"]
|
||||
layout_mode = 2
|
||||
texture = ExtResource("2_ppj84")
|
||||
expand_mode = 2
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="Stage 2" type="Button" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer2"]
|
||||
layout_mode = 2
|
||||
text = "2"
|
||||
|
@ -86,6 +99,12 @@ theme_override_constants/margin_top = 10
|
|||
theme_override_constants/margin_right = 20
|
||||
theme_override_constants/margin_bottom = 10
|
||||
|
||||
[node name="Locked" type="TextureRect" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer3"]
|
||||
layout_mode = 2
|
||||
texture = ExtResource("2_ppj84")
|
||||
expand_mode = 2
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="Stage 3" type="Button" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer3"]
|
||||
layout_mode = 2
|
||||
text = "3"
|
||||
|
@ -102,6 +121,12 @@ theme_override_constants/margin_top = 10
|
|||
theme_override_constants/margin_right = 10
|
||||
theme_override_constants/margin_bottom = 20
|
||||
|
||||
[node name="Locked" type="TextureRect" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer"]
|
||||
layout_mode = 2
|
||||
texture = ExtResource("2_ppj84")
|
||||
expand_mode = 2
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="Stage 4" type="Button" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer"]
|
||||
layout_mode = 2
|
||||
text = "4"
|
||||
|
@ -114,6 +139,12 @@ theme_override_constants/margin_top = 10
|
|||
theme_override_constants/margin_right = 10
|
||||
theme_override_constants/margin_bottom = 20
|
||||
|
||||
[node name="Locked" type="TextureRect" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer2"]
|
||||
layout_mode = 2
|
||||
texture = ExtResource("2_ppj84")
|
||||
expand_mode = 2
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="Stage 5" type="Button" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer2"]
|
||||
layout_mode = 2
|
||||
text = "5"
|
||||
|
@ -126,6 +157,12 @@ theme_override_constants/margin_top = 10
|
|||
theme_override_constants/margin_right = 20
|
||||
theme_override_constants/margin_bottom = 20
|
||||
|
||||
[node name="Locked" type="TextureRect" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer3"]
|
||||
layout_mode = 2
|
||||
texture = ExtResource("2_ppj84")
|
||||
expand_mode = 2
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="Stage 6" type="Button" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer3"]
|
||||
layout_mode = 2
|
||||
text = "6"
|
||||
|
|
31
scripts/data/data.gd
Normal file
31
scripts/data/data.gd
Normal file
|
@ -0,0 +1,31 @@
|
|||
extends Node
|
||||
|
||||
|
||||
const FILE_NAME = "user://data.foh"
|
||||
const KEY = "NO_OPPAI_NO_LIFE"
|
||||
|
||||
func save_data(data):
|
||||
var file = FileAccess.open_encrypted_with_pass(FILE_NAME, FileAccess.WRITE, KEY)
|
||||
if file == null:
|
||||
print(FileAccess.get_open_error())
|
||||
return
|
||||
|
||||
var json_string = JSON.stringify(data, "\t")
|
||||
file.store_string(json_string)
|
||||
file.close()
|
||||
|
||||
func load_data():
|
||||
if FileAccess.file_exists(FILE_NAME):
|
||||
var file = FileAccess.open_encrypted_with_pass(FILE_NAME, FileAccess.READ, KEY)
|
||||
if file == null:
|
||||
print(FileAccess.get_open_error())
|
||||
return
|
||||
|
||||
var content = file.get_as_text()
|
||||
file.close()
|
||||
|
||||
var data = JSON.parse_string(content)
|
||||
|
||||
return data
|
||||
else:
|
||||
return null
|
|
@ -113,4 +113,5 @@ func on_enemy_reward(value: int):
|
|||
|
||||
func _on_duration_timeout():
|
||||
get_tree().paused = true
|
||||
$CanvasLayer/Victory.unlock_next_stage()
|
||||
$CanvasLayer/Victory.show()
|
||||
|
|
|
@ -112,4 +112,5 @@ func on_enemy_reward(value: int):
|
|||
|
||||
func _on_duration_timeout():
|
||||
get_tree().paused = true
|
||||
$CanvasLayer/Victory.unlock_next_stage()
|
||||
$CanvasLayer/Victory.show()
|
|
@ -112,4 +112,5 @@ func on_enemy_reward(value: int):
|
|||
|
||||
func _on_duration_timeout():
|
||||
get_tree().paused = true
|
||||
$CanvasLayer/Victory.unlock_next_stage()
|
||||
$CanvasLayer/Victory.show()
|
||||
|
|
|
@ -112,4 +112,5 @@ func on_enemy_reward(value: int):
|
|||
|
||||
func _on_duration_timeout():
|
||||
get_tree().paused = true
|
||||
$CanvasLayer/Victory.unlock_next_stage()
|
||||
$CanvasLayer/Victory.show()
|
|
@ -112,4 +112,5 @@ func on_enemy_reward(value: int):
|
|||
|
||||
func _on_duration_timeout():
|
||||
get_tree().paused = true
|
||||
$CanvasLayer/Victory.unlock_next_stage()
|
||||
$CanvasLayer/Victory.show()
|
|
@ -112,4 +112,5 @@ func on_enemy_reward(value: int):
|
|||
|
||||
func _on_duration_timeout():
|
||||
get_tree().paused = true
|
||||
$CanvasLayer/Victory.unlock_next_stage()
|
||||
$CanvasLayer/Victory.show()
|
|
@ -1,6 +1,16 @@
|
|||
extends Control
|
||||
|
||||
|
||||
var game_data = load("res://scripts/data/data.gd").new()
|
||||
|
||||
func _ready():
|
||||
var data = game_data.load_data()
|
||||
if data == null:
|
||||
game_data.save_data({
|
||||
"debug": false,
|
||||
"unlocked_stage": 1
|
||||
})
|
||||
|
||||
func _on_start_game_pressed():
|
||||
get_tree().change_scene_to_file("res://scenes/ui/select_stage.tscn")
|
||||
|
||||
|
|
|
@ -1,23 +1,63 @@
|
|||
extends Control
|
||||
|
||||
|
||||
var game_data = load("res://scripts/data/data.gd").new()
|
||||
var data = game_data.load_data()
|
||||
|
||||
func _ready():
|
||||
match int(data['unlocked_stage']):
|
||||
1:
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer/Locked.hide()
|
||||
2:
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer/Locked.hide()
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer2/Locked.hide()
|
||||
3:
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer/Locked.hide()
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer2/Locked.hide()
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer3/Locked.hide()
|
||||
4:
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer/Locked.hide()
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer2/Locked.hide()
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer3/Locked.hide()
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer/Locked.hide()
|
||||
5:
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer/Locked.hide()
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer2/Locked.hide()
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer3/Locked.hide()
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer/Locked.hide()
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer2/Locked.hide()
|
||||
6:
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer/Locked.hide()
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer2/Locked.hide()
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer3/Locked.hide()
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer/Locked.hide()
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer2/Locked.hide()
|
||||
$Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer3/Locked.hide()
|
||||
_:
|
||||
pass
|
||||
|
||||
func _on_back_pressed():
|
||||
get_tree().change_scene_to_file("res://scenes/ui/main_menu.tscn")
|
||||
|
||||
func _on_stage_1_pressed():
|
||||
get_tree().change_scene_to_file("res://scenes/stages/stage_1.tscn")
|
||||
verify_selected_stage(1)
|
||||
|
||||
func _on_stage_2_pressed():
|
||||
get_tree().change_scene_to_file("res://scenes/stages/stage_2.tscn")
|
||||
verify_selected_stage(2)
|
||||
|
||||
func _on_stage_3_pressed():
|
||||
get_tree().change_scene_to_file("res://scenes/stages/stage_3.tscn")
|
||||
verify_selected_stage(3)
|
||||
|
||||
func _on_stage_4_pressed():
|
||||
get_tree().change_scene_to_file("res://scenes/stages/stage_4.tscn")
|
||||
verify_selected_stage(4)
|
||||
|
||||
func _on_stage_5_pressed():
|
||||
get_tree().change_scene_to_file("res://scenes/stages/stage_5.tscn")
|
||||
verify_selected_stage(5)
|
||||
|
||||
func _on_stage_6_pressed():
|
||||
get_tree().change_scene_to_file("res://scenes/stages/stage_6.tscn")
|
||||
verify_selected_stage(6)
|
||||
|
||||
func verify_selected_stage(stage_id: int):
|
||||
if int(data['unlocked_stage']) >= stage_id:
|
||||
get_tree().change_scene_to_file("res://scenes/stages/stage_{stage_id}.tscn".format({"stage_id": str(stage_id)}))
|
||||
pass
|
|
@ -1,6 +1,9 @@
|
|||
extends Control
|
||||
|
||||
|
||||
var game_data = load("res://scripts/data/data.gd").new()
|
||||
var data = game_data.load_data()
|
||||
|
||||
var next_stage: int = 0
|
||||
|
||||
func set_next_stage(value: int):
|
||||
|
@ -9,6 +12,11 @@ func set_next_stage(value: int):
|
|||
else:
|
||||
$Panel/MarginContainer/VBoxContainer/NextStage.text = "Main Menu"
|
||||
|
||||
func unlock_next_stage():
|
||||
if next_stage != 0:
|
||||
data['unlocked_stage'] = next_stage
|
||||
game_data.save_data(data)
|
||||
|
||||
func _on_next_stage_pressed():
|
||||
get_tree().paused = false
|
||||
|
||||
|
|
Loading…
Reference in a new issue