YetAnotherConfigLib

YetAnotherConfigLib

34M Downloads

Use Supplier<Text> instead of Text for option names

Qendolin opened this issue ยท 1 comments

commented

Currently all options are passed a fixed Text for their name. Sometimes, especially in the case of buttons, it would be nice to change their text. I propose updating the option implementations and builders to use a Supplier<Text> instead. This change would also easily be backwards compatible.

To demonstrate take this simple example:

This is currently possible:

AtomicBoolean added = new AtomicBoolean(false);
ButtonOption.createBuilder()
    .name(Text.literal("Add or Remove"))
    .action((scr, opt) -> {
        if(added.get()) {
            added.set(false);
        } else {
            added.set(true);
        }
    });

This would be possible with the proposal:

AtomicBoolean added = new AtomicBoolean(false);
ButtonOption.createBuilder()
    .name(() => added.get() ? Text.literal("Remove") : Text.literal("Add"))
    .action((scr, opt) -> {
        if(added.get()) {
            added.set(false);
        } else {
            added.set(true);
        }
    });
commented

I was able to do this with labels using a custom state manager (example using current system time which continually updates):

LabelOption.createBuilder()
.state(StateManager.createInstant(Binding.generic(Text.literal("default"), () -> Text.literal(Double.toString(System.currentTimeMillis())), v -> {})))
.build()

It might be possible to adapt this to buttons as well