ajout du déblocage/évolutions des plantes (#89) et fix divers

This commit is contained in:
2025-11-07 13:26:04 +01:00
parent 11ae967845
commit ed675ed532
54 changed files with 901 additions and 483 deletions

View File

@@ -15,10 +15,6 @@ const LIFETIME_ICON = preload("res://common/icons/calendar-week.svg")
const SHOVEL_ICON = preload("res://common/icons/shovel.svg")
const GROWING_ICON = preload("res://common/icons/chevrons-up.svg")
const HARVEST_EFFECT_ICON = preload("res://common/icons/shovel.svg")
const MATURE_EFFECT_ICON = preload("res://common/icons/chevrons-up.svg")
const CYCLIC_EFFECT_ICON = preload("res://common/icons/rotate-rectangle.svg")
const SPRITE_SCENE : PackedScene = preload("res://entities/plants/plant_sprite.tscn")
enum State {PLANTED, GROWING, MATURE}
@@ -32,9 +28,6 @@ var state: State = State.PLANTED
@onready var collision_shape: CollisionShape2D
@onready var influence_zone : PlantInfluenceZone
var harvest_effects = []
var mature_effects = []
var cyclic_effects = []
var plant_score = 0
var plant_mutations : Array[PlantMutation] = []
@@ -44,9 +37,6 @@ func _init(
_day = 0,
):
plant_type = _plant_type
harvest_effects = plant_type.default_harvest_effects.duplicate_deep()
mature_effects = plant_type.default_mature_effects.duplicate_deep()
cyclic_effects = plant_type.default_cyclic_effects.duplicate_deep()
day = _day
@@ -96,8 +86,8 @@ func generate_influence_zone() -> PlantInfluenceZone:
func _pass_day():
await get_tree().create_timer(randf_range(0., RANDOM_MAX_GROW_INTERVAL)).timeout
if state == State.MATURE and len(cyclic_effects):
for effect in cyclic_effects:
if state == State.MATURE and len(plant_type.cyclic_effects):
for effect in plant_type.cyclic_effects:
effect.effect(self)
var old_state = state
@@ -106,9 +96,9 @@ func _pass_day():
update_plant()
if old_state != state and state == State.MATURE:
for effect in mature_effects:
for effect in plant_type.mature_effects:
if effect : effect.effect(self)
for effect in cyclic_effects:
for effect in plant_type.cyclic_effects:
if effect : effect.effect(self)
func update_plant(with_animation : bool = true):
@@ -137,7 +127,7 @@ func calculate_grow_time() -> int:
for m in plant_mutations:
mutated_grow_time = m.mutate_grow_time(self, mutated_grow_time)
return mutated_grow_time
return max(1, mutated_grow_time)
func change_state(_state: State, with_animation : bool = true):
if state != _state:
@@ -148,7 +138,7 @@ func change_state(_state: State, with_animation : bool = true):
func harvest():
if state == State.MATURE:
for effect in harvest_effects:
for effect in plant_type.harvest_effects:
if effect : effect.effect(self)
plant_sprite.start_harvest_animation()
@@ -203,39 +193,10 @@ func card_info() -> CardInfo:
for m in plant_mutations:
info.sections.append(m.card_section())
info.sections.append_array(card_effect_sections())
info.sections.append_array(PlantEffect.card_effect_sections(
plant_type.mature_effects,
plant_type.harvest_effects,
plant_type.cyclic_effects,
))
return info
func card_effect_sections() -> Array[CardSectionInfo]:
var sections : Array[CardSectionInfo] = []
var effects_category = [
mature_effects,
harvest_effects,
cyclic_effects
]
var effects_category_labels : Array[String] = [
"On mature",
"When harvested",
"Each day when mature",
]
var effects_category_icon : Array[Texture] = [
MATURE_EFFECT_ICON,
HARVEST_EFFECT_ICON,
CYCLIC_EFFECT_ICON,
]
for i in range(len(effects_category)):
var effects = effects_category[i]
if len(effects):
var section = CardSectionInfo.new(
effects_category_labels[i]
)
section.title_icon = effects_category_icon[i]
var effects_text : Array = effects.map(
func (e : PlantEffect): return "[b]%s[/b] %s" % [e.get_styled_effect_name() , e.get_effect_description()]
)
section.text = "\n".join(effects_text)
sections.append(section)
return sections
return info