Skip to content

Commit

Permalink
Automatic code reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
Lonami committed Feb 5, 2018
1 parent d7db9b8 commit ef2fb8f
Show file tree
Hide file tree
Showing 23 changed files with 153 additions and 107 deletions.
50 changes: 24 additions & 26 deletions core/src/io/github/lonamiwebs/klooni/Klooni.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@
import io.github.lonamiwebs.klooni.screens.TransitionScreen;

public class Klooni extends Game {
// region Effects

//region Members

// FIXME theme should NOT be static as it might load textures which will expose it to the race condition iff GDX got initialized before or not
public static Theme theme;
public IEffectFactory effect;

// ordered list of effects. index 0 will get default if VanishEffectFactory is removed from list
public final static IEffectFactory[] EFFECTS = {
Expand All @@ -51,31 +56,7 @@ public class Klooni extends Game {
new ExplodeEffectFactory(),
};


private Map<String, Sound> effectSounds;

private void loadEffectSound(final String effectName) {
FileHandle soundFile = Gdx.files.internal("sound/effect_" + effectName + ".mp3");
if (!soundFile.exists())
soundFile = Gdx.files.internal("sound/effect_vanish.mp3");

effectSounds.put(effectName, Gdx.audio.newSound(soundFile));
}

public void playEffectSound() {
effectSounds.get(effect.getName())
.play(MathUtils.random(0.7f, 1f), MathUtils.random(0.8f, 1.2f), 0);
}

// endregion

//region Members

// FIXME theme should NOT be static as it might load textures which will expose it to the race condition iff GDX got initialized before or not
public static Theme theme;
public IEffectFactory effect;


public Skin skin;

public final ShareChallenge shareChallenge;
Expand Down Expand Up @@ -158,6 +139,23 @@ public void dispose() {

//endregion

// region Effects

private void loadEffectSound(final String effectName) {
FileHandle soundFile = Gdx.files.internal("sound/effect_" + effectName + ".mp3");
if (!soundFile.exists())
soundFile = Gdx.files.internal("sound/effect_vanish.mp3");

effectSounds.put(effectName, Gdx.audio.newSound(soundFile));
}

public void playEffectSound() {
effectSounds.get(effect.getName())
.play(MathUtils.random(0.7f, 1f), MathUtils.random(0.8f, 1.2f), 0);
}

// endregion

//region Settings

private static Preferences prefs;
Expand Down Expand Up @@ -283,7 +281,7 @@ private static void setMoney(float money) {
}

public static int getMoney() {
return (int)getRealMoney();
return (int) getRealMoney();
}

private static float getRealMoney() {
Expand Down
4 changes: 2 additions & 2 deletions core/src/io/github/lonamiwebs/klooni/SkinLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class SkinLoader {
// We cannot use a size which is over the device height,
// so use the closest smaller one
int i;
float desired = (float)Gdx.graphics.getHeight() / (float)Klooni.GAME_HEIGHT;
float desired = (float) Gdx.graphics.getHeight() / (float) Klooni.GAME_HEIGHT;
for (i = multipliers.length - 1; i > 0; --i) {
if (multipliers[i] < desired)
break;
Expand All @@ -57,7 +57,7 @@ static Skin loadSkin() {
Skin skin = new Skin(Gdx.files.internal("skin/uiskin.json"));

// Nine patches
final int border = (int)(28 * bestMultiplier);
final int border = (int) (28 * bestMultiplier);
skin.add("button_up", new NinePatch(new Texture(
Gdx.files.internal(folder + "button_up.png")), border, border, border, border));

Expand Down
28 changes: 14 additions & 14 deletions core/src/io/github/lonamiwebs/klooni/Theme.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private Theme() {
//region Static methods

static boolean exists(final String name) {
return Gdx.files.internal("themes/"+name+".theme").exists();
return Gdx.files.internal("themes/" + name + ".theme").exists();
}

// Gets all the available themes on the available on the internal game storage
Expand All @@ -86,7 +86,7 @@ public static Array<Theme> getThemes() {
else {
Gdx.app.log(
"Theme/Info", "Non-existing theme '" + themes[i] +
"' found on theme.list (line " + (i + 1) + ")");
"' found on theme.list (line " + (i + 1) + ")");
}
}

Expand Down Expand Up @@ -121,7 +121,7 @@ public static boolean shouldUseWhite(Color color) {

// Updates the theme with all the values from the specified file or name
public Theme update(final String name) {
return update(Gdx.files.internal("themes/"+name+".theme"));
return update(Gdx.files.internal("themes/" + name + ".theme"));
}

private Theme update(final FileHandle handle) {
Expand All @@ -137,13 +137,13 @@ private Theme update(final FileHandle handle) {

JsonValue colors = json.get("colors");
// Java won't allow unsigned integers, we need to use Long
background = new Color((int)Long.parseLong(colors.getString("background"), 16));
foreground = new Color((int)Long.parseLong(colors.getString("foreground"), 16));
background = new Color((int) Long.parseLong(colors.getString("background"), 16));
foreground = new Color((int) Long.parseLong(colors.getString("foreground"), 16));

JsonValue buttonColors = colors.get("buttons");
Color[] buttons = new Color[buttonColors.size];
for (int i = 0; i < buttons.length; ++i) {
buttons[i] = new Color((int)Long.parseLong(buttonColors.getString(i), 16));
buttons[i] = new Color((int) Long.parseLong(buttonColors.getString(i), 16));
if (buttonStyles[i] == null) {
buttonStyles[i] = new ImageButton.ImageButtonStyle();
}
Expand All @@ -153,22 +153,22 @@ private Theme update(final FileHandle handle) {
buttonStyles[i].down = skin.newDrawable("button_down", buttons[i]);
}

currentScore = new Color((int)Long.parseLong(colors.getString("current_score"), 16));
highScore = new Color((int)Long.parseLong(colors.getString("high_score"), 16));
bonus = new Color((int)Long.parseLong(colors.getString("bonus"), 16));
bandColor = new Color((int)Long.parseLong(colors.getString("band"), 16));
textColor = new Color((int)Long.parseLong(colors.getString("text"), 16));
currentScore = new Color((int) Long.parseLong(colors.getString("current_score"), 16));
highScore = new Color((int) Long.parseLong(colors.getString("high_score"), 16));
bonus = new Color((int) Long.parseLong(colors.getString("bonus"), 16));
bandColor = new Color((int) Long.parseLong(colors.getString("band"), 16));
textColor = new Color((int) Long.parseLong(colors.getString("text"), 16));

emptyCell = new Color((int)Long.parseLong(colors.getString("empty_cell"), 16));
emptyCell = new Color((int) Long.parseLong(colors.getString("empty_cell"), 16));

JsonValue cellColors = colors.get("cells");
cells = new Color[cellColors.size];
for (int i = 0; i < cells.length; ++i) {
cells[i] = new Color((int)Long.parseLong(cellColors.getString(i), 16));
cells[i] = new Color((int) Long.parseLong(cellColors.getString(i), 16));
}

String cellTextureFile = json.getString("cell_texture");
cellTexture = SkinLoader.loadPng("cells/"+cellTextureFile);
cellTexture = SkinLoader.loadPng("cells/" + cellTextureFile);

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void usedItemUpdated() {
else if (Klooni.isEffectBought(effect))
priceLabel.setText("bought");
else
priceLabel.setText("buy for "+effect.getPrice());
priceLabel.setText("buy for " + effect.getPrice());
}

@Override
Expand Down
6 changes: 2 additions & 4 deletions core/src/io/github/lonamiwebs/klooni/actors/MoneyBuyBand.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ private void interpolateText() {
if (shownText.length() > infoText.length()) {
// The old text was longer than the new one, so shorten it
shownText.setLength(shownText.length() - 1);
}
else {
} else {
// It can't be equal length or we wouldn't be here,
// so avoid checking shown.length() < info.length().
// We need to append the next character that we want to show
Expand All @@ -180,8 +179,7 @@ public void askBuy(final ShopCard toBuy) {
setTempText("cannot buy!");
confirmButton.setVisible(false);
cancelButton.setVisible(false);
}
else {
} else {
this.toBuy = toBuy;
setText("confirm?");
confirmButton.setVisible(true);
Expand Down
9 changes: 8 additions & 1 deletion core/src/io/github/lonamiwebs/klooni/actors/ShopCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,19 @@ public void draw(Batch batch, float parentAlpha) {
// Showcases the current effect (the shop will be showcasing them, one by one)
// This method should be called on the same card as long as it returns true.
// It should return false once it's done so that the next card can be showcased.
public boolean showcase(Batch batch, float yDisplacement) { return false; }
public boolean showcase(Batch batch, float yDisplacement) {
return false;
}

public abstract void usedItemUpdated();

public abstract void use();

public abstract boolean isBought();

public abstract boolean isUsed();

public abstract float getPrice();

public abstract void performBuy();
}
2 changes: 1 addition & 1 deletion core/src/io/github/lonamiwebs/klooni/actors/ThemeCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void usedItemUpdated() {
else if (Klooni.isThemeBought(theme))
priceLabel.setText("bought");
else
priceLabel.setText("buy for "+theme.getPrice());
priceLabel.setText("buy for " + theme.getPrice());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class WaterdropEffectFactory implements IEffectFactory {


private void init() {
if(dropTexture == null)
if (dropTexture == null)
dropTexture = SkinLoader.loadPng("cells/drop.png");
}

Expand Down
12 changes: 9 additions & 3 deletions core/src/io/github/lonamiwebs/klooni/game/BaseScorer.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,19 @@ public int getCurrentScore() {
return currentScore;
}

public void pause() { }
public void resume() { }
public void pause() {
}

public void resume() {
}

abstract public boolean isGameOver();

abstract protected boolean isNewRecord();

public String gameOverReason() { return ""; }
public String gameOverReason() {
return "";
}

abstract public void saveScore();

Expand Down
10 changes: 6 additions & 4 deletions core/src/io/github/lonamiwebs/klooni/game/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private boolean canPutPiece(Piece piece, int x, int y) {

for (int i = 0; i < piece.cellRows; ++i)
for (int j = 0; j < piece.cellCols; ++j)
if (!cells[y+i][x+j].isEmpty() && piece.filled(i, j))
if (!cells[y + i][x + j].isEmpty() && piece.filled(i, j))
return false;

return true;
Expand All @@ -113,7 +113,7 @@ public boolean putPiece(Piece piece, int x, int y) {
for (int i = 0; i < piece.cellRows; ++i)
for (int j = 0; j < piece.cellCols; ++j)
if (piece.filled(i, j))
cells[y+i][x+j].set(piece.colorIndex);
cells[y + i][x + j].set(piece.colorIndex);

return true;
}
Expand All @@ -129,7 +129,7 @@ public void draw(final Batch batch) {
for (int j = 0; j < cellCount; ++j)
cells[i][j].draw(batch);

for (int i = effects.size; i-- != 0;) {
for (int i = effects.size; i-- != 0; ) {
effects.get(i).draw(batch);
if (effects.get(i).isDone())
effects.removeIndex(i);
Expand Down Expand Up @@ -248,7 +248,9 @@ public void clearAll(final int clearFromX, final int clearFromY, final IEffectFa
}
}

public boolean effectsDone() { return effects.size == 0; }
public boolean effectsDone() {
return effects.size == 0;
}

//endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BonusParticle {
private final static float SPEED = 1f;

BonusParticle(final Vector2 pos, final int score, final Label.LabelStyle style) {
label = new Label("+"+score, style);
label = new Label("+" + score, style);
label.setBounds(pos.x, pos.y, 0, 0);
}

Expand Down
35 changes: 22 additions & 13 deletions core/src/io/github/lonamiwebs/klooni/game/Piece.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ private Piece(int lSize, int rotateCount, int colorIndex) {
for (int j = 0; j < lSize; ++j)
shape[0][j] = true;
for (int i = 0; i < lSize; ++i)
shape[i][lSize-1] = true;
shape[i][lSize - 1] = true;
break;
case 2: // ┘
for (int j = 0; j < lSize; ++j)
shape[lSize-1][j] = true;
shape[lSize - 1][j] = true;
for (int i = 0; i < lSize; ++i)
shape[i][lSize-1] = true;
shape[i][lSize - 1] = true;
break;
case 3: // └
for (int j = 0; j < lSize; ++j)
shape[lSize-1][j] = true;
shape[lSize - 1][j] = true;
for (int i = 0; i < lSize; ++i)
shape[i][0] = true;
break;
Expand All @@ -121,19 +121,28 @@ public static Piece random() {
private static Piece fromIndex(int colorIndex, int rotateCount) {
switch (colorIndex) {
// Squares
case 0: return new Piece(1, 1, 0, colorIndex);
case 1: return new Piece(2, 2, 0, colorIndex);
case 2: return new Piece(3, 3, 0, colorIndex);
case 0:
return new Piece(1, 1, 0, colorIndex);
case 1:
return new Piece(2, 2, 0, colorIndex);
case 2:
return new Piece(3, 3, 0, colorIndex);

// Lines
case 3: return new Piece(1, 2, rotateCount, colorIndex);
case 4: return new Piece(1, 3, rotateCount, colorIndex);
case 5: return new Piece(1, 4, rotateCount, colorIndex);
case 6: return new Piece(1, 5, rotateCount, colorIndex);
case 3:
return new Piece(1, 2, rotateCount, colorIndex);
case 4:
return new Piece(1, 3, rotateCount, colorIndex);
case 5:
return new Piece(1, 4, rotateCount, colorIndex);
case 6:
return new Piece(1, 5, rotateCount, colorIndex);

// L's
case 7: return new Piece(2, rotateCount, colorIndex);
case 8: return new Piece(3, rotateCount, colorIndex);
case 7:
return new Piece(2, rotateCount, colorIndex);
case 8:
return new Piece(3, rotateCount, colorIndex);
}
throw new RuntimeException("Random function is broken.");
}
Expand Down
8 changes: 5 additions & 3 deletions core/src/io/github/lonamiwebs/klooni/game/TimeScorer.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public TimeScorer(final Klooni game, GameLayout layout) {
//region Private methods

private int nanosToSeconds(long nano) {
return MathUtils.ceil((float)(nano * NANOS_TO_SECONDS));
return MathUtils.ceil((float) (nano * NANOS_TO_SECONDS));
}

private long scoreToNanos(int score) {
return (long)(score * SCORE_TO_NANOS);
return (long) (score * SCORE_TO_NANOS);
}

private int getTimeLeft() {
Expand All @@ -114,7 +114,9 @@ public boolean isGameOver() {
}

@Override
public String gameOverReason() { return "time is up"; }
public String gameOverReason() {
return "time is up";
}

@Override
public void saveScore() {
Expand Down
Loading

0 comments on commit ef2fb8f

Please sign in to comment.