From 032f111b5363be354ace74057ecade96b9fb306a Mon Sep 17 00:00:00 2001 From: P0nk Date: Thu, 9 Sep 2021 22:20:08 +0200 Subject: [PATCH] Rename and clean up MapleFoothold --- .../{MapleFoothold.java => Foothold.java} | 21 +++++++-------- .../java/server/maps/MapleFootholdTree.java | 26 +++++++++---------- src/main/java/server/maps/MapleMap.java | 2 +- .../java/server/maps/MapleMapFactory.java | 6 ++--- 4 files changed, 27 insertions(+), 28 deletions(-) rename src/main/java/server/maps/{MapleFoothold.java => Foothold.java} (87%) diff --git a/src/main/java/server/maps/MapleFoothold.java b/src/main/java/server/maps/Foothold.java similarity index 87% rename from src/main/java/server/maps/MapleFoothold.java rename to src/main/java/server/maps/Foothold.java index a59a972cb7..ced5fc42f8 100644 --- a/src/main/java/server/maps/MapleFoothold.java +++ b/src/main/java/server/maps/Foothold.java @@ -21,19 +21,18 @@ */ package server.maps; -import java.awt.Point; +import java.awt.*; /** - * * @author Matze */ -public class MapleFoothold implements Comparable { - private Point p1; - private Point p2; - private int id; +public class Foothold implements Comparable { + 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 { 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 { } @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()) { diff --git a/src/main/java/server/maps/MapleFootholdTree.java b/src/main/java/server/maps/MapleFootholdTree.java index 085d11d8d7..7b53a988a5 100644 --- a/src/main/java/server/maps/MapleFootholdTree.java +++ b/src/main/java/server/maps/MapleFootholdTree.java @@ -35,7 +35,7 @@ public class MapleFootholdTree { private MapleFootholdTree ne = null; private MapleFootholdTree sw = null; private MapleFootholdTree se = null; - private List footholds = new LinkedList<>(); + private List 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 getRelevants(Point p) { + private List getRelevants(Point p) { return getRelevants(p, new LinkedList<>()); } - private List getRelevants(Point p, List list) { + private List getRelevants(Point p, List 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 relevants = getRelevants(p); - List xMatches = new LinkedList<>(); - for (MapleFoothold fh : relevants) { + public Foothold findBelow(Point p) { + List relevants = getRelevants(p); + List 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; diff --git a/src/main/java/server/maps/MapleMap.java b/src/main/java/server/maps/MapleMap.java index f121a291dd..2d71aea543 100644 --- a/src/main/java/server/maps/MapleMap.java +++ b/src/main/java/server/maps/MapleMap.java @@ -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; } diff --git a/src/main/java/server/maps/MapleMapFactory.java b/src/main/java/server/maps/MapleMapFactory.java index e8a06aa279..a7ce8c5a85 100644 --- a/src/main/java/server/maps/MapleMapFactory.java +++ b/src/main/java/server/maps/MapleMapFactory.java @@ -187,7 +187,7 @@ public class MapleMapFactory { map.setMapLineBoundings(bounds[0], bounds[1], bounds[2], bounds[3]); } - List allFootholds = new LinkedList<>(); + List 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);