save data wip

This commit is contained in:
Harmony Monroe 2020-10-09 19:26:55 -04:00
parent 2e64e25dbc
commit bc4b569048
11 changed files with 80 additions and 34 deletions

View file

@ -10,6 +10,7 @@
[node name="Stage" type="Node2D"]
script = ExtResource( 1 )
stage_name = "1-2"
[node name="SolidTileMap" parent="." instance=ExtResource( 3 )]
tile_data = PoolIntArray( 65528, 0, 65538, 65529, 0, 65536, 65530, 0, 65538, 65531, 0, 196609, 65532, 0, 65538, 65533, 0, 1, 2, 0, 65538, 3, 0, 65536, 4, 0, 1, 5, 0, 196608, 6, 0, 65538, 7, 0, 65536, 131069, 0, 131073, 131070, 0, 1, 131071, 0, 65536, 65536, 0, 65538, 65537, 0, 2, 65538, 0, 196609 )

View file

@ -11,6 +11,7 @@
[node name="Stage" type="Node2D"]
script = ExtResource( 3 )
stage_name = "1-3"
[node name="SolidTileMap" parent="." instance=ExtResource( 5 )]
tile_data = PoolIntArray( 65530, 0, 65538, 65531, 0, 65536, 65532, 0, 131074, 65533, 0, 1, 65534, 0, 1, 65535, 0, 65537, 0, 0, 1, 1, 0, 196608, 2, 0, 65538, 3, 0, 65536, 4, 0, 2, 5, 0, 65536 )

View file

@ -9,13 +9,9 @@
[ext_resource path="res://Scene/Stage/SpikeTileMap.tscn" type="PackedScene" id=7]
[ext_resource path="res://Scene/Actor/Exit.tscn" type="PackedScene" id=8]
[node name="Stage" type="Node2D"]
script = ExtResource( 5 )
stage_name = "1-4"
[node name="SolidTileMap" parent="." instance=ExtResource( 4 )]
tile_data = PoolIntArray( -131070, 0, 1, -131069, 0, 196610, -131068, 0, 1, -131067, 0, 131074, -131066, 0, 65536, -65534, 0, 1, 65530, 0, 65538, 65531, 0, 131072, 65532, 0, 65537, 65533, 0, 1, 65534, 0, 65536, 65535, 0, 65538, 0, 0, 65536, 1, 0, 65538, 2, 0, 196608 )

View file

@ -9,13 +9,9 @@
[ext_resource path="res://Scene/Stage/SpikeTileMap.tscn" type="PackedScene" id=7]
[ext_resource path="res://Scene/Actor/Exit.tscn" type="PackedScene" id=8]
[node name="Stage" type="Node2D"]
script = ExtResource( 5 )
stage_name = "1-5"
[node name="SolidTileMap" parent="." instance=ExtResource( 4 )]
tile_data = PoolIntArray( -327678, 0, 131074, -327677, 0, 65537, -327676, 0, 0, -327675, 0, 65538, -327674, 0, 65536, -327673, 0, 196608, -262142, 0, 0, -196606, 0, 1, -131070, 0, 0, -65534, 0, 2, 65529, 0, 196609, 65530, 0, 65537, 65531, 0, 0, 65532, 0, 65538, 65533, 0, 0, 65534, 0, 65536, 65535, 0, 0, 0, 0, 0, 1, 0, 65537, 2, 0, 131072 )

View file

@ -9,13 +9,9 @@
[ext_resource path="res://Scene/Actor/Player.tscn" type="PackedScene" id=7]
[ext_resource path="res://Script/Stage/Stage.gd" type="Script" id=8]
[node name="Stage" type="Node2D"]
script = ExtResource( 8 )
stage_name = "1-6"
[node name="SolidTileMap" parent="." instance=ExtResource( 2 )]
tile_data = PoolIntArray( 65526, 0, 1, 65527, 0, 65538, 65528, 0, 0, 65529, 0, 196609, 65530, 0, 65536, 65531, 0, 0, 65532, 0, 0, 3, 0, 0, 4, 0, 65538, 5, 0, 65536, 6, 0, 65538, 7, 0, 65536, 8, 0, 0, 9, 0, 0, 131068, 0, 196608, 131069, 0, 65536, 131070, 0, 65538, 131071, 0, 65536, 65536, 0, 65537, 65537, 0, 0, 65538, 0, 0, 65539, 0, 131072 )

View file

@ -9,13 +9,9 @@
[ext_resource path="res://Scene/Actor/Player.tscn" type="PackedScene" id=7]
[ext_resource path="res://Script/Stage/Stage.gd" type="Script" id=8]
[node name="Stage" type="Node2D"]
script = ExtResource( 8 )
stage_name = "1-7"
[node name="SolidTileMap" parent="." instance=ExtResource( 2 )]
tile_data = PoolIntArray( -262145, 0, 65538, -327680, 0, 196609, 131069, 0, 131074, 131070, 0, 2, 131071, 0, 65536, 65536, 0, 0, 65537, 0, 65538, 65538, 0, 131072, 65539, 0, 65536, 65540, 0, 2, 196600, 0, 196609, 196601, 0, 65538, 196602, 0, 0, 196603, 0, 65536, 196604, 0, 65538, 196605, 0, 2, 131076, 0, 196608, 131077, 0, 0, 131078, 0, 0, 131079, 0, 196610 )

View file

@ -16,3 +16,14 @@ text = "testing 123"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Death" type="Label" parent="."]
margin_left = 5.0
margin_top = 16.0
margin_right = 77.0
margin_bottom = 24.0
custom_fonts/font = ExtResource( 1 )
text = "testing 123"
__meta__ = {
"_edit_use_anchors_": false
}

View file

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

View file

@ -1,6 +1,8 @@
extends CanvasLayer
var node_timer : Label
var node_death : Label
func _ready():
node_timer = $Timer
node_death = $Death

View file

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

View file

@ -1,6 +1,8 @@
extends Node2D
class_name Stage
export var stage_name := "1-1"
var timer := 0.0
var is_timer = true