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
|
||||
|
||||
19
entities/plants/scripts/plant_archetype.gd
Normal file
19
entities/plants/scripts/plant_archetype.gd
Normal file
@@ -0,0 +1,19 @@
|
||||
@tool
|
||||
extends Resource
|
||||
class_name PlantArchetype
|
||||
|
||||
@export var archetype_name = Random.generate_random_name()
|
||||
@export var texture_builder = TextureBuilder.new()
|
||||
@export var plant_area_radius = 20
|
||||
@export var plant_influence_radius = 100
|
||||
@export var growing_time= 2
|
||||
@export var lifetime = 5
|
||||
@export var base_score = 1
|
||||
@export var seed_number = 2
|
||||
@export var seed_random_loose = 1
|
||||
@export var available_mutations : Array[PlantMutation] = [
|
||||
AncientMutation.new(),
|
||||
PrecociousMutation.new(),
|
||||
QualityMutation.new(),
|
||||
QuickMutation.new()
|
||||
]
|
||||
1
entities/plants/scripts/plant_archetype.gd.uid
Normal file
1
entities/plants/scripts/plant_archetype.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://chdj832c0rrky
|
||||
@@ -1,20 +1,114 @@
|
||||
extends EntityData
|
||||
class_name PlantData
|
||||
|
||||
var plant_type : PlantType
|
||||
var plant_mutations : Array[PlantMutation]
|
||||
var day : int
|
||||
signal updated(p : PlantData)
|
||||
signal disappeared(p : PlantData)
|
||||
|
||||
func _init(plant : Plant):
|
||||
position = plant.global_position
|
||||
plant_type = plant.plant_type
|
||||
plant_mutations = plant.plant_mutations
|
||||
day = plant.day
|
||||
enum State {PLANTED, GROWING, MATURE, DEAD}
|
||||
|
||||
func load() -> Entity:
|
||||
var plant = Plant.new(
|
||||
plant_type,
|
||||
plant_mutations,
|
||||
day
|
||||
@export var archetype: PlantArchetype
|
||||
@export var plant_name : String
|
||||
@export var mutations : Array[PlantMutation]
|
||||
@export var day : int :
|
||||
set(v):
|
||||
day = v
|
||||
updated.emit(self)
|
||||
@export var random_seed : int
|
||||
|
||||
@export var leafs = 0 # +1 score
|
||||
@export var roots = 0 # +1 lifetime
|
||||
|
||||
func _init(
|
||||
_position : Vector2,
|
||||
_archetype : PlantArchetype,
|
||||
_plant_name : String = Random.generate_random_name(),
|
||||
_mutations : Array[PlantMutation] = [],
|
||||
_day : int = 0,
|
||||
_random_seed = randi()
|
||||
):
|
||||
position = _position
|
||||
archetype = _archetype
|
||||
plant_name = _plant_name
|
||||
mutations = _mutations
|
||||
day = _day
|
||||
random_seed = _random_seed
|
||||
|
||||
for m in mutations:
|
||||
m.mutate_plant_data(self)
|
||||
|
||||
static func generate_from_seed(plant_seed : Seed, plant_position : Vector2) -> PlantData:
|
||||
return PlantData.new(
|
||||
plant_position,
|
||||
plant_seed.plant_archetype,
|
||||
plant_seed.plant_name,
|
||||
plant_seed.plant_mutations
|
||||
)
|
||||
return plant
|
||||
|
||||
func load_entity() -> Entity:
|
||||
var plant = Plant.new(
|
||||
self
|
||||
)
|
||||
return plant
|
||||
|
||||
func get_lifetime() -> int:
|
||||
var lifetime = archetype.lifetime + roots
|
||||
|
||||
for m in mutations:
|
||||
lifetime = m.mutate_lifetime(self, lifetime)
|
||||
|
||||
return lifetime
|
||||
|
||||
func get_growing_time() -> int:
|
||||
var growing_time = archetype.growing_time
|
||||
|
||||
for m in mutations:
|
||||
growing_time = m.mutate_growing_time(self, growing_time)
|
||||
|
||||
return growing_time
|
||||
|
||||
func get_score(state : State = get_state()) -> int:
|
||||
var score = archetype.base_score + leafs if state == State.MATURE else 0
|
||||
|
||||
for m in mutations:
|
||||
score = m.mutate_score(self, score)
|
||||
|
||||
return score
|
||||
|
||||
func get_state() -> State:
|
||||
if day >= get_lifetime():
|
||||
return State.DEAD
|
||||
elif day == 0:
|
||||
return State.PLANTED
|
||||
elif day < archetype.growing_time:
|
||||
return State.GROWING
|
||||
return State.MATURE
|
||||
|
||||
func get_plant_texture() -> Texture:
|
||||
return archetype.texture_builder.build_plant_texture(self)
|
||||
|
||||
func get_seed_texture():
|
||||
return archetype.texture_builder.build_seed_texture(random_seed)
|
||||
|
||||
func get_seed_number(state = get_state()):
|
||||
var seed_number = archetype.seed_number if state == State.MATURE else 0
|
||||
|
||||
for m in mutations:
|
||||
seed_number = m.mutate_seed_number(self, seed_number)
|
||||
|
||||
return seed_number
|
||||
|
||||
func get_seed_random_loose():
|
||||
var seed_random_loose = archetype.seed_random_loose
|
||||
for m in mutations:
|
||||
seed_random_loose = m.mutate_seed_random_loose(self, seed_random_loose)
|
||||
|
||||
return seed_random_loose
|
||||
|
||||
func get_random_seed_income():
|
||||
return max(
|
||||
get_seed_number() - randi_range(0, get_seed_random_loose()),
|
||||
0
|
||||
)
|
||||
|
||||
func disappear():
|
||||
disappeared.emit(self)
|
||||
@@ -1,76 +0,0 @@
|
||||
# Classe abstraite permettant de développer divers effets de plantes
|
||||
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):
|
||||
level = _level
|
||||
|
||||
func get_effect_name() -> String:
|
||||
printerr("Classe abstraite PlantEffect appelée")
|
||||
return ""
|
||||
|
||||
func get_effect_description() -> String:
|
||||
printerr("Classe abstraite PlantEffect appelée")
|
||||
return ""
|
||||
|
||||
func effect(_plant):
|
||||
printerr("Classe abstraite PlantEffect appelée")
|
||||
|
||||
func get_styled_effect_name():
|
||||
var levels_bbcode = [
|
||||
"[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 level == 1:
|
||||
return levels_bbcode[0] % get_effect_name()
|
||||
else :
|
||||
return levels_bbcode[min(level - 1, len(levels_bbcode) - 1)] % [get_effect_name(), level]
|
||||
|
||||
static func card_effect_sections(
|
||||
mature_effects : Array[PlantEffect],
|
||||
harvest_effects : Array[PlantEffect],
|
||||
cyclic_effects : Array[PlantEffect]
|
||||
) -> 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) > 0:
|
||||
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
|
||||
@@ -1 +0,0 @@
|
||||
uid://bpycohqas4hff
|
||||
@@ -1,20 +0,0 @@
|
||||
extends PlantEffect
|
||||
class_name DecontaminateTerrainEffect
|
||||
|
||||
func get_decontamination_radius():
|
||||
return (1 + level)
|
||||
|
||||
func get_effect_name() -> String:
|
||||
return tr("DECONTAMINATE")
|
||||
|
||||
func get_effect_description() -> String:
|
||||
var ret = tr("DECONTAMINATE_%d_UNIT_AROUND_IT") % [get_decontamination_radius()]
|
||||
return ret
|
||||
|
||||
func effect(plant):
|
||||
var tiles := Math.get_tiles_in_circle(
|
||||
plant.global_position,
|
||||
get_decontamination_radius() * Planet.TILE_SIZE + Planet.TILE_SIZE/2.
|
||||
)
|
||||
|
||||
plant.planet.decontamination_layer.place_decontaminations(tiles, true)
|
||||
@@ -1 +0,0 @@
|
||||
uid://cgscbuxe4dawb
|
||||
@@ -1,29 +0,0 @@
|
||||
extends PlantEffect
|
||||
class_name ProduceSeedsEffect
|
||||
|
||||
func get_produce_number():
|
||||
return [level - 1, level]
|
||||
|
||||
func get_effect_name() -> String:
|
||||
return tr("SEED_PRODUCTION")
|
||||
|
||||
func get_effect_description() -> String:
|
||||
var number_str = ""
|
||||
|
||||
for i in range(len(get_produce_number())):
|
||||
if i != 0:
|
||||
if i == len(get_produce_number()) - 1:
|
||||
number_str += tr("OR")
|
||||
else :
|
||||
number_str += tr("COMMA")
|
||||
number_str += str(get_produce_number()[i])
|
||||
|
||||
return tr("PRODUCE_%s_SEEDS") % [number_str]
|
||||
|
||||
func effect(plant):
|
||||
for _i in range(get_produce_number().pick_random()):
|
||||
plant.planet.drop_item(
|
||||
Seed.new(plant.plant_type, plant.plant_mutations),
|
||||
plant.global_position,
|
||||
plant.HARVESTED_SEED_DISPLACEMENT_FACTOR,
|
||||
)
|
||||
@@ -1 +0,0 @@
|
||||
uid://ceqx5va1ormau
|
||||
@@ -20,13 +20,37 @@ func get_mutation_description() -> String:
|
||||
printerr("Classe abstraite PlantMutation appelée")
|
||||
return ""
|
||||
|
||||
func mutate_score(_plant_state : Plant.State, _plant : Plant, score,) -> int:
|
||||
func mutate_plant_data(_plant_data : PlantData):
|
||||
pass
|
||||
|
||||
func mutate_score(_plant_data : PlantData, score : int) -> int:
|
||||
return score
|
||||
|
||||
func mutate_grow_time(_plant : Plant, grow_time : int) -> int:
|
||||
return grow_time
|
||||
func mutate_lifetime(_plant_data : PlantData, lifetime : int) -> int:
|
||||
return lifetime
|
||||
|
||||
func mutate_plant(_plant : Plant):
|
||||
func mutate_growing_time(_plant_data : PlantData, growing_time : int) -> int:
|
||||
return growing_time
|
||||
|
||||
func mutate_seed_number(_plant_data, seed_number):
|
||||
return seed_number
|
||||
|
||||
func mutate_seed_random_loose(_plant_data, seed_random_loose):
|
||||
return seed_random_loose
|
||||
|
||||
func _start_planted_effect(_plant : Plant):
|
||||
pass
|
||||
|
||||
func _start_day_effect(_plant : Plant):
|
||||
pass
|
||||
|
||||
func _start_maturation_effect(_plant : Plant):
|
||||
pass
|
||||
|
||||
func _start_dead_effect(_plant : Plant):
|
||||
pass
|
||||
|
||||
func _start_harvested_effect(_plant : Plant):
|
||||
pass
|
||||
|
||||
func get_level_for_rarity(rarity : int) -> int :
|
||||
@@ -70,16 +94,3 @@ static func get_rarity_color(rarity : int) -> Color:
|
||||
]
|
||||
|
||||
return rarity_colors[min(rarity, len(rarity_colors) - 1)]
|
||||
|
||||
static func random_mutation(except_mutations : Array[PlantMutation] = []) -> PlantMutation:
|
||||
var all_mutations = GameInfo.game_data.unlocked_plant_mutations.duplicate_deep()
|
||||
all_mutations = all_mutations.filter(
|
||||
func (f1 : PlantMutation):
|
||||
return except_mutations.find_custom(
|
||||
func (f2 : PlantMutation): return f2.get_mutation_name() == f1.get_mutation_name()
|
||||
) == -1
|
||||
)
|
||||
if len(all_mutations):
|
||||
return all_mutations.pick_random()
|
||||
else :
|
||||
return null
|
||||
|
||||
@@ -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_state : Plant.State, plant : Plant, score) -> int:
|
||||
if plant_state != Plant.State.MATURE:
|
||||
func mutate_score(data : PlantData, score) -> int:
|
||||
if data.get_state() != PlantData.State.MATURE:
|
||||
return score
|
||||
return score + floori(plant.day / get_day_factor())
|
||||
return score + floori(data.day / get_day_factor())
|
||||
@@ -1,29 +0,0 @@
|
||||
extends PlantMutation
|
||||
class_name ElitistMutation
|
||||
|
||||
func get_icon() -> Texture:
|
||||
return preload("res://common/icons/copy.svg")
|
||||
|
||||
func get_base_rarity() -> int:
|
||||
return 0
|
||||
|
||||
func get_mutation_name() -> String:
|
||||
return tr("ELITIST")
|
||||
|
||||
func get_mutation_description() -> String:
|
||||
return tr("ELITIST_EFFECT_TEXT_LEVEL_%d") % level
|
||||
|
||||
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
|
||||
for area in plant.influence_zone.get_overlapping_areas():
|
||||
if area is Plant and area != plant and area.plant_type.name == plant.plant_type.name:
|
||||
plant_count += 1
|
||||
|
||||
if plant_count == 0:
|
||||
return 0
|
||||
else :
|
||||
return score + level * plant_count
|
||||
@@ -1 +0,0 @@
|
||||
uid://bt1xh7ss13e5e
|
||||
@@ -1,26 +0,0 @@
|
||||
extends PlantMutation
|
||||
class_name ErmitMutation
|
||||
|
||||
func get_icon() -> Texture:
|
||||
return preload("res://common/icons/seedling-off.svg")
|
||||
|
||||
func get_base_rarity() -> int:
|
||||
return 0
|
||||
|
||||
func get_mutation_name() -> String:
|
||||
return tr("ERMIT")
|
||||
|
||||
func get_mutation_description() -> String:
|
||||
return tr("ERMIT_EFFECT_TEXT_LEVEL_%d") % get_score_multiplier()
|
||||
|
||||
func get_score_multiplier():
|
||||
return level + 1
|
||||
|
||||
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()
|
||||
@@ -1 +0,0 @@
|
||||
uid://domy822vgxfxs
|
||||
@@ -13,5 +13,5 @@ func get_mutation_name() -> String:
|
||||
func get_mutation_description() -> String:
|
||||
return tr("PRECOCIOUS_EFFECT_TEXT_LEVEL_%d") % level
|
||||
|
||||
func mutate_score(plant_state : Plant.State, _plant : Plant, score) -> int:
|
||||
return score + (0 if plant_state == Plant.State.MATURE else level)
|
||||
func mutate_score(data : PlantData, score : int) -> int:
|
||||
return score + (0 if data.get_state() == PlantData.State.MATURE else level)
|
||||
@@ -13,5 +13,5 @@ func get_mutation_name() -> String:
|
||||
func get_mutation_description() -> String:
|
||||
return tr("QUALITY_EFFECT_TEXT_LEVEL_%d") % level
|
||||
|
||||
func mutate_score(plant_state : Plant.State, _plant : Plant, score : int) -> int:
|
||||
return score + (level if plant_state == Plant.State.MATURE else 0)
|
||||
func mutate_score(data : PlantData, score : int) -> int:
|
||||
return score + (level if data.get_state() == PlantData.State.MATURE else 0)
|
||||
@@ -13,5 +13,5 @@ func get_mutation_name() -> String:
|
||||
func get_mutation_description() -> String:
|
||||
return tr("QUICK_EFFECT_TEXT_LEVEL_%d") % level
|
||||
|
||||
func mutate_grow_time(_plant : Plant, grow_time : int) -> int:
|
||||
func mutate_grow_time(_data : PlantData, grow_time : int) -> int:
|
||||
return max(grow_time - level, 0)
|
||||
@@ -1,32 +0,0 @@
|
||||
extends PlantMutation
|
||||
class_name SociableMutation
|
||||
|
||||
const NEAR_PLANT_NEEDED = 2
|
||||
|
||||
func get_icon() -> Texture:
|
||||
return preload("res://common/icons/seedling.svg")
|
||||
|
||||
func get_base_rarity() -> int:
|
||||
return 0
|
||||
|
||||
func get_mutation_name() -> String:
|
||||
return tr("SOCIABLE")
|
||||
|
||||
func get_mutation_description() -> String:
|
||||
return tr("SOCIABLE_EFFECT_TEXT_LEVEL_%d") % [get_score_bonus(), NEAR_PLANT_NEEDED]
|
||||
|
||||
func get_score_bonus():
|
||||
return (level + 2)
|
||||
|
||||
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
|
||||
|
||||
for area in plant.influence_zone.get_overlapping_areas():
|
||||
if area is Plant and area != plant :
|
||||
plant_count += 1
|
||||
|
||||
return score + (get_score_bonus() if plant_count >= NEAR_PLANT_NEEDED else 0)
|
||||
@@ -1 +0,0 @@
|
||||
uid://b8q5xgvy85qeb
|
||||
@@ -1,20 +0,0 @@
|
||||
extends PlantMutation
|
||||
class_name StrongMutation
|
||||
|
||||
func get_icon() -> Texture:
|
||||
return preload("res://common/icons/dna.svg")
|
||||
|
||||
func get_base_rarity() -> int:
|
||||
return 0
|
||||
|
||||
func get_mutation_name() -> String:
|
||||
return tr("STRONG")
|
||||
|
||||
func get_mutation_description() -> String:
|
||||
return tr("STRONG_EFFECT_TEXT_LEVEL_%d") % [roundi(get_score_multiplier() * 100)]
|
||||
|
||||
func get_score_multiplier():
|
||||
return float(level)/2
|
||||
|
||||
func mutate_score(_plant_state : Plant.State, _plant : Plant, score: int) -> int:
|
||||
return score + roundi(score * get_score_multiplier())
|
||||
@@ -1 +0,0 @@
|
||||
uid://cwj3k4p6ci5t4
|
||||
@@ -8,47 +8,38 @@ const PARTICLES_SCENE : PackedScene = preload("res://common/vfx/particles/partic
|
||||
|
||||
signal harvest_animation_finished
|
||||
|
||||
func update_plant_sprite(plant : Plant, with_animation = false):
|
||||
if with_animation:
|
||||
%AnimationPlayer.play("bump")
|
||||
await %AnimationPlayer.animation_finished
|
||||
|
||||
%Sprite.flip_h = true if randi()%2 == 0 else false
|
||||
var last_updated_on_state : PlantData.State = PlantData.State.MATURE
|
||||
|
||||
%Sprite.texture = get_state_texture(plant.state, plant.plant_type)
|
||||
func update_plant_sprite(plant_data : PlantData, with_animation = false):
|
||||
if with_animation:
|
||||
%AnimationPlayer.play("bump")
|
||||
await %AnimationPlayer.animation_finished
|
||||
|
||||
%Sprite.flip_h = true if plant_data.random_seed%2 == 0 else false
|
||||
%Sprite.texture = plant_data.get_plant_texture()
|
||||
|
||||
%PlantedSeed.visible = plant.state == Plant.State.PLANTED
|
||||
%PlantedSeed.texture = plant.plant_type.seed_texture
|
||||
%PlantedSeed.texture = plant_data.get_seed_texture()
|
||||
%PlantedSeed.visible = plant_data.get_state() == PlantData.State.PLANTED
|
||||
|
||||
%PlantedSeed.region_rect = Rect2(
|
||||
0,
|
||||
PLANTED_SEED_POS_Y,
|
||||
plant.plant_type.seed_texture.get_width(),
|
||||
plant.plant_type.seed_texture.get_height() - PLANTED_SEED_CROP_WIDTH + -1 * PLANTED_SEED_POS_Y,
|
||||
)
|
||||
|
||||
func get_state_texture(s: Plant.State, plant_type : PlantType) -> Texture2D:
|
||||
match s:
|
||||
Plant.State.PLANTED:
|
||||
return null
|
||||
Plant.State.GROWING:
|
||||
return plant_type.growing_texture
|
||||
Plant.State.MATURE:
|
||||
return plant_type.mature_texture
|
||||
return null
|
||||
# %PlantedSeed.region_rect = Rect2(
|
||||
# 0,
|
||||
# PLANTED_SEED_POS_Y,
|
||||
# %PlantedSeed.texture.get_width(),
|
||||
# %PlantedSeed.texture.texture.get_height() - PLANTED_SEED_CROP_WIDTH + -1 * PLANTED_SEED_POS_Y,
|
||||
# )
|
||||
|
||||
func generate_mutation_effects(plant : Plant):
|
||||
for m in plant.plant_mutations:
|
||||
var particles_emitter : Particles = PARTICLES_SCENE.instantiate() as CPUParticles2D
|
||||
particles_emitter.setup_particles(
|
||||
Particles.Parameters.new(
|
||||
m.get_icon(),
|
||||
PlantMutation.get_rarity_color(m.get_rarity())
|
||||
)
|
||||
)
|
||||
add_child(particles_emitter)
|
||||
for m in plant.data.mutations:
|
||||
var particles_emitter : Particles = PARTICLES_SCENE.instantiate() as CPUParticles2D
|
||||
particles_emitter.setup_particles(
|
||||
Particles.Parameters.new(
|
||||
m.get_icon(),
|
||||
PlantMutation.get_rarity_color(m.get_rarity())
|
||||
)
|
||||
)
|
||||
add_child(particles_emitter)
|
||||
|
||||
func start_harvest_animation():
|
||||
$AnimationPlayer.play("harvest")
|
||||
await $AnimationPlayer.animation_finished
|
||||
harvest_animation_finished.emit()
|
||||
$AnimationPlayer.play("harvest")
|
||||
await $AnimationPlayer.animation_finished
|
||||
harvest_animation_finished.emit()
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
extends Resource
|
||||
class_name PlantType
|
||||
|
||||
@export var name : String
|
||||
@export_multiline var description : String
|
||||
|
||||
@export var default_growing_time : int = 2
|
||||
@export var default_plant_score : int = 1
|
||||
|
||||
@export var seed_texture : Texture
|
||||
@export var growing_texture : Texture
|
||||
@export var mature_texture : Texture
|
||||
|
||||
@export var harvest_effects : Array[PlantEffect] = []
|
||||
@export var mature_effects : Array[PlantEffect] = []
|
||||
@export var cyclic_effects : Array[PlantEffect] = []
|
||||
|
||||
func card_info() -> CardInfo:
|
||||
var info = CardInfo.new(
|
||||
name
|
||||
)
|
||||
|
||||
info.important_stat_icon = Plant.PLANT_POINT_ICON
|
||||
info.important_stat_text = "%d" % default_plant_score
|
||||
info.texture = mature_texture
|
||||
info.type_icon = Plant.PLANT_TYPE_ICON
|
||||
|
||||
info.stats.append(CardStatInfo.new(
|
||||
tr("GROW_IN_%d") % default_growing_time,
|
||||
Plant.GROWING_ICON
|
||||
))
|
||||
|
||||
info.stats.append(CardStatInfo.new(
|
||||
tr("%s_SCORE_WHEN_MATURE") % default_plant_score,
|
||||
Plant.PLANT_POINT_ICON
|
||||
))
|
||||
|
||||
info.sections.append_array(PlantEffect.card_effect_sections(
|
||||
mature_effects,
|
||||
harvest_effects,
|
||||
cyclic_effects,
|
||||
))
|
||||
|
||||
return info
|
||||
|
||||
func get_available_evolution() -> Array[Evolution]:
|
||||
var evolutions : Array[Evolution] = [
|
||||
ScoreEvolution.new(self)
|
||||
]
|
||||
|
||||
if len(mature_effects) > 0:
|
||||
evolutions.append(MatureEffectEvolution.new(self))
|
||||
if len(harvest_effects) > 0:
|
||||
evolutions.append(HarvestEffectEvolution.new(self))
|
||||
if len(cyclic_effects) > 0:
|
||||
evolutions.append(CyclicEffectEvolution.new(self))
|
||||
|
||||
return evolutions
|
||||
|
||||
class Evolution:
|
||||
|
||||
var level : int
|
||||
var plant_type : PlantType
|
||||
|
||||
func _init(_type : PlantType, _l : int = 1):
|
||||
plant_type = _type
|
||||
level = _l
|
||||
|
||||
func get_title():
|
||||
return ""
|
||||
|
||||
func get_description():
|
||||
return ""
|
||||
|
||||
func evolve(_pt : PlantType = plant_type):
|
||||
pass
|
||||
|
||||
class ScoreEvolution extends Evolution:
|
||||
|
||||
func get_title():
|
||||
return tr("%s_SCORE_EVOLUTION") % plant_type.name
|
||||
|
||||
func get_description():
|
||||
return tr("ADD_%s_TO_THE_DEFAULT_SCORE_OF_THE_PLANT") % level
|
||||
|
||||
func evolve(pt : PlantType = plant_type):
|
||||
pt.default_plant_score += level
|
||||
|
||||
class MatureEffectEvolution extends Evolution:
|
||||
|
||||
var effect_index : int
|
||||
|
||||
func _init(_type : PlantType, _l : int = 1):
|
||||
plant_type = _type
|
||||
level = _l
|
||||
|
||||
pick_effect()
|
||||
|
||||
func pick_effect():
|
||||
effect_index = randi() % len(plant_type.mature_effects)
|
||||
|
||||
func get_effect(pt : PlantType = plant_type) -> PlantEffect:
|
||||
return pt.mature_effects[effect_index]
|
||||
|
||||
func get_title():
|
||||
return tr("%s_EVOLUTION") % plant_type.name
|
||||
|
||||
func get_description():
|
||||
return tr("UPGRADE_THE_LEVEL_OF_%s_EFFECT_OF_%d_LEVEL") % [get_effect().get_effect_name(), level]
|
||||
|
||||
func evolve(pt : PlantType = plant_type):
|
||||
get_effect(pt).level += level
|
||||
|
||||
class HarvestEffectEvolution extends MatureEffectEvolution:
|
||||
|
||||
func pick_effect():
|
||||
effect_index = randi() % len(plant_type.harvest_effects)
|
||||
|
||||
func get_effect(pt : PlantType = plant_type) -> PlantEffect:
|
||||
return pt.harvest_effects[effect_index]
|
||||
|
||||
class CyclicEffectEvolution extends MatureEffectEvolution:
|
||||
|
||||
func pick_effect():
|
||||
effect_index = randi() % len(plant_type.harvest_effects)
|
||||
|
||||
func get_effect(pt : PlantType = plant_type) -> PlantEffect:
|
||||
return pt.harvest_effects[effect_index]
|
||||
@@ -1 +0,0 @@
|
||||
uid://jnye5pe1bgqw
|
||||
19
entities/plants/scripts/texture_builder/texture_builder.gd
Normal file
19
entities/plants/scripts/texture_builder/texture_builder.gd
Normal file
@@ -0,0 +1,19 @@
|
||||
extends Resource
|
||||
class_name TextureBuilder
|
||||
|
||||
const PLACEHOLDER_SEED_TEXTURE : Texture = preload("res://entities/plants/assets/sprites/default/seed.png")
|
||||
const PLACEHOLDER_MATURE_TEXTURE : Texture = preload("res://entities/plants/assets/sprites/default/mature.png")
|
||||
const PLACEHOLDER_GROWING_TEXTURE : Texture = preload("res://entities/plants/assets/sprites/default/growing.png")
|
||||
|
||||
|
||||
func build_seed_texture(_random_seed : int) -> Texture:
|
||||
return PLACEHOLDER_SEED_TEXTURE
|
||||
|
||||
func build_plant_texture(plant_data : PlantData) -> Texture:
|
||||
match plant_data.get_state():
|
||||
PlantData.State.MATURE:
|
||||
return PLACEHOLDER_MATURE_TEXTURE
|
||||
PlantData.State.GROWING:
|
||||
return PLACEHOLDER_GROWING_TEXTURE
|
||||
_:
|
||||
return null
|
||||
@@ -0,0 +1 @@
|
||||
uid://dt2ip3pw2cboy
|
||||
Reference in New Issue
Block a user