Skip to content

Commit

Permalink
Merge pull request #172 from KosmX/configurable_emotes_dir
Browse files Browse the repository at this point in the history
Configurable emotes dir
  • Loading branch information
KosmX authored Nov 16, 2021
2 parents dc8a994 + fa9b51d commit dd0de91
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import io.github.kosmx.emotes.executor.dataTypes.IGetters;
import io.github.kosmx.emotes.arch.executor.types.GettersImpl;

import java.io.File;

public abstract class AbstractEmotesMain extends EmoteInstance {

@Override
Expand All @@ -18,9 +16,4 @@ public IDefaultTypes getDefaults() {
public IGetters getGetters() {
return new GettersImpl();
}

@Override
public File getExternalEmoteDir() {
return getGameDirectory().resolve("emotes").toFile();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import io.github.kosmx.emotes.executor.dataTypes.IGetters;
import io.github.kosmx.emotes.arch.executor.types.GettersImpl;

import java.io.File;

public abstract class AbstractEmotesMain extends EmoteInstance {

@Override
Expand All @@ -19,8 +17,4 @@ public IGetters getGetters() {
return new GettersImpl();
}

@Override
public File getExternalEmoteDir() {
return getGameDirectory().resolve("emotes").toFile();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,22 @@ protected void init() {
this.addWidget(options);
}

private void addConfigEntry(SerializableConfig.ConfigEntry<?> entry, OptionsList options){
if(entry.showEntry() || ((ClientConfig)EmoteInstance.config).showHiddenConfig.get()) {
private void addConfigEntry(SerializableConfig.ConfigEntry<?> entry, OptionsList options) {
if (entry.showEntry() || ((ClientConfig) EmoteInstance.config).showHiddenConfig.get()) {
if (entry instanceof SerializableConfig.BooleanConfigEntry) {
if(entry.hasTooltip) {
if (entry.hasTooltip) {
options.addBig(CycleOption.createOnOff("emotecraft.otherconfig." + entry.getName(),
new TranslatableComponent("emotecraft.otherconfig." + entry.getName() + ".tooltip"),
gameOptions -> ((SerializableConfig.BooleanConfigEntry) entry).get(),
(gameOptions, option, aBoolean) -> ((SerializableConfig.BooleanConfigEntry) entry).set(aBoolean)
));
}
else {
} else {
options.addBig(CycleOption.createOnOff("emotecraft.otherconfig." + entry.getName(),
gameOptions -> ((SerializableConfig.BooleanConfigEntry) entry).get(),
(gameOptions, option, aBoolean) -> ((SerializableConfig.BooleanConfigEntry) entry).set(aBoolean)
));
}
}
else if (entry instanceof SerializableConfig.FloatConfigEntry) {
} else if (entry instanceof SerializableConfig.FloatConfigEntry) {
SerializableConfig.FloatConfigEntry floatEntry = (SerializableConfig.FloatConfigEntry) entry;
options.addBig(new ProgressOption(
EmoteInstance.config.validThreshold.getName(), floatEntry.min, floatEntry.max, floatEntry.step,
Expand All @@ -103,8 +101,8 @@ else if (entry instanceof SerializableConfig.FloatConfigEntry) {
}
}

private void resetAll(boolean bl){
if(bl) {
private void resetAll(boolean bl) {
if (bl) {
EmoteInstance.config.iterate(SerializableConfig.ConfigEntry::resetToDefault);
this.init(); //reload screen
}
Expand All @@ -123,7 +121,7 @@ public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {

}

static class DummyEntry extends Option{
static class DummyEntry extends Option {

public DummyEntry(String key) {
super(key);
Expand All @@ -135,7 +133,7 @@ public AbstractWidget createButton(Options options, int x, int y, int width) {
}
}

static class DummyButton extends AbstractWidget{
static class DummyButton extends AbstractWidget {

public DummyButton(int x, int y, int width, int height, Component message) {
super(x, y, width, height, message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.github.kosmx.emotes.executor.dataTypes.IDefaultTypes;
import io.github.kosmx.emotes.executor.dataTypes.IGetters;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;

Expand Down Expand Up @@ -49,9 +48,4 @@ public boolean isClient() {
public Path getGameDirectory() {
return Paths.get("");
}

@Override
public File getExternalEmoteDir() {
return Paths.get("").resolve("emotes").toFile();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class SerializableConfig {
public final BooleanConfigEntry loadEmotesServerSide = new BooleanConfigEntry("loadEmotesServerSide", true, false, expert);
public final ConfigEntry<Boolean> enableQuark = new BooleanConfigEntry("quark", "enablequark", false, true, basics);

public final StringConfigEntry emotesDir = new StringConfigEntry("emotesDirectory", "emotes", false, expert, true);

public void iterate(Consumer<ConfigEntry<?>> consumer){
basics.forEach(consumer);
expert.forEach(consumer);
Expand Down Expand Up @@ -141,4 +143,18 @@ public T getTextVal(){
return (T) get();
}
}

public static class StringConfigEntry extends ConfigEntry<String> {
public StringConfigEntry(String name, String defVal, boolean hasTooltip, List<ConfigEntry<?>> collection, boolean hidden) {
super(name, null, defVal, hasTooltip, collection, hidden);
}

public StringConfigEntry(String name, String defVal, boolean hasTooltip, List<ConfigEntry<?>> collection) {
super(name, defVal, hasTooltip, collection);
}

public StringConfigEntry(String name, String defVal, List<ConfigEntry<?>> collection, boolean hidden) {
super(name, defVal, collection, hidden);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ else if(node.has(entry.getOldConfigName())){
else if(entry instanceof SerializableConfig.FloatConfigEntry){
((SerializableConfig.FloatConfigEntry)entry).set(element.getAsFloat());
}
else if(entry instanceof SerializableConfig.StringConfigEntry){
((SerializableConfig.StringConfigEntry)entry).set(element.getAsString());
}
}
}

Expand All @@ -65,6 +68,9 @@ private void serializeEntry(SerializableConfig.ConfigEntry<?> entry, JsonObject
else if(entry instanceof SerializableConfig.FloatConfigEntry){
node.addProperty(entry.getName(), (float)((SerializableConfig.FloatConfigEntry) entry).get());
}
else if(entry instanceof SerializableConfig.StringConfigEntry){
node.addProperty(entry.getName(), ((SerializableConfig.StringConfigEntry)entry).get());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ public abstract class EmoteInstance {
public abstract boolean isClient();

public abstract Path getGameDirectory();
public abstract File getExternalEmoteDir();

public File getExternalEmoteDir(){
return getGameDirectory().resolve(config.emotesDir.get()).toFile();
}

public Path getConfigPath(){
if(!Files.exists(getGameDirectory().resolve("config"))){
try {
Expand Down

0 comments on commit dd0de91

Please sign in to comment.