Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Try to customise prettifier's wrapping #125

Merged
merged 5 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: creyD/[email protected]
with:
prettier_plugins: prettier-plugin-java
prettier_options: '--write **/*.java --tab-width 4'
prettier_options: '--write **/*.java --config ./.prettier.json'

build:
needs: format
Expand Down
4 changes: 4 additions & 0 deletions .prettier.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"printWidth": 120,
"tabWidth": 4
}
19 changes: 9 additions & 10 deletions core/src/cs/eng1/piazzapanic/PlayerState.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@ public class PlayerState {
}
};

private final HashMap<PowerUp, Integer> powerUpCosts =
new HashMap<PowerUp, Integer>() {
{
put(PowerUp.WALK_FAST, 100);
put(PowerUp.COOK_FAST, 100);
put(PowerUp.NO_SPOILING, 100);
put(PowerUp.NO_REP_LOSS, 100);
put(PowerUp.MORE_MONEY, 100);
}
};
private final HashMap<PowerUp, Integer> powerUpCosts = new HashMap<PowerUp, Integer>() {
{
put(PowerUp.WALK_FAST, 100);
put(PowerUp.COOK_FAST, 100);
put(PowerUp.NO_SPOILING, 100);
put(PowerUp.NO_REP_LOSS, 100);
put(PowerUp.MORE_MONEY, 100);
}
};

