aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/dev/isxander/yacl/impl/ButtonOptionImpl.java
blob: 4104ff02e1d628c9e52e66604d377a8c0b1a2cd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package dev.isxander.yacl.impl;

import dev.isxander.yacl.api.Binding;
import dev.isxander.yacl.api.ButtonOption;
import dev.isxander.yacl.api.Controller;
import net.minecraft.text.Text;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.function.Function;

@ApiStatus.Internal
public class ButtonOptionImpl implements ButtonOption {
    private final Text name;
    private final Text tooltip;
    private final Runnable action;
    private final Controller<Runnable> controller;
    private final Binding<Runnable> binding;

    public ButtonOptionImpl(
            @NotNull Text name,
            @Nullable Text tooltip,
            @NotNull Runnable action,
            @NotNull Function<ButtonOption, Controller<Runnable>> controlGetter
    ) {
        this.name = name;
        this.tooltip = tooltip;
        this.action = action;
        this.controller = controlGetter.apply(this);
        this.binding = new EmptyBinderImpl();
    }

    @Override
    public @NotNull Text name() {
        return name;
    }

    @Override
    public @NotNull Text tooltip() {
        return tooltip;
    }

    @Override
    public Runnable action() {
        return action;
    }

    @Override
    public @NotNull Controller<Runnable> controller() {
        return controller;
    }

    @Override
    public @NotNull Binding<Runnable> binding() {
        return binding;
    }

    @Override
    public boolean changed() {
        return false;
    }

    @Override
    public @NotNull Runnable pendingValue() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void requestSet(Runnable value) {
        throw new UnsupportedOperationException();
    }

    @Override
    public void applyValue() {

    }

    @Override
    public void forgetPendingValue() {

    }

    @Override
    public void requestSetDefault() {

    }

    private static class EmptyBinderImpl implements Binding<Runnable> {
        @Override
        public void setValue(Runnable value) {

        }

        @Override
        public Runnable getValue() {
            throw new UnsupportedOperationException();
        }

        @Override
        public Runnable defaultValue() {
            throw new UnsupportedOperationException();
        }
    }
}