Skip to content

Commit

Permalink
Further remove things from ModuleLoader.INSTANCE
Browse files Browse the repository at this point in the history
  • Loading branch information
quat1024 committed Oct 26, 2023
1 parent c2d1a26 commit 0fc95cc
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 59 deletions.
33 changes: 0 additions & 33 deletions src/main/java/vazkii/quark/base/module/ModuleLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import vazkii.quark.base.Quark;
import vazkii.quark.base.block.IQuarkBlock;
import vazkii.quark.base.item.IQuarkItem;
import vazkii.quark.base.module.config.ConfigFlagManager;
import vazkii.zeta.event.ZRegister;
import vazkii.zeta.event.bus.LoadEvent;
import vazkii.zeta.module.ZetaModule;

//TODO ZETA: im in the process of stripping this class for parts
Expand All @@ -17,30 +14,8 @@ public final class ModuleLoader {

public static final ModuleLoader INSTANCE = new ModuleLoader();

//private ConfigResolver config;
public Runnable onConfigReloadJEI;

private ModuleLoader() { }

public void start() {
//config = new ConfigResolver();
//config.makeSpec();
}

public ConfigFlagManager getConfigFlagManager() {
return Quark.ZETA.weirdConfigSingleton.getConfigFlagManager();
}

@LoadEvent
public void register(ZRegister event) {
}

public void configChanged() {
//if (onConfigReloadJEI != null)
// onConfigReloadJEI.run();
//config.configChanged();
}

//tempting to push this method directly through to Quark.ZETA.modules...
//but i think it's more appropriate to have this stored in a configuration class
@Deprecated
Expand Down Expand Up @@ -71,12 +46,4 @@ else if(i instanceof BlockItem bi) {
return true;
}

/**
* Meant only to be called internally.
*/
public void initJEICompat(Runnable jeiRunnable) {
onConfigReloadJEI = jeiRunnable;
onConfigReloadJEI.run();
}

}
11 changes: 5 additions & 6 deletions src/main/java/vazkii/quark/base/proxy/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void setup(ZCommonSetup event) {

@LoadEvent
public void register(ZRegister heck) {
Quark.ZETA.weirdConfigSingleton.getConfigFlagManager().registerConfigBoundElements();
Quark.ZETA.configManager.getConfigFlagManager().registerConfigBoundElements();
}

//forge event
Expand All @@ -118,14 +118,13 @@ public void setConfigGuiSaving(boolean saving) {
lastConfigChange = Quark.ZETA.ticker_SHOULD_NOT_BE_HERE.ticksInGame;
}

//TODO: mess, find a better spot for this
//TODO: probably find a better spot for this? It's not *only* fired when the
// config file is externally changed, but also when it's changed through config GUI,
// which means we roundtrip through the on-disk representation for no good reason
public void handleQuarkConfigChange() {
//ModuleLoader.INSTANCE.configChanged();
Quark.ZETA.weirdConfigSingleton.runDatabindings(Quark.ZETA.configInternals);
//Quark.ZETA.weirdConfigSingleton.getConfigFlagManager().clear();
Quark.ZETA.configManager.onReload();
Quark.ZETA.loadBus.fire(new ZConfigChanged());
if(ModuleLoader.INSTANCE.onConfigReloadJEI != null)
ModuleLoader.INSTANCE.onConfigReloadJEI.run();
EntitySpawnHandler.refresh();
SyncedFlagHandler.sendFlagInfoToPlayers();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void onRuntimeAvailable(@Nonnull final IJeiRuntime jeiRuntime) {
if (!disabledItems.isEmpty())
jeiRuntime.getIngredientManager().removeIngredientsAtRuntime(VanillaTypes.ITEM_STACK, disabledItems);

ModuleLoader.INSTANCE.initJEICompat(() -> {
Quark.ZETA.configManager.setJeiReloadListener(z -> {
if(ModuleLoader.INSTANCE.isModuleEnabled(DiamondRepairModule.class))
Minecraft.getInstance().submitAsync(() -> hideAnvilRepairRecipes(jeiRuntime.getRecipeManager()));

Expand Down
15 changes: 9 additions & 6 deletions src/main/java/vazkii/zeta/Zeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import vazkii.zeta.client.ClientTicker;
import vazkii.zeta.config.IZetaConfigInternals;
import vazkii.zeta.config.SectionDefinition;
import vazkii.zeta.config.WeirdConfigSingleton;
import vazkii.zeta.config.ConfigManager;
import vazkii.zeta.event.bus.IZetaLoadEvent;
import vazkii.zeta.event.bus.IZetaPlayEvent;
import vazkii.zeta.event.bus.LoadEvent;
Expand Down Expand Up @@ -51,7 +51,7 @@ public Zeta(String modid, Logger log) {
public final ZetaRegistry registry;
public final DyeablesRegistry dyeables; //TODO: move into ZetaRegistry?

public WeirdConfigSingleton weirdConfigSingleton; //Should probably split this up into various parts
public ConfigManager configManager; //This could do with being split up into various pieces
public IZetaConfigInternals configInternals;

//TODO: move to ZetaClient. Some bits of the server *do* actually need this for some raisin (config code)
Expand All @@ -61,11 +61,14 @@ public void loadModules(Iterable<ZetaCategory> categories, ModuleFinder finder,
modules.initCategories(categories);
modules.load(finder);

this.weirdConfigSingleton = new WeirdConfigSingleton(this, rootPojo);
this.configInternals = makeConfigInternals(weirdConfigSingleton.getRootConfig());
//The reason why there's a circular dependency between configManager and configInternals:
// - ConfigManager determines the shape and layout of the config file
// - The platform-specific configInternals loads the actual values, from the platform-specfic config file
// - Only then can ConfigManager do the initial config load

//the initial config load (TODO: might need to find a better spot for this)
weirdConfigSingleton.runDatabindings(configInternals);
this.configManager = new ConfigManager(this, rootPojo);
this.configInternals = makeConfigInternals(configManager.getRootConfig());
this.configManager.onReload();
}

public abstract ZetaSide getSide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected void init() {
super.init();

List<ZetaCategory> categories = z.modules.getInhabitedCategories();
@Nullable SectionDefinition generalSection = z.weirdConfigSingleton.getGeneralSection();
@Nullable SectionDefinition generalSection = z.configManager.getGeneralSection();

int buttonCount = categories.size();
if(generalSection != null)
Expand All @@ -57,8 +57,8 @@ protected void init() {
if(i < categories.size()) {
//a category button
ZetaCategory category = categories.get(i);
ValueDefinition<Boolean> categoryEnabled = z.weirdConfigSingleton.getCategoryEnabledOption(category);
SectionDefinition categorySection = z.weirdConfigSingleton.getCategorySection(category);
ValueDefinition<Boolean> categoryEnabled = z.configManager.getCategoryEnabledOption(category);
SectionDefinition categorySection = z.configManager.getCategorySection(category);

bWidth -= 20; //room for the checkbox
Button mainButton = addRenderableWidget(new CategoryButton(zc, x, y, bWidth, 20, componentFor(categorySection), category.icon.get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
import vazkii.zeta.module.ZetaModule;
import vazkii.zeta.module.ZetaModuleManager;

//TODO: find somewhere better to put this, better data structure etc
public class WeirdConfigSingleton {
public class ConfigManager {
private final Zeta z;
private final ConfigFlagManager cfm = new ConfigFlagManager();
private final SectionDefinition rootConfig;

//for updating the values of @Config annotations to match the current state of the config
// and other "listening for config load" purposes
private final List<Consumer<IZetaConfigInternals>> databindings = new ArrayList<>();
private Consumer<IZetaConfigInternals> onConfigReloadJEI;

//ummmmmmm i think my abstraction isn't very good
private final @Nullable SectionDefinition generalSection;
Expand All @@ -36,7 +37,7 @@ public class WeirdConfigSingleton {
//state
private final Set<ZetaCategory> enabledCategories = new HashSet<>();

public WeirdConfigSingleton(Zeta z, Object rootPojo) {
public ConfigManager(Zeta z, Object rootPojo) {
this.z = z;

ZetaModuleManager modules = z.modules;
Expand Down Expand Up @@ -100,7 +101,7 @@ public SectionDefinition getRootConfig() {
return rootConfig;
}

// bad bad bad
// mapping between internal and external representations of the config (?)

public @Nullable SectionDefinition getGeneralSection() {
return generalSection;
Expand Down Expand Up @@ -140,13 +141,21 @@ public boolean isCategoryEnabled(ZetaCategory cat) {
return enabledCategories.contains(cat);
}

//ummm
// ummm

public ConfigFlagManager getConfigFlagManager() {
return cfm;
}

public void runDatabindings(IZetaConfigInternals internals) {
public void onReload() {
IZetaConfigInternals internals = z.configInternals;
databindings.forEach(c -> c.accept(internals));

if(onConfigReloadJEI != null)
onConfigReloadJEI.accept(internals);
}

public void setJeiReloadListener(Consumer<IZetaConfigInternals> consumer) {
this.onConfigReloadJEI = consumer;
}
}
7 changes: 3 additions & 4 deletions src/main/java/vazkii/zeta/module/ZetaModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
import java.util.List;
import java.util.Set;

import com.google.common.collect.Lists;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.loading.FMLEnvironment;
import vazkii.quark.base.module.ModuleLoader;
import vazkii.quark.base.module.hint.HintManager;
import vazkii.quark.base.module.hint.HintObject;
import vazkii.zeta.Zeta;
import vazkii.zeta.event.ZGatherHints;
import vazkii.zeta.event.bus.PlayEvent;

public class ZetaModule {
public Zeta zeta;
public ZetaCategory category = null;

public String displayName = "";
Expand Down Expand Up @@ -45,7 +44,7 @@ public final void setEnabled(Zeta z, boolean willEnable) {
configEnabled = willEnable;

//TODO: i messed up the category enabled stuff, Its Weird now
if(z.weirdConfigSingleton != null && !z.weirdConfigSingleton.isCategoryEnabled(category))
if(z.configManager != null && !z.configManager.isCategoryEnabled(category))
willEnable = false;

disabledByOverlap = false;
Expand Down Expand Up @@ -80,7 +79,7 @@ private void setEnabledAndManageSubscriptions(Zeta z, boolean nowEnabled) {
@PlayEvent
public final void addAnnotationHints(ZGatherHints event) {
if(annotationHints == null)
annotationHints = HintManager.gatherHintAnnotations(ModuleLoader.INSTANCE.getConfigFlagManager(), this);
annotationHints = HintManager.gatherHintAnnotations(zeta.configManager.getConfigFlagManager(), this);

for(HintObject hint : annotationHints)
hint.apply(event);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/vazkii/zeta/module/ZetaModuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ private ZetaModule constructAndSetup(TentativeModule t) {
LEGACY_actuallySubscribe = true;
}

module.zeta = z;
module.category = t.category();

module.displayName = t.displayName();
Expand Down

0 comments on commit 0fc95cc

Please sign in to comment.