#37 ajout d'item outils ainsi que de visualisation de leur zone d'effet (avec la classe ActionArea
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
[gd_resource type="Resource" script_class="SeedItem" load_steps=3 format=3 uid="uid://lrl2okkhyxmx"]
|
||||
[gd_resource type="Resource" script_class="Seed" load_steps=3 format=3 uid="uid://lrl2okkhyxmx"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://dcgnamu7sb3ov" path="res://gui/assets/icons/bolt.svg" id="1_dy25s"]
|
||||
[ext_resource type="Script" uid="uid://bypjcvlc15gsm" path="res://common/inventory/scripts/items/seed_item.gd" id="2_mgcdi"]
|
||||
[ext_resource type="Script" uid="uid://bypjcvlc15gsm" path="res://common/inventory/scripts/items/seed.gd" id="2_mgcdi"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("2_mgcdi")
|
||||
|
||||
@@ -31,15 +31,26 @@ func add_items(items_to_add: Array[Item], fillup: bool = false):
|
||||
func lenght() -> int:
|
||||
return len(items)
|
||||
|
||||
func get_item(ind: int = 0):
|
||||
func set_item(item : Item, ind: int = 0) -> bool:
|
||||
if ind >= max_items:
|
||||
return false
|
||||
while len(items) <= ind:
|
||||
items.append(null)
|
||||
items[ind] = item
|
||||
emit_signal("inventory_changed", self)
|
||||
return true
|
||||
|
||||
func get_item(ind: int = 0) -> Item:
|
||||
if len(items) <= ind:
|
||||
return null;
|
||||
return items[ind]
|
||||
|
||||
func pop_item(ind: int = 0):
|
||||
func pop_item(ind: int = 0) -> Item:
|
||||
var item_removed: Item = items.pop_at(ind)
|
||||
emit_signal("inventory_changed", self)
|
||||
return item_removed
|
||||
|
||||
func swap_items(item_to_add: Item, ind_to_get: int = 0):
|
||||
func swap_items(item_to_add: Item, ind_to_get: int = 0) -> Item:
|
||||
var item_to_get := items[ind_to_get]
|
||||
items[ind_to_get] = item_to_add
|
||||
emit_signal("inventory_changed", self)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
@tool
|
||||
extends Item
|
||||
class_name SeedItem
|
||||
class_name Seed
|
||||
|
||||
@export var plant_type: PlantType :
|
||||
set(v):
|
||||
12
common/inventory/scripts/items/shovel.gd
Normal file
12
common/inventory/scripts/items/shovel.gd
Normal file
@@ -0,0 +1,12 @@
|
||||
extends ToolItem
|
||||
class_name Shovel
|
||||
|
||||
func can_use(player : Player) -> bool:
|
||||
var areas = player.action_area.get_overlapping_areas()
|
||||
for area in areas :
|
||||
if area is Plant:
|
||||
return true
|
||||
return false
|
||||
|
||||
func use(_player : Player) -> bool:
|
||||
return false
|
||||
1
common/inventory/scripts/items/shovel.gd.uid
Normal file
1
common/inventory/scripts/items/shovel.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dya38x1h1uiyg
|
||||
11
common/inventory/scripts/tool_item.gd
Normal file
11
common/inventory/scripts/tool_item.gd
Normal file
@@ -0,0 +1,11 @@
|
||||
extends Item
|
||||
class_name ToolItem
|
||||
|
||||
@export var area_width: float = 50
|
||||
@export var area_distance: float = 50
|
||||
|
||||
func generate_action_area():
|
||||
return ActionArea.new(
|
||||
area_width,
|
||||
area_distance
|
||||
)
|
||||
1
common/inventory/scripts/tool_item.gd.uid
Normal file
1
common/inventory/scripts/tool_item.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://jom8ulyopso
|
||||
Reference in New Issue
Block a user