Khaligufzel / Dimensionfall

A survival game inspired by Cataclysm: Dark Days Ahead and Bright Nights.
MIT License
12 stars 5 forks source link

Container icons are not accurately updated after loading a map #182

Closed snipercup closed 3 months ago

snipercup commented 4 months ago

The container icons on top of furniture stays grey even if there are items in the container after a map is loaded.

Steps to reproduce:

When a furniturestatic is loaded, it will deserialize the container inventory:

# It will deserialize the container data if the furniture is not new.
func deserialize_container_data():
    if "items" in furnitureJSON["Function"]["container"]:
        container.get_inventory().deserialize(furnitureJSON["Function"]["container"]["items"])
    else:
        print_debug("No items to deserialize in container for furniture ID: " + str(furnitureJSON.id))

Summary of Item Spawning in Containers

When a piece of furniture with container functionality is added to the scene, the following process occurs to manage item spawning:

  1. Adding a Container Node:

    • The add_container(pos: Vector3) function checks if the furniture has a container functionality based on its JSON data.
    • If the furniture is confirmed to have a container function, a new ContainerItem node is created, initialized, and added as a child to the furniture.
  2. Handling Container Population:

    • The handle_container_population() function determines whether the furniture is new or previously saved.
    • If the furniture is new, it populates the container with items from an assigned item group using the populate_container_from_itemgroup() function.
    • If the furniture is not new, it deserializes the existing container data using the deserialize_container_data() function.
  3. Populating from Item Group:

    • The populate_container_from_itemgroup() function checks if an item group is assigned to the container in the furniture's data.
    • If an item group is found, it assigns this group to the container, which will use it to fill up with items.
    • If no item group is found, a debug message is printed.
  4. Deserializing Container Data:

    • The deserialize_container_data() function checks for existing items in the container's data.
    • If items are found, they are deserialized and loaded into the container's inventory.
    • If no items are found, a debug message is printed.