Skip to content

Commit f68db0d

Browse files
committed
support nested editor on EditorStatusDisplay
1 parent bad4de6 commit f68db0d

File tree

1 file changed

+16
-45
lines changed

1 file changed

+16
-45
lines changed

editor-extra/src/main/java/io/github/projectunified/minigamecore/editor/extra/status/EditorStatusDisplay.java

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -92,53 +92,54 @@ protected Object preprocessValue(Object value, Editor<?> editor) {
9292
public T display(Editor<?> editor) {
9393
B builder = newBuilder();
9494
Deque<Entry> deque = new ArrayDeque<>();
95-
deque.addFirst(new Entry(0, "ROOT", editor, false));
95+
deque.addFirst(new Entry(0, "ROOT", editor, editor, false));
9696
while (!deque.isEmpty()) {
9797
Entry entry = deque.removeFirst();
98-
int level = entry.level();
99-
Object value = entry.value();
100-
Object preprocessedValue = preprocessValue(value, editor);
98+
int level = entry.level;
99+
Object value = entry.value;
100+
Object preprocessedValue = preprocessValue(value, entry.editor);
101101
if (preprocessedValue != value) {
102-
deque.addFirst(new Entry(level, entry.key(), preprocessedValue, entry.fromCollection()));
102+
deque.addFirst(new Entry(level, entry.key, preprocessedValue, entry.editor, entry.fromCollection));
103103
continue;
104104
}
105105

106106
if (value instanceof Editor<?>) {
107-
deque.addFirst(new Entry(level, entry.key(), ((Editor<?>) value).status(), false));
107+
Editor<?> subEditor = (Editor<?>) value;
108+
deque.addFirst(new Entry(level, entry.key, subEditor.status(), subEditor, false));
108109
continue;
109110
}
110111

111112
S section = newSection(builder, level);
112113

113-
appendKey(section, entry.key(), entry.fromCollection());
114+
appendKey(section, entry.key, entry.fromCollection);
114115
if (value instanceof Collection<?>) {
115116
Collection<?> collection = (Collection<?>) value;
116117
appendSize(section, collection.size());
117118
List<Object> copyList = new ArrayList<>(collection);
118119
for (int i = copyList.size() - 1; i >= 0; i--) {
119120
Object o = copyList.get(i);
120-
deque.addFirst(new Entry(level + 1, Integer.toString(i), o, true));
121+
deque.addFirst(new Entry(level + 1, Integer.toString(i), o, entry.editor, true));
121122
}
122123
} else if (value.getClass().isArray()) {
123124
int length = Array.getLength(value);
124125
appendSize(section, length);
125126
for (int i = length - 1; i >= 0; i--) {
126127
Object o = Array.get(value, i);
127-
deque.addFirst(new Entry(level + 1, Integer.toString(i), o, true));
128+
deque.addFirst(new Entry(level + 1, Integer.toString(i), o, entry.editor, true));
128129
}
129130
} else if (value instanceof Map<?, ?>) {
130131
Map<?, ?> subMap = (Map<?, ?>) value;
131132
appendSize(section, subMap.size());
132133
List<Map.Entry<?, ?>> copyList = new ArrayList<>(subMap.entrySet());
133134
for (int i = subMap.size() - 1; i >= 0; i--) {
134135
Map.Entry<?, ?> o = copyList.get(i);
135-
deque.addFirst(new Entry(level + 1, Objects.toString(o.getKey()), o.getValue(), false));
136+
deque.addFirst(new Entry(level + 1, Objects.toString(o.getKey()), o.getValue(), entry.editor, false));
136137
}
137138
} else if (value instanceof Map.Entry<?, ?>) {
138139
Map.Entry<?, ?> subEntry = (Map.Entry<?, ?>) value;
139-
deque.addFirst(new Entry(level + 1, Objects.toString(subEntry.getKey()), subEntry.getValue(), false));
140+
deque.addFirst(new Entry(level + 1, Objects.toString(subEntry.getKey()), subEntry.getValue(), entry.editor, false));
140141
} else {
141-
appendValue(section, value, editor);
142+
appendValue(section, value, entry.editor);
142143
}
143144
builder = addToBuilder(section, builder);
144145
}
@@ -149,45 +150,15 @@ private static final class Entry {
149150
private final int level;
150151
private final String key;
151152
private final Object value;
153+
private final Editor<?> editor;
152154
private final boolean fromCollection;
153155

154-
private Entry(int level, String key, Object value, boolean fromCollection) {
156+
private Entry(int level, String key, Object value, Editor<?> editor, boolean fromCollection) {
155157
this.level = level;
156158
this.key = key;
157159
this.value = value;
160+
this.editor = editor;
158161
this.fromCollection = fromCollection;
159162
}
160-
161-
public int level() {
162-
return level;
163-
}
164-
165-
public String key() {
166-
return key;
167-
}
168-
169-
public Object value() {
170-
return value;
171-
}
172-
173-
public boolean fromCollection() {
174-
return fromCollection;
175-
}
176-
177-
@Override
178-
public boolean equals(Object obj) {
179-
if (obj == this) return true;
180-
if (obj == null || obj.getClass() != this.getClass()) return false;
181-
Entry that = (Entry) obj;
182-
return this.level == that.level &&
183-
Objects.equals(this.key, that.key) &&
184-
Objects.equals(this.value, that.value) &&
185-
this.fromCollection == that.fromCollection;
186-
}
187-
188-
@Override
189-
public int hashCode() {
190-
return Objects.hash(level, key, value, fromCollection);
191-
}
192163
}
193164
}

0 commit comments

Comments
 (0)