Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose configuration file for other resources #13

Merged
merged 1 commit into from
Jul 26, 2024

Conversation

ktx-mega
Copy link
Contributor

@ktx-mega ktx-mega commented Jul 8, 2024

One might want to dynamically update the content of the config.lua of this resource.

In order to do that, I propose to expose encapsulation methods in order to let other resources interact directly with the configuration at runtime.

Here's a basic usage example :

-- Use encapsulation to fetch current configuration
local esx_animations_config = exports['esx_animations']:GetConfig()

-- Manipulate the configuration
local items = {}
for _, emote in pairs(data) do
    table.insert(items, {label = emote.data.name, type = "anim", data = {lib = emote.data.lib, anim = emote.data.anim }})
end
	
local newAnimCategory = {
    name  = 'custom',
    label = 'Custom',
    items = items,
}

-- Find & replace or insert
for i, obj in ipairs(esx_animations_config.Animations) do
    if obj.name == "custom" then
        esx_animations_config.Animations[i] = newAnimCategory
        exports['esx_animations']:SetConfig(esx_animations_config)
        return
    end
end
table.insert(esx_animations_config.Animations, newAnimCategory)

-- Use encapsulation to update current configuration
exports['esx_animations']:SetConfig(esx_animations_config)

@Gellipapa
Copy link
Contributor

@ktx-mega Hi! It's okey, thanks for implemented this feature.

@Gellipapa Gellipapa merged commit ca8b263 into esx-framework:main Jul 26, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants