Skip to content

Commit

Permalink
Add Locale Selection feature to the start of the game.
Browse files Browse the repository at this point in the history
  • Loading branch information
mhall119 committed Apr 2, 2016
2 parents b5da4ca + 72a94e0 commit 7e554c5
Show file tree
Hide file tree
Showing 44 changed files with 20,785 additions and 125 deletions.
19 changes: 15 additions & 4 deletions androrm/src/main/java/com/orm/androrm/QuerySet.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import android.content.Context;
import android.database.Cursor;
import android.os.Debug;

/**
* @author Philipp Giese
Expand All @@ -54,12 +55,12 @@ public QuerySet(Context context, Class<T> model) {
public void injectQuery(SelectStatement query) {
mQuery = query;
}

private Cursor getCursor(SelectStatement query) {
mAdapter.open();
return mAdapter.query(query);
}

private void closeConnection(Cursor c) {
c.close();
mAdapter.close();
Expand Down Expand Up @@ -108,10 +109,20 @@ public QuerySet<T> all() {
mQuery = new SelectStatement();
mQuery.from(DatabaseBuilder.getTableName(mClass));
}

return this;
}


// This is suboptimal, but I don't see an easy way to generate a delete statement from the current query
public int delete(Context context) {
int count = 0;
for (T instance : this.toList()) {
instance.delete(context);
count++;
}
return count;
}

public QuerySet<T> filter(Filter filter) throws NoSuchFieldException {
SelectStatement query = QueryBuilder.buildQuery(mClass, filter.getRules());

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ android {
}
}
compileSdkVersion 21
buildToolsVersion "21.1.2"
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.linguaculturalists.phoenicia"
minSdkVersion 19
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import android.test.ActivityTestCase;
import android.test.ActivityUnitTestCase;

import com.linguaculturalists.phoenicia.models.GameSession;
import com.linguaculturalists.phoenicia.ui.HUDManager;
import com.linguaculturalists.phoenicia.util.PhoeniciaContext;
import com.orm.androrm.Filter;

import java.io.IOException;

Expand All @@ -26,16 +29,29 @@ public PhoeniciaGameTest() {
public void setUp() throws Exception {
super.setUp();
activity = getActivity();
activity.syncDB();
assertNotNull("GameActivity is Null", activity);
game = new PhoeniciaGame(activity, activity.main_camera);
}

public void loadGame() {
this.loadGame("locales/en_us_test/manifest.xml");
}
public void loadGame(final String locale_pack_manifest) {
if (isLoaded) return;
try {
game.load();
GameSession session;
try {
Filter byLocale = new Filter();
byLocale.is("locale_pack", locale_pack_manifest);
session = GameSession.objects(PhoeniciaContext.context).filter(byLocale).toList().get(0);
} catch (IndexOutOfBoundsException e) {
session = GameSession.start(locale_pack_manifest);
}
session.save(PhoeniciaContext.context);
game.load(session);
} catch (IOException e) {
assertNull("Game loading failed", e);
assertNull("Game loading failed: "+e.getMessage(), e);
}
isLoaded = true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.linguaculturalists.phoenicia.components;

import android.os.SystemClock;
import android.test.ActivityInstrumentationTestCase2;
import android.view.MotionEvent;

import com.linguaculturalists.phoenicia.PhoeniciaGameTest;
import com.linguaculturalists.phoenicia.TestActivity;
import com.linguaculturalists.phoenicia.util.PhoeniciaContext;

import org.andengine.input.touch.TouchEvent;

/**
* Created by mhall on 3/1/16.
*/
public class ButtonTest extends PhoeniciaGameTest {

@Override
public void tearDown() throws Exception {
this.game.scene.detachChildren();
super.tearDown();
}

public void testCreateButton() {
Button component = new Button(this.activity.CAMERA_WIDTH/2, this.activity.CAMERA_HEIGHT/2, this.activity.CAMERA_WIDTH/2, this.activity.CAMERA_HEIGHT/2, "Test", PhoeniciaContext.vboManager, null);
assertNotNull(component);
this.game.scene.attachChild(component);
}

public void testButtonClickedListener() {
ClickTestListener listener = new ClickTestListener();
Button component = new Button(this.activity.CAMERA_WIDTH/2, this.activity.CAMERA_HEIGHT/2, this.activity.CAMERA_WIDTH/2, this.activity.CAMERA_HEIGHT/2, "Test", PhoeniciaContext.vboManager, listener);
assertNotNull(component);

assertFalse(listener.wasClicked);
component.onClick(null, 0, 0f, 0f);
assertTrue(listener.wasClicked);
}

public void testButtonTouchArea() {
this.startGame();
ClickTestListener listener = new ClickTestListener();
Button component = new Button(this.activity.CAMERA_WIDTH/2, this.activity.CAMERA_HEIGHT/2, this.activity.CAMERA_WIDTH/2, this.activity.CAMERA_HEIGHT/2, "Test", PhoeniciaContext.vboManager, listener);
assertNotNull(component);

assertFalse(listener.wasClicked);

final long uptimeMillis = SystemClock.uptimeMillis();
float[] surfaceCoordinates = this.activity.main_camera.getSurfaceCoordinatesFromSceneCoordinates(this.activity.CAMERA_WIDTH/2, this.activity.CAMERA_HEIGHT/2);
component.onAreaTouched(TouchEvent.obtain(this.activity.CAMERA_WIDTH / 2, this.activity.CAMERA_HEIGHT / 2, TouchEvent.ACTION_DOWN, 0, MotionEvent.obtain(uptimeMillis, uptimeMillis, MotionEvent.ACTION_DOWN, 0, 0, 0)), this.activity.CAMERA_WIDTH/2, this.activity.CAMERA_HEIGHT/2);
component.onAreaTouched(TouchEvent.obtain(this.activity.CAMERA_WIDTH / 2, this.activity.CAMERA_HEIGHT / 2, TouchEvent.ACTION_UP, 0, MotionEvent.obtain(uptimeMillis, uptimeMillis, MotionEvent.ACTION_UP, 0, 0, 0)), this.activity.CAMERA_WIDTH/2, this.activity.CAMERA_HEIGHT/2);
assertTrue(listener.wasClicked);
}

private class ClickTestListener implements Button.OnClickListener {
public boolean wasClicked = false;
@Override
public void onClicked(Button button) {
this.wasClicked = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.linguaculturalists.phoenicia.locale;

import android.test.ActivityInstrumentationTestCase2;
import android.test.AndroidTestCase;

import com.linguaculturalists.phoenicia.PhoeniciaGameTest;
import com.linguaculturalists.phoenicia.TestActivity;
import com.linguaculturalists.phoenicia.util.PhoeniciaContext;

import org.andengine.util.debug.Debug;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
* Created by mhall on 1/31/16.
*/
public class LocaleManagerTest extends ActivityInstrumentationTestCase2<TestActivity> {

private LocaleManager localeManager;
private Map<String, String> locales;

public LocaleManagerTest() {
super(TestActivity.class);
this.localeManager = new LocaleManager();
}

@Override
public void setUp() throws Exception {
super.setUp();
PhoeniciaContext.assetManager = this.getActivity().getAssets();
}

@Override
public void tearDown() throws Exception {
super.tearDown();
}

public void testLocaleScanning() {

try {
Map<String, String> locales = this.localeManager.scan("locales");

assertEquals(2, locales.size());
assertTrue(locales.containsKey("locales/en_us_test/manifest.xml"));
assertTrue(locales.containsValue("US English, Testing"));

assertTrue(locales.containsKey("locales/en_us_rural/manifest.xml"));
assertTrue(locales.containsValue("US English, Rural Setting"));
} catch (IOException e) {
assertNull(e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void testLocaleDefinitions() {
assertEquals("US English, Testing", locale.display_name);

assertEquals("locales/en_us_test/textures/gameui.png", locale.shell_src);
assertEquals("locales/en_us_test/textures/map.tmx", locale.map_src);
assertEquals("locales/en_us_test/map.tmx", locale.map_src);
}

public void testDefaultTiles() {
Expand Down Expand Up @@ -77,8 +77,8 @@ public void testLetterDefinitions() {
assertEquals(10, a.time);
assertEquals(100, a.points);
assertEquals("locales/en_us_test/textures/letters/a.png", a.texture_src);
assertEquals("sounds/a.ogg", a.sound);
assertEquals("phonemes/a.ogg", a.phoneme);
assertEquals("locales/en_us_test/sounds/a.ogg", a.sound);
assertEquals("locales/en_us_test/phonemes/a.ogg", a.phoneme);

Letter b = locale.letter_map.get("b");
assertNotNull(b);
Expand All @@ -97,7 +97,7 @@ public void testWordDefinitions() {
assertEquals(10, ab.time);
assertEquals(100, ab.points);
assertEquals("locales/en_us_test/textures/words/ab.png", ab.texture_src);
assertEquals("sounds/ab.ogg", ab.sound);
assertEquals("locales/en_us_test/sounds/ab.ogg", ab.sound);

Word ba = locale.word_map.get("ba");
assertNotNull(ba);
Expand All @@ -119,12 +119,12 @@ public void testLevelIntro() {
assertEquals(2, test1.intro.size());
IntroPage page1 = test1.intro.get(0);
assertEquals("Test level 1 intro page 1", page1.text);
assertEquals("sounds/intro1p1.ogg", page1.sound);
assertEquals("locales/en_us_test/sounds/intro1p1.ogg", page1.sound);

IntroPage page2 = test1.intro.get(1);
assertEquals("Test level 1 intro page 2", page2.text);
assertEquals("sounds/intro1p2.ogg", page2.sound);
assertEquals("textures/intro1p2.png", page2.texture_src);
assertEquals("locales/en_us_test/sounds/intro1p2.ogg", page2.sound);
assertEquals("locales/en_us_test/textures/intro1p2.png", page2.texture_src);
}

public void testLevelLetters() {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7e554c5

Please sign in to comment.