Search in sources :

Example 1 with JsonProcessor

use of com.builtbroken.mc.lib.json.processors.JsonProcessor in project Engine by VoltzEngine-Project.

the class JsonContentLoader method processEntries.

/**
 * Called to process current entries that are loaded.
 * Only entries that have processors will be loaded
 * and then removed from the list of entries.
 */
protected void processEntries() {
    if (jsonEntries.size() > 0) {
        // Collect all entries to sort
        final ArrayList<String> processorKeys = new ArrayList();
        for (final JsonProcessor processor : processors.values()) {
            String jsonKey = processor.getJsonKey();
            String loadOrder = processor.getLoadOrder();
            if (loadOrder != null && !loadOrder.isEmpty()) {
                jsonKey += "@" + loadOrder;
            }
            processorKeys.add(jsonKey);
        }
        // Sort entries
        final List<String> sortingProcessorList = sortSortingValues(processorKeys);
        // Loop threw processors in order
        for (final String processorKey : sortingProcessorList) {
            process(processorKey);
        }
    }
}
Also used : JsonProcessor(com.builtbroken.mc.lib.json.processors.JsonProcessor)

Example 2 with JsonProcessor

use of com.builtbroken.mc.lib.json.processors.JsonProcessor in project Engine by VoltzEngine-Project.

the class JsonContentLoader method process.

/**
 * Called to process a json element entry into a
 * generated object
 *
 * @param key     - json processor key
 * @param element - data
 * @return true if it was processed and added to the generated object list
 */
public boolean process(String key, JsonElement element) {
    final JsonProcessor processor = processors.get(key);
    if (processor != null) {
        if (processor.canProcess(key, element)) {
            IJsonGenObject data = processor.process(element);
            data.register();
            if (data instanceof IRegistryInit) {
                ((IRegistryInit) data).onRegistered();
            }
            return generatedObjects.add(data);
        } else {
        // TODO add error handling
        }
    }
    return false;
}
Also used : IJsonGenObject(com.builtbroken.mc.lib.json.imp.IJsonGenObject) JsonProcessor(com.builtbroken.mc.lib.json.processors.JsonProcessor) IRegistryInit(com.builtbroken.mc.core.registry.implement.IRegistryInit)

Aggregations

JsonProcessor (com.builtbroken.mc.lib.json.processors.JsonProcessor)2 IRegistryInit (com.builtbroken.mc.core.registry.implement.IRegistryInit)1 IJsonGenObject (com.builtbroken.mc.lib.json.imp.IJsonGenObject)1