Started working on DB interaction

This commit is contained in:
EljakimHerrewijnen 2020-10-07 22:24:10 +02:00
parent 8c9cc7e31d
commit bf2a5b8cf1
17 changed files with 125 additions and 5 deletions

View File

@ -2,6 +2,13 @@ extends Node2D
var ShowInventory = 0 var ShowInventory = 0
var LeftClick = 0 var LeftClick = 0
var player_inventory_items = []
func LoadSave():
Database.OpenConnection()
func _input(event): func _input(event):
pass pass
func _ready():
pass

View File

@ -47,3 +47,5 @@ func _input(event):
if Input.is_action_pressed("map_interaction"): if Input.is_action_pressed("map_interaction"):
pass pass
func _ready():
Global.player_inventory_items = Database.GetInventoryItems()

View File

@ -4,4 +4,5 @@ func _ready():
pass # Replace with function body. pass # Replace with function body.
func _on_Btn_PlayGame_pressed(): func _on_Btn_PlayGame_pressed():
Global.LoadSave()
get_tree().change_scene("res://river_intersection_home2.tscn") get_tree().change_scene("res://river_intersection_home2.tscn")

View File

@ -10,14 +10,23 @@ var empty_style: StyleBoxTexture = null
var ItemClass = preload("res://MiscScenes/Item.tscn") var ItemClass = preload("res://MiscScenes/Item.tscn")
var item = null var item = null
var id = 0
#onready var id = int(self.name[4:0])
func _ready(): func _ready():
if self.name.length() == 5:
self.id = int(self.name.right(1)) - 1
else:
self.id = int(self.name.right(2)) - 1
default_style = StyleBoxTexture.new() default_style = StyleBoxTexture.new()
empty_style = StyleBoxTexture.new() empty_style = StyleBoxTexture.new()
#default_style.texture = default_tex #default_style.texture = default_tex
#empty_style.texture = empty_tex #empty_style.texture = empty_tex
# print(self.get)
if randi() % 2 == 0: # 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 = ItemClass.instance()
add_child(item) add_child(item)
# refresh_style() # refresh_style()

31
Storage/Database.gd Normal file
View File

@ -0,0 +1,31 @@
extends Node
const SQLite = preload("res://addons/godot-sqlite/bin/gdsqlite.gdns")
var path = "res://Storage/World1.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 OpenConnection():
self.db = SQLite.new()
self.db.path = path
self.db.verbose_mode = verbose
self.db.open_db()
func OpenConnectionIfClosed():
if self.db == null:
OpenConnection()
func GetInventoryItems():
OpenConnectionIfClosed()
var ret = []
for x in range(40):
ret.append([x, "test"])
return ret
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass

0
Storage/World1.db Normal file
View File

View File

@ -1,6 +1,6 @@
extends TouchScreenButton extends TouchScreenButton
onready var ShowInventory = get_node("res://Global.gd") onready var ShowInventory = Global.ShowInventory
func _input(always): func _input(always):
ShowInventory = 1; ShowInventory = 1;

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019-present Piet Bronders & Jeroen De Geeter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,19 @@
[general]
singleton=false
load_once=true
symbol_prefix="godot_"
reloadable=false
[entry]
X11.64="res://addons/godot-sqlite/bin/x11/libgdsqlite.so"
Server="res://addons/godot-sqlite/bin/x11/libgdsqlite.so"
Windows.64="res://addons/godot-sqlite/bin/win64/libgdsqlite.dll"
OSX.64="res://addons/godot-sqlite/bin/osx/libgdsqlite.dylib"
[dependencies]
X11.64=[ ]
Server=[ ]
Windows.64=[ ]
OSX.64=[ ]

View File

@ -0,0 +1,8 @@
[gd_resource type="NativeScript" load_steps=2 format=2]
[ext_resource path="res://addons/godot-sqlite/bin/gdsqlite.gdnlib" type="GDNativeLibrary" id=1]
[resource]
resource_name = "gdsqlite"
class_name = "SQLite"
library = ExtResource( 1 )

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,14 @@
# ############################################################################ #
# Copyright © 2019-present Piet Bronders & Jeroen De Geeter <piet.bronders@gmail.com>
# Licensed under the MIT License.
# See LICENSE in the project root for license information.
# ############################################################################ #
tool
extends EditorPlugin
func _enter_tree():
pass
func _exit_tree():
pass

View File

@ -0,0 +1,7 @@
[plugin]
name="Godot SQLite"
description="GDNative wrapper for SQLite (Godot 3.1+), making it possible to use SQLite databases as data storage in all your future games."
author="Piet Bronders & Jeroen De Geeter"
version="1.7"
script="godot-sqlite.gd"

View File

@ -1,10 +1,10 @@
extends TileMap extends TileMap
onready var player = get_node("/root/Map1/Player") onready var player = get_node("/root/Map1/Player")
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
pass # Replace with function body. pass # Replace with function body.
func _get_cell_size(): func _get_cell_size():

View File

@ -21,7 +21,8 @@ config/icon="res://pictures/gui/buttons/delete_ringofraces.png"
[autoload] [autoload]
Global="*res://Global.tscn" Global="*res://Global.gd"
Database="*res://Storage/Database.gd"
[display] [display]