basic scene switching added

This commit is contained in:
EljakimHerrewijnen 2020-10-08 21:56:03 +02:00
parent bf2a5b8cf1
commit 7ae1e86f9d
9 changed files with 66 additions and 17 deletions

View File

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

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):

View File

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

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

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

View File

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

Binary file not shown.

View File

@ -23,4 +23,4 @@ func _unhandled_input(event):
func _on_Inventory_pressed():
get_tree().change_scene("res://MiscScenes/Inventory.tscn")
Global.GoToScene("inventory_screen")