Automatic code reformat

This commit is contained in:
Lonami Exo 2018-02-05 10:30:49 +01:00
parent d7db9b8f82
commit ef2fb8fa84
23 changed files with 153 additions and 107 deletions

View file

@ -40,7 +40,12 @@ import io.github.lonamiwebs.klooni.screens.MainMenuScreen;
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 = {
@ -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;
@ -158,6 +139,23 @@ public class Klooni extends Game {
//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;
@ -283,7 +281,7 @@ public class Klooni extends Game {
}
public static int getMoney() {
return (int)getRealMoney();
return (int) getRealMoney();
}
private static float getRealMoney() {

View file

@ -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;
@ -57,7 +57,7 @@ public class SkinLoader {
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));

View file

@ -71,7 +71,7 @@ public class 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
@ -121,7 +121,7 @@ public class Theme {
// 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) {
@ -137,13 +137,13 @@ public class Theme {
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();
}
@ -153,22 +153,22 @@ public class Theme {
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;
}

View file

@ -123,7 +123,7 @@ public class EffectCard extends ShopCard {
else if (Klooni.isEffectBought(effect))
priceLabel.setText("bought");
else
priceLabel.setText("buy for "+effect.getPrice());
priceLabel.setText("buy for " + effect.getPrice());
}
@Override

View file

@ -158,8 +158,7 @@ public class MoneyBuyBand extends Table {
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
@ -180,8 +179,7 @@ public class MoneyBuyBand extends Table {
setTempText("cannot buy!");
confirmButton.setVisible(false);
cancelButton.setVisible(false);
}
else {
} else {
this.toBuy = toBuy;
setText("confirm?");
confirmButton.setVisible(true);

View file

@ -73,12 +73,19 @@ public abstract class ShopCard extends Actor {
// 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();
}

View file

@ -80,7 +80,7 @@ public class ThemeCard extends ShopCard {
else if (Klooni.isThemeBought(theme))
priceLabel.setText("bought");
else
priceLabel.setText("buy for "+theme.getPrice());
priceLabel.setText("buy for " + theme.getPrice());
}
@Override

View file

@ -36,7 +36,7 @@ public class WaterdropEffectFactory implements IEffectFactory {
private void init() {
if(dropTexture == null)
if (dropTexture == null)
dropTexture = SkinLoader.loadPng("cells/drop.png");
}

View file

@ -102,13 +102,19 @@ public abstract class BaseScorer implements BinSerializable {
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();

View file

@ -98,7 +98,7 @@ public class Board implements BinSerializable {
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;
@ -113,7 +113,7 @@ public class Board implements BinSerializable {
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;
}
@ -129,7 +129,7 @@ public class Board implements BinSerializable {
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);
@ -248,7 +248,9 @@ public class Board implements BinSerializable {
}
}
public boolean effectsDone() { return effects.size == 0; }
public boolean effectsDone() {
return effects.size == 0;
}
//endregion

View file

@ -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);
}

View file

@ -91,17 +91,17 @@ public class Piece {
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;
@ -121,19 +121,28 @@ public class Piece {
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.");
}

View file

@ -83,11 +83,11 @@ public class TimeScorer extends BaseScorer implements BinSerializable {
//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() {
@ -114,7 +114,9 @@ public class TimeScorer extends BaseScorer implements BinSerializable {
}
@Override
public String gameOverReason() { return "time is up"; }
public String gameOverReason() {
return "time is up";
}
@Override
public void saveScore() {

View file

@ -7,6 +7,8 @@ import io.github.lonamiwebs.klooni.game.Cell;
public interface IEffect {
void setInfo(Cell deadCell, Vector2 culprit);
void draw(Batch batch);
boolean isDone();
}

View file

@ -23,14 +23,17 @@ import io.github.lonamiwebs.klooni.game.Cell;
/**
* IEffectEfactory interface has to be implemented for each effect.
*
* <p>
* It tells the name and the price of the effect and will create it, when needed.
*
* @see IEffect
*/
public interface IEffectFactory {
public String getName();
public String getDisplay();
public int getPrice();
public IEffect create(final Cell deadCell, final Vector2 culprit);
}

View file

@ -70,8 +70,8 @@ class CustomizeScreen implements Screen {
//region Static members
// As the examples show on the LibGdx wiki
private static final float MIN_DELTA = 1/30f;
private static final float DRAG_LIMIT_SQ = 20*20;
private static final float MIN_DELTA = 1 / 30f;
private static final float DRAG_LIMIT_SQ = 20 * 20;
//endregion
@ -210,7 +210,7 @@ class CustomizeScreen implements Screen {
// Scroll to the currently selected item
table.layout();
for (Actor a : shopGroup.getChildren()) {
ShopCard c = (ShopCard)a;
ShopCard c = (ShopCard) a;
if (c.isUsed()) {
shopScroll.scrollTo(
c.getX(), c.getY() + c.getHeight(),
@ -247,7 +247,7 @@ class CustomizeScreen implements Screen {
buyBand.askBuy(card);
for (Actor a : shopGroup.getChildren()) {
((ShopCard)a).usedItemUpdated();
((ShopCard) a).usedItemUpdated();
}
}
}
@ -276,7 +276,7 @@ class CustomizeScreen implements Screen {
// After everything is drawn, showcase the current shop item
SnapshotArray<Actor> children = shopGroup.getChildren();
if (children.size > 0) {
final ShopCard card = (ShopCard)children.get(showcaseIndex);
final ShopCard card = (ShopCard) children.get(showcaseIndex);
final Batch batch = stage.getBatch();
batch.begin();
@ -311,13 +311,16 @@ class CustomizeScreen implements Screen {
//region Empty methods
@Override
public void pause() { }
public void pause() {
}
@Override
public void resume() { }
public void resume() {
}
@Override
public void hide() { }
public void hide() {
}
//endregion
}

View file

@ -106,7 +106,7 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
scorer = new TimeScorer(game, layout);
break;
default:
throw new RuntimeException("Unknown game mode given: "+gameMode);
throw new RuntimeException("Unknown game mode given: " + gameMode);
}
board = new Board(layout, BOARD_SIZE);
@ -258,10 +258,12 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
//region Unused methods
@Override
public void resize(int width, int height) { }
public void resize(int width, int height) {
}
@Override
public void resume() { }
public void resume() {
}
@Override
public void hide() { /* Hide can only be called if the menu was shown. Place logic there. */ }
@ -341,7 +343,8 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
// After it's been loaded, delete the save file
deleteSave();
return true;
} catch (IOException ignored) { }
} catch (IOException ignored) {
}
}
return false;
}

View file

@ -43,7 +43,7 @@ public class MainMenuScreen extends InputListener implements Screen {
//region Static members
// As the examples show on the LibGdx wiki
private static final float minDelta = 1/30f;
private static final float minDelta = 1 / 30f;
//endregion
@ -62,7 +62,7 @@ public class MainMenuScreen extends InputListener implements Screen {
final SoftButton playButton = new SoftButton(
0, GameScreen.hasSavedData() ? "play_saved_texture" : "play_texture");
playButton.addListener(new ChangeListener() {
public void changed (ChangeEvent event, Actor actor) {
public void changed(ChangeEvent event, Actor actor) {
MainMenuScreen.this.game.transitionTo(
new GameScreen(MainMenuScreen.this.game, GameScreen.GAME_MODE_SCORE));
}
@ -95,7 +95,7 @@ public class MainMenuScreen extends InputListener implements Screen {
// Palette button (buy colors)
final SoftButton paletteButton = new SoftButton(3, "palette_texture");
paletteButton.addListener(new ChangeListener() {
public void changed (ChangeEvent event, Actor actor) {
public void changed(ChangeEvent event, Actor actor) {
// Don't dispose because then it needs to take us to the previous screen
MainMenuScreen.this.game.transitionTo(new CustomizeScreen(
MainMenuScreen.this.game, MainMenuScreen.this.game.getScreen()), false);
@ -140,13 +140,16 @@ public class MainMenuScreen extends InputListener implements Screen {
//region Unused methods
@Override
public void pause() { }
public void pause() {
}
@Override
public void resume() { }
public void resume() {
}
@Override
public void hide() { }
public void hide() {
}
//endregion
}

View file

@ -80,7 +80,7 @@ class PauseMenuStage extends Stage {
table.add(homeButton).space(16);
homeButton.addListener(new ChangeListener() {
public void changed (ChangeEvent event, Actor actor) {
public void changed(ChangeEvent event, Actor actor) {
game.transitionTo(new MainMenuScreen(game));
}
});

View file

@ -101,19 +101,24 @@ class ShareScoreScreen implements Screen {
//region Empty methods
@Override
public void resize(int width, int height) { }
public void resize(int width, int height) {
}
@Override
public void dispose() { }
public void dispose() {
}
@Override
public void pause() { }
public void pause() {
}
@Override
public void resume() { }
public void resume() {
}
@Override
public void hide() { }
public void hide() {
}
//endregion
}

View file

@ -96,8 +96,7 @@ public class TransitionScreen implements Screen {
fadedElapsed = 0;
fadingOut = false;
}
}
else {
} else {
toScreen.render(delta);
opacity = Math.min(fadedElapsed * FADE_INVERSE_DELAY, 1);
}
@ -146,13 +145,16 @@ public class TransitionScreen implements Screen {
//region Unused methods
@Override
public void pause() { }
public void pause() {
}
@Override
public void resume() { }
public void resume() {
}
@Override
public void hide() { }
public void hide() {
}
//endregion
}

View file

@ -23,5 +23,6 @@ import java.io.IOException;
public interface BinSerializable {
void write(final DataOutputStream out) throws IOException;
void read(final DataInputStream in) throws IOException;
}

View file

@ -27,7 +27,7 @@ import java.util.Arrays;
public class BinSerializer {
// ascii (klooni) and binary (1010b)
private final static byte[] HEADER = { 0x6B, 0x6C, 0x6F, 0x6F, 0x6E, 0x69, 0xa };
private final static byte[] HEADER = {0x6B, 0x6C, 0x6F, 0x6F, 0x6E, 0x69, 0xa};
// MODIFY THIS VALUE EVERY TIME A BinSerializable IMPLEMENTATION CHANGES
// Or unwanted results will happen and corrupt the game in an unknown way.
@ -43,7 +43,8 @@ public class BinSerializer {
} finally {
try {
out.close();
} catch (IOException ignored) { }
} catch (IOException ignored) {
}
}
}
@ -68,7 +69,8 @@ public class BinSerializer {
} finally {
try {
in.close();
} catch (IOException ignored) { }
} catch (IOException ignored) {
}
}
}
}