From 217d4b27a19d1bbcc8a65376f37567d1572d460a Mon Sep 17 00:00:00 2001 From: Eljakim Herrewijnen Date: Sat, 3 Apr 2021 16:06:23 +0200 Subject: [PATCH] Revert from public gitea to normal one. Also added fps counter --- Global.gd | 14 +++++++++++--- KinematicBody2D.gd | 1 + Scenes/Inventory.gd | 28 --------------------------- Scenes/Inventory.tscn | 34 +++++++++++++++++++++++++++++++-- Storage/Database.gd | 9 ++++++++- Tilemap_CameraView.gd | 9 +++++++-- river_intersection_home2.tscn | 36 ++++++++++++++++++++++++----------- 7 files changed, 84 insertions(+), 47 deletions(-) delete mode 100644 Scenes/Inventory.gd diff --git a/Global.gd b/Global.gd index 5f909b4..9308d3a 100644 --- a/Global.gd +++ b/Global.gd @@ -6,6 +6,8 @@ var player_inventory_items = [] var river_intersection_home_2 = preload("res://river_intersection_home2.tscn").instance() var inventory_screen = preload("res://MiscScenes/Inventory.tscn").instance() var current_scene = null +var current_camera = null +var dev_stats = true func AddInventoryItem(itemid, amount): for x in range(40): @@ -21,7 +23,6 @@ func AddInventoryItem(itemid, amount): player_inventory_items[x].shortdesc = "desc" player_inventory_items[x].item_id = itemid player_inventory_items[x].amount = amount - return func GoToScene(scene): if current_scene != null: @@ -30,12 +31,10 @@ func GoToScene(scene): "river_intersection_home_2": current_scene = river_intersection_home_2 get_tree().get_root().add_child(river_intersection_home_2) - #.change_scene_to(river_intersection_home_2) "inventory_screen": current_scene = inventory_screen get_tree().get_root().add_child(inventory_screen) - func LoadSave(): Database.OpenConnection() @@ -46,3 +45,12 @@ func _ready(): get_tree().get_root().add_child(river_intersection_home_2) get_tree().get_root().add_child(inventory_screen) pass + +func Log(msg, level=1): + match level: + 1: + print("[Log]" + msg) + 2: + print("[Warn]" + msg) + 3: + print("[Err]" + msg) diff --git a/KinematicBody2D.gd b/KinematicBody2D.gd index 9d98bf8..118e15c 100644 --- a/KinematicBody2D.gd +++ b/KinematicBody2D.gd @@ -28,6 +28,7 @@ func _physics_process(delta): velocity.x = 0 velocity.y = 0 move_and_slide(velocity, Vector2(0, -1)) + Global.current_camera.Update() # if(interaction.get_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y)) == -1): # interaction.clear() # interaction.set_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y), 0) diff --git a/Scenes/Inventory.gd b/Scenes/Inventory.gd deleted file mode 100644 index d748ee6..0000000 --- a/Scenes/Inventory.gd +++ /dev/null @@ -1,28 +0,0 @@ -extends Node2D - -#func _draw(): -# var center = Vector2(200, 200) -# var radius = 80 -# var angle_from = 75 -# var angle_to = 195 -# var color = Color(1.0, 0.0, 0.0) -# draw_circle_arc(center, radius, angle_from, angle_to, color) -# -#func draw_circle_arc(center, radius, angle_from, angle_to, color): -# var nb_points = 32 -# var points_arc = PoolVector2Array() -# -# for i in range(nb_points + 1): -# var angle_point = deg2rad(angle_from + i * (angle_to-angle_from) / nb_points - 90) -# points_arc.push_back(center + Vector2(cos(angle_point), sin(angle_point)) * radius) -# -# for index_point in range(nb_points): -# draw_line(points_arc[index_point], points_arc[index_point + 1], color) - -func _ready(): - pass # Replace with function body. - - -# Called every frame. 'delta' is the elapsed time since the previous frame. -#func _process(delta): -# pass diff --git a/Scenes/Inventory.tscn b/Scenes/Inventory.tscn index c48d79b..465be56 100644 --- a/Scenes/Inventory.tscn +++ b/Scenes/Inventory.tscn @@ -2,12 +2,42 @@ [ext_resource path="res://pictures/gui/backgrounds/inventory/inventory_background.png" type="Texture" id=1] [ext_resource path="res://Scenes/Inventory_Script.gd" type="Script" id=2] -[ext_resource path="res://Scenes/Inventory.gd" type="Script" id=3] [ext_resource path="res://Scenes/TextureRect2.gd" type="Script" id=4] +[sub_resource type="GDScript" id=1] +script/source = "extends Node2D + +#func _draw(): +# var center = Vector2(200, 200) +# var radius = 80 +# var angle_from = 75 +# var angle_to = 195 +# var color = Color(1.0, 0.0, 0.0) +# draw_circle_arc(center, radius, angle_from, angle_to, color) +# +#func draw_circle_arc(center, radius, angle_from, angle_to, color): +# var nb_points = 32 +# var points_arc = PoolVector2Array() +# +# for i in range(nb_points + 1): +# var angle_point = deg2rad(angle_from + i * (angle_to-angle_from) / nb_points - 90) +# points_arc.push_back(center + Vector2(cos(angle_point), sin(angle_point)) * radius) +# +# for index_point in range(nb_points): +# draw_line(points_arc[index_point], points_arc[index_point + 1], color) + +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass +" + [node name="Inventory" type="Node2D"] z_index = 1 -script = ExtResource( 3 ) +script = SubResource( 1 ) [node name="TextureRect" type="TextureRect" parent="."] margin_right = 40.0 diff --git a/Storage/Database.gd b/Storage/Database.gd index 803c46c..0eddc5e 100644 --- a/Storage/Database.gd +++ b/Storage/Database.gd @@ -40,7 +40,7 @@ func OpenConnection(): if !file.file_exists(path): create = true self.db.open_db() - if create: + if create: CreateWorldDatabase() func OpenConnectionIfClosed(): @@ -52,6 +52,13 @@ func GetInventoryItems(): var ret = [] ret = db.select_rows("player_inventory", "",["*"]) return ret + +func SaveInventory(inventory): + if(inventory == null or len(inventory) != 40): + Global.Log("Bad inventory save!", 3) + return + OpenConnectionIfClosed() + # Called every frame. 'delta' is the elapsed time since the previous frame. #func _process(delta): # pass diff --git a/Tilemap_CameraView.gd b/Tilemap_CameraView.gd index b3c56fa..12cf192 100644 --- a/Tilemap_CameraView.gd +++ b/Tilemap_CameraView.gd @@ -7,6 +7,8 @@ onready var screen_size = self.get_viewport_rect().size func _ready(): calculate_bounds() + Global.current_camera = self + $dev_statistics.visible = Global.dev_stats var once = true var lockedPlayerCamera = false @@ -35,6 +37,8 @@ func calculate_bounds(): # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): + if(Global.dev_stats): + $dev_statistics/fps_stats.text = "FPS: " + str(Performance.get_monitor(Performance.TIME_FPS)) CameraToPlayer() if once: once = false @@ -57,7 +61,7 @@ func MoveCamera(x, y): func _on_Tween_tween_completed(object, key): print(object, key) - lockedPlayerCamera = false + lockedPlayerCamera = false func AnimateMoveCamera(source, destination, key, time): lockedPlayerCamera = true @@ -69,4 +73,5 @@ func CameraToPlayer(): if lockedPlayerCamera == false: MoveCamera(player.position.x, player.position.y) - +func Update(): + CameraToPlayer() diff --git a/river_intersection_home2.tscn b/river_intersection_home2.tscn index b4adff5..734eb94 100644 --- a/river_intersection_home2.tscn +++ b/river_intersection_home2.tscn @@ -103,8 +103,8 @@ scale = Vector2( 1.73434, 1.80493 ) z_index = 13 normal = ExtResource( 14 ) -[node name="MoveDown" type="TouchScreenButton" parent="Camera2D"] -position = Vector2( -480.965, 178.192 ) +[node name="MoveDown" type="TouchScreenButton" parent="Camera2D/Interactive/GameButtons"] +position = Vector2( 224.332, 1376.07 ) scale = Vector2( 14.9928, 14.9987 ) z_index = 11 normal = ExtResource( 9 ) @@ -114,8 +114,8 @@ action = "move_down" visibility_mode = 1 script = ExtResource( 6 ) -[node name="MoveRight" type="TouchScreenButton" parent="Camera2D"] -position = Vector2( 478.572, -173.651 ) +[node name="MoveRight" type="TouchScreenButton" parent="Camera2D/Interactive/GameButtons"] +position = Vector2( 1183.87, 1024.23 ) scale = Vector2( 16.7497, 5.49206 ) z_index = 11 normal = ExtResource( 3 ) @@ -124,8 +124,8 @@ action = "move_right" visibility_mode = 1 script = ExtResource( 6 ) -[node name="MoveUp" type="TouchScreenButton" parent="Camera2D"] -position = Vector2( -480.936, -298.537 ) +[node name="MoveUp" type="TouchScreenButton" parent="Camera2D/Interactive/GameButtons"] +position = Vector2( 224.361, 899.343 ) scale = Vector2( 14.9907, 15.5676 ) z_index = 11 normal = ExtResource( 9 ) @@ -134,8 +134,8 @@ action = "move_up" visibility_mode = 1 script = ExtResource( 6 ) -[node name="MoveLeft" type="TouchScreenButton" parent="Camera2D"] -position = Vector2( -615.955, -175.335 ) +[node name="MoveLeft" type="TouchScreenButton" parent="Camera2D/Interactive/GameButtons"] +position = Vector2( 89.342, 1022.54 ) scale = Vector2( 16.8861, 5.52137 ) z_index = 11 z_as_relative = false @@ -146,6 +146,20 @@ action = "move_left" visibility_mode = 1 script = ExtResource( 6 ) +[node name="dev_statistics" type="MarginContainer" parent="Camera2D"] +margin_left = -615.0 +margin_top = -300.0 +margin_right = 614.0 +margin_bottom = 297.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="fps_stats" type="Label" parent="Camera2D/dev_statistics"] +margin_top = 291.0 +margin_right = 1229.0 +margin_bottom = 305.0 + [node name="Player" type="KinematicBody2D" parent="."] position = Vector2( 700, 1200 ) script = ExtResource( 5 ) @@ -168,8 +182,8 @@ action = "map_interaction" [node name="Tween" type="Tween" parent="."] [connection signal="pressed" from="Camera2D/Interactive/GameButtons/Inventory" to="background" method="_on_Inventory_pressed"] -[connection signal="pressed" from="Camera2D/MoveDown" to="Player" method="_on_TouchScreenButton_pressed"] -[connection signal="pressed" from="Camera2D/MoveRight" to="Player" method="_on_TouchScreenButton_pressed"] -[connection signal="pressed" from="Camera2D/MoveUp" to="Player" method="_on_TouchScreenButton_pressed"] +[connection signal="pressed" from="Camera2D/Interactive/GameButtons/MoveDown" to="Player" method="_on_TouchScreenButton_pressed"] +[connection signal="pressed" from="Camera2D/Interactive/GameButtons/MoveRight" to="Player" method="_on_TouchScreenButton_pressed"] +[connection signal="pressed" from="Camera2D/Interactive/GameButtons/MoveUp" to="Player" method="_on_TouchScreenButton_pressed"] [connection signal="released" from="Player/CollisionShape2D/MapInteraction" to="Player" method="_interaction_process"] [connection signal="tween_completed" from="Tween" to="Camera2D" method="_on_Tween_tween_completed"]