summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2022-09-03 02:25:11 +0600
committerilotterytea <iltsu@alright.party>2022-09-03 02:25:11 +0600
commit3d8639d62a2c28750654b767fd940cd223c62e32 (patch)
treecea94e151abb079eb8f0941ce6964c1a74c22d42 /core/src
parent344f66424c5d94b4443b477ef016730d8615cf91 (diff)
Localization!!!
Diffstat (limited to 'core/src')
-rw-r--r--core/src/com/ilotterytea/maxoning/MaxonGame.java3
-rw-r--r--core/src/com/ilotterytea/maxoning/screens/AssetLoadingScreen.java2
-rw-r--r--core/src/com/ilotterytea/maxoning/screens/GameScreen.java82
-rw-r--r--core/src/com/ilotterytea/maxoning/screens/MenuScreen.java8
-rw-r--r--core/src/com/ilotterytea/maxoning/screens/SplashScreen.java2
-rw-r--r--core/src/com/ilotterytea/maxoning/utils/AssetLoading.java12
-rw-r--r--core/src/com/ilotterytea/maxoning/utils/I18N.java49
7 files changed, 95 insertions, 63 deletions
diff --git a/core/src/com/ilotterytea/maxoning/MaxonGame.java b/core/src/com/ilotterytea/maxoning/MaxonGame.java
index a410a12..e0a4415 100644
--- a/core/src/com/ilotterytea/maxoning/MaxonGame.java
+++ b/core/src/com/ilotterytea/maxoning/MaxonGame.java
@@ -7,6 +7,7 @@ import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.ilotterytea.maxoning.player.MaxonPlayer;
import com.ilotterytea.maxoning.screens.AssetLoadingScreen;
+import com.ilotterytea.maxoning.utils.I18N;
import com.ilotterytea.maxoning.utils.serialization.GameDataSystem;
import java.io.IOException;
@@ -15,6 +16,7 @@ public class MaxonGame extends Game {
public SpriteBatch batch;
public AssetManager assetManager;
public Preferences prefs;
+ public I18N locale;
private static MaxonGame instance;
@@ -29,6 +31,7 @@ public class MaxonGame extends Game {
public void create () {
batch = new SpriteBatch();
prefs = Gdx.app.getPreferences("Maxoning");
+ locale = new I18N(prefs.getString("lang", "en_us"));
if (!GameDataSystem.exists()) {
try {
diff --git a/core/src/com/ilotterytea/maxoning/screens/AssetLoadingScreen.java b/core/src/com/ilotterytea/maxoning/screens/AssetLoadingScreen.java
index 4c2d876..e61dc90 100644
--- a/core/src/com/ilotterytea/maxoning/screens/AssetLoadingScreen.java
+++ b/core/src/com/ilotterytea/maxoning/screens/AssetLoadingScreen.java
@@ -52,7 +52,7 @@ public class AssetLoadingScreen implements Screen {
private void update() {
if (game.assetManager.update()) {
- AssetLoading.registerItems(game.assetManager);
+ AssetLoading.registerItems(game.assetManager, game.locale);
game.setScreen(new SplashScreen(game));
dispose();
}
diff --git a/core/src/com/ilotterytea/maxoning/screens/GameScreen.java b/core/src/com/ilotterytea/maxoning/screens/GameScreen.java
index b9970b0..424000c 100644
--- a/core/src/com/ilotterytea/maxoning/screens/GameScreen.java
+++ b/core/src/com/ilotterytea/maxoning/screens/GameScreen.java
@@ -62,7 +62,7 @@ public class GameScreen implements Screen, InputProcessor {
stage = new Stage(new FillViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()));
skin = new Skin(Gdx.files.internal("main.skin"));
- shopWindow = new Window("Pet Shop", skin);
+ shopWindow = new Window(game.locale.TranslatableText("game.petShop"), skin);
items = new ArrayList<>();
@@ -77,7 +77,7 @@ public class GameScreen implements Screen, InputProcessor {
blackBg = new Image(game.assetManager.get("sprites/black.png", Texture.class));
- shopButton = new SupaIconButton(button, "Pet Shop", skin);
+ shopButton = new SupaIconButton(button, game.locale.TranslatableText("game.petShop"), skin);
bgTile = game.assetManager.get("sprites/menu/tile_1.png", Texture.class);
bgTileAlt = game.assetManager.get("sprites/menu/tile_2.png", Texture.class);
@@ -116,31 +116,7 @@ public class GameScreen implements Screen, InputProcessor {
maxon.addListener(new ClickListener() {
@Override public void clicked(InputEvent event, float x, float y) {
- maxonCat.nextFrame();
- maxon.setDrawable(maxonCat.getDrawable());
- player.points += 1 * player.multiplier;
-
- final TypingLabel label = new TypingLabel("{SHAKE}{RAINBOW}+" + Math.round(1 * player.multiplier) + "{ENDRAINBOW}{ENDSHAKE}", skin, "default");
-
- label.setPosition(
- maxon.getX() + (maxon.getWidth() / 2f) - 8,
- maxon.getY() + maxon.getHeight()
- );
-
- label.addAction(Actions.parallel(
- Actions.fadeOut(5f),
- Actions.moveTo(
- label.getX(), label.getY() + (float) Math.floor(Math.random() * 156), 5f, Interpolation.exp5Out)
- ));
-
- Timer.schedule(new Timer.Task() {
- @Override
- public void run() {
- label.remove();
- }
- }, 10f);
-
- stage.addActor(label);
+ displayPointIncrease();
}
});
@@ -241,7 +217,7 @@ public class GameScreen implements Screen, InputProcessor {
player.points += 1 * itemMultiplier;
- TypingLabel label = new TypingLabel("{SHAKE}{RAINBOW}+" + Math.round(1 * itemMultiplier) + "{ENDRAINBOW}{ENDSHAKE}", skin, "default");
+ TypingLabel label = new TypingLabel(game.locale.FormattedText("game.newPoint", String.valueOf(Math.round(1 * itemMultiplier))), skin, "default");
label.setPosition(
maxon.getX() + (maxon.getWidth() / 2f) - 8,
@@ -296,7 +272,7 @@ public class GameScreen implements Screen, InputProcessor {
}
}
- pointsLabel.setText(Math.round(player.points) + " S (x" + player.multiplier + ")");
+ pointsLabel.setText(game.locale.FormattedText("game.points", String.valueOf(Math.round(player.points)), String.valueOf(player.multiplier)));
stage.draw();
stage.act(delta);
@@ -332,33 +308,37 @@ public class GameScreen implements Screen, InputProcessor {
dispose();
}
if (Gdx.input.isKeyPressed(Input.Keys.SPACE) || Gdx.input.isKeyPressed(Input.Keys.UP)) {
- maxonCat.nextFrame();
- maxon.setDrawable(maxonCat.getDrawable());
- player.points += 1 * player.multiplier;
+ displayPointIncrease();
+ }
+ return false;
+ }
- final TypingLabel label = new TypingLabel("{SHAKE}{RAINBOW}+" + Math.round(1 * player.multiplier) + "{ENDRAINBOW}{ENDSHAKE}", skin, "default");
+ private void displayPointIncrease() {
+ maxonCat.nextFrame();
+ maxon.setDrawable(maxonCat.getDrawable());
+ player.points += 1 * player.multiplier;
- label.setPosition(
- maxon.getX() + (maxon.getWidth() / 2f) - 8,
- maxon.getY() + maxon.getHeight()
- );
+ final TypingLabel label = new TypingLabel(game.locale.FormattedText("game.newPoint", String.valueOf(Math.round(1 * player.multiplier))), skin, "default");
- label.addAction(Actions.parallel(
- Actions.fadeOut(5f),
- Actions.moveTo(
- label.getX(), label.getY() + (float) Math.floor(Math.random() * 156), 5f, Interpolation.exp5Out)
- ));
+ label.setPosition(
+ maxon.getX() + (maxon.getWidth() / 2f) - 8,
+ maxon.getY() + maxon.getHeight()
+ );
- Timer.schedule(new Timer.Task() {
- @Override
- public void run() {
- label.remove();
- }
- }, 10f);
+ label.addAction(Actions.parallel(
+ Actions.fadeOut(5f),
+ Actions.moveTo(
+ label.getX(), label.getY() + (float) Math.floor(Math.random() * 156), 5f, Interpolation.exp5Out)
+ ));
- stage.addActor(label);
- }
- return false;
+ Timer.schedule(new Timer.Task() {
+ @Override
+ public void run() {
+ label.remove();
+ }
+ }, 10f);
+
+ stage.addActor(label);
}
@Override
diff --git a/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java b/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java
index 2f85558..dc3d8b1 100644
--- a/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java
+++ b/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java
@@ -67,12 +67,12 @@ public class MenuScreen implements Screen, InputProcessor {
this.brandLogo = new Image(game.assetManager.get("sprites/brand.png", Texture.class));
- this.startLabel = new Label("PRESS START", skin, "press");
+ this.startLabel = new Label(game.locale.TranslatableText("menu.pressStart"), skin, "press");
this.infoLabel = new DebugLabel(skin);
- this.playGameButton = new TextButton("PLAY GAME", skin);
- this.optionsButton = new TextButton("OPTIONS", skin);
- this.quitButton = new TextButton("QUIT TO DESKTOP", skin);
+ this.playGameButton = new TextButton(game.locale.TranslatableText("menu.playGame"), skin);
+ this.optionsButton = new TextButton(game.locale.TranslatableText("menu.options"), skin);
+ this.quitButton = new TextButton(game.locale.TranslatableText("menu.quit"), skin);
optionsButton.setDisabled(true);
diff --git a/core/src/com/ilotterytea/maxoning/screens/SplashScreen.java b/core/src/com/ilotterytea/maxoning/screens/SplashScreen.java
index bc3c472..eb067cd 100644
--- a/core/src/com/ilotterytea/maxoning/screens/SplashScreen.java
+++ b/core/src/com/ilotterytea/maxoning/screens/SplashScreen.java
@@ -35,7 +35,7 @@ public class SplashScreen implements InputProcessor, Screen {
this.skin = new Skin(Gdx.files.internal("main.skin"));
this.infoLabel = new DebugLabel(skin);
- this.disclaimer = new Label("This game contains an unbelievable dose of cheeky \"woolbags\". Please, it is not recommended for anyone to play. Any match in real life of the presented images of cats is pure coincidence! All cat images were generated by \"NUT-S\" neural network.", skin, "disclaimer");
+ this.disclaimer = new Label(game.locale.TranslatableText("splash.disclaimer"), skin, "disclaimer");
this.legalLabel = new Label("", skin, "disclaimer");
this.dev = new Image(game.assetManager.get("sprites/ilotterytea.png", Texture.class));
diff --git a/core/src/com/ilotterytea/maxoning/utils/AssetLoading.java b/core/src/com/ilotterytea/maxoning/utils/AssetLoading.java
index 85880d0..a81538f 100644
--- a/core/src/com/ilotterytea/maxoning/utils/AssetLoading.java
+++ b/core/src/com/ilotterytea/maxoning/utils/AssetLoading.java
@@ -40,9 +40,9 @@ public class AssetLoading {
// Sounds:
}
- public static void registerItems(AssetManager am) {
+ public static void registerItems(AssetManager am, I18N i18n) {
MaxonItemRegister.register(
- 0, "The Suspicious and Sleepy Bro", "A falling asleep Bror will help you to pet Maxon almost to besvimers.",
+ 0, i18n.TranslatableText("pet.bror.name"), i18n.TranslatableText("pet.bror.desc"),
new AnimatedImage(SpriteUtils.splitToTextureRegions(am.get("sprites/sheet/bror.png", Texture.class), 112, 112, 11, 7)),
MaxonItemEnum.SLAVE,
600,
@@ -50,7 +50,7 @@ public class AssetLoading {
);
MaxonItemRegister.register(
- 1, "The Sandwich Cat", "Even though his head is shielded from the light by bread, he can still to pet Maxon by his cheeks",
+ 1, i18n.TranslatableText("pet.sandwich.name"), i18n.TranslatableText("pet.sandwich.desc"),
new AnimatedImage(SpriteUtils.splitToTextureRegions(am.get("sprites/sheet/sandwich_cat.png", Texture.class), 112, 112, 4, 7)),
MaxonItemEnum.SLAVE,
2000,
@@ -58,7 +58,7 @@ public class AssetLoading {
);
MaxonItemRegister.register(
- 2, "Manlooshka", "rrrrr",
+ 2, i18n.TranslatableText("pet.manlooshka.name"), i18n.TranslatableText("pet.manlooshka.desc"),
new AnimatedImage(SpriteUtils.splitToTextureRegions(am.get("sprites/sheet/manlooshka.png", Texture.class), 112, 112, 10, 4)),
MaxonItemEnum.SLAVE,
8000,
@@ -66,7 +66,7 @@ public class AssetLoading {
);
MaxonItemRegister.register(
- 3, "The Thirsty Cat", "Every time the kitty drinks water, drops of spilled water fall on the screen and pet Maxon's dry cheeks.",
+ 3, i18n.TranslatableText("pet.thirsty.name"), i18n.TranslatableText("pet.thirsty.desc"),
new AnimatedImage(SpriteUtils.splitToTextureRegions(am.get("sprites/sheet/thirsty_cat.png", Texture.class), 112, 112, 6, 3)),
MaxonItemEnum.SLAVE,
20000,
@@ -74,7 +74,7 @@ public class AssetLoading {
);
MaxonItemRegister.register(
- 4, "The Furios Cat", "Petting FURIOSLY !!!",
+ 4, i18n.TranslatableText("pet.furios.name"), i18n.TranslatableText("pet.furios.desc"),
new AnimatedImage(SpriteUtils.splitToTextureRegions(am.get("sprites/sheet/furios_cat.png", Texture.class), 112, 112, 7, 4)),
MaxonItemEnum.SLAVE,
75000,
diff --git a/core/src/com/ilotterytea/maxoning/utils/I18N.java b/core/src/com/ilotterytea/maxoning/utils/I18N.java
new file mode 100644
index 0000000..ef81350
--- /dev/null
+++ b/core/src/com/ilotterytea/maxoning/utils/I18N.java
@@ -0,0 +1,49 @@
+package com.ilotterytea.maxoning.utils;
+
+import com.badlogic.gdx.files.FileHandle;
+import com.badlogic.gdx.utils.JsonReader;
+import com.badlogic.gdx.utils.JsonValue;
+
+import java.lang.StringBuilder;
+import java.util.*;
+
+public class I18N {
+ private Map<String, String> language = new HashMap<>();
+
+ public I18N(String languageId) {
+ FileHandle fh = new FileHandle(String.format("i18n/%s.json", languageId));
+
+ JsonValue json = new JsonReader().parse(fh);
+
+ for (JsonValue val : json.iterator()) {
+ language.put(val.name, json.getString(val.name));
+ }
+ }
+
+ public String TranslatableText(String id) {
+ if (language.containsKey(id)) {
+ return language.get(id);
+ }
+ return null;
+ }
+
+ public String FormattedText(String id, CharSequence... params) {
+ if (!language.containsKey(id)) { return null; }
+ Scanner scan = new Scanner(language.get(id));
+ StringBuilder result = new StringBuilder();
+ int index = 0;
+
+ while (scan.hasNext()) {
+ String next = scan.next();
+
+ if (next.contains("%s")) {
+ next = next.replace("%s", params[index]);
+ if (index + 1 < params.length) { index++; }
+ }
+
+ result.append(next);
+ }
+
+ return result.toString();
+ }
+}