Skip to content

Commit

Permalink
Merge branch 'dev' into 1.19.4-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
StavWasPlayZ committed Aug 27, 2023
2 parents 45233ff + 7c5c7a9 commit e725f91
Showing 1 changed file with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.HashMap;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

import org.slf4j.Logger;

Expand All @@ -14,6 +15,7 @@
import com.google.gson.JsonParser;
import com.mojang.logging.LogUtils;

import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
Expand Down Expand Up @@ -153,25 +155,29 @@ public static void registerReloadEvent(final RegisterClientReloadListenersEvent

@Override
public void onResourceManagerReload(ResourceManager resourceManager) {
// Handle global resource packs
isGlobalThemed = false;
InstrumentThemeLoader.reload(resourceManager);
}

});
}

try {
isGlobalThemed = JsonParser.parseReader(resourceManager.getResource(INSTRUMENTS_META_LOC).get().openAsReader())
.getAsJsonObject().get("is_global_pack").getAsBoolean();
private static void reload(final ResourceManager resourceManager) {
// Handle global resource packs
isGlobalThemed = false;

if (isGlobalThemed)
LOGGER.info("Instrument global themes enabled; loading all instrument resources from "+GLOBAL_LOC);
} catch (Exception e) {}
try {
isGlobalThemed = JsonParser.parseReader(resourceManager.getResource(INSTRUMENTS_META_LOC).get().openAsReader())
.getAsJsonObject().get("is_global_pack").getAsBoolean();

if (isGlobalThemed)
LOGGER.info("Instrument global themes enabled; loading all instrument resources from "+GLOBAL_LOC);
} catch (Exception e) {}

for (final InstrumentThemeLoader instrumentLoader : LOADERS)
instrumentLoader.performReload(resourceManager);

CACHES.clear();
}
});
for (final InstrumentThemeLoader instrumentLoader : LOADERS)
instrumentLoader.performReload(resourceManager);

CACHES.clear();
}

private void performReload(final ResourceManager resourceManager) {
Expand Down Expand Up @@ -225,31 +231,41 @@ public ResourceLocation getStylerLocation() {


public Color getNoteTheme() {
return noteTheme;
return getTheme(() -> noteTheme);
}
public void setNoteTheme(Color noteTheme) {
this.noteTheme = noteTheme;
}

public Color getPressedNoteTheme() {
return pressedNoteTheme;
return getTheme(() -> pressedNoteTheme);
}
public void setPressedNoteTheme(Color pressedNoteTheme) {
this.pressedNoteTheme = pressedNoteTheme;
}

public Color getLabelTheme() {
return labelTheme;
return getTheme(() -> labelTheme);
}
public void setLabelTheme(Color labelTheme) {
this.labelTheme = labelTheme;
}

public Color getNoteRingTheme() {
return noteRingTheme;
return getTheme(() -> noteRingTheme);
}
public void setNoteRingTheme(Color noteRingTheme) {
this.noteRingTheme = noteRingTheme;
}


protected <T> T getTheme(final Supplier<T> theme) {
if (theme.get() == null) {
LOGGER.warn("Requested theme not found, performing reload!");
performReload(Minecraft.getInstance().getResourceManager());
}

return theme.get();
}

}

0 comments on commit e725f91

Please sign in to comment.