Et on peut sauvegarder et charger la partie.
Et oui mon kiki
This commit is contained in:
Thomas
2025-03-29 22:28:24 +01:00
parent 95c45dcdb8
commit 8edd4bdf45
10 changed files with 98 additions and 17 deletions

View File

@@ -6,12 +6,23 @@ var destination_map = {
signal start signal start
signal save signal save
signal load
var instanciated_destinations = {} var instanciated_destinations = {}
func _ready() -> void:
$MarginContainer/Panel/VBoxContainer/Load.disabled = not FileAccess.file_exists("user://savegame.save")
func _on_button_pressed() -> void: func _on_button_pressed() -> void:
emit_signal("start") emit_signal("start")
$MarginContainer/Panel/VBoxContainer/Button.text="continue" $MarginContainer/Panel/VBoxContainer/Start.text="Continuer"
$MarginContainer/Panel/VBoxContainer/Save.disabled = false
func _on_save_pressed() -> void: func _on_save_pressed() -> void:
emit_signal("save") emit_signal("save")
$MarginContainer/Panel/VBoxContainer/Load.disabled = not FileAccess.file_exists("user://savegame.save")
func _on_load_pressed() -> void:
emit_signal("load")
_on_button_pressed()

View File

@@ -48,15 +48,22 @@ vertical_alignment = 1
[node name="HSeparator" type="HSeparator" parent="MarginContainer/Panel/VBoxContainer"] [node name="HSeparator" type="HSeparator" parent="MarginContainer/Panel/VBoxContainer"]
layout_mode = 2 layout_mode = 2
[node name="Button" type="Button" parent="MarginContainer/Panel/VBoxContainer"] [node name="Start" type="Button" parent="MarginContainer/Panel/VBoxContainer"]
layout_mode = 2 layout_mode = 2
theme = ExtResource("3_feq31") theme = ExtResource("3_feq31")
text = "start" text = "Démarrer une nouvelle partie"
[node name="Save" type="Button" parent="MarginContainer/Panel/VBoxContainer"] [node name="Save" type="Button" parent="MarginContainer/Panel/VBoxContainer"]
layout_mode = 2 layout_mode = 2
theme = ExtResource("3_feq31") theme = ExtResource("3_feq31")
text = "save" disabled = true
text = "Sauvegarder"
[connection signal="pressed" from="MarginContainer/Panel/VBoxContainer/Button" to="." method="_on_button_pressed"] [node name="Load" type="Button" parent="MarginContainer/Panel/VBoxContainer"]
layout_mode = 2
theme = ExtResource("3_feq31")
text = "Charger"
[connection signal="pressed" from="MarginContainer/Panel/VBoxContainer/Start" to="." method="_on_button_pressed"]
[connection signal="pressed" from="MarginContainer/Panel/VBoxContainer/Save" to="." method="_on_save_pressed"] [connection signal="pressed" from="MarginContainer/Panel/VBoxContainer/Save" to="." method="_on_save_pressed"]
[connection signal="pressed" from="MarginContainer/Panel/VBoxContainer/Load" to="." method="_on_load_pressed"]

View File

@@ -83,6 +83,9 @@ func stop_interaction():
func get_feet_global_position(): func get_feet_global_position():
return global_position + Vector2(0, 43) return global_position + Vector2(0, 43)
func set_feet_global_position(p : Vector2):
global_position = p - Vector2(0, 43)
func pause_or_stop_interaction_clue(): func pause_or_stop_interaction_clue():
if interactionZone: if interactionZone:

View File

@@ -32,6 +32,7 @@ func _unhandled_input(event: InputEvent) -> void:
pathFinder.destination = get_global_mouse_position() pathFinder.destination = get_global_mouse_position()
func _process(delta) -> void: func _process(delta) -> void:
GameState.player_positions = human.get_feet_global_position()
ray.target_position = human.last_facing_direction * 48 ray.target_position = human.last_facing_direction * 48
if human.last_facing_direction.y > 0 : if human.last_facing_direction.y > 0 :

View File

@@ -6,5 +6,26 @@ var hasChosenToMakeChoices = false
var hasCompletedBobDialogue = false var hasCompletedBobDialogue = false
var playerIsDeaf = false var playerIsDeaf = false
var player_positions = {"res://scenes/start.tscn" = Vector2(-171, -253)} var current_scene = "outside"
var current_scene = "res://scenes/start.tscn" var player_positions = Vector2(-171, -253)
func save():
var ret = {}
var thisScript: GDScript = get_script()
for propertyInfo in thisScript.get_script_property_list():
var propertyName: String = propertyInfo.name
var propertyValue = get(propertyName)
ret[propertyName] = JSON.stringify(propertyValue)
return ret
func load_save(data:Dictionary):
isUsingTouch = data.isUsingTouch == "true"
hasChosenNotToMakeChoices = data.hasChosenNotToMakeChoices == "true"
hasChosenToMakeChoices = data.hasChosenToMakeChoices == "true"
hasCompletedBobDialogue = data.hasCompletedBobDialogue == "true"
playerIsDeaf = data.playerIsDeaf == "true"
current_scene = data.current_scene
var strplps = (data.player_positions as String).replace("\"(", "").replace(")\"", "")
var parts = strplps.split(", ")
player_positions = Vector2(float(parts[0]), float(parts[1]))
print(player_positions)

13
scenes/gam6026.tmp Normal file
View File

@@ -0,0 +1,13 @@
[gd_scene load_steps=3 format=3 uid="uid://c645h6ap7niu1"]
[ext_resource type="PackedScene" uid="uid://44wla7mlivqm" path="res://UI/menu.tscn" id="1_64gp8"]
[ext_resource type="Script" path="res://scenes/game.gd" id="1_b2ju7"]
[node name="Game" type="Node2D"]
script = ExtResource("1_b2ju7")
[node name="Menu" parent="." instance=ExtResource("1_64gp8")]
[connection signal="load" from="Menu" to="." method="load_game"]
[connection signal="save" from="Menu" to="." method="save_game"]
[connection signal="start" from="Menu" to="." method="start_game"]

View File

@@ -1,27 +1,39 @@
extends Node2D extends Node2D
var destination_map = {
"oustide":preload("res://scenes/outside.tscn"),
}
func _unhandled_input(event: InputEvent) -> void: func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("menu"): if event.is_action_pressed("menu"):
open_menu() open_menu()
# list of scenes # list of scenes
var current_scene = "menu" var outside:Node2D = null
var outside = null var dest_outside = preload("res://scenes/outside.tscn")
var menu = null var menu = null
func start_game(): func start_game():
menu = get_child(0) menu = get_child(0)
if outside == null: if outside == null:
outside = destination_map["oustide"].instantiate() outside = dest_outside.instantiate()
add_child(outside) add_child(outside)
remove_child(menu) remove_child(menu)
current_scene = "outside" GameState.current_scene = "outside"
outside.load_from_game_state()
func open_menu(): func open_menu():
remove_child(outside) remove_child(outside)
add_child(menu) add_child(menu)
current_scene = "menu"
func load_game():
var save_file = FileAccess.open("user://savegame.save", FileAccess.READ)
var json_string = ""
while save_file.get_position() < save_file.get_length():
json_string += save_file.get_line()
var json = JSON.new()
if json.parse(json_string) == OK:
print("load", json.data)
GameState.load_save(json.data)
func save_game():
var save_file = FileAccess.open("user://savegame.save", FileAccess.WRITE)
save_file.store_line(JSON.stringify(GameState.save()))
print(OS.get_data_dir())
save_file.close()

View File

@@ -8,4 +8,6 @@ script = ExtResource("1_b2ju7")
[node name="Menu" parent="." instance=ExtResource("1_64gp8")] [node name="Menu" parent="." instance=ExtResource("1_64gp8")]
[connection signal="load" from="Menu" to="." method="load_game"]
[connection signal="save" from="Menu" to="." method="save_game"]
[connection signal="start" from="Menu" to="." method="start_game"] [connection signal="start" from="Menu" to="." method="start_game"]

9
scenes/outside.gd Normal file
View File

@@ -0,0 +1,9 @@
extends Node2D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
load_from_game_state()
func load_from_game_state():
$world/player.set_feet_global_position(GameState.player_positions)

View File

@@ -1,5 +1,6 @@
[gd_scene load_steps=8 format=3 uid="uid://b4ydi1vv8dvwr"] [gd_scene load_steps=9 format=3 uid="uid://b4ydi1vv8dvwr"]
[ext_resource type="Script" path="res://scenes/outside.gd" id="1_wyh83"]
[ext_resource type="PackedScene" uid="uid://d1oqt6sbjvopi" path="res://maps/world.tscn" id="1_ysg4m"] [ext_resource type="PackedScene" uid="uid://d1oqt6sbjvopi" path="res://maps/world.tscn" id="1_ysg4m"]
[ext_resource type="PackedScene" uid="uid://bleadp4yrdgj" path="res://caracters/bob/bob.tscn" id="2_vbahy"] [ext_resource type="PackedScene" uid="uid://bleadp4yrdgj" path="res://caracters/bob/bob.tscn" id="2_vbahy"]
[ext_resource type="PackedScene" uid="uid://vclpg4e4ql54" path="res://caracters/player/player.tscn" id="3_bt1tp"] [ext_resource type="PackedScene" uid="uid://vclpg4e4ql54" path="res://caracters/player/player.tscn" id="3_bt1tp"]
@@ -19,6 +20,7 @@ _data = {
point_count = 20 point_count = 20
[node name="scene1" type="Node2D"] [node name="scene1" type="Node2D"]
script = ExtResource("1_wyh83")
[node name="world" parent="." instance=ExtResource("1_ysg4m")] [node name="world" parent="." instance=ExtResource("1_ysg4m")]