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 e69de29..5864933 100644 Binary files a/Storage/World1.db and b/Storage/World1.db differ 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")