Skip to content

Introducing DataContainers#156

Open
MiquelBarbara wants to merge 43 commits into
mainfrom
feature/data_objects
Open

Introducing DataContainers#156
MiquelBarbara wants to merge 43 commits into
mainfrom
feature/data_objects

Conversation

@MiquelBarbara

Copy link
Copy Markdown
Contributor

Description

This PR introduces a new type of asset called DataContainers, designed to mimic the behavior of Unity’s ScriptableObjects.

The main goal is to provide a centralized way to modify enemy (and other gameplay) configuration without needing to recreate prefabs, enabling faster iteration during testing and balancing phases.


Changes

New Asset Type: DataContainers

  • Added a new asset type called DataContainer.

  • DataContainers allow configuration data to be stored independently from prefabs and scripts.

  • This enables:

    • Centralized configuration changes
    • Faster iteration during testing
    • Decoupling configuration from implementation

Creating a DataContainer

To create a new DataContainer:

  1. Define a class that inherits from DataContainer.
  2. Declare and expose the required configuration fields, following the same exposure pattern used for Scripts.

Example:

#pragma once

#include "DataContainerAPI.h"

class BoundConfig : public DataContainer
{
    DECLARE_DATACONTAINER(BoundConfig)

public:
    BoundConfig() = default;
    explicit BoundConfig(AssetReference& id)
        : DataContainer(id)
    {
    }

    float m_minDistance = 70.0f;
    float m_distanceDamage = 80.0f;
    float m_distanceInstaKill = 100.0f;
    float m_baseDamage = 20.0f;
    float m_maxDamage = 40.0f;
    float m_radiusThreshold = 2.0f;

    IMPLEMENT_DATACONTAINER_FIELDS(BoundConfig,
        SERIALIZED_FLOAT(m_minDistance, "Min Distance", 0.0f, 200.0f, 1.0f),
        SERIALIZED_FLOAT(m_distanceDamage, "Damage Distance", 0.0f, 200.0f, 1.0f),
        SERIALIZED_FLOAT(m_distanceInstaKill, "Insta Kill Distance", 0.0f, 200.0f, 1.0f),
        SERIALIZED_FLOAT(m_baseDamage, "Base Damage", 0.0f, 100.0f, 1.0f),
        SERIALIZED_FLOAT(m_maxDamage, "Max Damage", 0.0f, 100.0f, 1.0f),
        SERIALIZED_FLOAT(m_radiusThreshold, "Radius Threshold", 0.0f, 10.0f, 0.1f)
    )
};

IMPLEMENT_DATACONTAINER(BoundConfig)

Using DataContainers in Scripts

  • Scripts can reference DataContainers using the ScriptDataContainerRef wrapper.

  • This enables drag-and-drop assignment of configuration assets.

  • Benefits:

    • Full decoupling between configuration and logic

    • Support for inheritance, allowing:

      • Base configurations shared across multiple scripts
      • Specialized configurations that extend the base data

Editor Integration

  • Once the .h file is created, new DataContainers of the available types can be created from the Assets menu (top-left).

  • Added a new editor window:

    • WindowDataContainerManager
  • This window provides centralized, global management of all DataContainers in the project.

…*, Script&, ScriptComponent&) to void (*)(const FieldInfo&, void*, IFieldContainer&). All 11 handler .cpp files updated. Dummy DataContainerScriptDummy/DataContainerComponentDummy classes removed from DataContainer.cpp.
… deserialize, clone, fixReferences). ScriptComponent.cpp methods are now 1-line delegations. DataContainer.cpp uses FieldUtils for all field loops. The same code that was duplicated across 6 methods now lives in one place.
…), serializeScriptFields (60 lines), deserializeScriptFields (80 lines) — replaced by FieldUtils::drawUi/serialize/deserialize calls. ~450 lines of manual switch(field.type) eliminated. The component now uses the same FieldHandler dispatch as ScriptComponent and DataContainer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant