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:
@@ -6,93 +6,97 @@ signal updated(inventory: Inventory)
|
||||
@export var items: Array[Item] = []
|
||||
@export var current_item_ind: int = 0
|
||||
@export var size = 0 :
|
||||
set(s):
|
||||
size = s
|
||||
items.resize(size)
|
||||
updated.emit(self)
|
||||
set(s):
|
||||
size = s
|
||||
items.resize(size)
|
||||
updated.emit(self)
|
||||
|
||||
func _init(inventory_size: int = 1):
|
||||
size = inventory_size
|
||||
|
||||
|
||||
size = inventory_size
|
||||
|
||||
func get_best_available_slot_ind():
|
||||
if items[current_item_ind] == null:
|
||||
return current_item_ind
|
||||
for i in items.size():
|
||||
if items[i] == null:
|
||||
return i
|
||||
return current_item_ind
|
||||
if items[current_item_ind] == null:
|
||||
return current_item_ind
|
||||
for i in items.size():
|
||||
if items[i] == null:
|
||||
return i
|
||||
return current_item_ind
|
||||
|
||||
func set_current_item(new_ind: int):
|
||||
if new_ind >= items.size():
|
||||
return
|
||||
if new_ind >= items.size():
|
||||
return
|
||||
|
||||
if new_ind != current_item_ind:
|
||||
current_item_ind = new_ind
|
||||
updated.emit(self)
|
||||
if new_ind != current_item_ind:
|
||||
current_item_ind = new_ind
|
||||
updated.emit(self)
|
||||
|
||||
func change_current_item(ind_mod: int):
|
||||
if items.size() == 0:
|
||||
current_item_ind = 0
|
||||
return
|
||||
var new_ind: int = current_item_ind + ind_mod
|
||||
new_ind = new_ind % items.size()
|
||||
if new_ind < 0:
|
||||
new_ind += items.size()
|
||||
set_current_item(new_ind)
|
||||
if items.size() == 0:
|
||||
current_item_ind = 0
|
||||
return
|
||||
var new_ind: int = current_item_ind + ind_mod
|
||||
new_ind = new_ind % items.size()
|
||||
if new_ind < 0:
|
||||
new_ind += items.size()
|
||||
set_current_item(new_ind)
|
||||
|
||||
func add_item(item: Item):
|
||||
var best_ind = get_best_available_slot_ind()
|
||||
if best_ind != current_item_ind:
|
||||
set_item(item, best_ind)
|
||||
updated.emit(self)
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
var best_ind = get_best_available_slot_ind()
|
||||
if best_ind != current_item_ind:
|
||||
set_item(item, best_ind)
|
||||
updated.emit(self)
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
|
||||
func set_item(item: Item, ind: int = 0) -> bool:
|
||||
if ind < 0 || ind >= items.size():
|
||||
return false
|
||||
while len(items) <= ind:
|
||||
items.append(null)
|
||||
items[ind] = item
|
||||
updated.emit(self)
|
||||
return true
|
||||
if ind < 0 || ind >= items.size():
|
||||
return false
|
||||
while len(items) <= ind:
|
||||
items.append(null)
|
||||
items[ind] = item
|
||||
updated.emit(self)
|
||||
return true
|
||||
|
||||
func get_item(ind: int = current_item_ind) -> Item:
|
||||
if ind < 0 || items.size() <= ind:
|
||||
return null
|
||||
return items[ind]
|
||||
if ind < 0 || items.size() <= ind:
|
||||
return null
|
||||
return items[ind]
|
||||
|
||||
func has_item(item: Item) -> bool:
|
||||
return item in items
|
||||
return item in items
|
||||
|
||||
func remove_item(item: Item):
|
||||
var ind = items.find(item)
|
||||
if ind >= 0:
|
||||
items[ind] = null
|
||||
updated.emit(self)
|
||||
var ind = items.find(item)
|
||||
if ind >= 0:
|
||||
items[ind] = null
|
||||
updated.emit(self)
|
||||
|
||||
func remove_item_at(ind: int = current_item_ind):
|
||||
if items.size() <= ind:
|
||||
return
|
||||
if items.size() <= ind:
|
||||
return
|
||||
|
||||
items[ind] = null
|
||||
updated.emit(self)
|
||||
items[ind] = null
|
||||
updated.emit(self)
|
||||
|
||||
func remove_current_item():
|
||||
remove_item_at()
|
||||
remove_item_at()
|
||||
|
||||
func pop_item(ind: int = current_item_ind) -> Item:
|
||||
if items.size() == 0:
|
||||
return
|
||||
if items.size() == 0:
|
||||
return
|
||||
|
||||
var item_removed: Item = items[ind]
|
||||
items[ind] = null
|
||||
updated.emit(self)
|
||||
return item_removed
|
||||
var item_removed: Item = items[ind]
|
||||
items[ind] = null
|
||||
updated.emit(self)
|
||||
return item_removed
|
||||
|
||||
func is_full():
|
||||
for i in items:
|
||||
if i == null : return false
|
||||
return true
|
||||
for i in items:
|
||||
if i == null : return false
|
||||
return true
|
||||
|
||||
func clear():
|
||||
for i in range(len(items)):
|
||||
items[i] = null
|
||||
updated.emit(self)
|
||||
|
||||
@@ -33,11 +33,11 @@ func is_one_time_use():
|
||||
return true
|
||||
|
||||
func can_use(player : Player, _zone : Player.ActionZone) -> bool:
|
||||
return player.terrain is Planet
|
||||
return player.terrain is Region
|
||||
|
||||
func use(player : Player, zone : Player.ActionZone) -> bool:
|
||||
if machine_type and machine_level and player.planet:
|
||||
player.planet.add_entity(
|
||||
if machine_type and machine_level and player.region:
|
||||
player.region.add_entity(
|
||||
Machine.instantiate_machine(machine_type, machine_level),
|
||||
zone.get_global_position()
|
||||
)
|
||||
|
||||
@@ -25,8 +25,8 @@ func is_one_time_use():
|
||||
return true
|
||||
|
||||
func can_use(player : Player, _zone : Player.ActionZone) -> bool:
|
||||
return player.planet != null
|
||||
return player.region != null
|
||||
|
||||
func use(player : Player, zone : Player.ActionZone) -> bool:
|
||||
player.planet.instantiate_entity(scene, zone.get_global_position())
|
||||
player.region.instantiate_entity(scene, zone.get_global_position())
|
||||
return true
|
||||
|
||||
@@ -7,17 +7,51 @@ const SHOVEL_ICON = preload("res://common/icons/shovel.svg")
|
||||
const GROWING_ICON = preload("res://common/icons/chevrons-up.svg")
|
||||
const SCORE_ICON = preload("res://common/icons/growth.svg")
|
||||
|
||||
@export var plant_type: PlantType
|
||||
@export var plant_name : String
|
||||
@export var plant_archetype: PlantArchetype
|
||||
@export var plant_mutations: Array[PlantMutation]
|
||||
@export var random_seed : int
|
||||
|
||||
func _init(
|
||||
_plant_name : String,
|
||||
_plant_archetype : PlantArchetype,
|
||||
_plant_mutations : Array[PlantMutation] = [],
|
||||
):
|
||||
plant_name = _plant_name
|
||||
plant_archetype = _plant_archetype
|
||||
plant_mutations = _plant_mutations
|
||||
random_seed = randi()
|
||||
|
||||
static func generate_from_parent(plant_data : PlantData) -> Seed:
|
||||
if randf() > MUTATION_PROBABILITY:
|
||||
return Seed.new(
|
||||
plant_data.plant_name,
|
||||
plant_data.archetype,
|
||||
mutate(plant_data.mutations)
|
||||
)
|
||||
else :
|
||||
# TODO
|
||||
return Seed.new(
|
||||
plant_data.plant_name,
|
||||
plant_data.archetype,
|
||||
mutate(plant_data.mutations)
|
||||
)
|
||||
|
||||
static func generate_random() -> Seed:
|
||||
return Seed.new(
|
||||
Random.generate_random_name(),
|
||||
PlantArchetype.new(),
|
||||
[]
|
||||
)
|
||||
|
||||
func get_item_name() -> String:
|
||||
return tr("%s_SEED") % plant_type.name
|
||||
return tr("%s_SEED") % plant_name
|
||||
|
||||
func get_description() -> String:
|
||||
return tr("PLANT_%s_MUST_BE_USED_IN_DECONTAMINATED_ZONE") % plant_type.name
|
||||
return tr("PLANT_%s_MUST_BE_USED_IN_DECONTAMINATED_ZONE") % plant_name
|
||||
|
||||
func get_icon() -> Texture2D:
|
||||
return plant_type.seed_texture
|
||||
return plant_archetype.texture_builder.build_seed_texture(random_seed)
|
||||
|
||||
func get_energy_used() -> int:
|
||||
return 1
|
||||
@@ -28,22 +62,15 @@ func get_usage_zone_radius() -> int:
|
||||
func get_usage_object_affected(i : InspectableEntity) -> bool:
|
||||
return i is Plant
|
||||
|
||||
func _init(
|
||||
_plant_type : PlantType = null,
|
||||
_parent_mutation : Array[PlantMutation] = []
|
||||
):
|
||||
plant_type = _plant_type
|
||||
plant_mutations = Seed.mutate(_parent_mutation)
|
||||
|
||||
func use_text() -> String:
|
||||
return tr("PLANT_%s") % plant_type.name
|
||||
return tr("PLANT_%s") % plant_name
|
||||
|
||||
func is_one_time_use():
|
||||
return true
|
||||
|
||||
func can_use(player : Player, zone : Player.ActionZone) -> bool:
|
||||
if (
|
||||
player.planet == null
|
||||
player.region == null
|
||||
):
|
||||
return false
|
||||
|
||||
@@ -54,21 +81,17 @@ func can_use(player : Player, zone : Player.ActionZone) -> bool:
|
||||
|
||||
var is_there_contamination_in_zone = false
|
||||
for tile in zone.get_tiles():
|
||||
if not player.planet.decontamination_layer.is_decontamined(tile):
|
||||
if not player.region.decontamination_layer.is_decontamined(tile):
|
||||
is_there_contamination_in_zone = true
|
||||
|
||||
return not is_there_a_plant_here and not is_there_contamination_in_zone
|
||||
|
||||
func use(player : Player, zone : Player.ActionZone) -> bool:
|
||||
if player.planet == null:
|
||||
if player.region == null:
|
||||
return false
|
||||
|
||||
AudioManager.play_sfx("Dig")
|
||||
return player.planet.plant(
|
||||
plant_type,
|
||||
zone.get_global_position(),
|
||||
plant_mutations
|
||||
)
|
||||
return player.region.plant(self,zone.get_global_position())
|
||||
|
||||
func card_info() -> CardInfo:
|
||||
var info = CardInfo.new(
|
||||
@@ -113,7 +136,6 @@ func card_info() -> CardInfo:
|
||||
|
||||
return info
|
||||
|
||||
|
||||
func get_particles() -> Array[Particles.Parameters]:
|
||||
var param : Array[Particles.Parameters] = []
|
||||
|
||||
@@ -129,73 +151,67 @@ func get_particles() -> Array[Particles.Parameters]:
|
||||
|
||||
static func mutate(parent_mutation : Array[PlantMutation] = []) -> Array[PlantMutation]:
|
||||
|
||||
if randf() > MUTATION_PROBABILITY:
|
||||
return parent_mutation
|
||||
# TODO
|
||||
# var possible_mutations_change : Array[MutationPossibility] = [
|
||||
# AddMutation.new()
|
||||
# ]
|
||||
|
||||
var possible_mutations : Array[MutationPossibility] = [
|
||||
AddMutation.new()
|
||||
]
|
||||
|
||||
if (
|
||||
len(parent_mutation) >= 2
|
||||
):
|
||||
possible_mutations = [
|
||||
UpgradeMutation.new(),
|
||||
RemoveMutation.new(),
|
||||
]
|
||||
elif len(parent_mutation) > 0:
|
||||
possible_mutations = [
|
||||
AddMutation.new(),
|
||||
UpgradeMutation.new(),
|
||||
RemoveMutation.new(),
|
||||
]
|
||||
# if (
|
||||
# len(parent_mutation) >= 2
|
||||
# ):
|
||||
# possible_mutations_change = [
|
||||
# UpgradeMutation.new(),
|
||||
# RemoveMutation.new(),
|
||||
# ]
|
||||
# elif len(parent_mutation) > 0:
|
||||
# possible_mutations_change = [
|
||||
# AddMutation.new(),
|
||||
# UpgradeMutation.new(),
|
||||
# RemoveMutation.new(),
|
||||
# ]
|
||||
|
||||
var chosen_mutation = possible_mutations.pick_random()
|
||||
# var chosen_mutation = possible_mutations_change.pick_random()
|
||||
|
||||
return chosen_mutation.mutate(parent_mutation)
|
||||
return parent_mutation
|
||||
|
||||
|
||||
class MutationPossibility:
|
||||
func mutate(_parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
|
||||
return []
|
||||
# class MutationPossibility:
|
||||
# func mutate(_parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
|
||||
# return []
|
||||
|
||||
class DontMutate extends MutationPossibility:
|
||||
func mutate(parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
|
||||
return parent_mutation
|
||||
# class AddMutation extends MutationPossibility:
|
||||
# func mutate(parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
|
||||
# var new_mutations = parent_mutation.duplicate_deep()
|
||||
# var mut = PlantMutation.random_mutation(parent_mutation)
|
||||
|
||||
class AddMutation extends MutationPossibility:
|
||||
func mutate(parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
|
||||
var new_mutations = parent_mutation.duplicate_deep()
|
||||
var mut = PlantMutation.random_mutation(parent_mutation)
|
||||
|
||||
if mut:
|
||||
var existing_mut_id = new_mutations.find_custom(func(m:PlantMutation): return m.get_mutation_name() == mut.get_mutation_name())
|
||||
# if mut:
|
||||
# var existing_mut_id = new_mutations.find_custom(func(m:PlantMutation): return m.get_mutation_name() == mut.get_mutation_name())
|
||||
|
||||
if existing_mut_id >= 0:
|
||||
new_mutations[existing_mut_id].level += 1
|
||||
else :
|
||||
new_mutations.append(mut)
|
||||
# if existing_mut_id >= 0:
|
||||
# new_mutations[existing_mut_id].level += 1
|
||||
# else :
|
||||
# new_mutations.append(mut)
|
||||
|
||||
return new_mutations
|
||||
# return new_mutations
|
||||
|
||||
class UpgradeMutation extends MutationPossibility:
|
||||
func mutate(
|
||||
parent_mutation : Array[PlantMutation] = []
|
||||
) -> Array[PlantMutation]:
|
||||
var new_mutations = parent_mutation.duplicate_deep()
|
||||
# class UpgradeMutation extends MutationPossibility:
|
||||
# func mutate(
|
||||
# parent_mutation : Array[PlantMutation] = []
|
||||
# ) -> Array[PlantMutation]:
|
||||
# var new_mutations = parent_mutation.duplicate_deep()
|
||||
|
||||
new_mutations.pick_random().level += 1
|
||||
# new_mutations.pick_random().level += 1
|
||||
|
||||
return new_mutations
|
||||
# return new_mutations
|
||||
|
||||
class RemoveMutation extends MutationPossibility:
|
||||
func mutate(parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
|
||||
var new_mutations :Array[PlantMutation] = parent_mutation.duplicate_deep()
|
||||
# class RemoveMutation extends MutationPossibility:
|
||||
# func mutate(parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
|
||||
# var new_mutations :Array[PlantMutation] = parent_mutation.duplicate_deep()
|
||||
|
||||
var mut_to_remove = new_mutations.pick_random()
|
||||
if mut_to_remove.level > 1:
|
||||
mut_to_remove.level -= 1
|
||||
else:
|
||||
new_mutations.remove_at(new_mutations.find(mut_to_remove))
|
||||
# var mut_to_remove = new_mutations.pick_random()
|
||||
# if mut_to_remove.level > 1:
|
||||
# mut_to_remove.level -= 1
|
||||
# else:
|
||||
# new_mutations.remove_at(new_mutations.find(mut_to_remove))
|
||||
|
||||
return new_mutations
|
||||
# return new_mutations
|
||||
|
||||
Reference in New Issue
Block a user