public enum PowerUp {
WALK_FAST,
Expand Down
10 changes: 2 additions & 8 deletions core/src/cs/eng1/piazzapanic/box2d/Box2dRadiusProximity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@
* @author davebaol */
public class Box2dRadiusProximity extends Box2dSquareAABBProximity {

public Box2dRadiusProximity(
Steerable<Vector2> owner,
World world,
float detectionRadius
) {
public Box2dRadiusProximity(Steerable<Vector2> owner, World world, float detectionRadius) {
super(owner, world, detectionRadius);
}

Expand All @@ -49,9 +45,7 @@ protected boolean accept(Steerable<Vector2> steerable) {

// Make sure the current body is within the range.
// Notice we're working in distance-squared space to avoid square root.
float distanceSquare = steerable
.getPosition()
.dst2(owner.getPosition());
float distanceSquare = steerable.getPosition().dst2(owner.getPosition());

return distanceSquare <= range * range;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
*
* @author davebaol
*/
public class Box2dRaycastCollisionDetector
implements RaycastCollisionDetector<Vector2> {
public class Box2dRaycastCollisionDetector implements RaycastCollisionDetector<Vector2> {

World world;
Box2dRaycastCallback callback;
Expand All @@ -40,10 +39,7 @@ public Box2dRaycastCollisionDetector(World world) {
this(world, new Box2dRaycastCallback());
}

public Box2dRaycastCollisionDetector(
World world,
Box2dRaycastCallback callback
) {
public Box2dRaycastCollisionDetector(World world, Box2dRaycastCallback callback) {
this.world = world;
this.callback = callback;
}
Expand All @@ -54,17 +50,9 @@ public boolean collides(Ray<Vector2> ray) {
}

@Override
public boolean findCollision(
Collision<Vector2> outputCollision,
Ray<Vector2> inputRay
) {
public boolean findCollision(Collision<Vector2> outputCollision, Ray<Vector2> inputRay) {
callback.collided = false;
if (
!inputRay.start.epsilonEquals(
inputRay.end,
MathUtils.FLOAT_ROUNDING_ERROR
)
) {
if (!inputRay.start.epsilonEquals(inputRay.end, MathUtils.FLOAT_ROUNDING_ERROR)) {
callback.outputCollision = outputCollision;
world.rayCast(callback, inputRay.start, inputRay.end);
}
Expand All @@ -79,12 +67,7 @@ public static class Box2dRaycastCallback implements RayCastCallback {
public Box2dRaycastCallback() {}

@Override
public float reportRayFixture(
Fixture fixture,
Vector2 point,
Vector2 normal,
float fraction
) {
public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
if (outputCollision != null) outputCollision.set(point, normal);
collided = true;
return fraction;
Expand Down
17 changes: 3 additions & 14 deletions core/src/cs/eng1/piazzapanic/box2d/Box2dSquareAABBProximity.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
* square AABB built around the circle having the specified detection radius and whose center is the owner position.
*
* @author davebaol */
public class Box2dSquareAABBProximity
implements Proximity<Vector2>, QueryCallback {
public class Box2dSquareAABBProximity implements Proximity<Vector2>, QueryCallback {

protected Steerable<Vector2> owner;
protected World world;
Expand All @@ -43,11 +42,7 @@ public class Box2dSquareAABBProximity

private static final AABB aabb = new AABB();

public Box2dSquareAABBProximity(
Steerable<Vector2> owner,
World world,
float detectionRadius
) {
public Box2dSquareAABBProximity(Steerable<Vector2> owner, World world, float detectionRadius) {
this.owner = owner;
this.world = world;
this.detectionRadius = detectionRadius;
Expand Down Expand Up @@ -90,13 +85,7 @@ public int findNeighbors(ProximityCallback<Vector2> behaviorCallback) {
this.behaviorCallback = behaviorCallback;
neighborCount = 0;
prepareAABB(aabb);
world.QueryAABB(
this,
aabb.lowerX,
aabb.lowerY,
aabb.upperX,
aabb.upperY
);
world.QueryAABB(this, aabb.lowerX, aabb.lowerY, aabb.upperX, aabb.upperY);
this.behaviorCallback = null;
return neighborCount;
}
Expand Down
28 changes: 8 additions & 20 deletions core/src/cs/eng1/piazzapanic/box2d/Box2dSteeringBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,11 @@ public class Box2dSteeringBody implements Steerable<Vector2> {

protected SteeringBehavior<Vector2> steeringBehavior;

private static final SteeringAcceleration<Vector2> steeringOutput =
new SteeringAcceleration<Vector2>(new Vector2());

public Box2dSteeringBody(
Body body,
boolean independentFacing,
float boundingRadius
) {
private static final SteeringAcceleration<Vector2> steeringOutput = new SteeringAcceleration<Vector2>(
new Vector2()
);

public Box2dSteeringBody(Body body, boolean independentFacing, float boundingRadius) {
this.body = body;
this.independentFacing = independentFacing;
this.boundingRadius = boundingRadius;
Expand Down Expand Up @@ -139,9 +136,7 @@ public SteeringBehavior<Vector2> getSteeringBehavior() {
return steeringBehavior;
}

public void setSteeringBehavior(
SteeringBehavior<Vector2> steeringBehavior
) {
public void setSteeringBehavior(SteeringBehavior<Vector2> steeringBehavior) {
this.steeringBehavior = steeringBehavior;
}

Expand All @@ -154,10 +149,7 @@ public void update(float deltaTime) {
}
}

protected void applySteering(
SteeringAcceleration<Vector2> steering,
float deltaTime
) {
protected void applySteering(SteeringAcceleration<Vector2> steering, float deltaTime) {
boolean anyAccelerations = false;

// Update position and linear velocity.
Expand All @@ -182,11 +174,7 @@ protected void applySteering(
float currentSpeedSquare = velocity.len2();
float maxLinearSpeed = getMaxLinearSpeed();
if (currentSpeedSquare > maxLinearSpeed * maxLinearSpeed) {
body.setLinearVelocity(
velocity.scl(
maxLinearSpeed / (float) Math.sqrt(currentSpeedSquare)
)
);
body.setLinearVelocity(velocity.scl(maxLinearSpeed / (float) Math.sqrt(currentSpeedSquare)));
}

// Cap the angular speed
Expand Down
21 changes: 4 additions & 17 deletions core/src/cs/eng1/piazzapanic/box2d/MapBodyBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ public class MapBodyBuilder {
* @param world Box2D {@link World} to create objects in.
* @return Array of built shapes for further processing.
*/
public static Array<Body> buildShapes(
MapLayer layer,
float pixels,
World world
) {
public static Array<Body> buildShapes(MapLayer layer, float pixels, World world) {
ppt = pixels;
MapObjects shadowedObjects = layer.getObjects();

Expand Down Expand Up @@ -93,21 +89,14 @@ private static Shape decideShape(MapObject object) {
return shape;
}

private static PolygonShape getRectangle(
RectangleMapObject rectangleObject
) {
private static PolygonShape getRectangle(RectangleMapObject rectangleObject) {
Rectangle rectangle = rectangleObject.getRectangle();
PolygonShape polygon = new PolygonShape();
Vector2 size = new Vector2(
(rectangle.x + rectangle.width * 0.5f) / ppt,
(rectangle.y + rectangle.height * 0.5f) / ppt
);
polygon.setAsBox(
rectangle.width * 0.5f / ppt,
rectangle.height * 0.5f / ppt,
size,
0.0f
);
polygon.setAsBox(rectangle.width * 0.5f / ppt, rectangle.height * 0.5f / ppt, size, 0.0f);
return polygon;
}

Expand All @@ -127,9 +116,7 @@ private static PolygonShape getPolygon(PolygonMapObject polygonObject) {
}

private static ChainShape getPolyline(PolylineMapObject polylineObject) {
float[] vertices = polylineObject
.getPolyline()
.getTransformedVertices();
float[] vertices = polylineObject.getPolyline().getTransformedVertices();
Vector2[] worldVertices = new Vector2[vertices.length / 2];

for (int i = 0; i < vertices.length / 2; ++i) {
Expand Down
10 changes: 1 addition & 9 deletions core/src/cs/eng1/piazzapanic/chef/Chef.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,7 @@ public void draw(Batch batch, float parentAlpha) {

@Override
public void act(float delta) {
Vector2 movement = getInput()
.scl(
speed *
(
PlayerState.getInstance().getBuffActive(PowerUp.WALK_FAST)
? 2
: 1
)
);
Vector2 movement = getInput().scl(speed * (PlayerState.getInstance().getBuffActive(PowerUp.WALK_FAST) ? 2 : 1));
Vector2 bodyVector2 = body.getPosition();

if (!movement.isZero(0.1f)) {
Expand Down
30 changes: 6 additions & 24 deletions core/src/cs/eng1/piazzapanic/chef/ChefManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ public class ChefManager implements Disposable {
* @param keyboardInput Input processor for input from the keyboard. Passed down
* to the chefs this class owns.
*/
public ChefManager(
float chefScale,
UIOverlay overlay,
World world,
KeyboardInput keyboardInput
) {
public ChefManager(float chefScale, UIOverlay overlay, World world, KeyboardInput keyboardInput) {
this.overlay = overlay;
this.world = world;
this.keyboardInput = keyboardInput;
Expand All @@ -73,10 +68,7 @@ public ChefManager(
Texture chefTexture = new Texture(Gdx.files.internal(sprite));
Chef chef = new Chef(
chefTexture,
new Vector2(
chefTexture.getWidth() * chefScale,
chefTexture.getHeight() * chefScale
),
new Vector2(chefTexture.getWidth() * chefScale, chefTexture.getHeight() * chefScale),
this
);
chef.setInputEnabled(false);
Expand All @@ -100,15 +92,10 @@ public ChefManager(
chefs = new ArrayList<>();

for (SavedChef savedChef : save.savedChefs) {
Texture chefTexture = new Texture(
Gdx.files.internal(savedChef.imagePath)
);
Texture chefTexture = new Texture(Gdx.files.internal(savedChef.imagePath));
Chef chef = new Chef(
chefTexture,
new Vector2(
chefTexture.getWidth() * chefScale,
chefTexture.getHeight() * chefScale
),
new Vector2(chefTexture.getWidth() * chefScale, chefTexture.getHeight() * chefScale),
this
);
chef.init(savedChef.position.x, savedChef.position.y);
Expand Down Expand Up @@ -147,15 +134,10 @@ public void hireChef(Vector2 position, Stage stage) {
return;
}

Texture chefTexture = new Texture(
Gdx.files.internal(chefSprites[chefs.size()])
);
Texture chefTexture = new Texture(Gdx.files.internal(chefSprites[chefs.size()]));
Chef chef = new Chef(
chefTexture,
new Vector2(
chefTexture.getWidth() * chefScale,
chefTexture.getHeight() * chefScale
),
new Vector2(chefTexture.getWidth() * chefScale, chefTexture.getHeight() * chefScale),
this
);

Expand Down
13 changes: 2 additions & 11 deletions core/src/cs/eng1/piazzapanic/customer/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,7 @@ public class Customer extends Actor implements Disposable {
private boolean orderCompleted = false;
private Box2dLocation endObjective;

public Customer(
Texture texture,
Vector2 bounds,
Vector2 position,
Recipe order,
CustomerManager customerManager
) {
public Customer(Texture texture, Vector2 bounds, Vector2 position, Recipe order, CustomerManager customerManager) {
repTimer = new Timer(60000, true, false);
this.order = order;
this.customerManager = customerManager;
Expand Down Expand Up @@ -114,10 +108,7 @@ public void fulfillOrder() {
boolean happiness = (repTimer.getDelay() / repTimer.getElapsed()) > 0.5;
PlayerState.getInstance().earnCash(100, happiness);
orderCompleted = true;
Gdx.app.log(
"Current cash",
Float.toString(PlayerState.getInstance().getCash())
);
Gdx.app.log("Current cash", Float.toString(PlayerState.getInstance().getCash()));
customerManager.walkBack(this);
endObjective = customerManager.getObjective(currentObjective);
}
Expand Down
Loading