11package com .github .codestorm .bounceverse ;
22
3+ import com .almasb .fxgl .dsl .FXGL ;
4+ import com .almasb .fxgl .entity .Entity ;
5+ import com .almasb .fxgl .physics .PhysicsComponent ;
6+ import com .almasb .fxgl .time .TimerAction ;
7+ import com .github .codestorm .bounceverse .data .types .DirectionUnit ;
38import java .io .IOException ;
49import java .io .InputStream ;
510import java .util .ArrayList ;
813import java .util .Map ;
914import java .util .Properties ;
1015import java .util .Scanner ;
11-
12- import com .almasb .fxgl .dsl .FXGL ;
13- import com .almasb .fxgl .entity .Entity ;
14- import com .almasb .fxgl .physics .PhysicsComponent ;
15- import com .almasb .fxgl .time .TimerAction ;
16- import com .github .codestorm .bounceverse .data .types .DirectionUnit ;
17-
18- import javafx .geometry .Rectangle2D ;
1916import javafx .geometry .Point2D ;
17+ import javafx .geometry .Rectangle2D ;
2018import javafx .scene .shape .Circle ;
2119import javafx .util .Duration ;
2220
23- /**
24- * Utilities.
25- */
21+ /** Utilities. */
2622public final class Utils {
2723
28- private Utils () {
29- }
24+ private Utils () {}
3025
31- /**
32- * Input/Output utilities.
33- */
26+ /** Input/Output utilities. */
3427 public static final class IO {
3528
36- private IO () {
37- }
29+ private IO () {}
3830
3931 /**
4032 * Load .properties file.
4133 *
4234 * @param path Relative path
4335 * @return Parsed properties
44- * @throws IOException if an error occurred when reading from the input
45- * stream.
36+ * @throws IOException if an error occurred when reading from the input stream.
4637 */
4738 public static Properties loadProperties (String path ) throws IOException {
4839 InputStream fileStream = IO .class .getResourceAsStream (path );
@@ -57,18 +48,16 @@ public static Properties loadProperties(String path) throws IOException {
5748 }
5849
5950 /**
60- * Convert an array of key=value pairs into a hashmap. The string "key="
61- * maps key onto "", while just "key" maps key onto null. The value may
62- * contain '=' characters, only the first "=" is a delimiter. <br>
63- * Source code from
64- * <a href="https://stackoverflow.com/a/52940215/16410937">here</a>.
51+ * Convert an array of key=value pairs into a hashmap. The string "key=" maps key onto "",
52+ * while just "key" maps key onto null. The value may contain '=' characters, only the first
53+ * "=" is a delimiter. <br>
54+ * Source code from <a href="https://stackoverflow.com/a/52940215/16410937">here</a>.
6555 *
66- * @param args command-line arguments in the key=value format (or just
67- * key= or key)
68- * @param defaults a map of default values, may be null. Mappings to
69- * null are not copied to the resulting map.
70- * @param whiteList if not null, the keys not present in this map cause
71- * an exception (and keys mapped to null are ok)
56+ * @param args command-line arguments in the key=value format (or just key= or key)
57+ * @param defaults a map of default values, may be null. Mappings to null are not copied to
58+ * the resulting map.
59+ * @param whiteList if not null, the keys not present in this map cause an exception (and
60+ * keys mapped to null are ok)
7261 * @return a map that maps these keys onto the corresponding values.
7362 */
7463 public static HashMap <String , String > parseArgs (
@@ -114,8 +103,7 @@ public static List<String> readTextFile(String path) {
114103 public static final class Time {
115104
116105 /**
117- * Thời gian hồi để thực hiện lại gì đó. Thực hiện thông qua
118- * {@link #current}
106+ * Thời gian hồi để thực hiện lại gì đó. Thực hiện thông qua {@link #current}
119107 *
120108 * @see ActiveCooldown
121109 */
@@ -142,26 +130,20 @@ public ActiveCooldown getCurrent() {
142130 return current ;
143131 }
144132
145- public Cooldown () {
146- }
133+ public Cooldown () {}
147134
148135 public Cooldown (Duration duration ) {
149136 this .duration = duration ;
150137 }
151138
152- /**
153- * Cooldown thời điểm hiện tại. Giống như một wrapper của
154- * {@link TimerAction}.
155- */
139+ /** Cooldown thời điểm hiện tại. Giống như một wrapper của {@link TimerAction}. */
156140 public final class ActiveCooldown {
157141
158142 private TimerAction waiter = null ;
159143 private double timestamp = Double .NaN ;
160144 private Runnable onExpiredCallback = null ;
161145
162- /**
163- * Hành động khi cooldown hết.
164- */
146+ /** Hành động khi cooldown hết. */
165147 private void onExpired () {
166148 timestamp = Double .NaN ;
167149 if (onExpiredCallback != null ) {
@@ -187,18 +169,14 @@ public boolean expired() {
187169 return (waiter == null ) || waiter .isExpired ();
188170 }
189171
190- /**
191- * Khiến cooldown hết hạn ngay (nếu có).
192- */
172+ /** Khiến cooldown hết hạn ngay (nếu có). */
193173 public void expire () {
194174 if (!expired ()) {
195175 waiter .expire ();
196176 }
197177 }
198178
199- /**
200- * Set một cooldown mới.
201- */
179+ /** Set một cooldown mới. */
202180 public void makeNew () {
203181 expire ();
204182
@@ -207,18 +185,14 @@ public void makeNew() {
207185 timestamp = gameTimer .getNow ();
208186 }
209187
210- /**
211- * Tạm dừng cooldown.
212- */
188+ /** Tạm dừng cooldown. */
213189 public void pause () {
214190 if (!expired ()) {
215191 waiter .pause ();
216192 }
217193 }
218194
219- /**
220- * Tiếp tục cooldown.
221- */
195+ /** Tiếp tục cooldown. */
222196 public void resume () {
223197 if (!expired ()) {
224198 waiter .resume ();
@@ -253,8 +227,7 @@ public void reduce(Duration duration) {
253227 }
254228 }
255229
256- private ActiveCooldown () {
257- }
230+ private ActiveCooldown () {}
258231 }
259232 }
260233 }
@@ -284,15 +257,15 @@ public static List<Entity> getEntityInCircle(Circle circle) {
284257 * @return Các entity
285258 */
286259 public static List <Entity > getEntityInCircle (double cx , double cy , double radius ) {
287- final Rectangle2D outRect
288- = new Rectangle2D (cx - radius , cy - radius , 2 * radius , 2 * radius );
260+ final Rectangle2D outRect =
261+ new Rectangle2D (cx - radius , cy - radius , 2 * radius , 2 * radius );
289262 return FXGL .getGameWorld ().getEntitiesInRange (outRect ).stream ()
290263 .filter (
291264 e -> {
292- double nearestX
293- = Math .max (e .getX (), Math .min (cx , e .getX () + e .getWidth ()));
294- double nearestY
295- = Math .max (e .getY (), Math .min (cy , e .getY () + e .getHeight ()));
265+ double nearestX =
266+ Math .max (e .getX (), Math .min (cx , e .getX () + e .getWidth ()));
267+ double nearestY =
268+ Math .max (e .getY (), Math .min (cy , e .getY () + e .getHeight ()));
296269 double dx = cx - nearestX ;
297270 double dy = cy - nearestY ;
298271 return (dx * dx + dy * dy ) <= radius * radius ;
@@ -304,9 +277,9 @@ public static List<Entity> getEntityInCircle(double cx, double cy, double radius
304277 public static final class Collision {
305278
306279 /**
307- * Xác định hướng va chạm giữa hai Entity bằng cách tính độ chồng lấn
308- * (overlap). Trả về hướng mà source "tiếp xúc" với target: UP, DOWN,
309- * LEFT, RIGHT. Nếu không chồng lấn rõ ràng, trả về null.
280+ * Xác định hướng va chạm giữa hai Entity bằng cách tính độ chồng lấn (overlap). Trả về
281+ * hướng mà source "tiếp xúc" với target: UP, DOWN, LEFT, RIGHT. Nếu không chồng lấn rõ
282+ * ràng, trả về null.
310283 */
311284 public static DirectionUnit getCollisionDirection (Entity source , Entity target ) {
312285 var fromBox = source .getBoundingBoxComponent ();
0 commit comments