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

@@ -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