Rename and clean up MapleFoothold

This commit is contained in:
P0nk
2021-09-09 22:20:08 +02:00
parent c0fedc8589
commit 032f111b53
4 changed files with 27 additions and 28 deletions

View File

@@ -21,19 +21,18 @@
*/
package server.maps;
import java.awt.Point;
import java.awt.*;
/**
*
* @author Matze
*/
public class MapleFoothold implements Comparable<MapleFoothold> {
private Point p1;
private Point p2;
private int id;
public class Foothold implements Comparable<Foothold> {
private final Point p1;
private final Point p2;
private final int id;
private int next, prev;
public MapleFoothold(Point p1, Point p2, int id) {
public Foothold(Point p1, Point p2, int id) {
this.p1 = p1;
this.p2 = p2;
this.id = id;
@@ -57,8 +56,8 @@ public class MapleFoothold implements Comparable<MapleFoothold> {
public int getY2() {
return p2.y;
}
}
// XXX may need more precision
public int calculateFooting(int x) {
if (p1.y == p2.y) {
@@ -70,8 +69,8 @@ public class MapleFoothold implements Comparable<MapleFoothold> {
}
@Override
public int compareTo(MapleFoothold o) {
MapleFoothold other = o;
public int compareTo(Foothold o) {
Foothold other = o;
if (p2.y < other.getY1()) {
return -1;
} else if (p1.y > other.getY2()) {

View File

@@ -35,7 +35,7 @@ public class MapleFootholdTree {
private MapleFootholdTree ne = null;
private MapleFootholdTree sw = null;
private MapleFootholdTree se = null;
private List<MapleFoothold> footholds = new LinkedList<>();
private List<Foothold> footholds = new LinkedList<>();
private Point p1;
private Point p2;
private Point center;
@@ -57,7 +57,7 @@ public class MapleFootholdTree {
center = new Point((p2.x - p1.x) / 2, (p2.y - p1.y) / 2);
}
public void insert(MapleFoothold f) {
public void insert(Foothold f) {
if (depth == 0) {
if (f.getX1() > maxDropX) {
maxDropX = f.getX1();
@@ -95,11 +95,11 @@ public class MapleFootholdTree {
}
}
private List<MapleFoothold> getRelevants(Point p) {
private List<Foothold> getRelevants(Point p) {
return getRelevants(p, new LinkedList<>());
}
private List<MapleFoothold> getRelevants(Point p, List<MapleFoothold> list) {
private List<Foothold> getRelevants(Point p, List<Foothold> list) {
list.addAll(footholds);
if (nw != null) {
if (p.x <= center.x && p.y <= center.y) {
@@ -115,9 +115,9 @@ public class MapleFootholdTree {
return list;
}
private MapleFoothold findWallR(Point p1, Point p2) {
MapleFoothold ret;
for (MapleFoothold f : footholds) {
private Foothold findWallR(Point p1, Point p2) {
Foothold ret;
for (Foothold f : footholds) {
if (f.isWall() && f.getX1() >= p1.x && f.getX1() <= p2.x &&
f.getY1() >= p1.y && f.getY2() <= p1.y) {
return f;
@@ -152,23 +152,23 @@ public class MapleFootholdTree {
return null;
}
public MapleFoothold findWall(Point p1, Point p2) {
public Foothold findWall(Point p1, Point p2) {
if (p1.y != p2.y) {
throw new IllegalArgumentException();
}
return findWallR(p1, p2);
}
public MapleFoothold findBelow(Point p) {
List<MapleFoothold> relevants = getRelevants(p);
List<MapleFoothold> xMatches = new LinkedList<>();
for (MapleFoothold fh : relevants) {
public Foothold findBelow(Point p) {
List<Foothold> relevants = getRelevants(p);
List<Foothold> xMatches = new LinkedList<>();
for (Foothold fh : relevants) {
if (fh.getX1() <= p.x && fh.getX2() >= p.x) {
xMatches.add(fh);
}
}
Collections.sort(xMatches);
for (MapleFoothold fh : xMatches) {
for (Foothold fh : xMatches) {
if (!fh.isWall()) {
if (fh.getY1() != fh.getY2()) {
int calcY;

View File

@@ -470,7 +470,7 @@ public class MapleMap {
}
private Point calcPointBelow(Point initial) {
MapleFoothold fh = footholds.findBelow(initial);
Foothold fh = footholds.findBelow(initial);
if (fh == null) {
return null;
}

View File

@@ -187,7 +187,7 @@ public class MapleMapFactory {
map.setMapLineBoundings(bounds[0], bounds[1], bounds[2], bounds[3]);
}
List<MapleFoothold> allFootholds = new LinkedList<>();
List<Foothold> allFootholds = new LinkedList<>();
Point lBound = new Point();
Point uBound = new Point();
for (Data footRoot : mapData.getChildByPath("foothold")) {
@@ -197,7 +197,7 @@ public class MapleMapFactory {
int y1 = DataTool.getInt(footHold.getChildByPath("y1"));
int x2 = DataTool.getInt(footHold.getChildByPath("x2"));
int y2 = DataTool.getInt(footHold.getChildByPath("y2"));
MapleFoothold fh = new MapleFoothold(new Point(x1, y1), new Point(x2, y2), Integer.parseInt(footHold.getName()));
Foothold fh = new Foothold(new Point(x1, y1), new Point(x2, y2), Integer.parseInt(footHold.getName()));
fh.setPrev(DataTool.getInt(footHold.getChildByPath("prev")));
fh.setNext(DataTool.getInt(footHold.getChildByPath("next")));
if (fh.getX1() < lBound.x) {
@@ -217,7 +217,7 @@ public class MapleMapFactory {
}
}
MapleFootholdTree fTree = new MapleFootholdTree(lBound, uBound);
for (MapleFoothold fh : allFootholds) {
for (Foothold fh : allFootholds) {
fTree.insert(fh);
}
map.setFootholds(fTree);