Added Itemsmanager
Items now can be stored. I wanna kill myself
This commit is contained in:
@@ -2,11 +2,13 @@ class_name Interactable
|
||||
extends Node
|
||||
|
||||
signal action_stoped
|
||||
signal object_placed()
|
||||
|
||||
|
||||
var can_pick: bool
|
||||
|
||||
var can_store: bool
|
||||
var stored_objects: Array
|
||||
var stored_items: Array
|
||||
|
||||
var max_person_using
|
||||
var persons_using: Array
|
||||
@@ -48,3 +50,6 @@ func can_be_used():
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
|
||||
func create():
|
||||
pass
|
||||
|
||||
4
Scripts/Item.gd
Normal file
4
Scripts/Item.gd
Normal file
@@ -0,0 +1,4 @@
|
||||
extends Node3D
|
||||
class_name Item
|
||||
var item_name
|
||||
var shelf_owner
|
||||
1
Scripts/Item.gd.uid
Normal file
1
Scripts/Item.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c1ic8jloyqlnt
|
||||
4
Scripts/Items/food_item.gd
Normal file
4
Scripts/Items/food_item.gd
Normal file
@@ -0,0 +1,4 @@
|
||||
extends Item
|
||||
|
||||
func _init() -> void:
|
||||
item_name = "food"
|
||||
1
Scripts/Items/food_item.gd.uid
Normal file
1
Scripts/Items/food_item.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bd3vhk86ac1nu
|
||||
@@ -4,19 +4,20 @@ extends Node3D
|
||||
|
||||
@export var meshInstance: MeshInstance3D
|
||||
@export var preview_shader: ShaderMaterial
|
||||
@export var ActionNode: Node3D
|
||||
|
||||
var default_shaders: Array
|
||||
var staic_body: StaticBody3D
|
||||
var ActionNode: Node3D
|
||||
var static_body: StaticBody3D
|
||||
#var ActionNode: Node3D
|
||||
var is_placed: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
BuildManager.preview_created.connect(_on_preview_create)
|
||||
BuildManager.object_placed.connect(_on_object_placed)
|
||||
set_default_shaders()
|
||||
|
||||
staic_body = $StaticBody3D
|
||||
staic_body.mouse_entered.connect(_on_mouse_enter)
|
||||
staic_body.mouse_exited.connect(_on_mouse_exit)
|
||||
static_body = $StaticBody3D
|
||||
|
||||
|
||||
ActionNode = $ActionNode
|
||||
|
||||
@@ -53,8 +54,11 @@ func _on_preview_create():
|
||||
|
||||
|
||||
func _on_object_placed(build_postion):
|
||||
#BuildManager.add_object_to_array(self)
|
||||
#print(ActionNode.global_position)
|
||||
|
||||
is_placed = true
|
||||
static_body.input_ray_pickable = true
|
||||
static_body.mouse_entered.connect(_on_mouse_enter)
|
||||
static_body.mouse_exited.connect(_on_mouse_exit)
|
||||
restore_default_shaders()
|
||||
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ func hide_preview():
|
||||
buildTransparentPreivew.visible = true
|
||||
|
||||
func place_object():
|
||||
#is_placed = true
|
||||
is_placed = true
|
||||
#buildTransparentPreivew.visible = false
|
||||
BuildManager.object_placed.emit(self.position)
|
||||
self.queue_free()
|
||||
|
||||
@@ -21,4 +21,5 @@ func _on_object_placed(build_postion):
|
||||
var newObject = BuildManager.get_preview_object().instantiate()
|
||||
newObject.global_position = build_postion
|
||||
BuildManager.add_object_to_array(newObject)
|
||||
newObject.ActionNode.create()
|
||||
self.add_child(newObject)
|
||||
|
||||
@@ -11,15 +11,4 @@ func _ready() -> void:
|
||||
|
||||
func _on_interact(person, object):
|
||||
object.ActionNode.start_action(person, object)
|
||||
|
||||
|
||||
func give_item(person, item_id):
|
||||
var item = get_item_form_id(item_id)
|
||||
person.hold_item(item)
|
||||
|
||||
|
||||
|
||||
func get_item_form_id(id):
|
||||
match id:
|
||||
0:
|
||||
return food_item
|
||||
print(object)
|
||||
|
||||
54
Scripts/item_manager.gd
Normal file
54
Scripts/item_manager.gd
Normal file
@@ -0,0 +1,54 @@
|
||||
extends Node
|
||||
@onready var food_item = preload("res://Scenes/Prefabs/food_item.tscn")
|
||||
signal object_placed
|
||||
var shelfes: Array
|
||||
|
||||
|
||||
|
||||
func set_person_target_item(person,item_name):
|
||||
var result = find_item(item_name)
|
||||
print(result)
|
||||
if result != null:
|
||||
person.set_target(result.shelf_owner.owner)
|
||||
|
||||
|
||||
|
||||
func find_item(item_name):
|
||||
|
||||
for shelf in shelfes:
|
||||
if shelf != null:
|
||||
for item in shelf.stored_items:
|
||||
if item.item_name == item_name:
|
||||
return item
|
||||
return null
|
||||
|
||||
func get_item_name():
|
||||
pass
|
||||
|
||||
|
||||
func add_shelf(object):
|
||||
shelfes.append(object)
|
||||
print(object)
|
||||
|
||||
|
||||
func add_item_to_shelf(shelf, item):
|
||||
item.shelf_owner = shelf
|
||||
shelf.stored_items.append(item)
|
||||
|
||||
func get_item(id):
|
||||
return get_item_from_id(id)
|
||||
|
||||
func give_item(person, item_id):
|
||||
var item = get_item_from_id(item_id)
|
||||
person.hold_item(item)
|
||||
|
||||
|
||||
|
||||
func get_item_from_id(id):
|
||||
match id:
|
||||
0:
|
||||
return food_item
|
||||
|
||||
|
||||
|
||||
|
||||
1
Scripts/item_manager.gd.uid
Normal file
1
Scripts/item_manager.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c3bt4qr6bip5y
|
||||
40
Scripts/objects/shelf_object.gd
Normal file
40
Scripts/objects/shelf_object.gd
Normal file
@@ -0,0 +1,40 @@
|
||||
extends Interactable
|
||||
|
||||
|
||||
var test: bool = false
|
||||
|
||||
func _init() -> void:
|
||||
max_person_using = 1
|
||||
can_store = true
|
||||
print("init")
|
||||
func _ready() -> void:
|
||||
self.owner = $".."
|
||||
print(self)
|
||||
#object_placed.connect(_on_object_placed.bind(self))
|
||||
print("ready")
|
||||
|
||||
|
||||
|
||||
|
||||
func start_action(person, object):
|
||||
pass
|
||||
|
||||
|
||||
func give_out(person):
|
||||
pass
|
||||
|
||||
|
||||
func _on_object_placed(_owner):
|
||||
print(2)
|
||||
print(_owner)
|
||||
var newItem = ItemManager.get_item(0).instantiate()
|
||||
ItemManager.add_shelf(_owner)
|
||||
#ItemManager.shelfes.append(_owner)
|
||||
ItemManager.add_item_to_shelf(_owner, newItem)
|
||||
print("placed")
|
||||
|
||||
func create():
|
||||
var newItem = ItemManager.get_item(0).instantiate()
|
||||
ItemManager.shelfes.append(self)
|
||||
ItemManager.add_item_to_shelf(self, newItem)
|
||||
print("placed")
|
||||
1
Scripts/objects/shelf_object.gd.uid
Normal file
1
Scripts/objects/shelf_object.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dw0nntbakhny6
|
||||
@@ -19,12 +19,13 @@ var is_holding_item: bool = false
|
||||
var holdingItem: Object
|
||||
|
||||
|
||||
var target_item: int
|
||||
|
||||
func _ready() -> void:
|
||||
nav_agent = $NavigationAgent3D
|
||||
meshI = $MeshInstance3D
|
||||
shirt_shader = meshI.get_surface_override_material(1)
|
||||
|
||||
BuildManager.object_added.connect(_on_object_added)
|
||||
|
||||
set_random_shirt()
|
||||
|
||||
@@ -33,8 +34,7 @@ func _ready() -> void:
|
||||
is_in_action = false
|
||||
|
||||
timer = $Timer
|
||||
|
||||
Global.give_item(self, 0)
|
||||
|
||||
#nav_agent.target_position = Vector3(-15.955,3.486,-58.942)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
@@ -46,10 +46,10 @@ func _physics_process(delta: float) -> void:
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("test"):
|
||||
set_target_position()
|
||||
ItemManager.set_person_target_item(self, "food")
|
||||
#set_target_position()
|
||||
|
||||
|
||||
func _on_object_added(object):
|
||||
set_target(object)
|
||||
|
||||
|
||||
func set_random_shirt():
|
||||
@@ -63,6 +63,7 @@ func set_target(object):
|
||||
#if !is_in_action and object.ActionNode.can_be_used():
|
||||
if !is_in_action:
|
||||
target_object = object
|
||||
set_target_position()
|
||||
#nav_agent.target_position = target_object.ActionNode.global_position
|
||||
func set_target_position():
|
||||
is_target_reached = false
|
||||
@@ -70,7 +71,7 @@ func set_target_position():
|
||||
newPos.y = self.position.y
|
||||
nav_agent.target_position = newPos
|
||||
print(target_object.ActionNode.can_be_used())
|
||||
|
||||
|
||||
#nav_agent.target_position = start_pos
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user