From bc4b56904818bc348ab7c8ab0026feebe37ca4a2 Mon Sep 17 00:00:00 2001 From: Harmony Monroe Date: Fri, 9 Oct 2020 19:26:55 -0400 Subject: [PATCH] save data wip --- Map/map1.tscn | 1 + Map/map2.tscn | 1 + Map/map3.tscn | 6 +--- Map/map4.tscn | 6 +--- Map/map5.tscn | 6 +--- Map/map6.tscn | 6 +--- Scene/AutoLoad/HUD.tscn | 11 ++++++ Script/Actor/Player.gd | 3 +- Script/AutoLoad/HUD.gd | 2 ++ Script/AutoLoad/Shared.gd | 70 +++++++++++++++++++++++++++++++-------- Script/Stage/Stage.gd | 2 ++ 11 files changed, 80 insertions(+), 34 deletions(-) diff --git a/Map/map1.tscn b/Map/map1.tscn index 10ca3ff..46f4311 100644 --- a/Map/map1.tscn +++ b/Map/map1.tscn @@ -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 ) diff --git a/Map/map2.tscn b/Map/map2.tscn index ab23f64..4f7141e 100644 --- a/Map/map2.tscn +++ b/Map/map2.tscn @@ -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 ) diff --git a/Map/map3.tscn b/Map/map3.tscn index b66efcf..d8b9dea 100644 --- a/Map/map3.tscn +++ b/Map/map3.tscn @@ -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 ) diff --git a/Map/map4.tscn b/Map/map4.tscn index bec0cea..208b09a 100644 --- a/Map/map4.tscn +++ b/Map/map4.tscn @@ -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 ) diff --git a/Map/map5.tscn b/Map/map5.tscn index 61827fb..bb2dbb9 100644 --- a/Map/map5.tscn +++ b/Map/map5.tscn @@ -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 ) diff --git a/Map/map6.tscn b/Map/map6.tscn index 65684a7..5ad4038 100644 --- a/Map/map6.tscn +++ b/Map/map6.tscn @@ -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 ) diff --git a/Scene/AutoLoad/HUD.tscn b/Scene/AutoLoad/HUD.tscn index cbfe8e8..f210ec7 100644 --- a/Scene/AutoLoad/HUD.tscn +++ b/Scene/AutoLoad/HUD.tscn @@ -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 +} diff --git a/Script/Actor/Player.gd b/Script/Actor/Player.gd index 22ec0d0..65e8a44 100644 --- a/Script/Actor/Player.gd +++ b/Script/Actor/Player.gd @@ -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 diff --git a/Script/AutoLoad/HUD.gd b/Script/AutoLoad/HUD.gd index dfb266a..9fbb60f 100644 --- a/Script/AutoLoad/HUD.gd +++ b/Script/AutoLoad/HUD.gd @@ -1,6 +1,8 @@ extends CanvasLayer var node_timer : Label +var node_death : Label func _ready(): node_timer = $Timer + node_death = $Death diff --git a/Script/AutoLoad/Shared.gd b/Script/AutoLoad/Shared.gd index 0d7f022..f219be1 100644 --- a/Script/AutoLoad/Shared.gd +++ b/Script/AutoLoad/Shared.gd @@ -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 + + + + diff --git a/Script/Stage/Stage.gd b/Script/Stage/Stage.gd index 6637efa..a48657d 100644 --- a/Script/Stage/Stage.gd +++ b/Script/Stage/Stage.gd @@ -1,6 +1,8 @@ extends Node2D class_name Stage +export var stage_name := "1-1" + var timer := 0.0 var is_timer = true