ajout des mutation et refonte de l'inspecteur

* ajout des mutations #86
* changement de l'objectif #85
* refonte de l'inspecteur #71
* changement léger de la plantation
* les plantes ne donnent que des graines de leurs espèces
* refonte partielle du code, refacto
This commit is contained in:
2025-10-12 01:03:08 +02:00
parent bb24efe46b
commit ef392595de
108 changed files with 1921 additions and 477 deletions

View File

@@ -1,10 +1,15 @@
extends InspectableEntity
class_name Plant
const PLANT_AREA_WIDTH = 20
const PLANT_AREA_RADIUS = 20
const PLANT_INFLUENCE_RADIUS = 100
const HARVESTED_SEED_DISPLACEMENT_FACTOR = 100
const RANDOM_MAX_GROW_INTERVAL = Planet.PASS_DAY_ANIMATION_TIME/2. - 0.1
const PLANT_POINT_ICON = preload("res://common/icons/growth.svg")
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 SPRITE_SCENE : PackedScene = preload("res://entities/plants/plant_sprite.tscn")
@@ -18,82 +23,167 @@ var state: State = State.PLANTED: set = change_state
@onready var plant_sprite: PlantSprite = generate_sprite()
@onready var collision_shape: CollisionShape2D = generate_collision_shape()
@onready var influence_zone : PlantInfluenceZone = generate_influence_zone()
func _init(_plant_type = null, _planet = null):
var harvest_effects = []
var mature_effects = []
var cyclic_effects = []
var plant_score = 0
var plant_mutations : Array[PlantMutation] = []
func _init(
_plant_type : PlantType,
_planet : Planet,
_plant_mutations : Array[PlantMutation] = []
):
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()
planet = _planet
plant_mutations = _plant_mutations
func pointer_text():
var state_text = "Growing"
if state == State.MATURE: state_text = "Mature"
return state_text + " " + plant_type.name
func inspect(is_inspected : bool = true):
modulate = MODULATE_INSPECTED_COLOR if is_inspected else default_modulate
influence_zone.show_influence = is_inspected
func inspector_info() -> Inspector.Info:
return Inspector.Info.new(
var info = Inspector.Info.new(
pointer_text(),
plant_type.description,
"",
plant_type.mature_texture
)
for m in plant_mutations:
info.framed_infos.append(
PlantMutation.get_framed_info_from_mutation(m)
)
info.framed_infos.append_array(
PlantEffect.get_framed_info_from_all_trigger_effects(
mature_effects, harvest_effects, cyclic_effects
)
)
info.stat_infos.append(
Inspector.StatInfo.new(
"Day [b]%d[/b]" % day,
LIFETIME_ICON
)
)
if state != State.MATURE:
info.stat_infos.append_array([
Inspector.StatInfo.new(
"Mature on day [b]%d[/b]" % calculate_grow_time(),
GROWING_ICON,
),
Inspector.StatInfo.new(
"[b]%d[/b]" % [
calculate_plant_score()
],
PLANT_POINT_ICON
),
])
else:
info.stat_infos.append(
Inspector.StatInfo.new(
"[b]%d[/b] point%s" % [
calculate_plant_score(),
"s" if calculate_plant_score() > 0 else ""
],
PLANT_POINT_ICON
),
)
return info
func generate_sprite() -> PlantSprite:
var spriteObject : PlantSprite = SPRITE_SCENE.instantiate()
var sprite_object : PlantSprite = SPRITE_SCENE.instantiate()
add_child(spriteObject)
spriteObject.update_plant_sprite(self)
add_child(sprite_object)
sprite_object.update_plant_sprite(self)
sprite_object.generate_mutation_effects(self)
return spriteObject
return sprite_object
func generate_collision_shape() -> CollisionShape2D:
var collision = CollisionShape2D.new()
var shape = CircleShape2D.new()
shape.radius = PLANT_AREA_WIDTH
shape.radius = PLANT_AREA_RADIUS
collision.shape = shape
add_child(collision)
return collision
func generate_influence_zone() -> PlantInfluenceZone:
var zone = PlantInfluenceZone.new(PLANT_INFLUENCE_RADIUS)
add_child(zone)
return zone
# Méthode déclenchée par la classe planet
func _pass_day():
await get_tree().create_timer(randf_range(0., RANDOM_MAX_GROW_INTERVAL)).timeout
if state == State.MATURE and plant_type.cyclic_effect:
plant_type.cyclic_effect.effect(self)
if state == State.MATURE and len(cyclic_effects):
for effect in cyclic_effects:
effect.effect(self)
day += 1
func set_day(d):
day = d
if day == 0:
change_state(State.PLANTED)
if day > plant_type.growing_time:
if day + 1 > calculate_grow_time():
if state != State.MATURE:
change_state(State.MATURE)
elif day == 0:
change_state(State.PLANTED)
else:
if state != State.GROWING:
change_state(State.GROWING)
func calculate_plant_score() -> int:
var mutated_plant_score = plant_type.default_plant_score if state == State.MATURE else 0
for m in plant_mutations:
mutated_plant_score = m.mutate_score(self, mutated_plant_score)
return mutated_plant_score
func calculate_grow_time() -> int:
var mutated_grow_time = plant_type.default_growing_time
for m in plant_mutations:
mutated_grow_time = m.mutate_grow_time(self, mutated_grow_time)
return mutated_grow_time
func change_state(_state: State):
state = _state
if state == State.MATURE and plant_type.mature_effect:
plant_type.mature_effect.effect(self)
if state == State.MATURE and len(mature_effects):
for effect in mature_effects:
if effect : effect.effect(self)
for effect in cyclic_effects:
if effect : effect.effect(self)
plant_sprite.update_plant_sprite(self, true)
func harvest():
if state == State.MATURE:
var seed_number = plant_type.harvest_number.pick_random()
for i in range(seed_number):
var seed_plant_type : PlantType = plant_type
if len(plant_type.harvest_types_path):
seed_plant_type = load(plant_type.harvest_types_path.pick_random())
planet.drop_item(
Seed.new(seed_plant_type),
global_position,
HARVESTED_SEED_DISPLACEMENT_FACTOR,
)
for effect in harvest_effects:
if effect : effect.effect(self)
plant_sprite.start_harvest_animation()
await plant_sprite.harvest_animation_finished
queue_free()