From 285ee79e16745a7ccae7b20b3428facc364faa46 Mon Sep 17 00:00:00 2001 From: Eljakim Herrewijnen Date: Thu, 8 Apr 2021 21:43:34 +0200 Subject: [PATCH] Fixed preloading of add on --- Menu.tscn | 8 +- MiscScenes/VBoxContainer.gd | 36 +++++++++ Storage/Database.gd | 144 ++++++++++++++++++------------------ omgeving/Floor.tres | 2 - storage.db | Bin 0 -> 8192 bytes 5 files changed, 114 insertions(+), 76 deletions(-) create mode 100644 MiscScenes/VBoxContainer.gd create mode 100644 storage.db diff --git a/Menu.tscn b/Menu.tscn index 09fa892..dcb5e87 100644 --- a/Menu.tscn +++ b/Menu.tscn @@ -5,12 +5,12 @@ [ext_resource path="res://MiscCodes/loading_ring.gd" type="Script" id=3] [ext_resource path="res://pictures/gui/backgrounds/treesbackground1.png" type="Texture" id=5] -[sub_resource type="DynamicFontData" id=2] +[sub_resource type="DynamicFontData" id=1] font_path = "res://ring_of_races_font.ttf" -[sub_resource type="DynamicFont" id=1] +[sub_resource type="DynamicFont" id=2] size = 30 -font_data = SubResource( 2 ) +font_data = SubResource( 1 ) [node name="Main Menu" type="Node2D"] script = ExtResource( 1 ) @@ -36,7 +36,7 @@ margin_left = 484.204 margin_top = 100.226 margin_right = 679.204 margin_bottom = 153.226 -custom_fonts/font = SubResource( 1 ) +custom_fonts/font = SubResource( 2 ) text = "Play Game" __meta__ = { "_edit_use_anchors_": false diff --git a/MiscScenes/VBoxContainer.gd b/MiscScenes/VBoxContainer.gd new file mode 100644 index 0000000..0804b84 --- /dev/null +++ b/MiscScenes/VBoxContainer.gd @@ -0,0 +1,36 @@ +extends VBoxContainer + +# Many thanks to Arkeve! https://github.com/arkeve + +const SlotClass = preload("res://MiscCodes/Slot.gd") +onready var inventory_slots = $GridContainer +var holding_item = null + +func _ready(): + for inv_slot in inventory_slots.get_children(): + inv_slot.connect("gui_input", self, "slot_gui_input", [inv_slot]) + +func slot_gui_input(event: InputEvent, slot: SlotClass): + if event is InputEventMouseButton: + if event.button_index == BUTTON_LEFT && event.pressed: + if holding_item != null: + if !slot.item: # Place holding item to slot + slot.putIntoSlot(holding_item) + holding_item = null + else: # Swap holding item with item in slot + var temp_item = slot.item + slot.pickFromSlot() + temp_item.global_position = event.global_position + slot.putIntoSlot(holding_item) + holding_item = temp_item + elif slot.item: + holding_item = slot.item + slot.pickFromSlot() + holding_item.global_position = get_global_mouse_position() + +func _input(event): + if holding_item: + holding_item.global_position = get_global_mouse_position() + +func _on_TouchScreenButton_pressed(): + Global.GoToScene("river_intersection_home_2") diff --git a/Storage/Database.gd b/Storage/Database.gd index 6e684b9..cdd0e9e 100644 --- a/Storage/Database.gd +++ b/Storage/Database.gd @@ -1,70 +1,74 @@ -extends Node - -var path = "user://storage.db" -var db_name = "RingOfRaces" -var db = null -var verbose = true - -# Called when the node enters the scene tree for the first time. -func _ready(): - pass # Replace with function body. - -func CreateWorldDatabase(): - print("Creating new database") - var SQLite = load("user://gdsqlite.gdns") - 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(): - var SQLite = load("user://gdsqlite.gdns") - self.db = SQLite.new() - var file = File.new() - self.db.path = path - self.db.verbose_mode = verbose - var create = false - print(path) - - # This does not seem to work. The file is in the right place, but being recreated everytime. The file is findable in Res:// and C:/ .. But not after the user folder - if !file.file_exists(path): - print("File not existing, so creating new db") - create = true - self.db.open_db() - if create: - CreateWorldDatabase() - -func OpenConnectionIfClosed(): - if self.db == null: - OpenConnection() - -func GetInventoryItems(): - OpenConnectionIfClosed() - var ret = [] - ret = db.select_rows("player_inventory", "",["*"]) - return ret - -func SaveInventory(player_inventory_items): - print("Now on inventory save file") - if(player_inventory_items == null or len(player_inventory_items) != 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 +extends Node +const SQLite = preload("res://addons/godot-sqlite/bin/gdsqlite.gdns") + +var path = "user://storage.db" +var db_name = "RingOfRaces" +var db = null +var verbose = true + +var host = null + +# Called when the node enters the scene tree for the first time. +func _ready(): + host = OS.get_name() + +func CreateWorldDatabase(): + print("Creating new database") + var SQLite = load("user://gdsqlite.gdns") + 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(): + if(str(OS.get_name()) == "X11"): + path = "res://storage.db" + self.db = SQLite.new() + var file = File.new() + self.db.path = path + self.db.verbose_mode = verbose + var create = false + print(path) + + # This does not seem to work. The file is in the right place, but being recreated everytime. The file is findable in Res:// and C:/ .. But not after the user folder + if !file.file_exists(path): + print("File not existing, so creating new db") + create = true + self.db.open_db() + if create: + CreateWorldDatabase() + +func OpenConnectionIfClosed(): + if self.db == null: + OpenConnection() + +func GetInventoryItems(): + OpenConnectionIfClosed() + var ret = [] + ret = db.select_rows("player_inventory", "",["*"]) + return ret + +func SaveInventory(player_inventory_items): + print("Now on inventory save file") + if(player_inventory_items == null or len(player_inventory_items) != 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/omgeving/Floor.tres b/omgeving/Floor.tres index d6e402e..365c2a0 100644 --- a/omgeving/Floor.tres +++ b/omgeving/Floor.tres @@ -2,8 +2,6 @@ [ext_resource path="res://pictures/tileset_images/TilesetGodotVloer.png" type="Texture" id=1] - - [sub_resource type="ConcavePolygonShape2D" id=1] segments = PoolVector2Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ) diff --git a/storage.db b/storage.db new file mode 100644 index 0000000000000000000000000000000000000000..5864933d2fdcb59110f62b1513f7f66638af5a96 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