From d3cb740603bcaed4c7a16ca3ec43906f93540ca2 Mon Sep 17 00:00:00 2001 From: github-actions <> Date: Sat, 25 Jan 2025 20:46:34 +0000 Subject: [PATCH] Google Java Format --- examples/java/Tiled/Tiled.java | 2 +- src/org/openpatch/scratch/Stage.java | 299 +++++++----------- src/org/openpatch/scratch/Window.java | 84 ++--- .../scratch/extensions/text/Text.java | 154 ++++----- .../openpatch/scratch/internal/Applet.java | 52 +-- src/org/openpatch/scratch/internal/Font.java | 15 +- 6 files changed, 246 insertions(+), 360 deletions(-) diff --git a/examples/java/Tiled/Tiled.java b/examples/java/Tiled/Tiled.java index 68753cf..15a7e02 100644 --- a/examples/java/Tiled/Tiled.java +++ b/examples/java/Tiled/Tiled.java @@ -18,7 +18,7 @@ public static void main(String[] args) { Window.TEXTURE_SAMPLING_MODE = 2; Text.DEFAULT_FONT = "Tiled/assets/Retro Gaming.ttf"; Text.DEFAULT_FONT_SIZE = 11; - Text.FONT_SIZES = new int[] { 11 }; + Text.FONT_SIZES = new int[] {11}; Text.SPEAK_BUBBLE_MAX_LIMIT = 200; Text.SMOOTHING = false; diff --git a/src/org/openpatch/scratch/Stage.java b/src/org/openpatch/scratch/Stage.java index 6a22c4a..ae28c66 100644 --- a/src/org/openpatch/scratch/Stage.java +++ b/src/org/openpatch/scratch/Stage.java @@ -34,10 +34,8 @@ import processing.opengl.PGraphicsOpenGL; /** - * The Stage class represents a stage where various elements such as sprites, - * texts, pens, and - * backdrops can be added and manipulated. It provides methods to manage these - * elements, handle + * The Stage class represents a stage where various elements such as sprites, texts, pens, and + * backdrops can be added and manipulated. It provides methods to manage these elements, handle * events, and control the stage's appearance and behavior. */ public class Stage { @@ -90,8 +88,7 @@ public class Stage { private Camera camera; /** - * Constructs a new Stage with default dimensions. The default width is 480 - * pixels and the default + * Constructs a new Stage with default dimensions. The default width is 480 pixels and the default * height is 360 pixels. */ public Stage() { @@ -101,7 +98,7 @@ public Stage() { /** * Constructs a new Stage with the specified width and height. * - * @param width the width of the stage + * @param width the width of the stage * @param height the height of the stage */ public Stage(int width, final int height) { @@ -111,7 +108,7 @@ public Stage(int width, final int height) { /** * Constructs a new Stage with the specified width, height, and assets path. * - * @param width the width of the stage + * @param width the width of the stage * @param height the height of the stage * @param assets the path to the assets directory */ @@ -122,8 +119,7 @@ public Stage(int width, int height, String assets) { /** * Constructs a new Stage. * - * @param fullScreen a boolean indicating whether the stage should be in full - * screen mode. + * @param fullScreen a boolean indicating whether the stage should be in full screen mode. */ public Stage(boolean fullScreen) { this(fullScreen, null); @@ -132,9 +128,8 @@ public Stage(boolean fullScreen) { /** * Constructs a new Stage with the specified fullscreen mode and assets path. * - * @param fullScreen a boolean indicating whether the stage should be in - * fullscreen mode - * @param assets the path to the assets directory + * @param fullScreen a boolean indicating whether the stage should be in fullscreen mode + * @param assets the path to the assets directory */ public Stage(boolean fullScreen, String assets) { this(0, 0, fullScreen, assets); @@ -143,8 +138,8 @@ public Stage(boolean fullScreen, String assets) { /** * Constructs a new Stage with the specified width and height. * - * @param width the width of the stage - * @param height the height of the stage + * @param width the width of the stage + * @param height the height of the stage * @param fullScreen whether the stage should be in full screen mode */ public Stage(boolean fullScreen, int width, int height) { @@ -155,9 +150,9 @@ public Stage(boolean fullScreen, int width, int height) { * Constructs a new Stage with the specified parameters. * * @param fullScreen whether the stage should be in full screen mode - * @param width the width of the stage - * @param height the height of the stage - * @param assets the path to the assets directory + * @param width the width of the stage + * @param height the height of the stage + * @param assets the path to the assets directory */ public Stage(boolean fullScreen, int width, int height, String assets) { this(width, height, fullScreen, assets); @@ -166,10 +161,10 @@ public Stage(boolean fullScreen, int width, int height, String assets) { /** * Constructs a new Stage with the specified parameters. * - * @param width the width of the stage - * @param height the height of the stage + * @param width the width of the stage + * @param height the height of the stage * @param fullScreen whether the stage should be in full screen mode - * @param assets the path to the assets directory + * @param assets the path to the assets directory */ private Stage(int width, final int height, boolean fullScreen, String assets) { this.cursor = null; @@ -193,20 +188,27 @@ private Stage(int width, final int height, boolean fullScreen, String assets) { } Applet applet = Applet.getInstance(); - this.shaderBuffer = applet.createGraphics( - applet.getRenderWidth(), applet.getRenderHeight(), applet.sketchRenderer()); - this.mainBuffer = applet.createGraphics( - applet.getRenderWidth(), applet.getRenderHeight(), applet.sketchRenderer()); - this.backdropBuffer = applet.createGraphics( - applet.getRenderWidth(), applet.getRenderHeight(), applet.sketchRenderer()); - this.backgroundBuffer = applet.createGraphics( - applet.getRenderWidth(), applet.getRenderHeight(), applet.sketchRenderer()); - this.foregroundBuffer = applet.createGraphics( - applet.getRenderWidth(), applet.getRenderHeight(), applet.sketchRenderer()); - this.uiBuffer = applet.createGraphics( - applet.getRenderWidth(), applet.getRenderHeight(), applet.sketchRenderer()); - this.debugBuffer = applet.createGraphics( - applet.getRenderWidth(), applet.getRenderHeight(), applet.sketchRenderer()); + this.shaderBuffer = + applet.createGraphics( + applet.getRenderWidth(), applet.getRenderHeight(), applet.sketchRenderer()); + this.mainBuffer = + applet.createGraphics( + applet.getRenderWidth(), applet.getRenderHeight(), applet.sketchRenderer()); + this.backdropBuffer = + applet.createGraphics( + applet.getRenderWidth(), applet.getRenderHeight(), applet.sketchRenderer()); + this.backgroundBuffer = + applet.createGraphics( + applet.getRenderWidth(), applet.getRenderHeight(), applet.sketchRenderer()); + this.foregroundBuffer = + applet.createGraphics( + applet.getRenderWidth(), applet.getRenderHeight(), applet.sketchRenderer()); + this.uiBuffer = + applet.createGraphics( + applet.getRenderWidth(), applet.getRenderHeight(), applet.sketchRenderer()); + this.debugBuffer = + applet.createGraphics( + applet.getRenderWidth(), applet.getRenderHeight(), applet.sketchRenderer()); ((PGraphicsOpenGL) this.shaderBuffer).textureSampling(Window.TEXTURE_SAMPLING_MODE); ((PGraphicsOpenGL) this.mainBuffer).textureSampling(Window.TEXTURE_SAMPLING_MODE); ((PGraphicsOpenGL) this.backgroundBuffer).textureSampling(Window.TEXTURE_SAMPLING_MODE); @@ -225,12 +227,13 @@ private Stage(int width, final int height, boolean fullScreen, String assets) { } this.timer.put("default", new Timer()); - this.display = new Text( - null, - -applet.getRenderWidth() / 2, - -applet.getRenderHeight() / 2, - applet.getRenderWidth(), - TextStyle.BOX); + this.display = + new Text( + null, + -applet.getRenderWidth() / 2, + -applet.getRenderHeight() / 2, + applet.getRenderWidth(), + TextStyle.BOX); this.display.addedToStage(this); var p = new Polygon(); @@ -265,9 +268,8 @@ private Stage(int width, final int height, boolean fullScreen, String assets) { /** * Enables or disables the debug mode for the application. * - * @param debug a boolean value where {@code true} enables debug mode and - * {@code false} disables - * it. + * @param debug a boolean value where {@code true} enables debug mode and {@code false} disables + * it. */ public void setDebug(boolean debug) { Applet.getInstance().setDebug(debug); @@ -313,31 +315,20 @@ public void add(Pen pen) { } /** - * <<<<<<< HEAD - * Adds a new shader to the sprite. If a shader with the received name already - * exists, this method - * ======= - * Sets the texture sampling mode Point sampling: both magnification and - * minification filtering - * are set to nearest. Linear sampling: magnification filtering is nearest, - * minification set to - * linear Bilinear sampling: both magnification filtering is set to linear and - * minification either - * to linear-mipmap-nearest (linear interpolation is used within a mipmap, but - * not between - * different mipmaps). Trilinear sampling: magnification filtering set to - * linear, minification to - * linear-mipmap-linear, which offers the best mipmap quality since linear - * interpolation to - * compute the value in each of two maps and then interpolates linearly between + * <<<<<<< HEAD Adds a new shader to the sprite. If a shader with the received name already + * exists, this method ======= Sets the texture sampling mode Point sampling: both magnification + * and minification filtering are set to nearest. Linear sampling: magnification filtering is + * nearest, minification set to linear Bilinear sampling: both magnification filtering is set to + * linear and minification either to linear-mipmap-nearest (linear interpolation is used within a + * mipmap, but not between different mipmaps). Trilinear sampling: magnification filtering set to + * linear, minification to linear-mipmap-linear, which offers the best mipmap quality since linear + * interpolation to compute the value in each of two maps and then interpolates linearly between * these two values. * - * @param mode the texture sampling mode. 2: Point Sampling. 3: Linear. 4: - * Bilinear. 5: Trilinear. + * @param mode the texture sampling mode. 2: Point Sampling. 3: Linear. 4: Bilinear. 5: Trilinear. */ public void setTextureSampling(int mode) { - if (mode < 2 || mode > 5) - return; + if (mode < 2 || mode > 5) return; Applet.getInstance().setTextureSampling(mode); ((PGraphicsOpenGL) this.shaderBuffer).textureSampling(mode); ((PGraphicsOpenGL) this.mainBuffer).textureSampling(mode); @@ -349,10 +340,8 @@ public void setTextureSampling(int mode) { } /** - * Adds a new shader to the sprite. If a shader with the received name already - * exists, this method - * >>>>>>> d7b76036d7d2175245fa8de40d42d972914b35f6 - * does nothing. + * Adds a new shader to the sprite. If a shader with the received name already exists, this method + * >>>>>>> d7b76036d7d2175245fa8de40d42d972914b35f6 does nothing. * * @param name * @param shaderPath @@ -402,8 +391,7 @@ public void resetShader() { * Retrieves a shader by name. * * @param name the name of a shader - * @return the shader with the specified name, or null if no shader with that - * name exists + * @return the shader with the specified name, or null if no shader with that name exists */ public Shader getShader(String name) { for (Shader shader : this.shaders) { @@ -425,8 +413,7 @@ public void nextShader() { * @return the name of the current shader, or null if no shaders exist */ public String getCurrentShaderName() { - if (this.shaders.size() == 0 || this.currentShader == -1) - return null; + if (this.shaders.size() == 0 || this.currentShader == -1) return null; return this.shaders.get(this.currentShader).getName(); } @@ -446,51 +433,41 @@ public int getCurrentShaderIndex() { * @return the current shader, or null if no shaders exist */ public Shader getCurrentShader() { - if (this.shaders.size() == 0 || this.currentShader == -1) - return null; + if (this.shaders.size() == 0 || this.currentShader == -1) return null; return this.shaders.get(this.currentShader); } /** - * Moves the specified sprite backwards by a given number of layers in the - * sprite list. If the - * resulting position is less than zero, the sprite is moved to the first - * position. If the - * resulting position is greater than the last index, the sprite is moved to the - * last position. + * Moves the specified sprite backwards by a given number of layers in the sprite list. If the + * resulting position is less than zero, the sprite is moved to the first position. If the + * resulting position is greater than the last index, the sprite is moved to the last position. * * @param sprite the sprite to be moved backwards in the layer order * @param number the number of layers to move the sprite backwards */ public void goLayersBackwards(Sprite sprite, int number) { int index = this.sprites.indexOf(sprite); - if (index == -1) - return; + if (index == -1) return; int newIndex = index - number; - if (newIndex < 0) - newIndex = 0; + if (newIndex < 0) newIndex = 0; newIndex = Math.min(newIndex, this.sprites.size() - 1); this.sprites.remove(index); this.sprites.add(newIndex, sprite); } /** - * Moves the specified sprite forward by a given number of layers in the sprite - * list. If the - * resulting position is out of bounds, it will be adjusted to the nearest valid - * position. + * Moves the specified sprite forward by a given number of layers in the sprite list. If the + * resulting position is out of bounds, it will be adjusted to the nearest valid position. * * @param sprite the sprite to be moved forward in the layer order * @param number the number of layers to move the sprite forward */ public void goLayersForwards(Sprite sprite, int number) { int index = this.sprites.indexOf(sprite); - if (index == -1) - return; + if (index == -1) return; int newIndex = index + number; - if (newIndex < 0) - newIndex = 0; + if (newIndex < 0) newIndex = 0; newIndex = Math.min(newIndex, this.sprites.size() - 1); this.sprites.remove(index); this.sprites.add(newIndex, sprite); @@ -517,8 +494,7 @@ public void goToBackLayer(Sprite sprite) { } /** - * Moves the specified sprite to the UI layer by removing it from the current - * list of sprites. + * Moves the specified sprite to the UI layer by removing it from the current list of sprites. * * @param sprite the sprite to be moved to the UI layer */ @@ -527,10 +503,8 @@ public void goToUILayer(Sprite sprite) { } /** - * Sets a custom sorter for the sprites. Use enableYSort() to enable the sorting - * of sprites using - * the y-coordinates. This overwrites goToBackLayer(), goToFrontLayer(), - * goLayersBackwards() and + * Sets a custom sorter for the sprites. Use enableYSort() to enable the sorting of sprites using + * the y-coordinates. This overwrites goToBackLayer(), goToFrontLayer(), goLayersBackwards() and * goLayersForwards(). * * @see #enableYSort() @@ -541,15 +515,14 @@ public void setSorter(Comparator sorter) { } /** - * Enables the sorting of sprites using y-sorting. This means that sprites with - * a lower - * y-coordinate will be drawn on top of sprites with a higher y-coordinate. This - * sorting respects + * Enables the sorting of sprites using y-sorting. This means that sprites with a lower + * y-coordinate will be drawn on top of sprites with a higher y-coordinate. This sorting respects * the height of the sprites. This overwrites goToBackLayer(), goToFrontLayer(), * goLayersBackwards() and goLayersForwards(). */ public void enableYSort() { - this.sorter = (s1, s2) -> (int) ((s2.getY() - s2.getHeight() / 2) - (s1.getY() - s1.getHeight() / 2)); + this.sorter = + (s1, s2) -> (int) ((s2.getY() - s2.getHeight() / 2) - (s1.getY() - s1.getHeight() / 2)); } /** Disables the sorting of sprites. */ @@ -752,12 +725,11 @@ public long countPensOf(Class c) { } /** - * Add a backdrop to the stage. If a backdrop with the received name already - * exists do nothing. + * Add a backdrop to the stage. If a backdrop with the received name already exists do nothing. * - * @param name a unique name + * @param name a unique name * @param imagePath a image path - * @param stretch stretch image to window size + * @param stretch stretch image to window size */ public void addBackdrop(String name, final String imagePath, boolean stretch) { for (Image backdrop : this.backdrops) { @@ -773,10 +745,9 @@ public void addBackdrop(String name, final String imagePath, boolean stretch) { } /** - * Add a backdrop to the stage. If a backdrop with the received name already - * exists do nothing. + * Add a backdrop to the stage. If a backdrop with the received name already exists do nothing. * - * @param name a unique name + * @param name a unique name * @param imagePath a image path */ public void addBackdrop(String name, final String imagePath) { @@ -822,14 +793,12 @@ private void emitBackdropSwitch() { } /** - * This method is called when the backdrop switches to the specified name. - * Override this method to + * This method is called when the backdrop switches to the specified name. Override this method to * add custom behavior. * * @param name the name of the backdrop to switch to */ - public void whenBackdropSwitches(String name) { - } + public void whenBackdropSwitches(String name) {} /** Switch to the next backdrop. */ public void nextBackdrop() { @@ -901,18 +870,16 @@ public int[] getPixels() { } /** - * This method marks the UI buffer to be erased, which will be processed in the - * next update cycle. + * This method marks the UI buffer to be erased, which will be processed in the next update cycle. */ public void eraseUI() { this.eraseUIBuffer = true; } /** - * Add a sound to the stage. If a sound with the received name already exists do - * nothing. + * Add a sound to the stage. If a sound with the received name already exists do nothing. * - * @param name a unique name + * @param name a unique name * @param soundPath a sound path */ public void addSound(String name, final String soundPath) { @@ -1047,8 +1014,7 @@ public void changeColor(double h) { * @param b a blue value [0...255] */ public void setTint(double r, double g, double b) { - if (this.backdrops.size() == 0) - return; + if (this.backdrops.size() == 0) return; this.backdrops.get(this.currentBackdrop).setTint(r, g, b); } @@ -1058,8 +1024,7 @@ public void setTint(double r, double g, double b) { * @see Image#setTint(double) */ public void setTint(double h) { - if (this.backdrops.size() == 0) - return; + if (this.backdrops.size() == 0) return; this.backdrops.get(this.currentBackdrop).setTint(h); } @@ -1070,8 +1035,7 @@ public void setTint(double h) { * @param step a step value */ public void changeTint(double step) { - if (this.backdrops.size() == 0) - return; + if (this.backdrops.size() == 0) return; this.backdrops.get(this.currentBackdrop).changeTint(step); } @@ -1093,15 +1057,13 @@ public void setTransparency(double transparency) { * @param step a step value */ public void changeTransparency(double step) { - if (this.backdrops.size() == 0) - return; + if (this.backdrops.size() == 0) return; this.backdrops.get(this.currentBackdrop).changeTransparency(step); } /** - * Return the width of the current costume or the pen size, when no costume is - * available. + * Return the width of the current costume or the pen size, when no costume is available. * * @return the width of the sprite */ @@ -1110,8 +1072,7 @@ public int getWidth() { } /** - * Return the height of the current costume or the pen size, when no costume is - * available. + * Return the height of the current costume or the pen size, when no costume is available. * * @return the height of the sprite */ @@ -1144,8 +1105,7 @@ public Timer getTimer(String name) { * @param name the name of the timer */ public void addTimer(String name) { - if ("default".equals(name)) - return; + if ("default".equals(name)) return; this.timer.put(name, new Timer()); } @@ -1156,8 +1116,7 @@ public void addTimer(String name) { * @param name the name of the timer */ public void removeTimer(String name) { - if ("default".equals(name)) - return; + if ("default".equals(name)) return; this.timer.remove(name); } @@ -1198,27 +1157,21 @@ public void mouseEvent(MouseEvent e) { } /** - * This method is called when a mouse click event occurs. Overwrite this method - * to add custom + * This method is called when a mouse click event occurs. Overwrite this method to add custom * behavior. * * @param mouseEvent The mouse event that triggered this method. */ - public void whenMouseClicked(MouseCode mouseEvent) { - } + public void whenMouseClicked(MouseCode mouseEvent) {} /** - * This method is called when the mouse wheel is moved. Overwrite this method to - * add custom + * This method is called when the mouse wheel is moved. Overwrite this method to add custom * behavior. * - * @param steps the number of steps the mouse wheel has moved. Positive values - * indicate movement - * away from the user, while negative values indicate movement - * towards the user. + * @param steps the number of steps the mouse wheel has moved. Positive values indicate movement + * away from the user, while negative values indicate movement towards the user. */ - public void whenMouseWheelMoved(int steps) { - } + public void whenMouseWheelMoved(int steps) {} /** * Returns the current x-position of the mouse cursor @@ -1252,22 +1205,18 @@ public boolean isMouseDown() { } /** - * This method is called when a key is pressed. Override this method to add - * custom behavior. + * This method is called when a key is pressed. Override this method to add custom behavior. * * @param keyCode the code of the key that was pressed */ - public void whenKeyPressed(int keyCode) { - } + public void whenKeyPressed(int keyCode) {} /** - * This method is called when a key is released. Override this method to add - * custom behavior. + * This method is called when a key is released. Override this method to add custom behavior. * * @param keyCode the code of the key that was released */ - public void whenKeyReleased(int keyCode) { - } + public void whenKeyReleased(int keyCode) {} public void keyEvent(KeyEvent e) { switch (e.getAction()) { @@ -1402,7 +1351,7 @@ public int getDaysSince2000() { * Returns a random integer between the specified range (inclusive). * * @param from the lower bound of the range (inclusive) - * @param to the upper bound of the range (inclusive) + * @param to the upper bound of the range (inclusive) * @return a random integer between {@code from} and {@code to} (inclusive) */ public int pickRandom(int from, final int to) { @@ -1424,17 +1373,15 @@ public void display(String text) { /** * Displays the given text on the screen for a specified duration. * - * @param text The text to be displayed. - * @param millis The duration in milliseconds for which the text will be - * displayed. + * @param text The text to be displayed. + * @param millis The duration in milliseconds for which the text will be displayed. */ public void display(String text, final int millis) { this.display.showText(text, millis); } /** - * Broadcasts a message to all sprites in the stage. Each sprite will execute - * its `whenIReceive` + * Broadcasts a message to all sprites in the stage. Each sprite will execute its `whenIReceive` * method with the given message. * * @param message The message to broadcast to all sprites. @@ -1444,8 +1391,7 @@ public void broadcast(String message) { } /** - * Broadcasts a message to all sprites in the stage. Each sprite will execute - * its `whenIReceive` + * Broadcasts a message to all sprites in the stage. Each sprite will execute its `whenIReceive` * method with the given message. * * @param message The message to broadcast to all sprites. @@ -1455,22 +1401,19 @@ public void broadcast(Object message) { } /** - * This method is called when a specific message is received. Override this - * method to add custom + * This method is called when a specific message is received. Override this method to add custom * behavior. * * @param message The message that triggers this method. */ - public void whenIReceive(String message) { - } + public void whenIReceive(String message) {} /** * This method is called when a message is received. * * @param message The message object that is received. */ - public void whenIReceive(Object message) { - } + public void whenIReceive(Object message) {} /** * Sets the cursor image for the stage. @@ -1487,8 +1430,8 @@ public void setCursor(String path) { * Sets the cursor image and its active spot coordinates. * * @param path the file path to the cursor image - * @param x the x-coordinate of the cursor's active spot - * @param y the y-coordinate of the cursor's active spot + * @param x the x-coordinate of the cursor's active spot + * @param y the y-coordinate of the cursor's active spot */ public void setCursor(String path, int x, int y) { this.cursor = path; @@ -1522,17 +1465,14 @@ public double getFrameRate() { } /** - * Executes the main logic of the stage. This method should be overridden by - * subclasses to define + * Executes the main logic of the stage. This method should be overridden by subclasses to define * the specific behavior of the stage. */ - public void run() { - } + public void run() {} public void pre() { Applet applet = Applet.getInstance(); - if (applet == null) - return; + if (applet == null) return; var targetWidth = applet.getRenderWidth(); var targetHeight = applet.getRenderHeight(); var width = applet.getWidth(); @@ -1565,8 +1505,7 @@ public void exit() { public void draw() { Applet applet = Applet.getInstance(); - if (applet == null) - return; + if (applet == null) return; applet.background(0); diff --git a/src/org/openpatch/scratch/Window.java b/src/org/openpatch/scratch/Window.java index 7d08450..c939ac1 100644 --- a/src/org/openpatch/scratch/Window.java +++ b/src/org/openpatch/scratch/Window.java @@ -3,23 +3,16 @@ import org.openpatch.scratch.internal.*; /** - * The Window class represents a singleton window for the application. It - * provides various - * constructors to create a window with different configurations such as - * dimensions, full screen - * mode, and asset paths. The class ensures that only one instance of the window - * can be created at + * The Window class represents a singleton window for the application. It provides various + * constructors to create a window with different configurations such as dimensions, full screen + * mode, and asset paths. The class ensures that only one instance of the window can be created at * any time. * - *

- * The class also provides methods to interact with the window and the - * application, such as - * retrieving the window dimensions, setting the debug mode, managing stages, - * and exiting the + *

The class also provides methods to interact with the window and the application, such as + * retrieving the window dimensions, setting the debug mode, managing stages, and exiting the * application. * - *

- * Example usage: + *

Example usage: * *

{@code
  * Window window = new Window();
@@ -30,32 +23,26 @@
  */
 public class Window {
 
-  /**
-   * The default color used for debugging purposes.
-   */
-  public static final int[] DEBUG_COLOR = { 255, 0, 0 };
+  /** The default color used for debugging purposes. */
+  public static final int[] DEBUG_COLOR = {255, 0, 0};
 
   /**
    * 2: Point Sampling. 3: Linear. 4: Bilinear. 5: Trilinear.
    *
-   * Point sampling: both magnification and minification filtering are set to
-   * nearest.
-   * Linear sampling: magnification filtering is nearest, minification set to
-   * linear
-   * Bilinear sampling: both magnification filtering is set to linear and
-   * minification either to linear-mipmap-nearest (linear interpolation is used
-   * within a mipmap, but not between different mipmaps).
-   * Trilinear sampling: magnification filtering set to linear, minification to
-   * linear-mipmap-linear, which offers the best mipmap quality since linear
-   * interpolation to compute the value in each of two maps and then
-   * interpolates linearly between these two values.
+   * 

Point sampling: both magnification and minification filtering are set to nearest. Linear + * sampling: magnification filtering is nearest, minification set to linear Bilinear sampling: + * both magnification filtering is set to linear and minification either to linear-mipmap-nearest + * (linear interpolation is used within a mipmap, but not between different mipmaps). Trilinear + * sampling: magnification filtering set to linear, minification to linear-mipmap-linear, which + * offers the best mipmap quality since linear interpolation to compute the value in each of two + * maps and then interpolates linearly between these two values. */ public static int TEXTURE_SAMPLING_MODE = 4; + private static Window instance; /** - * Constructs a new Window with default dimensions. The default width is 480 - * pixels and the + * Constructs a new Window with default dimensions. The default width is 480 pixels and the * default height is 360 pixels. */ public Window() { @@ -63,8 +50,7 @@ public Window() { } /** - * Constructs a new Window with the specified assets. The window will have a - * default width of 480 + * Constructs a new Window with the specified assets. The window will have a default width of 480 * pixels and a height of 360 pixels. * * @param assets the path to the assets to be used in the window @@ -76,7 +62,7 @@ public Window(String assets) { /** * Constructs a new Window with the specified width and height. * - * @param width the width of the window + * @param width the width of the window * @param height the height of the window */ public Window(int width, int height) { @@ -84,11 +70,10 @@ public Window(int width, int height) { } /** - * Constructs a new Window with the specified width, height, and assets path. - * Ensures that only + * Constructs a new Window with the specified width, height, and assets path. Ensures that only * one instance of Window can be created. * - * @param width the width of the window + * @param width the width of the window * @param height the height of the window * @param assets the path to the assets * @throws Error if an instance of Window already exists @@ -106,21 +91,18 @@ public Window(int width, int height, String assets) { /** * Constructs a new Window. * - * @param fullScreen a boolean indicating whether the window should be in full - * screen mode. + * @param fullScreen a boolean indicating whether the window should be in full screen mode. */ public Window(boolean fullScreen) { this(fullScreen, null); } /** - * Constructs a new Window instance. If an instance of Window already exists, an - * Error is thrown + * Constructs a new Window instance. If an instance of Window already exists, an Error is thrown * to ensure only one Window instance is created. * - * @param fullScreen a boolean indicating whether the window should be in full - * screen mode - * @param assets a String specifying the path to the assets + * @param fullScreen a boolean indicating whether the window should be in full screen mode + * @param assets a String specifying the path to the assets * @throws Error if an instance of Window already exists */ public Window(boolean fullScreen, String assets) { @@ -170,9 +152,8 @@ public boolean isDebug() { /** * Enables or disables the debug mode for the application. * - * @param debug a boolean value where {@code true} enables debug mode and - * {@code false} disables - * it. + * @param debug a boolean value where {@code true} enables debug mode and {@code false} disables + * it. */ public void setDebug(boolean debug) { Applet.getInstance().setDebug(debug); @@ -207,7 +188,7 @@ public void setStage(Stage stage) { /** * @deprecated since 4.0.0. Use setStage instead. - * @param name Name of the stage + * @param name Name of the stage * @param stage A stage object */ @Deprecated(since = "4.0.0") @@ -243,8 +224,7 @@ public Stage getStage() { } /** - * Exits the application by invoking the `whenExits` method and then calling the - * `exit` method on + * Exits the application by invoking the `whenExits` method and then calling the `exit` method on * the `Applet` instance. */ public void exit() { @@ -253,10 +233,8 @@ public void exit() { } /** - * This method is called when the window exits. Override this method to define - * custom behavior + * This method is called when the window exits. Override this method to define custom behavior * when the window is closed. */ - public void whenExits() { - } + public void whenExits() {} } diff --git a/src/org/openpatch/scratch/extensions/text/Text.java b/src/org/openpatch/scratch/extensions/text/Text.java index abc88f1..ab0a2eb 100644 --- a/src/org/openpatch/scratch/extensions/text/Text.java +++ b/src/org/openpatch/scratch/extensions/text/Text.java @@ -14,12 +14,9 @@ import processing.core.PGraphics; /** - * The Text class represents a text object that can be displayed on the stage. - * It provides methods - * to set the text content, position, size, style, and alignment. The text can - * be displayed in - * various styles such as plain, speech bubble, or box. The text can be - * associated with a sprite and + * The Text class represents a text object that can be displayed on the stage. It provides methods + * to set the text content, position, size, style, and alignment. The text can be displayed in + * various styles such as plain, speech bubble, or box. The text can be associated with a sprite and * displayed relative to the sprite's position. Example usage: * *

{@code
@@ -56,36 +53,27 @@ public class Text {
   private Color strokeColor;
   private int textAlign = -1;
 
-  /**
-   * SPEAK_BUBBLE_MAX_LIMIT is the maximum width of the speech bubble.
-   */
+  /** SPEAK_BUBBLE_MAX_LIMIT is the maximum width of the speech bubble. */
   public static int SPEAK_BUBBLE_MAX_LIMIT = 330;
-  /**
-   * SPEAK_BUBBLE_MIN_LIMIT is the minimum width of the speech bubble.
-   */
+
+  /** SPEAK_BUBBLE_MIN_LIMIT is the minimum width of the speech bubble. */
   public static int SPEAK_BUBBLE_MIN_LIMIT = 80;
-  /**
-   * DEFAULT_FONT_SIZE is the default font size for the text.
-   */
+
+  /** DEFAULT_FONT_SIZE is the default font size for the text. */
   public static int DEFAULT_FONT_SIZE = 14;
-  /**
-   * DEFAULT_FONT is the default font for the text.
-   */
+
+  /** DEFAULT_FONT is the default font for the text. */
   public static String DEFAULT_FONT = "UbuntuMono-Regular.ttf";
-  /**
-   * FONT_SIZES is an array of font sizes that can be used for the text.
-   */
-  public static int[] FONT_SIZES = { DEFAULT_FONT_SIZE };
-  /**
-   * SMOOTHING is a boolean flag that indicates whether text will be smoothed
-   */
+
+  /** FONT_SIZES is an array of font sizes that can be used for the text. */
+  public static int[] FONT_SIZES = {DEFAULT_FONT_SIZE};
+
+  /** SMOOTHING is a boolean flag that indicates whether text will be smoothed */
   public static boolean SMOOTHING = true;
 
   /**
-   * Constructs a new Text object with default values. The text is initialized to
-   * an empty string,
-   * positioned at (0, 0), with a default size of 0. The text style is set to
-   * plain and the text
+   * Constructs a new Text object with default values. The text is initialized to an empty string,
+   * positioned at (0, 0), with a default size of 0. The text style is set to plain and the text
    * alignment is set to center.
    */
   public Text() {
@@ -108,9 +96,9 @@ public Text(Sprite s) {
   /**
    * Constructs a new Text object with the specified text, position, and width.
    *
-   * @param text  the text to be displayed
-   * @param x     the x-coordinate of the text's position
-   * @param y     the y-coordinate of the text's position
+   * @param text the text to be displayed
+   * @param x the x-coordinate of the text's position
+   * @param y the y-coordinate of the text's position
    * @param width the width of the text
    */
   public Text(String text, double x, double y, double width) {
@@ -128,12 +116,11 @@ public Text(String text, double x, double y, double width) {
   }
 
   /**
-   * Constructs a new Text object with the specified text, position, width, and
-   * style.
+   * Constructs a new Text object with the specified text, position, width, and style.
    *
-   * @param text  the text content to be displayed
-   * @param x     the x-coordinate of the text's position
-   * @param y     the y-coordinate of the text's position
+   * @param text the text content to be displayed
+   * @param x the x-coordinate of the text's position
+   * @param y the y-coordinate of the text's position
    * @param width the width of the text area
    * @param style the style to be applied to the text
    */
@@ -143,8 +130,7 @@ public Text(String text, double x, double y, double width, TextStyle style) {
   }
 
   /**
-   * Copy constructor for the Text class. Creates a new Text object by copying the
-   * properties of the
+   * Copy constructor for the Text class. Creates a new Text object by copying the properties of the
    * given Text object.
    *
    * @param t the Text object to copy
@@ -185,45 +171,35 @@ public void removedFromStage(Stage stage) {
   }
 
   /**
-   * This method is called when the object is added to the stage. Override this
-   * method to define
+   * This method is called when the object is added to the stage. Override this method to define
    * custom behavior when the object is added to the stage.
    */
-  public void whenAddedToStage() {
-  }
+  public void whenAddedToStage() {}
 
   /**
-   * This method is called when the text is added to the stage. Override this
-   * method to define
+   * This method is called when the text is added to the stage. Override this method to define
    * custom behavior when the text.
    *
    * @param stage The stage to which the text is added.
    */
-  public void whenAddedToStage(Stage stage) {
-  }
+  public void whenAddedToStage(Stage stage) {}
 
   /**
-   * This method is called when the object is removed from the stage. Override
-   * this method to define
-   * custom behavior that should occur when the object is no longer part of the
-   * stage.
+   * This method is called when the object is removed from the stage. Override this method to define
+   * custom behavior that should occur when the object is no longer part of the stage.
    */
-  public void whenRemovedFromStage() {
-  }
+  public void whenRemovedFromStage() {}
 
   /**
-   * This method is called when the text is removed from the stage. Override this
-   * method to define
+   * This method is called when the text is removed from the stage. Override this method to define
    * custom behavior that should occur.
    *
    * @param stage The stage from which the text is removed.
    */
-  public void whenRemovedFromStage(Stage stage) {
-  }
+  public void whenRemovedFromStage(Stage stage) {}
 
   /**
-   * Removes this object from its current stage if it is associated with one. If
-   * the object is not
+   * Removes this object from its current stage if it is associated with one. If the object is not
    * associated with any stage, this method does nothing.
    */
   public void remove() {
@@ -274,10 +250,8 @@ public void switchFont(String name) {
   }
 
   /**
-   * Advances to the next font in the list of available fonts. The current font
-   * index is incremented
-   * by one and wraps around to the beginning of the list if it exceeds the number
-   * of available
+   * Advances to the next font in the list of available fonts. The current font index is incremented
+   * by one and wraps around to the beginning of the list if it exceeds the number of available
    * fonts.
    */
   public void nextFont() {
@@ -287,8 +261,7 @@ public void nextFont() {
   /**
    * Retrieves the name of the current font.
    *
-   * @return the name of the current font, or {@code null} if no fonts are
-   *         available.
+   * @return the name of the current font, or {@code null} if no fonts are available.
    */
   public String getCurrentFontName() {
     if (this.fonts.size() == 0) {
@@ -374,9 +347,8 @@ public double getY() {
   /**
    * Displays the specified text.
    *
-   * @param text The text to be displayed. If the text is null or empty, the text
-   *             will be set to
-   *             null.
+   * @param text The text to be displayed. If the text is null or empty, the text will be set to
+   *     null.
    */
   public void showText(String text) {
     this.show = true;
@@ -390,9 +362,8 @@ public void showText(String text) {
   /**
    * Displays the specified text for a given duration.
    *
-   * @param text   The text to be displayed.
-   * @param millis The duration in milliseconds for which the text should be
-   *               displayed.
+   * @param text The text to be displayed.
+   * @param millis The duration in milliseconds for which the text should be displayed.
    */
   public void showText(String text, int millis) {
     this.showText(text);
@@ -553,9 +524,8 @@ public void setWidth(double width) {
   /**
    * Sets the alignment of the text.
    *
-   * @param align the alignment value to set. This could be a constant
-   *              representing left, center, or
-   *              right alignment.
+   * @param align the alignment value to set. This could be a constant representing left, center, or
+   *     right alignment.
    */
   public void setAlign(int align) {
     this.textAlign = align;
@@ -573,8 +543,7 @@ public void setIsUI(boolean isUI) {
   /**
    * Checks if the current instance is a UI element.
    *
-   * @return {@code true} if this instance is a UI element, {@code false}
-   *         otherwise.
+   * @return {@code true} if this instance is a UI element, {@code false} otherwise.
    */
   public boolean isUI() {
     return this.isUI;
@@ -725,10 +694,8 @@ private void drawPlain(PGraphics buffer) {
   }
 
   public void draw(PGraphics buffer) {
-    if (this.stage == null)
-      return;
-    if (!this.show || this.originalText == null)
-      return;
+    if (this.stage == null) return;
+    if (!this.show || this.originalText == null) return;
 
     buffer.push();
     if (this.textAlign != TextAlign.DEFAULT) {
@@ -741,18 +708,21 @@ public void draw(PGraphics buffer) {
 
     switch (this.style) {
       case SPEAK:
-      case THINK: {
-        this.drawBubble(buffer);
-        break;
-      }
-      case PLAIN: {
-        this.drawPlain(buffer);
-        break;
-      }
-      case BOX: {
-        this.drawBox(buffer);
-        break;
-      }
+      case THINK:
+        {
+          this.drawBubble(buffer);
+          break;
+        }
+      case PLAIN:
+        {
+          this.drawPlain(buffer);
+          break;
+        }
+      case BOX:
+        {
+          this.drawBox(buffer);
+          break;
+        }
     }
     buffer.pop();
 
diff --git a/src/org/openpatch/scratch/internal/Applet.java b/src/org/openpatch/scratch/internal/Applet.java
index 9336f24..6d65d37 100644
--- a/src/org/openpatch/scratch/internal/Applet.java
+++ b/src/org/openpatch/scratch/internal/Applet.java
@@ -21,8 +21,7 @@
 import processing.sound.SoundFile;
 
 /**
- * The Applet class represents the main application window. It is responsible
- * for loading assets,
+ * The Applet class represents the main application window. It is responsible for loading assets,
  * managing stages, and handling mouse and keyboard events.
  */
 public class Applet extends PApplet {
@@ -45,13 +44,12 @@ public class Applet extends PApplet {
   private String loadingText = "";
 
   /**
-   * Constructs an Applet with the specified width, height, fullscreen mode, and
-   * assets path.
+   * Constructs an Applet with the specified width, height, fullscreen mode, and assets path.
    *
-   * @param width      the width of the window
-   * @param height     the height of the window
+   * @param width the width of the window
+   * @param height the height of the window
    * @param fullscreen whether the window should be fullscreen
-   * @param assets     the path to the assets directory
+   * @param assets the path to the assets directory
    */
   public Applet(int width, final int height, final boolean fullscreen, final String assets) {
     if (height == 0) {
@@ -90,9 +88,8 @@ public static Applet getInstance() {
   /**
    * Enables or disables the debug mode for the application.
    *
-   * @param debug a boolean value where {@code true} enables debug mode and
-   *              {@code false} disables
-   *              it.
+   * @param debug a boolean value where {@code true} enables debug mode and {@code false} disables
+   *     it.
    */
   public void setDebug(boolean debug) {
     this.debug = debug;
@@ -144,7 +141,7 @@ public double getTextSize() {
 
   /**
    * @deprecated since 4.0.0. Use setStage instead.
-   * @param name  Name of the stage
+   * @param name Name of the stage
    * @param stage A stage object
    */
   @Deprecated(since = "4.0.0")
@@ -234,8 +231,7 @@ public void redrawSketch() {
   public void runSketch() {
     if (!this.isRunning) {
       super.runSketch();
-      while (this.surface.isStopped()) {
-      }
+      while (this.surface.isStopped()) {}
       this.isRunning = true;
     }
   }
@@ -249,7 +245,8 @@ public void setup() {
 
     this.loading = this.loadImage("loading.png");
     var loadingScaleX = this.RENDER_WIDTH / 480.0;
-    var loadingScaleY = this.RENDER_HEIGHT / (360.0 + 150); // normal height + padding for loading text
+    var loadingScaleY =
+        this.RENDER_HEIGHT / (360.0 + 150); // normal height + padding for loading text
     var scale = Math.min(1, Math.min(loadingScaleX, loadingScaleY));
     this.loading.resize((int) (this.loading.width * scale), (int) (this.loading.height * scale));
   }
@@ -279,18 +276,21 @@ public void loadAssets() {
           }
         }
 
-        var imageFiles = Files.find(p, Integer.MAX_VALUE, (filePath, fileAttr) -> fileAttr.isRegularFile())
-            .map(f -> f.toString())
-            .filter(f -> f.endsWith(".png") || f.endsWith(".jpg") || f.endsWith(".jpeg"))
-            .collect(Collectors.toList());
-        var soundFiles = Files.find(p, Integer.MAX_VALUE, (filePath, fileAttr) -> fileAttr.isRegularFile())
-            .map(f -> f.toString())
-            .filter(f -> f.endsWith(".mp3") || f.endsWith(".wav"))
-            .collect(Collectors.toList());
-        var fontFiles = Files.find(p, Integer.MAX_VALUE, (filePath, fileAttr) -> fileAttr.isRegularFile())
-            .map(f -> f.toString())
-            .filter(f -> f.endsWith(".ttf") || f.endsWith(".otf"))
-            .collect(Collectors.toList());
+        var imageFiles =
+            Files.find(p, Integer.MAX_VALUE, (filePath, fileAttr) -> fileAttr.isRegularFile())
+                .map(f -> f.toString())
+                .filter(f -> f.endsWith(".png") || f.endsWith(".jpg") || f.endsWith(".jpeg"))
+                .collect(Collectors.toList());
+        var soundFiles =
+            Files.find(p, Integer.MAX_VALUE, (filePath, fileAttr) -> fileAttr.isRegularFile())
+                .map(f -> f.toString())
+                .filter(f -> f.endsWith(".mp3") || f.endsWith(".wav"))
+                .collect(Collectors.toList());
+        var fontFiles =
+            Files.find(p, Integer.MAX_VALUE, (filePath, fileAttr) -> fileAttr.isRegularFile())
+                .map(f -> f.toString())
+                .filter(f -> f.endsWith(".ttf") || f.endsWith(".otf"))
+                .collect(Collectors.toList());
         this.numberAssets += imageFiles.size();
         this.numberAssets += soundFiles.size();
         this.numberAssets += fontFiles.size();
diff --git a/src/org/openpatch/scratch/internal/Font.java b/src/org/openpatch/scratch/internal/Font.java
index 9d97ef3..13f11b0 100644
--- a/src/org/openpatch/scratch/internal/Font.java
+++ b/src/org/openpatch/scratch/internal/Font.java
@@ -2,23 +2,20 @@
 
 import java.util.AbstractMap;
 import java.util.concurrent.ConcurrentHashMap;
-
 import org.openpatch.scratch.extensions.text.Text;
-
 import processing.core.PFont;
 
 /**
- * The Font class represents a font that can be used to render text on the
- * screen. It supports
- * various functionalities such as loading fonts from files, setting font sizes,
- * and getting the
+ * The Font class represents a font that can be used to render text on the screen. It supports
+ * various functionalities such as loading fonts from files, setting font sizes, and getting the
  * font object for a specific size.
  */
 public class Font {
   private String name;
   private AbstractMap fontMap;
 
-  private static final AbstractMap> fonts = new ConcurrentHashMap<>();
+  private static final AbstractMap> fonts =
+      new ConcurrentHashMap<>();
 
   /** The default font. */
   public static PFont defaultFont;
@@ -62,7 +59,9 @@ public String getName() {
    */
   public static PFont getDefaultFont() {
     if (defaultFont == null) {
-      defaultFont = Applet.getInstance().createFont(Text.DEFAULT_FONT, Text.DEFAULT_FONT_SIZE, Text.SMOOTHING);
+      defaultFont =
+          Applet.getInstance()
+              .createFont(Text.DEFAULT_FONT, Text.DEFAULT_FONT_SIZE, Text.SMOOTHING);
     }
     return defaultFont;
   }