generated from W-OVERFLOW/MixinModTemplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
201 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/dummy/java/cc/polyfrost/oneconfig/internal/config/annotations/Option.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package cc.polyfrost.oneconfig.internal.config.annotations; | ||
|
||
public @interface Option { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/org/polyfrost/glintcolorizer/mixin/oneconfig/ConfigMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.polyfrost.glintcolorizer.mixin.oneconfig; | ||
|
||
import cc.polyfrost.oneconfig.config.Config; | ||
import cc.polyfrost.oneconfig.config.core.ConfigUtils; | ||
import cc.polyfrost.oneconfig.config.data.Mod; | ||
import cc.polyfrost.oneconfig.config.elements.BasicOption; | ||
import cc.polyfrost.oneconfig.config.elements.OptionPage; | ||
import cc.polyfrost.oneconfig.internal.config.annotations.Option; | ||
import org.polyfrost.glintcolorizer.config.ColorEntry; | ||
import org.polyfrost.glintcolorizer.config.ColorSettings; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.ModifyVariable; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
|
||
@Mixin(value = Config.class, remap = false) | ||
public class ConfigMixin { | ||
|
||
@Unique | ||
private transient OptionPage page; | ||
@Unique | ||
private transient Object instance; | ||
|
||
@Inject(method = "generateOptionList(Ljava/lang/Object;Ljava/lang/Class;Lcc/polyfrost/oneconfig/config/elements/OptionPage;Lcc/polyfrost/oneconfig/config/data/Mod;Z)V", at = @At("HEAD")) | ||
private void capture(Object instance, Class<?> targetClass, OptionPage page, Mod mod, boolean migrate, CallbackInfo ci) { | ||
this.instance = instance; | ||
this.page = page; | ||
} | ||
|
||
@ModifyVariable(method = "generateOptionList(Ljava/lang/Object;Ljava/lang/Class;Lcc/polyfrost/oneconfig/config/elements/OptionPage;Lcc/polyfrost/oneconfig/config/data/Mod;Z)V", at = @At(value = "LOAD", ordinal = 0), name = "field") | ||
private Field generate(Field field) { | ||
if (field.isAnnotationPresent(ColorEntry.class)) { | ||
addOptions(page, field, instance); | ||
} | ||
return field; | ||
} | ||
|
||
@Unique | ||
private void addOptions(OptionPage page, Field field, Object instance) { | ||
ColorEntry annotation = field.getAnnotation(ColorEntry.class); | ||
ColorSettings colorSettings = (ColorSettings) ConfigUtils.getField(field, instance); | ||
for (BasicOption option : glintColorizer$getClassOptions(colorSettings)) { | ||
ConfigUtils.getSubCategory(page, annotation.category(), option.subcategory).options.add(option); | ||
} | ||
} | ||
|
||
@Unique | ||
private static ArrayList<BasicOption> glintColorizer$getClassOptions(Object object) { | ||
ArrayList<BasicOption> options = new ArrayList<>(); | ||
ArrayList<Field> fields = ConfigUtils.getClassFields(object.getClass()); | ||
for (Field field : fields) { | ||
Option option = ConfigUtils.findAnnotation(field, Option.class); | ||
if (option == null) continue; | ||
options.add(ConfigUtils.getOption(option, field, object)); | ||
} | ||
return options; | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
src/main/kotlin/org/polyfrost/glintcolorizer/config/ColorEntry.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package org.polyfrost.glintcolorizer.config | ||
|
||
@Target(AnnotationTarget.FIELD) | ||
annotation class ColorEntry(val category: String = "General") |
56 changes: 56 additions & 0 deletions
56
src/main/kotlin/org/polyfrost/glintcolorizer/config/ColorSettings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.polyfrost.glintcolorizer.config | ||
|
||
import cc.polyfrost.oneconfig.config.annotations.* | ||
import cc.polyfrost.oneconfig.config.core.ConfigUtils | ||
import cc.polyfrost.oneconfig.config.core.OneColor | ||
|
||
class ColorSettings { | ||
|
||
@Button( | ||
name = "Reset Held Glint Colors", | ||
subcategory = "Configuration", | ||
text = "Reset", | ||
description = "Resets ALL custom glint colors." | ||
) | ||
var resetColor = Runnable { | ||
reset(false) | ||
} | ||
|
||
@Switch( | ||
name = "Modify Strokes Individually", | ||
subcategory = "Color" | ||
) | ||
var individualStrokes = false | ||
|
||
@Color( | ||
name = "Glint Color", | ||
subcategory = "Color", | ||
description = "Modifies the color of the enchantment glint." | ||
) | ||
var glintColor = OneColor(GlintConfig.defaultColor) | ||
|
||
@Color( | ||
name = "Stroke 1 Color", | ||
subcategory = "Color", | ||
description = "Modifies the first stroke of the enchantment glint effect." | ||
) | ||
var strokeOneColor = OneColor(GlintConfig.defaultColor) | ||
|
||
@Color( | ||
name = "Stroke 2 Color", | ||
subcategory = "Color", | ||
description = "Modifies the second stroke of the enchantment glint effect." | ||
) | ||
var strokeTwoColor = OneColor(GlintConfig.defaultColor) | ||
|
||
fun reset(resetAll: Boolean) { | ||
val target = ColorSettings() | ||
val newFields = ConfigUtils.getClassFields(target::class.java) | ||
val fields = ConfigUtils.getClassFields(this::class.java) | ||
for (i in 0 until fields.size) { | ||
if (!resetAll && fields[i].type != OneColor::class.java) continue | ||
fields[i].set(this, ConfigUtils.getField(newFields[i], target)) | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.