feat: introduce Toggleable api
This commit is contained in:
@@ -12,10 +12,11 @@ import me.alpha432.oyvey.features.settings.Bind;
|
||||
import me.alpha432.oyvey.features.settings.Setting;
|
||||
import me.alpha432.oyvey.manager.ConfigManager;
|
||||
import me.alpha432.oyvey.util.traits.Jsonable;
|
||||
import me.alpha432.oyvey.util.traits.Toggleable;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import org.joml.Vector2f;
|
||||
|
||||
public class Module extends Feature implements Jsonable {
|
||||
public class Module extends Feature implements Jsonable, Toggleable {
|
||||
private final String description;
|
||||
private final Category category;
|
||||
|
||||
@@ -61,14 +62,6 @@ public class Module extends Feature implements Jsonable {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
if (enabled) {
|
||||
this.enable();
|
||||
} else {
|
||||
this.disable();
|
||||
}
|
||||
}
|
||||
|
||||
public void enable() {
|
||||
this.enabled.setValue(true);
|
||||
EVENT_BUS.register(this);
|
||||
@@ -85,10 +78,6 @@ public class Module extends Feature implements Jsonable {
|
||||
this.onDisable();
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
this.setEnabled(!this.isEnabled());
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return this.displayName.getValue();
|
||||
}
|
||||
@@ -109,6 +98,11 @@ public class Module extends Feature implements Jsonable {
|
||||
return enabled.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isToggled() {
|
||||
return isEnabled();
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package me.alpha432.oyvey.util.traits;
|
||||
|
||||
public interface Toggleable {
|
||||
boolean isToggled();
|
||||
|
||||
void enable();
|
||||
|
||||
void disable();
|
||||
|
||||
default void toggle() {
|
||||
if (isToggled()) disable();
|
||||
else enable();
|
||||
}
|
||||
|
||||
default void setToggled(boolean toggled) {
|
||||
if(isToggled() != toggled) toggle();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user