ajout d'un terrain infini et la possibilité de planter n'importe où
This commit is contained in:
@@ -5,9 +5,8 @@ const BORDER_WIDTH = 100
|
||||
|
||||
var player : Player
|
||||
|
||||
@export var import_entities_from_node : Node2D = null
|
||||
@export var entity_container : Node2D
|
||||
|
||||
@onready var entity_container : Node2D = create_entity_container()
|
||||
|
||||
func instantiate_entity(s: PackedScene, entity_position : Vector2):
|
||||
var entity = s.instantiate() as Node2D
|
||||
@@ -23,15 +22,18 @@ func add_entity(entity : Node2D, entity_global_position : Vector2 = Vector2.ZERO
|
||||
else:
|
||||
entity.get_parent().remove_child(entity)
|
||||
|
||||
enroll_entity(entity)
|
||||
|
||||
container.add_child(entity)
|
||||
entity.global_position = entity_global_position
|
||||
|
||||
func enroll_entity(entity : Node2D):
|
||||
if "terrain" in entity:
|
||||
entity.terrain = self
|
||||
|
||||
if entity is Player:
|
||||
player = entity
|
||||
|
||||
container.add_child(entity)
|
||||
entity.global_position = entity_global_position
|
||||
|
||||
func save_entities() -> Array[EntityData]:
|
||||
var saved_entities_data : Array[EntityData] = []
|
||||
for e in entity_container.get_children():
|
||||
@@ -42,6 +44,9 @@ func save_entities() -> Array[EntityData]:
|
||||
return saved_entities_data
|
||||
|
||||
func load_entities(saved_entities_data : Array[EntityData]):
|
||||
for static_entity in entity_container.get_children():
|
||||
enroll_entity(static_entity)
|
||||
|
||||
for save_data in saved_entities_data:
|
||||
var entity = save_data.load()
|
||||
if entity:
|
||||
@@ -57,14 +62,6 @@ func create_entity_container() -> Node2D:
|
||||
|
||||
add_child(container)
|
||||
|
||||
if import_entities_from_node:
|
||||
for child in import_entities_from_node.get_children():
|
||||
add_entity(
|
||||
child,
|
||||
child.global_position + (container.global_position - import_entities_from_node.global_position),
|
||||
container
|
||||
)
|
||||
|
||||
return container
|
||||
|
||||
func drop_item(item: Item, item_position : Vector2, random_displacement_factor = 0) -> ItemObject:
|
||||
|
||||
Reference in New Issue
Block a user