Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
fix: Fix entry creation on MapOptionImpl creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveplays28 committed Jan 11, 2024
1 parent c78d546 commit e38a969
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private static ConfigCategory buildMainCategory() {
Text.translatable("blendium.config.category.main.title.tooltip")).group(MapOption.<String, Double>createBuilder().name(
Text.translatable("blendium.config.shaderpackBrightnessMultipliers")).description(
OptionDescription.of(Text.translatable("blendium.config.shaderpackBrightnessMultipliers.tooltip"))).binding(
Collections.emptyMap(), () -> BlendiumClient.config.shaderpackBrightnessMultipliers,
BlendiumClient.config.shaderpackBrightnessMultipliers, () -> BlendiumClient.config.shaderpackBrightnessMultipliers,
newValue -> BlendiumClient.config.shaderpackBrightnessMultipliers = newValue
).initial(() -> new AbstractMap.SimpleEntry<>("(off)", 1.0)).keyController(stringDoubleMapOptionEntry -> StringControllerBuilder.create(
(Option<String>) (Object) stringDoubleMapOptionEntry)).valueController(DoubleFieldControllerBuilder::create).build()).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void render(DrawContext graphics, int mouseX, int mouseY, float delta) {
removeButton.render(graphics, mouseX, mouseY, delta);
moveUpButton.render(graphics, mouseX, mouseY, delta);
moveDownButton.render(graphics, mouseX, mouseY, delta);
entryWidget.render(graphics, mouseX, mouseY, delta);
// entryWidget.render(graphics, mouseX, mouseY, delta);
}

protected void updateButtonStates() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,11 @@ public boolean changed() {
@Override
public @NotNull Map<S, T> pendingValue() {
// TODO: Refactor into a method
Map<S, T> mapEntries = new Object2ObjectArrayMap<>();
Map<S, T> mapEntries = new HashMap<>();

for (MapOptionEntry<S, T> entry : entries) {
mapEntries.entrySet().add((Map.Entry<S, T>) entry.pendingValue());
var mapEntry = (Map.Entry<S, T>) entry.pendingValue();
mapEntries.put(mapEntry.getKey(), mapEntry.getValue());
}

return mapEntries;
Expand Down Expand Up @@ -224,9 +225,8 @@ public boolean isRoot() {
return false;
}

@SuppressWarnings("unchecked")
private List<MapOptionEntry<S, T>> createEntries(Map<S, T> values) {
return values.entrySet().stream().filter(Map.class::isInstance).map(entryFactory::create).filter(MapOptionEntry.class::isInstance).toList();
return values.entrySet().stream().filter(Objects::nonNull).map(entryFactory::create).toList();
}

void callListeners(boolean bypass) {
Expand Down Expand Up @@ -426,8 +426,9 @@ public MapOption<S, T> build() {
Validate.notNull(binding, "`binding` must not be null");
Validate.notNull(initialValue, "`initialValue` must not be null");

return new MapOptionImpl<>(name, description, binding, initialValue, keyControllerFunction, valueControllerFunction, ImmutableSet.copyOf(flags), collapsed,
available, minimumNumberOfEntries, maximumNumberOfEntries, insertEntriesAtEnd, listeners
return new MapOptionImpl<>(name, description, binding, initialValue, keyControllerFunction, valueControllerFunction,
ImmutableSet.copyOf(flags), collapsed, available, minimumNumberOfEntries, maximumNumberOfEntries, insertEntriesAtEnd,
listeners
);
}
}
Expand Down

0 comments on commit e38a969

Please sign in to comment.