inventaire #35
11
common/inventory/resources/items/default_seed.tres
Normal file
11
common/inventory/resources/items/default_seed.tres
Normal file
@ -0,0 +1,11 @@
|
||||
[gd_resource type="Resource" script_class="SeedItem" load_steps=3 format=3 uid="uid://lrl2okkhyxmx"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://dcgnamu7sb3ov" path="res://gui/player_info/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"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("2_mgcdi")
|
||||
plant_type = ""
|
||||
name = "Boule"
|
||||
icon = ExtResource("1_dy25s")
|
||||
metadata/_custom_type_script = "uid://bypjcvlc15gsm"
|
||||
5
common/inventory/scripts/generic_item.gd
Normal file
5
common/inventory/scripts/generic_item.gd
Normal file
@ -0,0 +1,5 @@
|
||||
extends Resource
|
||||
class_name GenericItem
|
||||
|
||||
@export var name: String
|
||||
@export var icon: Texture2D
|
||||
1
common/inventory/scripts/generic_item.gd.uid
Normal file
1
common/inventory/scripts/generic_item.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://do1a37cqva05e
|
||||
44
common/inventory/scripts/inventory.gd
Normal file
44
common/inventory/scripts/inventory.gd
Normal file
@ -0,0 +1,44 @@
|
||||
extends Resource
|
||||
class_name Inventory
|
||||
|
||||
signal inventory_changed(inventory: Inventory)
|
||||
|
||||
@export var items: Array[GenericItem] = []
|
||||
@export var max_items: int = 10
|
||||
|
||||
func add_item(item: GenericItem):
|
||||
if items.size() < max_items:
|
||||
items.append(item)
|
||||
emit_signal("inventory_changed", self)
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
|
||||
func add_items(items_to_add: Array[GenericItem], fillup: bool = false):
|
||||
if fillup:
|
||||
var has_changed := false
|
||||
for i in min(items_to_add.size(), max_items - items.size()):
|
||||
items.append(items_to_add[i])
|
||||
has_changed = true
|
||||
if has_changed:
|
||||
emit_signal("inventory_changed", self)
|
||||
return has_changed
|
||||
elif !fillup && items.size() + items_to_add.size() < max_items:
|
||||
items.append_array(items_to_add)
|
||||
emit_signal("inventory_changed", self)
|
||||
return true
|
||||
|
||||
|
||||
func get_item(ind: int = 0):
|
||||
return items[ind]
|
||||
|
||||
func get_and_remove_item(ind: int = 0):
|
||||
var item_removed: GenericItem = items.pop_at(ind)
|
||||
emit_signal("inventory_changed", self)
|
||||
return item_removed
|
||||
|
||||
func swap_items(item_to_add: GenericItem, ind_to_get: int = 0):
|
||||
var item_to_get := items[ind_to_get]
|
||||
items[ind_to_get] = item_to_add
|
||||
emit_signal("inventory_changed", self)
|
||||
return item_to_get
|
||||
1
common/inventory/scripts/inventory.gd.uid
Normal file
1
common/inventory/scripts/inventory.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://fnu2d6wna4yc
|
||||
4
common/inventory/scripts/items/seed_item.gd
Normal file
4
common/inventory/scripts/items/seed_item.gd
Normal file
@ -0,0 +1,4 @@
|
||||
extends GenericItem
|
||||
class_name SeedItem
|
||||
|
||||
@export var plant_type: String
|
||||
1
common/inventory/scripts/items/seed_item.gd.uid
Normal file
1
common/inventory/scripts/items/seed_item.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://bypjcvlc15gsm
|
||||
@ -0,0 +1,7 @@
|
||||
[gd_resource type="Resource" script_class="GetSeedInteraction" load_steps=2 format=3 uid="uid://chmmu2jlo2eu0"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://j5xvcabrspyb" path="res://entities/interactables/scripts/actions/get_seed.gd" id="1_ys78p"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_ys78p")
|
||||
metadata/_custom_type_script = "uid://j5xvcabrspyb"
|
||||
8
entities/interactables/scripts/actions/get_seed.gd
Normal file
8
entities/interactables/scripts/actions/get_seed.gd
Normal file
@ -0,0 +1,8 @@
|
||||
extends InteractableAction
|
||||
class_name GetSeedInteraction
|
||||
|
||||
func action(p: Player, i : Interactable):
|
||||
if i is Plant:
|
||||
p.inventory.add_item(i.seed_item)
|
||||
else :
|
||||
printerr("No plant selected or interactable is not a plant")
|
||||
1
entities/interactables/scripts/actions/get_seed.gd.uid
Normal file
1
entities/interactables/scripts/actions/get_seed.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://j5xvcabrspyb
|
||||
@ -1,8 +1,8 @@
|
||||
extends InteractableAction
|
||||
class_name WaterPlantAction
|
||||
|
||||
func action(_p: Player, _i : Interactable):
|
||||
if _i is Plant:
|
||||
_i.watered = true
|
||||
func action(_p: Player, i : Interactable):
|
||||
if i is Plant:
|
||||
i.watered = true
|
||||
else :
|
||||
printerr("No plant selected or interactable is not a plant")
|
||||
@ -1,7 +1,7 @@
|
||||
extends Area2D
|
||||
class_name Interactable
|
||||
|
||||
@export var actions : Array[InteractableAction] = [];
|
||||
@export var actions : Array[InteractableAction] = []
|
||||
|
||||
func interact(p : Player):
|
||||
for a in actions:
|
||||
|
||||
@ -1,37 +0,0 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://clpcqkdlj3d8e"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cega715smavh3" path="res://entities/plants/scripts/plant.gd" id="1_d8u7e"]
|
||||
[ext_resource type="Texture2D" uid="uid://c6vby5r0pfni2" path="res://entities/plants/assets/sprites/default_plant.png" id="4_dq24f"]
|
||||
[ext_resource type="Texture2D" uid="uid://b3wom2xu26g43" path="res://entities/plants/assets/sprites/default_plant_glowing.png" id="5_2gcie"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_cdbrd"]
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_ocwgi"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("4_dq24f")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"default",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("5_2gcie")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"watered",
|
||||
"speed": 5.0
|
||||
}]
|
||||
|
||||
[node name="DefaultPlant" type="Area2D"]
|
||||
script = ExtResource("1_d8u7e")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
scale = Vector2(4.01154, 4.01154)
|
||||
shape = SubResource("CircleShape2D_cdbrd")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
scale = Vector2(0.160462, 0.160462)
|
||||
sprite_frames = SubResource("SpriteFrames_ocwgi")
|
||||
@ -1,7 +1,7 @@
|
||||
extends CharacterBody2D
|
||||
class_name Player
|
||||
|
||||
signal player_stats_updated(player : Player)
|
||||
signal player_updated(player: Player)
|
||||
|
||||
var controlling_player : bool = true
|
||||
var planet : Planet # mis à jour par la classe Planet
|
||||
@ -14,10 +14,14 @@ var max_energy : int = 10
|
||||
var energy : int = max_energy :
|
||||
set(v):
|
||||
energy = v
|
||||
emit_signal("player_stats_updated", self)
|
||||
emit_signal("player_updated", self)
|
||||
|
||||
func _ready():
|
||||
emit_signal("player_stats_updated", self)
|
||||
emit_signal("player_updated", self)
|
||||
inventory.inventory_changed.connect(_on_inventory_updated)
|
||||
|
||||
func _on_inventory_updated(_inventory: Inventory):
|
||||
emit_signal("player_updated", self)
|
||||
|
||||
func get_input():
|
||||
if controlling_player:
|
||||
@ -27,7 +31,7 @@ func get_input():
|
||||
action()
|
||||
|
||||
func calculate_direction():
|
||||
var input_direction : Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
var input_direction: Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
velocity = input_direction * speed
|
||||
if input_direction.x:
|
||||
$Sprite.flip_h = (input_direction.x < 0)
|
||||
|
||||
@ -58,3 +58,11 @@ text = "0"
|
||||
label_settings = ExtResource("5_s4ggy")
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="Inventory" type="HBoxContainer" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 157.0
|
||||
offset_top = 86.0
|
||||
offset_right = 291.0
|
||||
offset_bottom = 126.0
|
||||
alignment = 1
|
||||
|
||||
@ -1,4 +1,12 @@
|
||||
extends Control
|
||||
|
||||
func _on_root_gui_player_stats_updated(player:Player):
|
||||
func _on_root_gui_player_updated(player: Player):
|
||||
$EnergyInfo/Label.text = str(player.energy)
|
||||
|
||||
var children = $Inventory.get_children()
|
||||
for child in children:
|
||||
child.free()
|
||||
for item in player.inventory.items:
|
||||
var item_rect = TextureRect.new()
|
||||
item_rect.texture = item.icon
|
||||
$Inventory.add_child(item_rect)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user