2021-11-14 15:37:01 +01:00
|
|
|
package io.gitlab.jfronny.respackopts.model.tree;
|
2021-06-10 13:10:12 +02:00
|
|
|
|
2024-04-24 19:33:50 +02:00
|
|
|
import io.gitlab.jfronny.commons.serialize.databind.api.SerializeWithAdapter;
|
2023-09-22 19:19:55 +02:00
|
|
|
import io.gitlab.jfronny.libjf.config.api.v2.dsl.CategoryBuilder;
|
2023-02-23 18:15:37 +01:00
|
|
|
import io.gitlab.jfronny.muscript.data.dynamic.DBool;
|
2021-10-21 18:06:09 +02:00
|
|
|
import io.gitlab.jfronny.respackopts.Respackopts;
|
2022-08-28 20:06:59 +02:00
|
|
|
import io.gitlab.jfronny.respackopts.RespackoptsConfig;
|
2024-04-24 19:33:50 +02:00
|
|
|
import io.gitlab.jfronny.respackopts.gson.entry.BooleanEntrySerializer;
|
|
|
|
import io.gitlab.jfronny.respackopts.gson.entry.ConfigBranchSerializer;
|
2021-06-14 17:04:43 +02:00
|
|
|
|
2022-01-12 18:23:49 +01:00
|
|
|
import java.util.Objects;
|
|
|
|
|
2024-04-24 19:33:50 +02:00
|
|
|
@SerializeWithAdapter(adapter = BooleanEntrySerializer.class)
|
2023-08-14 17:04:59 +02:00
|
|
|
public class ConfigBooleanEntry extends ConfigEntry<Boolean> implements DBool {
|
2021-06-10 13:10:12 +02:00
|
|
|
public ConfigBooleanEntry(boolean v) {
|
2021-10-21 18:45:31 +02:00
|
|
|
super(Boolean.class);
|
2021-06-10 14:55:03 +02:00
|
|
|
setValue(v);
|
2021-07-12 22:17:22 +02:00
|
|
|
setDefault(v);
|
2021-06-10 14:55:03 +02:00
|
|
|
}
|
|
|
|
|
2021-06-10 19:26:59 +02:00
|
|
|
@Override
|
2021-06-14 16:33:15 +02:00
|
|
|
public ConfigEntry<Boolean> clone() {
|
2021-06-10 19:26:59 +02:00
|
|
|
ConfigBooleanEntry be = new ConfigBooleanEntry(getValue());
|
|
|
|
be.setDefault(getDefault());
|
|
|
|
return be;
|
|
|
|
}
|
2021-06-14 17:04:43 +02:00
|
|
|
|
|
|
|
@Override
|
2021-06-19 13:32:16 +02:00
|
|
|
public void buildShader(StringBuilder sb, String valueName) {
|
2021-06-14 17:04:43 +02:00
|
|
|
if (getValue()) {
|
|
|
|
sb.append("\n#define ");
|
|
|
|
sb.append(valueName);
|
|
|
|
}
|
|
|
|
}
|
2021-06-19 13:32:16 +02:00
|
|
|
|
|
|
|
@Override
|
2022-08-28 20:06:59 +02:00
|
|
|
public CategoryBuilder<?> buildEntry(GuiEntryBuilderParam args) {
|
|
|
|
return args.builder().value(args.name(), getDefault(), this::getValue, v -> {
|
|
|
|
if (getValue() != v) {
|
|
|
|
if (RespackoptsConfig.debugLogs) Respackopts.LOGGER.info("ConfigBooleanEntry SaveCallback");
|
|
|
|
args.saveCallback();
|
|
|
|
}
|
|
|
|
setValue(v);
|
|
|
|
});
|
2021-06-19 13:32:16 +02:00
|
|
|
}
|
2022-01-12 18:23:49 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
return super.equals(o) && o instanceof ConfigBooleanEntry cb && getValue().equals(cb.getValue()) && getDefault().equals(cb.getDefault());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return Objects.hash(super.hashCode(), getValue(), getDefault());
|
|
|
|
}
|
2021-06-10 13:10:12 +02:00
|
|
|
}
|