-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathload_menu.gd
58 lines (45 loc) · 1.54 KB
/
load_menu.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
extends Control
@export var LoadButton : PackedScene
var saveToLoad
signal LoadingLevel
signal HideInterface
# Called when the node enters the scene tree for the first time.
func _ready():
var dir = DirAccess.get_directories_at("user://savedGames")
for i in dir:
var button : Button = LoadButton.instantiate()
button.LoadButtonDown.connect(OnLoadButtonDown)
var file = FileAccess.open("user://savedGames/" + i + "/" +i + "_saveGame.json", FileAccess.READ)
var content = file.get_as_text()
var obj = JSON.parse_string(content)
button.SetupButton(obj)
button.text = obj.name
$Panel/ScrollContainer/LoadButtons.add_child(button)
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func OnLoadButtonDown(date, saveName, imagePath):
$SaveName.text = saveName
$SaveDate.text = date
saveToLoad = saveName
$TextureRect.texture = LoadImageTexture(imagePath)
#$TextureRect.texture
pass
func LoadImageTexture(path : String):
var loadedImage = Image.new()
var error = loadedImage.load(path)
if error != OK:
print("image failed to load")
return
return ImageTexture.create_from_image(loadedImage)
func _on_load_scene_button_button_down():
var obj = SaveLoadManager.LoadGame(saveToLoad)
GameManager.LoadingFromSave = true
GameManager.LoadLevel(obj.gamemanager.scene, obj.gamemanager.spawnIndex)
LoadingLevel.emit()
queue_free()
pass # Replace with function body.
func _on_back_button_down():
HideInterface.emit()
pass # Replace with function body.