From 7ae1e86f9daf18221a3442b579799bd1bd645fb2 Mon Sep 17 00:00:00 2001 From: EljakimHerrewijnen Date: Thu, 8 Oct 2020 21:56:03 +0200 Subject: [PATCH] basic scene switching added --- Global.gd | 22 ++++++++++++++++++++++ KinematicBody2D.gd | 8 +++----- Menu.gd | 3 ++- MiscCodes/Inventory.gd | 2 +- MiscCodes/Item.gd | 12 ++++++++---- MiscCodes/Slot.gd | 4 +--- Storage/Database.gd | 30 ++++++++++++++++++++++++++++-- Storage/World1.db | Bin 0 -> 8192 bytes background_script.gd | 2 +- 9 files changed, 66 insertions(+), 17 deletions(-) diff --git a/Global.gd b/Global.gd index a9ae229..aedf82c 100644 --- a/Global.gd +++ b/Global.gd @@ -3,6 +3,26 @@ extends Node2D var ShowInventory = 0 var LeftClick = 0 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 +#func _add_a_scene_manually(): +# # This is like autoloading the scene, only +# # it happens after already loading the main scene. +# get_tree().get_root().add_child(simultaneous_scene) + +func GoToScene(scene): + if current_scene != null: + get_tree().get_root().remove_child(current_scene) + match 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() @@ -11,4 +31,6 @@ func _input(event): pass func _ready(): + get_tree().get_root().add_child(river_intersection_home_2) + get_tree().get_root().add_child(inventory_screen) pass diff --git a/KinematicBody2D.gd b/KinematicBody2D.gd index 76c6045..53a4451 100644 --- a/KinematicBody2D.gd +++ b/KinematicBody2D.gd @@ -28,16 +28,14 @@ func _physics_process(delta): velocity.x = 0 velocity.y = 0 move_and_slide(velocity, Vector2(0, -1)) - 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) +# 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) #Handles interaction with the map func _interaction_process(): if Input.is_action_pressed("map_interaction") or Input.is_key_pressed((KEY_SPACE)): var x = plants_map.get_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y)) -# if x > 0: -# print("woo") plants_map.set_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y), 10) func _input(event): diff --git a/Menu.gd b/Menu.gd index 54d3a76..41fc6a5 100644 --- a/Menu.gd +++ b/Menu.gd @@ -5,4 +5,5 @@ func _ready(): func _on_Btn_PlayGame_pressed(): Global.LoadSave() - get_tree().change_scene("res://river_intersection_home2.tscn") + Global.GoToScene("river_intersection_home_2") + diff --git a/MiscCodes/Inventory.gd b/MiscCodes/Inventory.gd index e49c7a8..d46e78f 100644 --- a/MiscCodes/Inventory.gd +++ b/MiscCodes/Inventory.gd @@ -33,4 +33,4 @@ func _input(event): holding_item.global_position = get_global_mouse_position() func _on_TouchScreenButton_pressed(): - get_tree().change_scene("res://river_intersection_home2.tscn") + Global.GoToScene("river_intersection_home_2") diff --git a/MiscCodes/Item.gd b/MiscCodes/Item.gd index 40309f1..a0d049d 100644 --- a/MiscCodes/Item.gd +++ b/MiscCodes/Item.gd @@ -1,9 +1,13 @@ extends Node2D +var id = 0 # Many thanks to Arkeve! https://github.com/arkeve func _ready(): - if randi() % 3 == 0: - $TextureRect.texture = load("res://pictures/inventory_iconpictures/miscellaneous/magic_formulae.png") - else: - $TextureRect.texture = load("res://pictures/inventory_iconpictures/tools_and_weapons/tools/ploeg.png") + match Global.player_inventory_items[self.id].item_id: + 0: + pass + 1: + $TextureRect.texture = load("res://pictures/inventory_iconpictures/miscellaneous/magic_formulae.png") + 2: + $TextureRect.texture = load("res://pictures/inventory_iconpictures/tools_and_weapons/tools/ploeg.png") diff --git a/MiscCodes/Slot.gd b/MiscCodes/Slot.gd index 3364baf..864e971 100644 --- a/MiscCodes/Slot.gd +++ b/MiscCodes/Slot.gd @@ -23,11 +23,9 @@ func _ready(): #default_style.texture = default_tex #empty_style.texture = empty_tex # print(self.get) -# if randi() % 2 == 0: - print(Global.player_inventory_items) - print(Global.player_inventory_items[self.id]) if Global.player_inventory_items[self.id] != null: item = ItemClass.instance() + item.set("id", self.id) add_child(item) # refresh_style() diff --git a/Storage/Database.gd b/Storage/Database.gd index 7e10788..803c46c 100644 --- a/Storage/Database.gd +++ b/Storage/Database.gd @@ -10,11 +10,38 @@ var verbose = true func _ready(): pass # Replace with function body. +func CreateWorldDatabase(): + print("Creating new database") + var player_inventory : Dictionary = Dictionary() + player_inventory["id"] = {"data_type":"int", "primary_key": true, "not_null": true} #slot id + player_inventory["item_id"] = {"data_type":"int", "not_null": true} #item id + player_inventory["item_name"] = {"data_type":"text", "not_null": true} #item name + player_inventory["amount"] = {"data_type":"int", "not_null": true} #amount + player_inventory["shortdesc"] = {"data_type":"char(80)", "not_null": true} #short description + db.create_table("player_inventory", player_inventory) + var items : Dictionary = Dictionary() + for i in range(40): + items["id"] = i + items["item_id"] = 0 + items["item_name"] = "No Item" + items["amount"] = 0 + items["shortdesc"] = "No item here" + + # Insert a new row in the table + db.insert_row("player_inventory", items) + items.clear() + func OpenConnection(): self.db = SQLite.new() + var file = File.new() self.db.path = path self.db.verbose_mode = verbose + var create = false + if !file.file_exists(path): + create = true self.db.open_db() + if create: + CreateWorldDatabase() func OpenConnectionIfClosed(): if self.db == null: @@ -23,8 +50,7 @@ func OpenConnectionIfClosed(): func GetInventoryItems(): OpenConnectionIfClosed() var ret = [] - for x in range(40): - ret.append([x, "test"]) + ret = db.select_rows("player_inventory", "",["*"]) return ret # Called every frame. 'delta' is the elapsed time since the previous frame. #func _process(delta): diff --git a/Storage/World1.db b/Storage/World1.db index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..5864933d2fdcb59110f62b1513f7f66638af5a96 100644 GIT binary patch literal 8192 zcmeI#O-~a+9LMq5icsu4fTCCs{mX;22@n%8@n~r_rm+;L<-kG60%KaGU9&8P9yP%? zpf5n*fW81ZaZ+9Yz5w9`=nGJ%2MUt>;>pCrf3lO^$!B&B-`hM|DAr<2Pr|4k#B@jW z2+tGuiG&bYHxq6i56^vc9539vwf@`4imCjba=Sb;A>6}*3vdB0zy-Jf7vKV1fD3Q| zF2Du2z<*!h<$~AMKRM~WT8x9$4f}i}XxeC{)_7qXaTqnvt`qsPpR4#($;}jfI;)ha zty7^?@gMkQnlBe-bLAy^=r2)eu0o~7VsXOV%j+wrHvI{Wpl&I)+wsW{K|S1R#O*`d z`!}m$6tCOOHCn3%QRd$5Z2O;V>u#P&eHP}(?3<6~t!bKNlQ$Wo^bh@2@9OvZwSK1O z^<6!neyKzCMSW0j)V6x8X4JTn^1D2cpX58aBcIASIW5zvpQ&%|KptFx3vdB0zy-Jf z7vKV1fD8Py0_pKiksM5pl|m}GdxLwmt`AhTkxk#iG=^yu(+H+vOgAwRrW=^9V;aJA z4bvc|0ZeI3S26Wtx`OF4ranxUFkQsdi>U{b!K5)MOcGNH(*;c3n39;fFm+-&kEsLG MIZO#m9wq_lH)P9)h5!Hn literal 0 HcmV?d00001 diff --git a/background_script.gd b/background_script.gd index 4c4cb3d..064f490 100644 --- a/background_script.gd +++ b/background_script.gd @@ -23,4 +23,4 @@ func _unhandled_input(event): func _on_Inventory_pressed(): - get_tree().change_scene("res://MiscScenes/Inventory.tscn") + Global.GoToScene("inventory_screen")