Skip to content

Configuration system

Bogdan T edited this page Jan 27, 2024 · 15 revisions

Here you will find the information how to take advantage of using the AtumCore configuration api

As you have probably already noticed the library has its own Config class, with more methods to use

Basics

How to create new config file?

AtumAPI.getInstance().createLoadableConfig()

image

It is automatically added to the ConfigManager of the AtumMod instance.

How to save&reload configs?

Use ConfigManager in AtumMod

image

Hey! Where the Config#getConfigurationSection method?!

No worries, it has been renamed to a more meaningful name - getSubsection()

Config Categories

Besides the single config files, you can create Configuration categories.

In a nutshell it is just the folder with configs and the configuration category contains & manages them

How to use it:

getConfigManager().addConfigCategory(ConfigCategory object)

ConfigCategory is an abstract class that has couple of important methods to implement.

Example:

  getConfigManager().addConfigCategory(new ConfigCategory(
            this,
            ConfigType.JSON,
            "display",
            "display",
            true) {
        private List<String> elements = new ArrayList<>();
        @Override
        protected void clear() {
            elements.forEach(it->getDisplayManager().getElementRegistry().unregisterTemplate(it));
        }
        @Override
        protected void acceptConfig(@NotNull String id, @NotNull Config config) {
            getAtumMod().getLogger().info("Loading display element with id " + id);
            if(getDisplayManager().getElementRegistry().getElementTemplate(id) != null) {
                getAtumMod().getLogger().warn("Display element with id " + id + 
                        " already added or is a default element!");
                return;
            }

            DisplayElement element = getDisplayManager().getElementRegistry()
                    .compileCanvasTemplate(id,config);
            if (element != null) {
                getDisplayManager().getElementRegistry().registerTemplate(id, element);
                elements.add(id);
            }
        }
    });

As you can see, here we use the config object to load the display template and on clear remove all loaded elements

Clone this wiki locally