mirror of
https://github.com/HarmonyHoney/tiny_crate.git
synced 2026-07-28 18:22:40 +00:00
save data wip
This commit is contained in:
parent
2e64e25dbc
commit
bc4b569048
11 changed files with 80 additions and 34 deletions
|
|
@ -244,6 +244,7 @@ func death():
|
|||
Shared.start_reset()
|
||||
queue_free()
|
||||
dev.out(name + " died")
|
||||
Shared.death()
|
||||
|
||||
func win():
|
||||
# explosion
|
||||
|
|
@ -260,7 +261,7 @@ func win():
|
|||
Shared.start_reset("hub")
|
||||
queue_free()
|
||||
dev.out("map complete")
|
||||
Shared.stage.stop_timer()
|
||||
Shared.win()
|
||||
|
||||
func open_door():
|
||||
# explosion
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
extends CanvasLayer
|
||||
|
||||
var node_timer : Label
|
||||
var node_death : Label
|
||||
|
||||
func _ready():
|
||||
node_timer = $Timer
|
||||
node_death = $Death
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
extends Node
|
||||
|
||||
|
||||
var node_map_solid : TileMap
|
||||
var node_map_spike : TileMap
|
||||
var node_camera_game : Camera2D
|
||||
|
|
@ -12,20 +11,21 @@ var reset_clock := 0.0
|
|||
var reset_time := 1.0
|
||||
|
||||
var _window_scale := 1.0
|
||||
|
||||
var map_name := "hub"
|
||||
|
||||
var hub_pos := Vector2(-16, -16)
|
||||
var death_count := 0
|
||||
|
||||
var stage_data = []
|
||||
|
||||
func _ready():
|
||||
|
||||
# _window_scale window
|
||||
_window_scale = floor(OS.get_screen_size().x / get_viewport().size.x)
|
||||
_window_scale = max(1, _window_scale- 2)
|
||||
_window_scale = max(1, _window_scale - 2)
|
||||
set_window_scale()
|
||||
|
||||
#OS.window_size = Vector2(1920, 1080)
|
||||
#OS.set_window_position(OS.get_screen_size() * 0.5 - OS.get_window_size() * 0.5)
|
||||
# load stage save data
|
||||
stage_data = JSON.parse(load_data("box.save")).result
|
||||
dev.out(JSON.print(stage_data, "\t"))
|
||||
|
||||
func set_window_scale(arg := _window_scale):
|
||||
_window_scale = arg if arg else _window_scale
|
||||
|
|
@ -33,8 +33,6 @@ func set_window_scale(arg := _window_scale):
|
|||
OS.window_size = Vector2(320 * _window_scale, 180 * _window_scale)
|
||||
# center window
|
||||
OS.set_window_position(OS.get_screen_size() * 0.5 - OS.get_window_size() * 0.5)
|
||||
|
||||
#print("_window_scale: ", _window_scale, " - ", OS.get_window_size())
|
||||
return "_window_scale: " + str(_window_scale) + " - resolution: " + str(OS.get_window_size())
|
||||
|
||||
func _process(delta):
|
||||
|
|
@ -42,10 +40,7 @@ func _process(delta):
|
|||
if is_reset:
|
||||
reset_clock -= delta
|
||||
if reset_clock < 0:
|
||||
is_reset = false
|
||||
dev.out("loading scene: " + "res://Map/" + map_name + ".tscn")
|
||||
get_tree().change_scene("res://Map/" + map_name + ".tscn")
|
||||
#get_tree().reload_current_scene()
|
||||
do_reset()
|
||||
|
||||
func start_reset(arg = ""):
|
||||
if !is_reset:
|
||||
|
|
@ -53,3 +48,52 @@ func start_reset(arg = ""):
|
|||
reset_clock = reset_time
|
||||
if arg:
|
||||
map_name = arg
|
||||
|
||||
func do_reset():
|
||||
is_reset = false
|
||||
dev.out("loading scene: " + "res://Map/" + map_name + ".tscn")
|
||||
get_tree().change_scene("res://Map/" + map_name + ".tscn")
|
||||
|
||||
func death():
|
||||
death_count += 1
|
||||
HUD.node_death.text = "deaths: " + str(death_count)
|
||||
|
||||
func win():
|
||||
if stage:
|
||||
stage.stop_timer()
|
||||
|
||||
var new_data = {
|
||||
"name": stage.stage_name,
|
||||
"time": stage.timer,
|
||||
"death": death_count,
|
||||
}
|
||||
|
||||
for i in stage_data:
|
||||
if i["name"] == new_data["name"]:
|
||||
stage_data.erase(i)
|
||||
stage_data.append(new_data)
|
||||
|
||||
save_data("box.save", JSON.print(stage_data, "\t"))
|
||||
dev.out("(box.save)")
|
||||
dev.out(load_data("box.save"))
|
||||
|
||||
death_count = 0
|
||||
|
||||
func save_data(fname, arg):
|
||||
var file = File.new()
|
||||
file.open("user://" + str(fname), File.WRITE)
|
||||
file.store_string(arg)
|
||||
file.close()
|
||||
#dev.out("(Shared.save) user://box.save")
|
||||
#dev.out("[\n" + str(arg) + "\n]")
|
||||
|
||||
func load_data(fname):
|
||||
var file = File.new()
|
||||
file.open("user://" + str(fname), File.READ)
|
||||
var content = file.get_as_text()
|
||||
file.close()
|
||||
return content
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
extends Node2D
|
||||
class_name Stage
|
||||
|
||||
export var stage_name := "1-1"
|
||||
|
||||
var timer := 0.0
|
||||
var is_timer = true
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue