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

@@ -0,0 +1,92 @@
extends Resource
class_name Inventory
signal updated(inventory: Inventory)
@export var items: Array[Item] = []
@export var current_item_ind: int = 0
func _init(inventory_size: int = 1):
items.resize(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
func set_current_item(new_ind: int):
if new_ind >= items.size():
return
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)
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
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
func get_item(ind: int = current_item_ind) -> Item:
if ind < 0 || items.size() <= ind:
return null
return items[ind]
func has_item(item: Item) -> bool:
return item in items
func remove_item(item: Item):
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
items[ind] = null
updated.emit(self)
func remove_current_item():
remove_item_at()
func pop_item(ind: int = current_item_ind) -> Item:
if items.size() == 0:
return
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

View File

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

View File

@@ -0,0 +1,81 @@
extends Resource
class_name Item
const TYPE_ICON = preload("res://common/icons/backpack.svg")
const ACTION_ICON = preload("res://common/icons/swipe-down.svg")
const ENERGY_ICON = preload("res://common/icons/bolt.svg")
const ONE_TIME_ICON = preload("res://common/icons/circle-number-1.svg")
var name: String : get = get_item_name
var description: String : get = get_description
var icon: Texture2D : get = get_icon
var usage_zone_radius: int = 5 : get = get_usage_zone_radius
var energy_usage : int = 1 : get = get_energy_used
func get_item_name() -> String:
return name
func get_description() -> String:
return description
func get_icon() -> Texture2D:
return icon
func get_energy_used() -> int:
return energy_usage
func get_usage_zone_radius() -> int:
return usage_zone_radius
func get_usage_object_affected(_i : InspectableEntity) -> bool:
return false
func is_one_time_use():
return false
func can_use(_player : Player, zone: Player.ActionZone) -> bool:
return false
func use_text() -> String:
return ""
func use(_player : Player, zone: Player.ActionZone):
return false
func card_info() -> CardInfo:
var info = CardInfo.new(
get_item_name()
)
info.texture = icon
info.type_icon = TYPE_ICON
info.stats.append(
CardStatInfo.new(
"Cost %d energy" % energy_usage,
ENERGY_ICON
)
)
if is_one_time_use():
info.stats.append(
CardStatInfo.new(
"One time use",
ONE_TIME_ICON
)
)
var effect_section = CardSectionInfo.new(
"Effect",
get_description()
)
effect_section.title_icon = ACTION_ICON
if energy_usage > 0:
effect_section.title_icon = ENERGY_ICON
info.sections.append(effect_section)
return info
func get_particles() -> Array[Particles.Parameters]:
return []

View File

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

View File

@@ -0,0 +1,42 @@
extends Item
class_name Blueprint
@export var machine_type: MachineType
@export var machine_level: int = 1
func _init(_machine_type : MachineType = null, _machine_level : int = 1):
machine_type = _machine_type
machine_level = _machine_level
func get_item_name() -> String:
if machine_type:
return machine_type.name
return ""
func get_description() -> String:
if machine_type:
return machine_type.description
return ""
func get_icon() -> Texture2D:
return preload("res://common/icons/cube-3d-sphere.svg")
func use_text() -> String:
if machine_type:
return "Build " + machine_type.name
return ""
func is_one_time_use():
return true
func can_use(player : Player, zone : Player.ActionZone) -> bool:
return player.terrain is Planet
func use(player : Player, zone : Player.ActionZone) -> bool:
if machine_type and machine_level and player.planet:
player.planet.add_entity(
Machine.instantiate_machine(machine_type, machine_level),
zone.get_global_position()
)
return true
return false

View File

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

View File

@@ -0,0 +1,44 @@
extends Item
class_name Fork
const USE_INTERVAL = 0.15
func get_item_name() -> String:
return "Fork"
func get_description() -> String:
return "Use it to harvest mature plants."
func get_icon() -> Texture2D:
return preload("res://common/icons/fork.svg")
func get_energy_used() -> int:
return 1
func get_usage_zone_radius() -> int:
return 50
func get_usage_object_affected(i : InspectableEntity) -> bool:
return i is Plant
func use_text() -> String:
return "Harvest"
func can_use(_player : Player, zone : Player.ActionZone) -> bool:
var areas = zone.get_affected_areas()
for area in areas :
if area is Plant:
return true
return false
func use(player : Player, zone : Player.ActionZone) -> bool:
for area in zone.get_affected_areas():
if area and area is Plant:
harvest(area, player)
await player.get_tree().create_timer(USE_INTERVAL).timeout
return true
func harvest(p : Plant, player: Player):
player.play_sfx("harvest")
p.harvest()

View File

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

View File

@@ -0,0 +1,19 @@
extends Fork
class_name Knife
const KNIFE_ZONE_RADIUS = 10
func get_item_name() -> String:
return "Knife"
func get_description() -> String:
return "Use it to harvest mature plants. Do not cost energy."
func get_energy_used() -> int:
return 0
func get_icon() -> Texture2D:
return preload("res://common/icons/slice.svg")
func get_usage_zone_radius() -> int:
return KNIFE_ZONE_RADIUS

View File

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

View File

@@ -0,0 +1,32 @@
extends Item
class_name Package
@export var scene: PackedScene
@export var package_name : String
@export_multiline var package_description : String
func _init(_scene : PackedScene = null):
scene = _scene
func get_item_name() -> String:
return package_name
func get_description() -> String:
return package_description
func get_icon() -> Texture2D:
return preload("res://common/icons/package.svg")
func use_text() -> String:
return "Open"
func is_one_time_use():
return true
func can_use(player : Player, zone : Player.ActionZone) -> bool:
return player.planet != null
func use(player : Player, zone : Player.ActionZone) -> bool:
player.planet.instantiate_entity(scene, zone.get_global_position())
return true

View File

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

View File

@@ -0,0 +1,194 @@
extends Item
class_name Seed
const MUTATION_PROBABILITY = 0.3
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_mutations: Array[PlantMutation]
func get_item_name() -> String:
return "%s Seed" % plant_type.name
func get_description() -> String:
return "Plant [b]%s[/b]. Must be used in decontamined zone." % plant_type.name
func get_icon() -> Texture2D:
return plant_type.seed_texture
func get_energy_used() -> int:
return 1
func get_usage_zone_radius() -> int:
return 30
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 "Plant " + plant_type.name
func is_one_time_use():
return true
func can_use(player : Player, zone : Player.ActionZone) -> bool:
if (
player.planet == null
or not player.planet.garden.is_in_garden(zone.get_global_position())
):
return false
var is_there_a_plant_here = false
for area in zone.get_affected_areas():
if area is Plant:
is_there_a_plant_here = true
var is_there_contamination_in_zone = false
for point in zone.get_points_in_zone():
if player.planet.garden.is_there_contamination(point):
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:
return false
player.play_sfx("dig")
return player.planet.plant(
plant_type,
zone.get_global_position(),
plant_mutations
)
func card_info() -> CardInfo:
var info = CardInfo.new(
get_item_name()
)
info.texture = icon
info.type_icon = TYPE_ICON
info.stats.append(
CardStatInfo.new(
"Cost %d energy" % energy_usage,
ENERGY_ICON
)
)
if is_one_time_use():
info.stats.append(
CardStatInfo.new(
"One time use",
ONE_TIME_ICON
)
)
var effect_section = CardSectionInfo.new(
"Effect",
get_description()
)
effect_section.title_icon = ACTION_ICON
if energy_usage > 0:
effect_section.title_icon = ENERGY_ICON
info.sections.append(effect_section)
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())
return info
func get_particles() -> Array[Particles.Parameters]:
var param : Array[Particles.Parameters] = []
for m in plant_mutations:
param.append(
Particles.Parameters.new(
m.get_icon(),
PlantMutation.get_rarity_color(m.get_rarity())
)
)
return param
static func mutate(parent_mutation : Array[PlantMutation] = []) -> Array[PlantMutation]:
if randf() > MUTATION_PROBABILITY:
return parent_mutation
var possible_mutations : Array[MutationPossibility] = [
AddMutation.new()
]
if len(parent_mutation):
possible_mutations.append_array( [
UpgradeMutation.new(),
RemoveMutation.new(),
])
var chosen_mutation = possible_mutations.pick_random()
return chosen_mutation.mutate(parent_mutation)
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()
if mut:
var existing_mut_id = new_mutations.find_custom(func(m:PlantMutation): 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)
return new_mutations
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
return new_mutations
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))
return new_mutations

View File

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

View File

@@ -0,0 +1,44 @@
extends Fork
class_name Shovel
const SHOVEL_ZONE_RADIUS = 50
func get_item_name() -> String:
return "Shovel"
func get_description() -> String:
return "Can dig up buried seeds and can be used to harvest mature plants."
func get_icon() -> Texture2D:
return preload("res://common/icons/shovel.svg")
func get_usage_zone_radius() -> int:
return SHOVEL_ZONE_RADIUS
func get_usage_object_affected(i : InspectableEntity) -> bool:
return i is Plant or i is UndergroundLoot
func use_text() -> String:
return "Dig"
func can_use(_player : Player, zone : Player.ActionZone) -> bool:
var areas = zone.get_affected_areas()
for area in areas :
if area is Plant or area is UndergroundLoot:
return true
return false
func use(player : Player, zone : Player.ActionZone) -> bool:
for area in zone.get_affected_areas():
if area and area is Plant:
harvest(area, player)
await player.get_tree().create_timer(USE_INTERVAL).timeout
if area and area is UndergroundLoot:
dig(area, player)
await player.get_tree().create_timer(USE_INTERVAL).timeout
return true
func dig(u: UndergroundLoot, player: Player):
player.play_sfx("dig")
u.dig()

View File

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

View File

@@ -0,0 +1,21 @@
extends Fork
class_name Trowel
const TROWEL_ZONE_RADIUS = 50
func get_item_name() -> String:
return "Trowel"
func get_description() -> String:
return "Use it to harvest mature plants, can get a [b]bonus seed[/b] from each plant."
func get_icon() -> Texture2D:
return preload("res://common/icons/trowel.svg")
func get_usage_zone_radius() -> int:
return TROWEL_ZONE_RADIUS
func harvest(p : Plant, player: Player):
ProduceSeedsEffect.new(1).effect(p)
player.play_sfx("harvest")
p.harvest()

View File

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

View File

