improved code to pass the code analysis

This commit is contained in:
Daniel Grigencha
2024-10-09 23:30:28 +02:00
parent 08c5eeb63d
commit 2c4e2fd92d
2 changed files with 5 additions and 17 deletions

View File

@@ -19,17 +19,12 @@
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box; import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Cylinder;
import pp.battleship.client.BattleshipApp; import pp.battleship.client.BattleshipApp;
import pp.battleship.model.Battleship; import pp.battleship.model.Battleship;
import pp.battleship.model.Rotation; import pp.battleship.model.Rotation;
import pp.battleship.model.ShipMap; import pp.battleship.model.ShipMap;
import pp.battleship.model.Shot; import pp.battleship.model.Shot;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
import static pp.util.FloatMath.HALF_PI; import static pp.util.FloatMath.HALF_PI;
import static pp.util.FloatMath.PI; import static pp.util.FloatMath.PI;
@@ -40,8 +35,7 @@
* It extends the {@link ShipMapSynchronizer} to provide specific synchronization * It extends the {@link ShipMapSynchronizer} to provide specific synchronization
* logic for the sea map. * logic for the sea map.
*/ */
class SeaSynchronizer extends ShipMapSynchronizer { class SeaSynchronizer extends ShipMapSynchronizer { ;
private static final Logger LOGGER = System.getLogger(SeaSynchronizer.class.getName());
private static final String UNSHADED = "Common/MatDefs/Misc/Unshaded.j3md"; //NON-NLS private static final String UNSHADED = "Common/MatDefs/Misc/Unshaded.j3md"; //NON-NLS
private static final String KING_GEORGE_V_MODEL = "Models/KingGeorgeV/KingGeorgeV.j3o"; //NON-NLS private static final String KING_GEORGE_V_MODEL = "Models/KingGeorgeV/KingGeorgeV.j3o"; //NON-NLS
@@ -52,10 +46,7 @@ class SeaSynchronizer extends ShipMapSynchronizer {
private static final String ATLANTICA_MODEL = "Models/Atlantica/Atlantica.j3o"; //NON-NLS private static final String ATLANTICA_MODEL = "Models/Atlantica/Atlantica.j3o"; //NON-NLS
private static final String COLOR = "Color"; //NON-NLS private static final String COLOR = "Color"; //NON-NLS
private static final String SHIP = "ship"; //NON-NLS private static final String SHIP = "ship"; //NON-NLS
private static final String SHOT = "shot"; //NON-NLS
private static final ColorRGBA BOX_COLOR = ColorRGBA.Gray; private static final ColorRGBA BOX_COLOR = ColorRGBA.Gray;
private static final ColorRGBA SPLASH_COLOR = new ColorRGBA(0f, 0f, 1f, 0.4f);
private static final ColorRGBA HIT_COLOR = new ColorRGBA(1f, 0f, 0f, 0.4f);
private final ShipMap map; private final ShipMap map;
private final BattleshipApp app; private final BattleshipApp app;
@@ -233,7 +224,7 @@ private Spatial createBox(Battleship ship) {
0.3f, 0.3f,
0.5f * (ship.getMaxX() - ship.getMinX()) + 0.3f); 0.5f * (ship.getMaxX() - ship.getMinX()) + 0.3f);
final Geometry geometry = new Geometry(SHIP, box); final Geometry geometry = new Geometry(SHIP, box);
geometry.setMaterial(createColoredMaterial(BOX_COLOR)); geometry.setMaterial(createColoredMaterial());
geometry.setShadowMode(ShadowMode.CastAndReceive); geometry.setShadowMode(ShadowMode.CastAndReceive);
return geometry; return geometry;
@@ -245,16 +236,14 @@ private Spatial createBox(Battleship ship) {
* the material's render state is set to use alpha blending, allowing for * the material's render state is set to use alpha blending, allowing for
* semi-transparent rendering. * semi-transparent rendering.
* *
* @param color the {@link ColorRGBA} to be applied to the material. If the alpha value
* of the color is less than 1, the material will support transparency.
* @return a {@link Material} instance configured with the specified color and, * @return a {@link Material} instance configured with the specified color and,
* if necessary, alpha blending enabled. * if necessary, alpha blending enabled.
*/ */
private Material createColoredMaterial(ColorRGBA color) { private Material createColoredMaterial() {
final Material material = new Material(app.getAssetManager(), UNSHADED); final Material material = new Material(app.getAssetManager(), UNSHADED);
if (color.getAlpha() < 1f) if (SeaSynchronizer.BOX_COLOR.getAlpha() < 1f)
material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
material.setColor(COLOR, color); material.setColor(COLOR, SeaSynchronizer.BOX_COLOR);
return material; return material;
} }

View File

@@ -13,7 +13,6 @@
import com.jme3.renderer.ViewPort; import com.jme3.renderer.ViewPort;
import com.jme3.scene.control.AbstractControl; import com.jme3.scene.control.AbstractControl;
import pp.battleship.model.Battleship; import pp.battleship.model.Battleship;
import pp.battleship.model.ShipMap;
import static pp.util.FloatMath.DEG_TO_RAD; import static pp.util.FloatMath.DEG_TO_RAD;
import static pp.util.FloatMath.TWO_PI; import static pp.util.FloatMath.TWO_PI;