able to runClient, config saving works

This commit is contained in:
Daniella / Tove 2024-03-22 00:04:56 +01:00
parent 9c73c8de30
commit 6c0bb42b73
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
15 changed files with 97 additions and 20 deletions

View file

@ -3,10 +3,14 @@ package com.baseband.client;
import com.baseband.client.configuration.Updater;
import com.baseband.client.module.Module;
import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import javax.annotation.Nonnull;
import javax.swing.*;
import java.util.ArrayList;
@Mod(modid = "baseband_testing")
public class BaseBand {
public static BaseBand INSTANCE; { INSTANCE = this; }
@ -20,6 +24,12 @@ public class BaseBand {
updater.populate();
}
@Mod.EventHandler
public void onInit(FMLPostInitializationEvent event) {
onInit();
}
public void onInit() {
mc = Minecraft.getMinecraft();
@ -28,6 +38,27 @@ public class BaseBand {
for (int i = 0; i < modules.length; i++) {
modules[i].register(this, mc);
}
for (Updater updater : updaters) {
System.out.println("populating updater " + updater);
updater.populate();
}
new Thread(() -> {
while (true) {
for (Updater updater : updaters) {
System.out.println("polling updater " + updater);
updater.poll();
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}).start();
new Thread(() -> JOptionPane.showMessageDialog(null, "Gaming")).start();
}
@Nonnull

View file

@ -2,7 +2,7 @@ package com.baseband.client;
import com.baseband.client.module.Module;
import com.baseband.client.module.command.Test;
import de.tudbut.parsing.TCN;
import com.baseband.client.module.render.ClickGUI;
/**
* @author TudbuT
@ -14,6 +14,7 @@ public class Setup {
public final String REGISTRY_FILENAME = "baseband.db";
public final Module[] MODULES = new Module[] {
new Test(),
new ClickGUI()
};

View file

@ -25,8 +25,9 @@ public class ConfigHandle {
return tcn;
}
public void updated() {
public void updated(String id) {
for (Updater updater : onUpdate) {
if(updater.id.equals(id))
updater.onUpdateConfig();
}
}

View file

@ -1,11 +1,9 @@
package com.baseband.client.configuration;
import com.baseband.client.Setup;
import de.tudbut.parsing.TCN;
import de.tudbut.tools.Registry;
import java.io.IOException;
import java.util.HashMap;
public class Configuration {

View file

@ -1,5 +1,7 @@
package com.baseband.client.configuration;
import de.tudbut.tools.ReflectUtil;
import java.lang.reflect.Field;
public class Updater {
@ -13,6 +15,7 @@ public class Updater {
this.handle = handle;
this.o = o;
this.field = field;
ReflectUtil.forceAccessible(field);
}
void onUpdateConfig() {
@ -45,7 +48,7 @@ public class Updater {
field.getType() == double.class ||
field.getType() == boolean.class) {
handle.getContent().set(id, field.get(o));
handle.updated();
handle.updated(id);
} else {
throw new IllegalStateException("Unhandled type of field: " + field.getType());
}
@ -63,6 +66,7 @@ public class Updater {
}
public void populate() {
if(handle.getContent().get(id) != null)
onUpdateConfig();
}
@ -70,4 +74,9 @@ public class Updater {
this.id = id;
return this;
}
@Override
public String toString() {
return this.handle.name + "::" + this.id;
}
}

View file

@ -21,7 +21,7 @@ public class EnumButton extends Component {
int finalI = i;
subComponents.add(button = new Button(enums[i].toString(), it -> {
handle.getContent().set(field, finalI);
handle.updated();
handle.updated(field);
for (Component component : subComponents) {
component.green = false;
}

View file

@ -26,7 +26,6 @@ public class IntSlider extends Component {
this.mapper = mapper;
this.adder = adder;
this.updateMethod = updateMethod;
update();
}
public IntSlider(String s, ConfigHandle handle, String field, Function<Integer, String> text, int mapper, int adder) {
@ -51,7 +50,7 @@ public class IntSlider extends Component {
f = Math.max(Math.min(x, 100), 0) / 100f;
handle.getContent().set(field, Math.round(f * mapper + adder));
handle.updated();
handle.updated(field);
if(!updateMethod.apply(Math.round(f * mapper + adder))) {
System.out.println("Something went wrong handling the sliders!");
throw new RuntimeException();

View file

@ -26,7 +26,6 @@ public class Slider extends Component {
this.mapper = mapper;
this.adder = adder;
this.updateMethod = updateMethod;
update();
}
public Slider(String s, ConfigHandle handle, String field, Function<Float, String> text, float mapper, float adder) {
@ -51,7 +50,7 @@ public class Slider extends Component {
f = Math.max(Math.min(x, 100), 0) / 100f;
handle.getContent().set(field, f * mapper + adder);
handle.updated();
handle.updated(field);
if(!updateMethod.apply(f * mapper + adder)) {
System.out.println("Something went wrong handling the sliders!");
throw new RuntimeException();

View file

@ -12,14 +12,12 @@ public class ToggleButton extends Component {
this.text = s;
this.handle = handle;
this.field = field;
update();
}
public ToggleButton(String s, ConfigHandle handle, String field, Runnable lambda) {
this.lambda = lambda;
this.text = s;
this.handle = handle;
this.field = field;
update();
}
@Override
@ -31,7 +29,7 @@ public class ToggleButton extends Component {
public synchronized void click(int x, int y, int mouseButton) {
super.click(x, y, mouseButton);
handle.getContent().set(field, green);
handle.updated();
handle.updated(field);
if(lambda != null)
lambda.run();
}

View file

@ -3,20 +3,24 @@ package com.baseband.client.module;
import com.baseband.client.BaseBand;
import com.baseband.client.configuration.ConfigHandle;
import com.baseband.client.configuration.Configuration;
import com.baseband.client.module.category.Command;
import com.baseband.client.module.category.Render;
import com.baseband.client.util.FieldUtil;
import com.baseband.client.util.Marker;
import javax.annotation.Nonnull;
import java.lang.annotation.Annotation;
public enum Category {
COMMAND("Commands"),
RENDER("Render")
COMMAND("Commands", Command.class),
RENDER("Render", Render.class)
;
Category(String name) {
Category(String name, Class<? extends Annotation> annotationClass) {
this.name = name;
this.annotationClass = annotationClass;
try {
handle = Configuration.register("Category/" + name.toLowerCase().replace(' ', '_'));
BaseBand.registerUpdater(handle.linkWith(this, FieldUtil.findMarked(getClass(), 1)).name("x"));
@ -28,6 +32,7 @@ public enum Category {
}
}
private Class<? extends Annotation> annotationClass;
private ConfigHandle handle;
@Marker(1)
public int x;
@ -50,4 +55,8 @@ public enum Category {
}
return null;
}
public Class<? extends Annotation> getAnnotationClass() {
return annotationClass;
}
}

View file

@ -62,6 +62,11 @@ public abstract class Module extends ToggleButton {
this.bb = bbInst;
this.mc = mc;
for (Category c : Category.values()) {
if(getClass().getDeclaredAnnotation(c.getAnnotationClass()) != null)
category = c;
}
subComponents.clear();
ConfigHandle settings = config("Settings");
@ -99,7 +104,7 @@ public abstract class Module extends ToggleButton {
}
handle = settings;
BaseBand.registerUpdater(settings.linkWith(this, FieldUtil.findMarked(getClass(), 1)).name("Enabled"));
BaseBand.registerUpdater(settings.linkWith(this, FieldUtil.findMarked(Module.class, 1)).name("Enabled"));
setup();
}
@ -134,6 +139,7 @@ public abstract class Module extends ToggleButton {
try {
ConfigHandle h = Configuration.register(getID() + "/" + handle);
ownedHandles.put(handle, h);
System.out.println("Module " + toString() + " registered config: " + handle);
return h;
} catch (IllegalAccessException e) {
throw new RuntimeException(e);

View file

@ -0,0 +1,11 @@
package com.baseband.client.module.category;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Command {
}

View file

@ -0,0 +1,11 @@
package com.baseband.client.module.category;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Render {
}

View file

@ -3,17 +3,19 @@ package com.baseband.client.module.command;
import com.baseband.client.configuration.annotation.Config;
import com.baseband.client.configuration.annotation.Range;
import com.baseband.client.module.Module;
import com.baseband.client.module.category.Command;
/**
* @author TudbuT
*
* Self-Test command, checks if everything is working
*/
@Command
public class Test extends Module {
@Config("Int Setting")
@Range("0..10")
private int intSetting = 5;
public int intSetting = 5;
@Override

View file

@ -3,7 +3,9 @@ package com.baseband.client.module.render;
import com.baseband.client.configuration.annotation.Config;
import com.baseband.client.gui.GuiTTC;
import com.baseband.client.module.Module;
import com.baseband.client.module.category.Render;
@Render
public class ClickGUI extends Module {
@Config("Mouse Fix")
public boolean mouseFix;