@@ -3,8 +3,6 @@ class_name Player
const MAX_REACH = 100
const HOLDING_ITEM_SPRITE_SIZE = 20.
const DEFAULT_INVENTORY_SIZE = 2
const DEFAULT_MAX_ENERGY = 2
signal player_updated(player: Player)
signal upgraded
@@ -14,9 +12,10 @@ var planet : Planet :
get(): return terrain if terrain is Planet else null
@export var speed = 350
var max_energy : int = DEFAULT_MAX_ENERGY
var has_just_received_instruction : bool = false # pour récupérer les zones dans les action_area, une frame doit être passée depuis la création de la zone
var data : PlayerData
var controlling_player : bool = true :
set(v):
controlling_player = v
@@ -24,28 +23,23 @@ var controlling_player : bool = true :
var instruction : Instruction = null
var energy : int = max_energy :
set(v):
energy = v
player_updated.emit(self)
@onready var inventory : Inventory = Inventory.new(DEFAULT_INVENTORY_SIZE)
@onready var preview_zone : ActionZone = null
@onready var action_zone : ActionZone = null
@onready var preview_zone : ActionZone = setup_action_zone(Vector2.ZERO, null)
@onready var action_zone : ActionZone = setup_action_zone(Vector2.ZERO, null)
func _ready():
data = GameInfo.game_data.player_data
data.inventory.updated.connect(_on_inventory_updated)
player_updated.emit(self)
inventory.inventory_changed.connect(_on_inventory_updated)
Pointer.player = self
func _input(_event) -> void:
if Input.is_action_pressed("change_item_left"):
inventory.change_current_item(1)
data.inventory.change_current_item(1)
if Input.is_action_pressed("change_item_right"):
inventory.change_current_item(-1)
data.inventory.change_current_item(-1)
for i in range(1, 10):
if Input.is_action_pressed("item_" + str(i)):
inventory.set_current_item(i - 1)
data.inventory.set_current_item(i - 1)
# Méthode déclenchée par la classe planet
func _start_pass_day():
@@ -80,8 +74,8 @@ func _process(_delta):
move_and_slide()
func _on_inventory_updated(_inventory: Inventory):
var item : Item = inventory.get_item()
setup_preview_zone(item)
setup_preview_zone(data.inventory.get_item())
var item : Item = data.inventory.get_item()
if item:
var item_texture = item.icon
%ItemSprite.texture = item_texture
@@ -128,27 +122,30 @@ func try_move(move_to : Vector2):
func pick_item(item : Item) -> Item:
play_sfx("pick")
if inventory.is_full():
if data.inventory.is_full():
drop_item()
var available_slot_ind = inventory.get_best_available_slot_ind()
if available_slot_ind == inventory.current_item_ind && inventory.items[available_slot_ind] != null:
var current_item : Item = inventory.get_item()
inventory.set_item(item, available_slot_ind)
var available_slot_ind = data.inventory.get_best_available_slot_ind()
if (
available_slot_ind == data.inventory.current_item_ind
&& data.inventory.items[available_slot_ind] != null
):
var current_item : Item = data.inventory.get_item()
data.inventory.set_item(item, available_slot_ind)
return current_item
else :
if inventory.set_item(item, available_slot_ind):
inventory.set_current_item(available_slot_ind);
if data.inventory.set_item(item, available_slot_ind):
data.inventory.set_current_item(available_slot_ind);
return null
func drop_item():
var item_to_drop = inventory.pop_item()
var item_to_drop = data.inventory.pop_item()
if item_to_drop:
terrain.drop_item(item_to_drop, global_position)
play_sfx("drop")
func delete_item(item: Item):
inventory.remove_item(item)
data.inventory.remove_item(item)
func try_use_item(item : Item, use_position : Vector2):
has_just_received_instruction = true
@@ -163,7 +160,7 @@ func preview_could_use_item(item : Item) -> bool:
func could_use_item_on_zone(item : Item, zone: ActionZone) -> bool:
return (
inventory.has_item(item)
data.inventory.has_item(item)
and item.can_use(self, zone)
)
@@ -174,32 +171,32 @@ func can_use_item_on_zone(item : Item, zone: ActionZone) -> bool:
)
func has_energy_to_use_item(item : Item):
return (energy - item.energy_usage) >= 0
return (data.energy - item.energy_usage) >= 0
func use_item(item : Item):
if can_use_item_on_zone(item, action_zone):
var is_item_used = await item.use(self, action_zone)
if is_item_used:
energy -= item.energy_usage
data.energy -= item.energy_usage
if item.is_one_time_use():
inventory.remove_item(item)
data.inventory.remove_item(item)
func upgrade_max_energy(amount = 1):
max_energy += amount
data.max_energy += amount
upgraded.emit()
player_updated.emit(self)
func upgrade_inventory_size(amount = 1):
inventory.items.resize(inventory.items.size() + amount)
data.inventory.items.resize(data.inventory.items.size() + amount)
upgraded.emit()
player_updated.emit(self)
func recharge(amount : int = max_energy):
energy = energy + amount
func recharge(amount : int = data.max_energy):
data.energy += + amount
upgraded.emit()
func full_recharge():
energy = max(energy, max_energy)
data.energy = max(data.energy, data.max_energy)
func generate_action_zone(item : Item) -> ActionZone:
var zone = ActionZone.new(item)
@@ -226,7 +223,7 @@ func setup_action_zone(zone_position : Vector2, item: Item) -> ActionZone:
if action_zone:
action_zone.destroy()
action_zone = generate_action_zone(item)
action_zone.area.global_position = zone_position
action_zone.move_to_position(zone_position)
return action_zone
func move_preview_zone(zone_position : Vector2):
@@ -320,11 +317,13 @@ class ActionZone:
affected_areas = new_affected_areas
func get_affected_areas() -> Array[Area2D]:
return [] if area == null else area.get_overlapping_areas()
var empty_array : Array[Area2D] = []
return empty_array if area == null else area.get_overlapping_areas()
func destroy():
clear_preview_on_affected_area()
area.queue_free()
if area:
area.queue_free()
func get_global_position() -> Vector2:
return Vector2.ZERO if area == null else area.global_position

View File

@@ -0,0 +1,17 @@
extends Resource
class_name PlayerData
signal updated(player_data : PlayerData)
const DEFAULT_MAX_ENERGY = 2
const DEFAULT_INVENTORY_SIZE = 3
@export var max_energy : int = DEFAULT_MAX_ENERGY :
set(v):
max_energy = v
updated.emit(self)
@export var energy : int = DEFAULT_MAX_ENERGY :
set(v):
energy = v
updated.emit(self)
@export var inventory = Inventory.new(DEFAULT_INVENTORY_SIZE)

View File

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