Добавить постоянную локализацию RU и EN

This commit is contained in:
2026-08-18 16:25:46 +03:00
parent 00323d7916
commit dcb16ef4d0
7 changed files with 721 additions and 58 deletions
@@ -0,0 +1,89 @@
package com.projectsacrifice.game;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import android.os.SystemClock;
import android.view.MotionEvent;
import androidx.test.core.app.ActivityScenario;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public final class GameLanguagePersistenceTest {
@Test
public void settingsLanguageSwitchSurvivesRecreationWithoutChangingProgressOrControls() {
try (ActivityScenario<MainActivity> activity = ActivityScenario.launch(MainActivity.class)) {
int[] expectedUnlocked = new int[1];
int[] expectedBestDeaths = new int[1];
long[] expectedBestTime = new long[1];
activity.onActivity(current -> {
GameView view = current.gameViewForAutomation();
view.resetLanguageForAutomation();
view.resetControlSettingsForAutomation();
view.selectNextControlSizeForAutomation();
view.selectNextControlOpacityForAutomation();
view.toggleHapticsForAutomation();
ProgressStore progress = new ProgressStore(current);
progress.recordCompletion(2, 4, 22_222L);
expectedUnlocked[0] = progress.unlockedCount();
expectedBestDeaths[0] = progress.bestDeaths(2);
expectedBestTime[0] = progress.bestTimeMs(2);
});
tap(activity, 1_700f, 115f); // Settings from level select.
activity.onActivity(current -> assertTrue(current.gameViewForAutomation()
.settingsVisibleForAutomation()));
tap(activity, 1_700f, 115f); // Language switch on Settings.
activity.onActivity(current -> {
GameView view = current.gameViewForAutomation();
assertEquals(GameLanguage.RU, view.languageForAutomation());
assertTrue(view.visibleLocalizedTextForAutomation().contains("НАСТРОЙКИ"));
assertTrue(view.visibleLocalizedTextForAutomation().contains("Русский"));
});
activity.recreate();
activity.onActivity(current -> {
GameView view = current.gameViewForAutomation();
assertEquals(GameLanguage.RU, view.languageForAutomation());
assertFalse(view.settingsVisibleForAutomation());
ControlSettings settings = view.controlSettingsForAutomation();
assertEquals("Large", settings.controlSizeLabel());
assertEquals("High", settings.controlOpacityLabel());
assertFalse(settings.hapticsEnabled());
ProgressStore progress = new ProgressStore(current);
assertEquals(expectedUnlocked[0], progress.unlockedCount());
assertEquals(expectedBestDeaths[0], progress.bestDeaths(2));
assertEquals(expectedBestTime[0], progress.bestTimeMs(2));
view.setLanguageForAutomation(GameLanguage.EN);
view.resetControlSettingsForAutomation();
});
}
}
private static void tap(ActivityScenario<MainActivity> activity, float canvasX, float canvasY) {
activity.onActivity(current -> {
GameView view = current.gameViewForAutomation();
float scale = Math.min(view.getWidth() / 1_920f, view.getHeight() / 1_080f);
float x = (view.getWidth() - 1_920f * scale) * 0.5f + canvasX * scale;
float y = (view.getHeight() - 1_080f * scale) * 0.5f + canvasY * scale;
long now = SystemClock.uptimeMillis();
MotionEvent down = MotionEvent.obtain(now, now, MotionEvent.ACTION_DOWN, x, y, 0);
view.dispatchTouchEvent(down);
down.recycle();
MotionEvent up = MotionEvent.obtain(now, now, MotionEvent.ACTION_UP, x, y, 0);
view.dispatchTouchEvent(up);
up.recycle();
});
}
}