#42 ajout d'un inspecteur
This commit is contained in:
@@ -4,13 +4,13 @@ class_name Compost
|
||||
|
||||
@export var value_per_seed : float = 0.5
|
||||
|
||||
var fill_value : float = 0.
|
||||
@onready var fill_value : float = 0.
|
||||
|
||||
func _process(_delta):
|
||||
%ProgressBar.value = lerp(%ProgressBar.value, fill_value * 100, 0.5)
|
||||
|
||||
func _ready():
|
||||
fill_value = 0.
|
||||
func inspected_text():
|
||||
return "Compost"
|
||||
|
||||
func can_interact(p : Player) -> bool:
|
||||
return p.inventory.get_item() and p.inventory.get_item() is Seed
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
extends Interactable
|
||||
class_name ItemObject
|
||||
|
||||
const ITEM_AREA_WIDTH = 10
|
||||
const ITEM_AREA_WIDTH = 20
|
||||
const ITEM_SPRITE_SIZE = 40.
|
||||
const SPRITE_SCENE : PackedScene = preload("res://entities/interactables/item_object/item_object_sprite.tscn")
|
||||
|
||||
@@ -19,7 +19,10 @@ func _init(_item = null):
|
||||
item = _item
|
||||
|
||||
func _ready():
|
||||
generate_collision(10)
|
||||
generate_collision(ITEM_AREA_WIDTH)
|
||||
|
||||
func inspected_text():
|
||||
return item.name + (" Seed" if item is Seed else "")
|
||||
|
||||
func interact(player : Player) -> bool:
|
||||
var swapped_item = player.inventory.get_item()
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
extends Area2D
|
||||
extends InspectableEntity
|
||||
class_name Interactable
|
||||
|
||||
var available : bool = true
|
||||
|
||||
func _ready():
|
||||
printerr("Abstract Interactable class used")
|
||||
|
||||
func can_interact(_p : Player) -> bool:
|
||||
return true
|
||||
|
||||
|
||||
@@ -99,7 +99,6 @@ script = ExtResource("1_pq8o7")
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
scale = Vector2(0.15, 0.15)
|
||||
texture = ExtResource("2_hyinx")
|
||||
offset = Vector2(0, -100)
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
extends Area2D
|
||||
extends InspectableEntity
|
||||
class_name Plant
|
||||
|
||||
const PLANT_AREA_WIDTH = 10
|
||||
const PLANT_AREA_WIDTH = 20
|
||||
const HARVESTED_SEED_POSITION_RANGE = 100
|
||||
|
||||
const RANDOM_MAX_GROW_INTERVAL = 0.4
|
||||
@@ -23,6 +23,11 @@ func _init(_plant_type = null, _planet = null):
|
||||
plant_type = _plant_type
|
||||
planet = _planet
|
||||
|
||||
func inspected_text():
|
||||
var state_text = "Growing"
|
||||
if state == State.MATURE: state_text = "Mature"
|
||||
return state_text + " " + plant_type.name
|
||||
|
||||
func generate_sprite() -> PlantSprite:
|
||||
var spriteObject : PlantSprite = SPRITE_SCENE.instantiate()
|
||||
|
||||
|
||||
27
entities/scripts/inspectable_entity.gd
Normal file
27
entities/scripts/inspectable_entity.gd
Normal file
@@ -0,0 +1,27 @@
|
||||
extends Area2D
|
||||
class_name InspectableEntity
|
||||
|
||||
const MODULATE_INSPECTED_COLOR = Color.GRAY
|
||||
|
||||
@onready var default_modulate : Color = modulate
|
||||
@onready var mouse_signals_setuped : bool = setup_mouse_signals()
|
||||
|
||||
var inspected : bool = false :
|
||||
set(v):
|
||||
print(v)
|
||||
inspected = v
|
||||
modulate = MODULATE_INSPECTED_COLOR if inspected else default_modulate
|
||||
|
||||
func setup_mouse_signals() -> bool:
|
||||
mouse_entered.connect(_on_mouse_entered)
|
||||
mouse_exited.connect(_on_mouse_excited)
|
||||
return true
|
||||
|
||||
func _on_mouse_entered():
|
||||
Pointer.inspect_entity(self)
|
||||
|
||||
func _on_mouse_excited():
|
||||
Pointer.stop_inspect_entity(self)
|
||||
|
||||
func inspected_text():
|
||||
return ""
|
||||
1
entities/scripts/inspectable_entity.gd.uid
Normal file
1
entities/scripts/inspectable_entity.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://d3bk52402ylvl
|
||||
@@ -1,7 +1,7 @@
|
||||
extends Area2D
|
||||
extends InspectableEntity
|
||||
class_name UndergroundLoot
|
||||
|
||||
const AREA_WIDTH = 10
|
||||
const AREA_WIDTH = 20
|
||||
const LOOTED_ITEM_RANDOM_RANGE = 100
|
||||
|
||||
const SPRITE_SCENE : PackedScene = preload("res://entities/underground_loot/underground_loot_sprite.tscn")
|
||||
@@ -15,6 +15,9 @@ var planet : Planet # mis à jour par la classe Planet
|
||||
func _init(_planet = null):
|
||||
planet = _planet
|
||||
|
||||
func inspected_text():
|
||||
return "Buried Loot"
|
||||
|
||||
func generate_sprite() -> Node2D:
|
||||
var object = SPRITE_SCENE.instantiate()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user