Compare commits

...

2 Commits

Author SHA1 Message Date
EljakimHerrewijnen
7ae1e86f9d basic scene switching added 2020-10-08 21:56:03 +02:00
EljakimHerrewijnen
bf2a5b8cf1 Started working on DB interaction 2020-10-07 22:24:10 +02:00
19 changed files with 186 additions and 17 deletions

View File

@ -2,6 +2,35 @@ 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()
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

View File

@ -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):
@ -47,3 +45,5 @@ func _input(event):
if Input.is_action_pressed("map_interaction"):
pass
func _ready():
Global.player_inventory_items = Database.GetInventoryItems()

View File

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

View File

@ -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")

View File

@ -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")

View File

@ -10,15 +10,22 @@ var empty_style: StyleBoxTexture = null
var ItemClass = preload("res://MiscScenes/Item.tscn")
var item = null
var id = 0
#onready var id = int(self.name[4:0])
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()
empty_style = StyleBoxTexture.new()
#default_style.texture = default_tex
#empty_style.texture = empty_tex
if randi() % 2 == 0:
# print(self.get)
if Global.player_inventory_items[self.id] != null:
item = ItemClass.instance()
item.set("id", self.id)
add_child(item)
# refresh_style()

57
Storage/Database.gd Normal file
View File

@ -0,0 +1,57 @@
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 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:
OpenConnection()
func GetInventoryItems():
OpenConnectionIfClosed()
var ret = []
ret = db.select_rows("player_inventory", "",["*"])
return ret
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass

BIN
Storage/World1.db Normal file

Binary file not shown.

View File

@ -1,6 +1,6 @@
extends TouchScreenButton
onready var ShowInventory = get_node("res://Global.gd")
onready var ShowInventory = Global.ShowInventory
func _input(always):
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
onready var player = get_node("/root/Map1/Player")
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func _get_cell_size():
@ -23,4 +23,4 @@ func _unhandled_input(event):
func _on_Inventory_pressed():
get_tree().change_scene("res://MiscScenes/Inventory.tscn")
Global.GoToScene("inventory_screen")

View File

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