aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/features
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/features')
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/features/AbstractFeature.java64
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/features/FeatureParameter.java16
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java49
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java73
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/features/SimpleFeature.java10
5 files changed, 212 insertions, 0 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/AbstractFeature.java b/src/main/java/kr/syeyoung/dungeonsguide/features/AbstractFeature.java
new file mode 100644
index 00000000..4964ee5f
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/features/AbstractFeature.java
@@ -0,0 +1,64 @@
+package kr.syeyoung.dungeonsguide.features;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import kr.syeyoung.dungeonsguide.config.types.TypeConverter;
+import kr.syeyoung.dungeonsguide.config.types.TypeConverterRegistry;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.*;
+
+public abstract class AbstractFeature {
+ @Getter
+ private final String category;
+ @Getter
+ private final String name;
+
+ @Getter
+ private final String description;
+
+ @Getter
+ private final String key;
+
+ protected Map<String, FeatureParameter> parameters = new HashMap<String, FeatureParameter>();
+
+ protected AbstractFeature(String category, String name, String description, String key) {
+ this.category = category;
+ this.name = name;
+ this.description = description;
+ this.key = key;
+ }
+
+ @Getter
+ @Setter
+ private boolean enabled = false;
+
+ public void drawWorld(float partialTicks) {}
+ public void drawScreen(float partialTicks) {}
+
+ public List<FeatureParameter> getParameters() { return new ArrayList<FeatureParameter>(parameters.values()); }
+
+
+
+ public void loadConfig(JsonObject jsonObject) { // gets key, calls it
+ enabled = jsonObject.get("$enabled").getAsBoolean();
+ for (Map.Entry<String, FeatureParameter> parameterEntry : parameters.entrySet()) {
+ JsonElement element = jsonObject.get(parameterEntry.getKey());
+ if (element == null) continue;
+ TypeConverter typeConverter = TypeConverterRegistry.getTypeConverter(parameterEntry.getValue().getValue_type());
+ parameterEntry.getValue().setValue(typeConverter.deserialize(element));
+ }
+ }
+
+ public JsonObject saveConfig() {
+ JsonObject object = new JsonObject();
+ for (Map.Entry<String, FeatureParameter> parameterEntry : parameters.entrySet()) {
+ TypeConverter typeConverter = TypeConverterRegistry.getTypeConverter(parameterEntry.getValue().getValue_type());
+ JsonElement obj = typeConverter.serialize(parameterEntry.getValue().getValue());
+ object.add(parameterEntry.getKey(), obj);
+ }
+ object.addProperty("$enabled", isEnabled());
+ return object;
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureParameter.java b/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureParameter.java
new file mode 100644
index 00000000..98532d1b
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureParameter.java
@@ -0,0 +1,16 @@
+package kr.syeyoung.dungeonsguide.features;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public class FeatureParameter<T> {
+ private String key;
+
+ private String name;
+ private String description;
+
+ private T value;
+ private String value_type;
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java b/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java
new file mode 100644
index 00000000..67d1e971
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureRegistry.java
@@ -0,0 +1,49 @@
+package kr.syeyoung.dungeonsguide.features;
+
+import lombok.Getter;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class FeatureRegistry {
+ @Getter
+ private static List<AbstractFeature> featureList = new ArrayList<AbstractFeature>();
+ private static Map<String, AbstractFeature> featureByKey = new HashMap<String, AbstractFeature>();
+ @Getter
+ private static Map<String, List<AbstractFeature>> featuresByCategory = new HashMap<String, List<AbstractFeature>>();
+
+ public static AbstractFeature getFeatureByKey(String key) {
+ return featureByKey.get(key);
+ }
+
+ public static AbstractFeature register(AbstractFeature abstractFeature) {
+ featureList.add(abstractFeature);
+ featureByKey.put(abstractFeature.getKey(), abstractFeature);
+ List<AbstractFeature> features = featuresByCategory.get(abstractFeature.getCategory());
+ if (features == null)
+ features = new ArrayList<AbstractFeature>();
+ features.add(abstractFeature);
+ featuresByCategory.put(abstractFeature.getCategory(), features);
+
+ return abstractFeature;
+ }
+
+ public static final AbstractFeature SOLVER_RIDDLE = register(new SimpleFeature("solver", "Riddle Puzzle (3 weirdo) Solver", "Highlights the correct box after clicking on all 3 weirdos", "solver.riddle"));
+ public static final AbstractFeature SOLVER_KAHOOT = register(new SimpleFeature("solver", "Trivia Puzzle (Omnicrescent) Solver", "Highlights the correct solution for trivia puzzle", "solver.trivia"));
+ public static final AbstractFeature SOLVER_BLAZE = register(new SimpleFeature("solver", "Blaze Puzzle Solver", "Highlights the blaze that needs to be killed in an blaze room", "solver.blaze"));
+ public static final AbstractFeature SOLVER_TICTACTOE = register(new SimpleFeature("solver", "Tictactoe Solver", "Shows the best move that could be taken by player in the tictactoe room", "solver.tictactoe"));
+ public static final AbstractFeature SOLVER_ICEPATH = register(new SimpleFeature("solver", "Icepath Puzzle Solver (Advanced)", "Calculates solution for icepath puzzle and displays it to user", "solver.icepath"));
+ public static final AbstractFeature SOLVER_SILVERFISH = register(new SimpleFeature("solver", "Silverfish Puzzle Solver (Advanced)", "Actively calculates solution for silverfish puzzle and displays it to user", "solver.silverfish"));
+ public static final AbstractFeature SOLVER_WATERPUZZLE = register(new SimpleFeature("solver", "Waterboard Puzzle Solver (Advanced)", "Calculates solution for waterboard puzzle and displays it to user", "solver.waterboard"));
+ public static final AbstractFeature SOLVER_BOX = register(new SimpleFeature("solver", "Box Puzzle Solver (Advanced)", "Calculates solution for box puzzle room, and displays it to user", "solver.box"));
+ public static final AbstractFeature SOLVER_CREEPER = register(new SimpleFeature("solver", "Creeper Puzzle Solver", "Draws line between prismarine lamps in creeper room", "solver.creeper"));
+ public static final AbstractFeature SOLVER_TELEPORT = register(new SimpleFeature("solver", "Teleport Puzzle Solver", "Shows teleport pads you've visited in a teleport maze room", "solver.teleport"));
+
+ public static final AbstractFeature TOOLTIP_DUNGEONSTAT = register(new SimpleFeature("tooltip", "Dungeon Item Stats", "Shows quality of dungeon items (floor, percentage)", "tooltip.dungeonitem"));
+ public static final AbstractFeature TOOLTIP_PRICE = register(new SimpleFeature("tooltip", "Item Price", "Shows price of items", "tooltip.price"));
+
+ public static final AbstractFeature DEBUG = register(new SimpleFeature("advanced", "Debug", "Toggles debug mode", "debug"));
+
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java b/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java
new file mode 100644
index 00000000..d7b58dbc
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java
@@ -0,0 +1,73 @@
+package kr.syeyoung.dungeonsguide.features;
+
+import com.google.gson.JsonObject;
+import kr.syeyoung.dungeonsguide.config.types.TypeConverterRegistry;
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.Setter;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.ScaledResolution;
+import net.minecraft.client.renderer.OpenGlHelper;
+import org.lwjgl.opengl.GL11;
+
+import java.awt.*;
+
+@Getter
+public abstract class GuiFeature extends AbstractFeature {
+ @Setter
+ private Rectangle featureRect;
+ @Setter(value = AccessLevel.PROTECTED)
+ private boolean keepRatio;
+ @Setter(value = AccessLevel.PROTECTED)
+ private int defaultWidth;
+ @Setter(value = AccessLevel.PROTECTED)
+ private int defaultHeight;
+
+ protected GuiFeature(String category, String name, String description, String key, boolean keepRatio, int width, int height) {
+ super(category, name, description, key);
+ this.keepRatio = keepRatio;
+ this.defaultWidth = width;
+ this.defaultHeight = height;
+ this.featureRect = new Rectangle(0, 0, width, height);
+ }
+
+ @Override
+ public void drawScreen(float partialTicks) {
+ clip(new ScaledResolution(Minecraft.getMinecraft()), featureRect.x, featureRect.y, featureRect.width, featureRect.height);
+ GL11.glPushAttrib(GL11.GL_SCISSOR_BIT);
+ GL11.glEnable(GL11.GL_SCISSOR_TEST);
+
+ GL11.glEnable(GL11.GL_BLEND);
+ OpenGlHelper.glBlendFunc(770, 771, 1, 0);
+ GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
+
+ GL11.glPushMatrix();
+ GL11.glTranslated(featureRect.x, featureRect.y, 0);
+ drawHUD(partialTicks);
+ GL11.glPopMatrix();
+
+ GL11.glDisable(GL11.GL_SCISSOR_TEST);
+ GL11.glPopAttrib();
+ }
+
+ public abstract void drawHUD(float partialTicks);
+
+
+ private void clip(ScaledResolution resolution, int x, int y, int width, int height) {
+ int scale = resolution.getScaleFactor();
+ GL11.glScissor((x ) * scale, Minecraft.getMinecraft().displayHeight - (y + height) * scale, (width) * scale, height * scale);
+ }
+
+ @Override
+ public void loadConfig(JsonObject jsonObject) {
+ super.loadConfig(jsonObject);
+ featureRect = TypeConverterRegistry.getTypeConverter("rect", Rectangle.class).deserialize(jsonObject.get("$bounds"));
+ }
+
+ @Override
+ public JsonObject saveConfig() {
+ JsonObject object = super.saveConfig();
+ object.add("$bounds", TypeConverterRegistry.getTypeConverter("rect", Rectangle.class).serialize(featureRect));
+ return object;
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/SimpleFeature.java b/src/main/java/kr/syeyoung/dungeonsguide/features/SimpleFeature.java
new file mode 100644
index 00000000..cdeaaa44
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/features/SimpleFeature.java
@@ -0,0 +1,10 @@
+package kr.syeyoung.dungeonsguide.features;
+
+public class SimpleFeature extends AbstractFeature {
+ protected SimpleFeature(String category, String name, String key) {
+ super(category, name, name, key);
+ }
+ protected SimpleFeature(String category, String name, String description, String key) {
+ super(category, name, description, key);
+ }
+}