changement du scene manager, amélioration du cockpit et autres
* refonte du scene manager * refonte du audio manager * premier rework des plantes * nettoyage des dossiers/fichiers * renommage de planète en region * fix des run
This commit is contained in:
@@ -1,205 +1,184 @@
|
||||
extends InspectableEntity
|
||||
class_name Plant
|
||||
|
||||
signal harvested(p: Plant)
|
||||
signal state_changed(p: Plant)
|
||||
|
||||
const PLANT_AREA_RADIUS = 20
|
||||
const PLANT_INFLUENCE_RADIUS = 100
|
||||
const HARVESTED_SEED_DISPLACEMENT_FACTOR = 100
|
||||
|
||||
const RANDOM_MAX_GROW_INTERVAL = Planet.MIN_PASS_DAY_ANIMATION_TIME/2. - 0.1
|
||||
const RANDOM_MAX_GROW_INTERVAL = Region.MIN_PASS_DAY_ANIMATION_TIME/2. - 0.1
|
||||
const PLANT_TYPE_ICON = preload("res://common/icons/seedling.svg")
|
||||
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 DEATH_ICON = preload("res://common/icons/skull.svg")
|
||||
|
||||
const SPRITE_SCENE : PackedScene = preload("res://entities/plants/plant_sprite.tscn")
|
||||
|
||||
enum State {PLANTED, GROWING, MATURE}
|
||||
|
||||
@export var plant_type: PlantType
|
||||
|
||||
var state: State = State.PLANTED
|
||||
@export var day: int
|
||||
@export var data : PlantData
|
||||
|
||||
@onready var plant_sprite: PlantSprite
|
||||
@onready var collision_shape: CollisionShape2D
|
||||
@onready var influence_zone : PlantInfluenceZone
|
||||
|
||||
var plant_score = 0
|
||||
var plant_mutations : Array[PlantMutation] = []
|
||||
|
||||
func _init(
|
||||
_plant_type : PlantType,
|
||||
_plant_mutations : Array[PlantMutation] = [],
|
||||
_day = 0,
|
||||
_data : PlantData
|
||||
):
|
||||
plant_type = _plant_type
|
||||
|
||||
day = _day
|
||||
|
||||
plant_mutations = _plant_mutations
|
||||
data = _data
|
||||
|
||||
func _ready():
|
||||
plant_sprite = generate_sprite()
|
||||
collision_shape = generate_collision_shape()
|
||||
influence_zone = generate_influence_zone()
|
||||
plant_sprite = generate_sprite()
|
||||
collision_shape = generate_collision_shape()
|
||||
influence_zone = generate_influence_zone()
|
||||
|
||||
update_plant(false)
|
||||
plant_sprite.update_plant_sprite(self, false)
|
||||
plant_sprite.update_plant_sprite(data, false)
|
||||
|
||||
func pointer_text() -> String:
|
||||
return plant_type.name
|
||||
return data.plant_name
|
||||
|
||||
func inspect(is_inspected : bool = true):
|
||||
plant_sprite.modulate = MODULATE_INSPECTED_COLOR if is_inspected else default_modulate
|
||||
influence_zone.show_influence = is_inspected
|
||||
plant_sprite.modulate = MODULATE_INSPECTED_COLOR if is_inspected else default_modulate
|
||||
influence_zone.show_influence = is_inspected
|
||||
|
||||
func affect_preview(is_affected : bool = true):
|
||||
plant_sprite.modulate = MODULATE_AFFECTED_COLOR if is_affected else default_modulate
|
||||
plant_sprite.modulate = MODULATE_AFFECTED_COLOR if is_affected else default_modulate
|
||||
|
||||
func generate_sprite() -> PlantSprite:
|
||||
var sprite_object : PlantSprite = SPRITE_SCENE.instantiate()
|
||||
var sprite_object : PlantSprite = SPRITE_SCENE.instantiate()
|
||||
|
||||
add_child(sprite_object)
|
||||
sprite_object.generate_mutation_effects(self)
|
||||
add_child(sprite_object)
|
||||
sprite_object.generate_mutation_effects(self)
|
||||
|
||||
return sprite_object
|
||||
return sprite_object
|
||||
|
||||
func generate_collision_shape() -> CollisionShape2D:
|
||||
var collision = CollisionShape2D.new()
|
||||
var shape = CircleShape2D.new()
|
||||
shape.radius = PLANT_AREA_RADIUS
|
||||
var collision = CollisionShape2D.new()
|
||||
var shape = CircleShape2D.new()
|
||||
shape.radius = PLANT_AREA_RADIUS
|
||||
|
||||
collision.shape = shape
|
||||
add_child(collision)
|
||||
collision.shape = shape
|
||||
add_child(collision)
|
||||
|
||||
return collision
|
||||
return collision
|
||||
|
||||
func generate_influence_zone() -> PlantInfluenceZone:
|
||||
var zone = PlantInfluenceZone.new(PLANT_INFLUENCE_RADIUS)
|
||||
var zone = PlantInfluenceZone.new(PLANT_INFLUENCE_RADIUS)
|
||||
|
||||
add_child(zone)
|
||||
add_child(zone)
|
||||
|
||||
return zone
|
||||
return zone
|
||||
|
||||
# Méthode déclenchée par la classe planet
|
||||
# Méthode déclenchée par la classe region
|
||||
func _pass_day():
|
||||
await get_tree().create_timer(randf_range(0., RANDOM_MAX_GROW_INTERVAL)).timeout
|
||||
|
||||
if state == State.MATURE and len(plant_type.cyclic_effects):
|
||||
for effect in plant_type.cyclic_effects:
|
||||
effect.effect(self)
|
||||
|
||||
var old_state = state
|
||||
await get_tree().create_timer(randf_range(0., RANDOM_MAX_GROW_INTERVAL)).timeout
|
||||
|
||||
var last_state = data.get_state()
|
||||
|
||||
day += 1
|
||||
update_plant()
|
||||
data.day += 1
|
||||
|
||||
for m in data.mutations:
|
||||
m._start_day_effect(self)
|
||||
|
||||
if old_state != state and state == State.MATURE:
|
||||
for effect in plant_type.mature_effects:
|
||||
if effect : effect.effect(self)
|
||||
for effect in plant_type.cyclic_effects:
|
||||
if effect : effect.effect(self)
|
||||
match data.get_state():
|
||||
PlantData.State.MATURE:
|
||||
if last_state != PlantData.State.MATURE:
|
||||
mature()
|
||||
PlantData.State.DEAD:
|
||||
die()
|
||||
|
||||
|
||||
plant_sprite.update_plant_sprite(data, last_state != data.get_state())
|
||||
|
||||
func update_plant(with_animation : bool = true):
|
||||
if day + 1 > calculate_grow_time():
|
||||
if state != State.MATURE:
|
||||
change_state(State.MATURE, with_animation)
|
||||
elif day == 0:
|
||||
change_state(State.PLANTED, with_animation)
|
||||
else:
|
||||
if state != State.GROWING:
|
||||
change_state(State.GROWING, with_animation)
|
||||
|
||||
func calculate_plant_score(
|
||||
overwite_state : State = state
|
||||
with_state : PlantData.State = data.get_state()
|
||||
) -> int:
|
||||
var mutated_plant_score = plant_type.default_plant_score if overwite_state == State.MATURE else 0
|
||||
|
||||
for m in plant_mutations:
|
||||
mutated_plant_score = m.mutate_score(overwite_state, 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 max(1, mutated_grow_time)
|
||||
|
||||
func change_state(_state: State, with_animation : bool = true):
|
||||
if state != _state:
|
||||
state = _state
|
||||
|
||||
plant_sprite.update_plant_sprite(self, with_animation)
|
||||
state_changed.emit(self)
|
||||
return data.get_score(with_state)
|
||||
|
||||
func harvest():
|
||||
if state == State.MATURE:
|
||||
for effect in plant_type.harvest_effects:
|
||||
if effect : effect.effect(self)
|
||||
for i in range(data.get_random_seed_income()):
|
||||
produce_seed()
|
||||
|
||||
plant_sprite.start_harvest_animation()
|
||||
await plant_sprite.harvest_animation_finished
|
||||
harvested.emit(self)
|
||||
queue_free()
|
||||
if data.get_state() == PlantData.State.MATURE:
|
||||
for m in data.mutations:
|
||||
m._start_harvested_effect(self)
|
||||
|
||||
plant_sprite.start_harvest_animation()
|
||||
await plant_sprite.harvest_animation_finished
|
||||
disappear()
|
||||
|
||||
func produce_seed():
|
||||
region.drop_item(
|
||||
Seed.generate_from_parent(data),
|
||||
global_position,
|
||||
HARVESTED_SEED_DISPLACEMENT_FACTOR,
|
||||
)
|
||||
|
||||
func mature():
|
||||
for m in data.mutations:
|
||||
m._start_maturation_effect(self)
|
||||
|
||||
func die():
|
||||
for m in data.mutations:
|
||||
m._start_dead_effect(self)
|
||||
disappear()
|
||||
|
||||
func disappear():
|
||||
data.disappear()
|
||||
queue_free()
|
||||
|
||||
func save() -> EntityData:
|
||||
return PlantData.new(self)
|
||||
return data
|
||||
|
||||
func card_info() -> CardInfo:
|
||||
var info = CardInfo.new(
|
||||
pointer_text()
|
||||
)
|
||||
var info = CardInfo.new(
|
||||
pointer_text()
|
||||
)
|
||||
|
||||
info.important_stat_icon = PLANT_POINT_ICON
|
||||
info.important_stat_text = "%d" % calculate_plant_score()
|
||||
info.texture = plant_type.mature_texture
|
||||
info.type_icon = PLANT_TYPE_ICON
|
||||
var state = data.get_state()
|
||||
|
||||
var state_text = tr("MATURE")
|
||||
if state != State.MATURE:
|
||||
state_text = tr("GROWING")
|
||||
info.important_stat_icon = PLANT_POINT_ICON
|
||||
info.important_stat_text = "%d" % calculate_plant_score()
|
||||
info.texture = null #TODO
|
||||
info.type_icon = PLANT_TYPE_ICON
|
||||
|
||||
info.stats.append(CardStatInfo.new(
|
||||
tr("DAY_%d") % day,
|
||||
LIFETIME_ICON
|
||||
))
|
||||
var state_text = tr("MATURE")
|
||||
if state != PlantData.State.MATURE:
|
||||
state_text = tr("GROWING")
|
||||
|
||||
info.stats.append(CardStatInfo.new(
|
||||
state_text,
|
||||
PLANT_TYPE_ICON
|
||||
))
|
||||
info.stats.append(CardStatInfo.new(
|
||||
tr("DAY_%d") % data.day,
|
||||
LIFETIME_ICON
|
||||
))
|
||||
|
||||
if state != State.MATURE:
|
||||
info.stats.append(CardStatInfo.new(
|
||||
tr("MATURE_ON_DAY_%d") % calculate_grow_time(),
|
||||
GROWING_ICON
|
||||
))
|
||||
info.stats.append(CardStatInfo.new(
|
||||
state_text,
|
||||
PLANT_TYPE_ICON
|
||||
))
|
||||
|
||||
info.stats.append(CardStatInfo.new(
|
||||
tr("%d_SCORE_WHEN_MATURE") % calculate_plant_score(State.MATURE),
|
||||
PLANT_POINT_ICON
|
||||
))
|
||||
if state != PlantData.State.MATURE:
|
||||
info.stats.append(CardStatInfo.new(
|
||||
tr("MATURE_ON_DAY_%d") % data.get_growing_time(),
|
||||
GROWING_ICON
|
||||
))
|
||||
|
||||
info.stats.append(CardStatInfo.new(
|
||||
tr("%d_SCORE_WHEN_MATURE") % data.get_score(PlantData.State.MATURE),
|
||||
PLANT_POINT_ICON
|
||||
))
|
||||
|
||||
info.stats.append(CardStatInfo.new(
|
||||
tr("DIE_ON_DAY_%d") % (data.get_lifetime()),
|
||||
DEATH_ICON
|
||||
))
|
||||
|
||||
|
||||
if len(plant_mutations) != 0:
|
||||
var rarest : int = plant_mutations.map(
|
||||
func(m : PlantMutation) : return m.get_rarity()
|
||||
).max()
|
||||
info.bg_color = PlantMutation.get_rarity_color(rarest)
|
||||
for m in plant_mutations:
|
||||
info.sections.append(m.card_section())
|
||||
if len(data.mutations) != 0:
|
||||
var rarest : int = data.mutations.map(
|
||||
func(m : PlantMutation) : return m.get_rarity()
|
||||
).max()
|
||||
info.bg_color = PlantMutation.get_rarity_color(rarest)
|
||||
for m in data.mutations:
|
||||
info.sections.append(m.card_section())
|
||||
|
||||
info.sections.append_array(PlantEffect.card_effect_sections(
|
||||
plant_type.mature_effects,
|
||||
plant_type.harvest_effects,
|
||||
plant_type.cyclic_effects,
|
||||
))
|
||||
|
||||
return info
|
||||
return info
|
||||
|
||||
Reference in New Issue
Block a user