Skip to content

[Question] How to implement string-based data loading (lookup ID by name)? #41

@talesmm14

Description

@talesmm14

Hi,

I am migrating a project from Concord to evolved.lua and I rely heavily on data-driven loading from files (JSON/Lua tables).

In Concord, I have a generic loader that iterates over keys (strings) and maps them directly to components, like this:

-- My current workflow in Concord
function loadEntitiesFromFile(world, entities)
    for _, entityData in ipairs(entities) do
        local e = Concord.entity(world)
        for component_name, params in pairs(entityData) do
            -- "component_name" is a string (e.g., "position")
            -- Concord resolves this string to the component class automatically
            if type(params) == "table" then
                e:give(component_name, unpack(params))
            else
                e:give(component_name, params)
            end
        end
    end
end

In evolved.lua, Fragments are IDs generated at runtime.

My Question:
Is there a built-in mechanism or a helper function to retrieve a Fragment ID by its string name?

For example, if I define a fragment using the builder:

local Position = evolved.builder():name("position"):build()

Is there something like evolved.find_by_name("position") that returns the ID? Or is the only solution to manually maintain a global Table<String, ID> registry to map the file keys to the fragment IDs?

I am looking for a way to keep my generic loader working without hardcoding every single component mapping manually.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions