gros dev pre proto

* Changement de l'UI, ajouts de l'inspecteur par carte et changement de police
* Ajout d'un semblant d'exploration
* Ajout de la sauvegarde des entités
* Restructuration mineure de l'arborescence
* Fix divers et réécriture des textes
This commit is contained in:
2025-10-31 13:52:45 +01:00
parent ceae7af589
commit ed7a8bcb6e
167 changed files with 2665 additions and 1201 deletions

View File

@@ -121,6 +121,7 @@ scale = Vector2(0.426047, 0.430108)
texture = ExtResource("4_j6jm5")
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
unique_name_in_owner = true
libraries = {
&"": SubResource("AnimationLibrary_8eofq")
}

View File

@@ -9,7 +9,7 @@
[sub_resource type="Resource" id="Resource_cf34j"]
script = ExtResource("1_cf34j")
level = 1
level = 2
metadata/_custom_type_script = "uid://ceqx5va1ormau"
[sub_resource type="AtlasTexture" id="AtlasTexture_my6by"]

View File

@@ -1,28 +1,36 @@
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.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 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}
@export var plant_type: PlantType
var state: State = State.PLANTED: set = change_state
@export var day: int = 0 : set = set_day
var state: State = State.PLANTED
@export var day: int
@onready var plant_sprite: PlantSprite = generate_sprite()
@onready var collision_shape: CollisionShape2D = generate_collision_shape()
@onready var influence_zone : PlantInfluenceZone = generate_influence_zone()
@onready var plant_sprite: PlantSprite
@onready var collision_shape: CollisionShape2D
@onready var influence_zone : PlantInfluenceZone
var harvest_effects = []
var mature_effects = []
@@ -32,83 +40,37 @@ var plant_mutations : Array[PlantMutation] = []
func _init(
_plant_type : PlantType,
_planet : Planet,
_plant_mutations : Array[PlantMutation] = []
_plant_mutations : Array[PlantMutation] = [],
_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()
planet = _planet
day = _day
plant_mutations = _plant_mutations
func _ready():
plant_sprite = generate_sprite()
collision_shape = generate_collision_shape()
influence_zone = generate_influence_zone()
update_plant(false)
plant_sprite.update_plant_sprite(self, false)
func pointer_text() -> String:
var state_text = "Growing"
if state == State.MATURE: state_text = "Mature"
return state_text + " " + plant_type.name
return 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:
var info = Inspector.Info.new(
pointer_text(),
"",
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 sprite_object : PlantSprite = SPRITE_SCENE.instantiate()
add_child(sprite_object)
sprite_object.update_plant_sprite(self)
sprite_object.generate_mutation_effects(self)
return sprite_object
@@ -138,24 +100,34 @@ func _pass_day():
for effect in cyclic_effects:
effect.effect(self)
day += 1
var old_state = state
func set_day(d):
day = d
day += 1
update_plant()
if old_state != state and state == State.MATURE:
for effect in mature_effects:
if effect : effect.effect(self)
for effect in cyclic_effects:
if effect : effect.effect(self)
func update_plant(with_animation : bool = true):
if day + 1 > calculate_grow_time():
if state != State.MATURE:
change_state(State.MATURE)
change_state(State.MATURE, with_animation)
elif day == 0:
change_state(State.PLANTED)
change_state(State.PLANTED, with_animation)
else:
if state != State.GROWING:
change_state(State.GROWING)
change_state(State.GROWING, with_animation)
func calculate_plant_score() -> int:
var mutated_plant_score = plant_type.default_plant_score if state == State.MATURE else 0
func calculate_plant_score(
overwite_state : State = 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(self, mutated_plant_score)
mutated_plant_score = m.mutate_score(overwite_state, self, mutated_plant_score)
return mutated_plant_score
@@ -167,16 +139,12 @@ func calculate_grow_time() -> int:
return mutated_grow_time
func change_state(_state: State):
state = _state
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 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)
func harvest():
if state == State.MATURE:
@@ -185,4 +153,89 @@ func harvest():
plant_sprite.start_harvest_animation()
await plant_sprite.harvest_animation_finished
harvested.emit(self)
queue_free()
func save() -> EntityData:
return PlantData.new(self)
func card_info() -> CardInfo:
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_text = "Mature"
if state != State.MATURE:
state_text = "Growing"
info.stats.append(CardStatInfo.new(
"Day [b]%d[/b]" % day,
LIFETIME_ICON
))
info.stats.append(CardStatInfo.new(
state_text,
PLANT_TYPE_ICON
))
if state != State.MATURE:
info.stats.append(CardStatInfo.new(
"Mature on day [b]%d[/b]" % calculate_grow_time(),
GROWING_ICON
))
info.stats.append(CardStatInfo.new(
"[b]%d[/b] score when mature" % calculate_plant_score(State.MATURE),
PLANT_POINT_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())
info.sections.append_array(card_effect_sections())
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

View File

@@ -0,0 +1,20 @@
extends EntityData
class_name PlantData
var plant_type : PlantType
var plant_mutations : Array[PlantMutation]
var day : int
func _init(plant : Plant):
position = plant.global_position
plant_type = plant.plant_type
plant_mutations = plant.plant_mutations
day = plant.day
func load() -> Entity:
var plant = Plant.new(
plant_type,
plant_mutations,
day
)
return plant

View File

@@ -0,0 +1 @@
uid://da6j333qs7wse

View File

@@ -2,10 +2,6 @@
extends Resource
class_name PlantEffect
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")
@export var level : int
func _init(_level : int = 1):
@@ -22,67 +18,17 @@ func get_effect_description() -> String:
func effect(plant):
printerr("Classe abstraite PlantEffect appelée")
static func get_framed_info_from_effects(
effects : Array[PlantEffect],
trigger_text = "",
trigger_icon: Texture = null
) -> Array[Inspector.FramedInfo]:
if len(effects) == 0 : return []
var desc = "%s %s" % [PlantEffect.get_framed_info_effect_name(effects[0]), effects[0].get_effect_description()]
for i in range(1, len(effects)):
if effects[i]:
desc += "\n%s %s" % [PlantEffect.get_framed_info_effect_name(effects[i]), effects[i].get_effect_description()]
return [Inspector.FramedInfo.new(
trigger_text,
desc,
trigger_icon
)]
static func get_framed_info_effect_name(e : PlantEffect):
func get_styled_effect_name():
var levels_bbcode = [
"[color=#ffffff][b]%s[/b][/color]",
"[color=#FFBE0B][b]%s %d[/b][/color]",
"[color=#FB5607][b]%s %d[/b][/color]",
"[color=#3A86FF][b]%s %d[/b][/color]",
"[color=#8338EC][b]%s %d[/b][/color]",
"[color=#FF006E][b]%s %d[/b][/color]",
"[rainbow][b]%s %d[/b][/rainbow]"
"[color=#2364AA]%s[/color]",
"[color=#25C147]%s %d[/color]",
"[color=#8B2DFF]%s %d[/color]",
"[color=#FF006E]%s %d[/color]",
"[color=#FFA617]%s %d[/color]",
"[rainbow]%s %d[/rainbow]"
]
if e.level == 1:
return levels_bbcode[0] % e.get_effect_name()
if level == 1:
return levels_bbcode[0] % get_effect_name()
else :
return levels_bbcode[min(e.level - 1, len(levels_bbcode) - 1)] % [e.get_effect_name(), e.level]
static func get_framed_info_from_all_trigger_effects(
mature_effects : Array[PlantEffect],
harvest_effects : Array[PlantEffect],
cyclic_effects : Array[PlantEffect],
) -> Array[Inspector.FramedInfo] :
var framed_infos : Array[Inspector.FramedInfo] = []
framed_infos.append_array(
PlantEffect.get_framed_info_from_effects(
mature_effects,
"On maturation",
MATURE_EFFECT_ICON
)
)
framed_infos.append_array(
PlantEffect.get_framed_info_from_effects(
harvest_effects,
"When harvested",
HARVEST_EFFECT_ICON
)
)
framed_infos.append_array(
PlantEffect.get_framed_info_from_effects(
cyclic_effects,
"Each days",
CYCLIC_EFFECT_ICON
)
)
return framed_infos
return levels_bbcode[min(level - 1, len(levels_bbcode) - 1)] % [get_effect_name(), level]

View File

@@ -14,7 +14,7 @@ func get_effect_description() -> String:
func effect(plant):
var radius = get_decontamination_radius()
plant.planet.impact_contamination(
plant.planet.garden.impact_contamination(
plant.global_position,
radius
)

View File

@@ -2,11 +2,10 @@ extends Resource
class_name PlantMutation
const BASE_RARITY_CHANCE : Array[float] = [
0.6,
0.8,
0.75,
0.9,
0.95,
1
1,
1,
]
@export var level : int = 1
@@ -28,7 +27,7 @@ func get_mutation_description() -> String:
printerr("Classe abstraite PlantMutation appelée")
return ""
func mutate_score(_plant : Plant, score) -> int:
func mutate_score(_plant_state : Plant.State, _plant : Plant, score,) -> int:
return score
func mutate_grow_time(_plant : Plant, grow_time : int) -> int:
@@ -40,56 +39,44 @@ func mutate_plant(_plant : Plant):
func get_level_for_rarity(rarity : int) -> int :
return rarity - get_base_rarity() + 1
static func get_rarity(mutation : PlantMutation) -> int:
return mutation.get_base_rarity() + mutation.level - 1
func get_rarity() -> int:
return get_base_rarity() + level - 1
static func get_rarity_text(mutation : PlantMutation) -> String:
func card_section() -> CardSectionInfo:
var section = CardSectionInfo.new(
get_mutation_name() + (" %d" % level if level > 1 else ""),
"[b]%s[/b] %s" % [PlantMutation.get_rarity_text(get_rarity()), get_mutation_description()]
)
section.title_color = PlantMutation.get_rarity_color(get_rarity())
section.title_colored = true
section.title_icon = get_icon()
return section
static func get_rarity_text(rarity) -> String:
var rarity_text : Array[String] = [
"Common",
"Rare",
"Very rare",
"Impossible",
"Absurd",
"[rainbow]Absurd[/rainbow]",
]
var rarity = PlantMutation.get_rarity(mutation)
if rarity < len(rarity_text):
return rarity_text[rarity]
else :
return rarity_text[len(rarity_text) - 1] + " " + str(rarity - len(rarity_text) + 2)
static func get_rarity_bg_color(mutation : PlantMutation) -> Color:
static func get_rarity_color(rarity : int) -> Color:
var rarity_colors : Array[Color] = [
Color("4b3700"),
Color("6d2300"),
Color("001f50"),
Color("311558"),
Color("780235"),
]
return rarity_colors[min(PlantMutation.get_rarity(mutation), len(rarity_colors) - 1)]
static func get_rarity_color(mutation : PlantMutation) -> Color:
var rarity_colors : Array[Color] = [
Color("FFBE0B"),
Color("FB5607"),
Color("3A86FF"),
Color("8338EC"),
Color("25C147"),
Color("8B2DFF"),
Color("FF006E"),
Color("FFA617"),
]
return rarity_colors[min(PlantMutation.get_rarity(mutation), len(rarity_colors) - 1)]
static func get_framed_info_from_mutation(
mutation : PlantMutation
) -> Inspector.FramedInfo:
return Inspector.FramedInfo.new(
mutation.get_mutation_name() + (" %d" % mutation.level if mutation.level > 1 else ""),
"[b]%s[/b] %s" % [PlantMutation.get_rarity_text(mutation), mutation.get_mutation_description()],
mutation.get_icon(),
PlantMutation.get_rarity_bg_color(mutation)
)
return rarity_colors[min(rarity, len(rarity_colors) - 1)]
static func random_rarity() -> int:
var random_float = randf()

View File

@@ -18,7 +18,7 @@ func get_mutation_description() -> String:
func get_day_factor():
return max(1, DEFAULT_DAY_FACTOR - level + 1)
func mutate_score(plant : Plant, score) -> int:
if plant.state != Plant.State.MATURE:
func mutate_score(plant_state : Plant.State, plant : Plant, score) -> int:
if plant_state != Plant.State.MATURE:
return score
return score + floori(plant.day / get_day_factor())

View File

@@ -13,8 +13,10 @@ func get_mutation_name() -> String:
func get_mutation_description() -> String:
return "When mature, add [b]%d[/b] to the score for each plant of the same species around, but score become 0 if none is around." % level
func mutate_score(plant : Plant, score) -> int:
if plant.state != Plant.State.MATURE:
func mutate_score(plant_state : Plant.State, plant : Plant, score) -> int:
if plant.influence_zone == null:
return score
if plant_state != Plant.State.MATURE:
return score
var plant_count = 0

View File

@@ -2,23 +2,25 @@ extends PlantMutation
class_name ErmitMutation
func get_icon() -> Texture:
return preload("res://common/icons/seedling-off.svg")
return preload("res://common/icons/seedling-off.svg")
func get_base_rarity() -> int:
return 0
return 0
func get_mutation_name() -> String:
return "Ermit"
return "Ermit"
func get_mutation_description() -> String:
return "Multiply the score by [b]%d[/b] if no plant is near, but set it to 0 otherwise." % get_score_multiplier()
return "Multiply the score by [b]%d[/b] if no plant is near, but set it to 0 otherwise." % get_score_multiplier()
func get_score_multiplier():
return level + 1
return level + 1
func mutate_score(plant : Plant, score) -> int:
for area in plant.influence_zone.get_overlapping_areas():
if area is Plant and area != plant:
return 0
func mutate_score(_plant_state : Plant.State, plant : Plant, score) -> int:
if plant.influence_zone == null:
return score
for area in plant.influence_zone.get_overlapping_areas():
if area is Plant and area != plant:
return 0
return score * get_score_multiplier()
return score * get_score_multiplier()

View File

@@ -13,5 +13,5 @@ func get_mutation_name() -> String:
func get_mutation_description() -> String:
return "Add [b]%d[/b] to the score while the plant is growing" % level
func mutate_score(plant : Plant, score) -> int:
return score + (0 if plant.state == Plant.State.MATURE else level)
func mutate_score(plant_state : Plant.State, _plant : Plant, score) -> int:
return score + (0 if plant_state == Plant.State.MATURE else level)

View File

@@ -13,5 +13,5 @@ func get_mutation_name() -> String:
func get_mutation_description() -> String:
return "Add [b]%d[/b] to the score if the plant is mature." % level
func mutate_score(plant : Plant, score : int) -> int:
return score + (level if plant.state == Plant.State.MATURE else 0)
func mutate_score(plant_state : Plant.State, _plant : Plant, score : int) -> int:
return score + (level if plant_state == Plant.State.MATURE else 0)

View File

@@ -18,8 +18,10 @@ func get_mutation_description() -> String:
func get_score_bonus():
return (level + 2)
func mutate_score(plant : Plant, score) -> int:
if plant.state != Plant.State.MATURE:
func mutate_score(plant_state : Plant.State, plant : Plant, score) -> int:
if plant.influence_zone == null:
return score
if plant_state != Plant.State.MATURE:
return score
var plant_count = 0

View File

@@ -16,5 +16,5 @@ func get_mutation_description() -> String:
func get_score_multiplier():
return float(level)/2.
func mutate_score(_plant : Plant, score: int) -> int:
func mutate_score(_plant_state : Plant.State, _plant : Plant, score: int) -> int:
return score + roundi(score * get_score_multiplier())

View File

@@ -10,8 +10,8 @@ signal harvest_animation_finished
func update_plant_sprite(plant : Plant, with_animation = false):
if with_animation:
$AnimationPlayer.play("bump")
await $AnimationPlayer.animation_finished
%AnimationPlayer.play("bump")
await %AnimationPlayer.animation_finished
%Sprite.flip_h = true if randi()%2 == 0 else false
@@ -43,7 +43,7 @@ func generate_mutation_effects(plant : Plant):
particles_emitter.setup_particles(
Particles.Parameters.new(
m.get_icon(),
PlantMutation.get_rarity_color(m)
PlantMutation.get_rarity_color(m.get_rarity())
)
)
add_child(particles_emitter)