Skip to content

Commit

Permalink
Fix issue with quad symmetry
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Sep 15, 2024
1 parent 42be3d1 commit 6673747
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 38 deletions.
3 changes: 2 additions & 1 deletion shared/src/main/java/com/faforever/neroxis/mask/Mask.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public abstract sealed class Mask<T, U extends Mask<T, U>> permits OperationsMas
private String visualName;

protected Mask(U other, String name) {
this(other.getSize(), (name != null && name.endsWith(MOCK_NAME)) ? null : other.getNextSeed(),
this(other.getSize(), other.isMock() ? null : other.getNextSeed(),
other.getSymmetrySettings(), name, other.isParallel());
init(other);
}
Expand Down Expand Up @@ -191,6 +191,7 @@ public static boolean inBounds(Vector2 location, int size) {
@SneakyThrows
public U immutableCopy() {
Mask<?, U> copy = copy(getName() + MOCK_NAME);
copy.setVisualName(getName());
return copy.enqueue(copy::makeImmutable);
}

Expand Down
36 changes: 22 additions & 14 deletions shared/src/main/java/com/faforever/neroxis/util/SymmetryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,25 +202,33 @@ public static Vector2 getSourcePoint(int x, int y, int size, Symmetry symmetry)
}
}
case QUAD -> {
if (x >= halfSizeBound && y >= halfSizeBound) {
yield new Vector2(size - x - 1, size - y - 1);
} else if (x <= halfSizeBound && y >= halfSizeBound) {
yield new Vector2(x, size - y - 1);
} else if (x >= halfSizeBound) {
yield new Vector2(size - x - 1, y);
if (x >= halfSizeBound) {
if (y >= halfSizeBound) {
yield new Vector2(size - x - 1, size - y - 1);
} else {
yield new Vector2(size - x - 1, y);
}
} else {
yield new Vector2(x, y);
if (y >= halfSizeBound) {
yield new Vector2(x, size - y - 1);
} else {
yield new Vector2(x, y);
}
}
}
case DIAG -> {
if (x >= halfSizeBound && y < x && y >= size - x - 1) {
yield new Vector2(size - x - 1, y);
} else if (y <= halfSizeBound && x > y && x <= size - y - 1) {
yield new Vector2(y, x);
} else if (y >= halfSizeBound && x <= y && x > size - y - 1) {
yield new Vector2(x, size - y - 1);
if (x > y) {
if (y > size - x - 1) {
yield new Vector2(size - x - 1, size - y - 1);
} else {
yield new Vector2(y, x);
}
} else {
yield new Vector2(x, y);
if (y > size - x - 1) {
yield new Vector2(size - y - 1, size - x - 1);
} else {
yield new Vector2(x, y);
}
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class VisualDebugger {
private static DefaultListModel<MaskListItem> listModel;
private static JFrame frame;
private static JList<MaskListItem> list;
private static EntryPanel canvas;
private static final Map<String, List<MaskListItem>> MASK_ITEMS_BY_NAME = new HashMap<>();
private static JTextField filter;

public static void visualizeMask(Mask<?, ?> mask) {
visualizeMask(mask, null, null);
Expand All @@ -24,7 +31,6 @@ public static void visualizeMask(Mask<?, ?> mask, String method, String line) {
SwingUtilities.invokeLater(() -> {
createGui();
String name = copyOfmask.getVisualName();
name = name == null ? copyOfmask.getName() : name;
updateList(name + " " + method + " " + line, copyOfmask.immutableCopy());
}
);
Expand Down Expand Up @@ -56,21 +62,38 @@ private static void setupList() {
list.addListSelectionListener(event -> {
if (!event.getValueIsAdjusting()) {
MaskListItem selectedItem = list.getSelectedValue();
if (selectedItem == null) {
return;
}
updateVisibleCanvas(selectedItem);
}
});

filter = new JTextField();
filter.addActionListener(event -> refreshList());
filter.setMinimumSize(new Dimension(350, 50));

GridBagConstraints filterConstraints = new GridBagConstraints();
filterConstraints.fill = GridBagConstraints.HORIZONTAL;
filterConstraints.gridx = 0;
filterConstraints.weightx = 0;
filterConstraints.gridy = 0;
filterConstraints.weighty = 0;

frame.add(filter, filterConstraints);

JScrollPane listScroller = new JScrollPane(list);
listScroller.setMinimumSize(new Dimension(350, 0));
listScroller.setPreferredSize(new Dimension(350, 0));

GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.BOTH;
constraints.gridx = 0;
constraints.weightx = 0;
constraints.gridy = 0;
constraints.weighty = 1;
GridBagConstraints scrollerConstraints = new GridBagConstraints();
scrollerConstraints.fill = GridBagConstraints.BOTH;
scrollerConstraints.gridx = 0;
scrollerConstraints.weightx = 0;
scrollerConstraints.gridy = 1;
scrollerConstraints.weighty = 1;

frame.add(listScroller, constraints);
frame.add(listScroller, scrollerConstraints);
}

private static void updateVisibleCanvas(MaskListItem maskListItem) {
Expand All @@ -89,28 +112,37 @@ private static void setupCanvas() {
constraints.weightx = 1;
constraints.gridy = 0;
constraints.weighty = 1;
constraints.gridheight = 2;
frame.add(canvas, constraints);
}

public synchronized static void updateList(String uniqueMaskName, Mask<?, ?> mask) {
if (!uniqueMaskName.isEmpty()) {
int ind = listModel.getSize();
for (int i = 0; i < listModel.getSize(); i++) {
if (listModel.get(i).maskName.split(" ")[0].equals(uniqueMaskName.split(" ")[0])) {
ind = i + 1;
}
}
private static void updateList(String uniqueMaskName, Mask<?, ?> mask) {
MASK_ITEMS_BY_NAME.computeIfAbsent(uniqueMaskName, ignored -> new ArrayList<>())
.add(new MaskListItem(uniqueMaskName, mask));
refreshList();
}

listModel.insertElementAt(new MaskListItem(uniqueMaskName, mask), ind);
if (list.getSelectedIndex() == -1) {
list.setSelectedIndex(ind);
}
list.revalidate();
list.repaint();
private static void refreshList() {
MaskListItem selectedValue = list.getSelectedValue();
listModel.clear();
String text = filter.getText();
listModel.addAll(MASK_ITEMS_BY_NAME.entrySet()
.stream()
.filter(entry -> text.isBlank() || entry.getKey().contains(text))
.sorted(Map.Entry.comparingByKey())
.map(Map.Entry::getValue)
.flatMap(
Collection::stream)
.toList());
list.revalidate();
list.repaint();
int selected = listModel.indexOf(selectedValue);
if (selected != -1) {
list.setSelectedIndex(selected);
}
}

public record MaskListItem(String maskName, Mask<?, ?> mask) {
private record MaskListItem(String maskName, Mask<?, ?> mask) {
@Override
public String toString() {
return maskName;
Expand Down

0 comments on commit 6673747

Please sign in to comment.