Commit 93f8ce57 authored by Matyáš Latner's avatar Matyáš Latner

#140 Pursuits maps are loaded separately

parent b2caa5cf
......@@ -26,6 +26,7 @@ final assetsDestinationDirName = "dest"
final assetsGameDirectory = "game"
final assetsGameGlobalDirectory = "_global"
final assetsGameCommonDifficultyDirectory = "common"
final assetsGameExcludedDirectory = "excluded"
final String ASSETS_DOWNLOAD_URL = "https://www.tablexia.cz/static/assets/"
......@@ -177,11 +178,21 @@ task prepareGraphicAssets(dependsOn: prepareAssets) {
sectionDir.eachDir() { atlasDir ->
if (assetsGameDirectory.equals(sectionDir.name) && !assetsGameGlobalDirectory.equals(atlasDir.name)) {
atlasDir.eachDir() { difficultyDir ->
String packFileName = assetsGameCommonDifficultyDirectory.equals(difficultyDir.name) ? atlasDir.name : difficultyDir.name;
TexturePacker.process(settings,
"${difficultyDir}",
"${assetsDir.absolutePath}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/",
"${packFileName}")
if (!assetsGameExcludedDirectory.equals(difficultyDir.name)) {
String packFileName = assetsGameCommonDifficultyDirectory.equals(difficultyDir.name) ? atlasDir.name : difficultyDir.name;
TexturePacker.process(settings,
"${difficultyDir}",
"${assetsDir.absolutePath}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/",
"${packFileName}")
} else {
task("${name}_" + sectionDir.name + "_" + langDir.name + "_" + atlasDir.name + "_" + difficultyDir.name, type: Copy) {
from difficultyDir
into "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/${difficultyDir.name}"
include '**/*'
includeEmptyDirs false
outputs.upToDateWhen { false }
}.execute()
}
}
} else {
TexturePacker.process(settings,
......
package cz.nic.tablexia.game.games.pursuit;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
......@@ -34,6 +35,8 @@ import cz.nic.tablexia.game.games.pursuit.model.Maps;
import cz.nic.tablexia.game.games.pursuit.model.PuzzlePiece;
import cz.nic.tablexia.game.games.pursuit.model.Vehicle;
import cz.nic.tablexia.game.games.pursuit.model.VehicleType;
import cz.nic.tablexia.loader.TablexiaAbstractFileManager;
import cz.nic.tablexia.loader.TablexiaTextureManager;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.model.game.GameDAO;
import cz.nic.tablexia.shared.model.Game;
......@@ -131,7 +134,11 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> {
private Vehicle vehicle;
private Image finishFlag;
private TextureRegion roadMap;
private Texture roadMap;
private TablexiaTextureManager textureManager;
private String clickMapTextureName;
private String mapTextureName;
@Override
......@@ -164,22 +171,56 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> {
soundsFileNames.add(PursuitAssets.SOUND_SWITCH);
}
@Override
@Override
protected int[][] prepareGameData(Map<String, String> gameState) {
updateMapIndex();
final Object loaderLock = new Object();
updateMapIndex();
mapTextureName = prepareScreenAssetsPath(prepareScreenName()) + TextureHelper.getMapFullName(mapNumber);
clickMapTextureName = prepareScreenAssetsPath(prepareScreenName()) + TextureHelper.getClickMapPath(mapNumber);
synchronized (loaderLock) {
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
synchronized (loaderLock) {
tryToDisposeTextureManager();
textureManager = new TablexiaTextureManager(TablexiaAbstractFileManager.AssetsStorageType.EXTERNAL);
textureManager.loadTexture(mapTextureName);
textureManager.loadTexture(clickMapTextureName);
textureManager.finishLoading();
loaderLock.notify();
}
}
});
try {
loaderLock.wait();
} catch (InterruptedException e) {
Log.err(getClass(), "Error while waiting to texture loader!", e);
}
roadMap = getScreenTextureRegion(TextureHelper.getClickMapPath(mapNumber));
if (!roadMap.getTexture().getTextureData().isPrepared()) {
roadMap.getTexture().getTextureData().prepare();
roadMap = textureManager.getTexture(clickMapTextureName);
if (!roadMap.getTextureData().isPrepared()) {
roadMap.getTextureData().prepare();
}
}
return Utility.createColorMap(roadMap);
}
private void tryToDisposeTextureManager() {
if (textureManager != null) {
textureManager.dispose();
textureManager = null;
}
}
@Override
protected void screenResized(int width, int height) {
ScaleUtil.setFullScreen(contentGroup, getStage());
float minSide = Math.min(getViewportWidth(), getViewportHeight());
grid.setSize(minSide-2*GRID_PADDING,minSide-2*GRID_PADDING);
grid.setSize(minSide - 2 * GRID_PADDING, minSide - 2 * GRID_PADDING);
grid.setPosition(getViewportWidth() / 2 - grid.getWidth() / 2, (getViewportHeight() / 2 - grid.getHeight() / 2));
grid.scaleGrid();
......@@ -298,6 +339,12 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> {
backgroundImage.addListener(dragAndRotateActorListener);
}
@Override
protected void gameDisposed() {
tryToDisposeTextureManager();
super.gameDisposed();
}
private void updateMapIndex() {
String lastMap = GameDAO.getLastGameScoreValueForGameAndKey(GameDefinition.PURSUIT.getGameNumber(), SCORE_KEY_LAST_MAP);
......@@ -324,7 +371,8 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> {
}
private void prepareGrid() {
TextureRegion mapTextureRegion = getScreenTextureRegion(TextureHelper.getMapFullName(mapNumber));
Texture mapTextureRegion = textureManager.getTexture(mapTextureName);
mapTextureRegion.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
float minSide = Math.min(getViewportWidth(),getViewportHeight());
grid = new Grid(((getViewportWidth()/2) - minSide/2)+GRID_PADDING,(getViewportHeight() / 2 - minSide/2)+GRID_PADDING, minSide- 2*GRID_PADDING, gridColumnCount, mapTextureRegion, getRandom());
contentGroup.addActor(grid);
......@@ -338,7 +386,7 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> {
Music[] vehicleSounds = getVehicleSounds(vehicleType);
vehicle = new Vehicle(getScreenTextureRegion(vehicleType.getTextureName()), vehiclePosition, vehicleSize);
vehicle.addListener(new VehicleDragListener(vehicle, vehicleSounds, getData(), new Point(roadMap.getRegionWidth(), roadMap.getRegionHeight()), finishFlag, new VehicleDragListener.OnVehicleDragCompleteListener() {
vehicle.addListener(new VehicleDragListener(vehicle, vehicleSounds, getData(), new Point(roadMap.getWidth(), roadMap.getHeight()), finishFlag, new VehicleDragListener.OnVehicleDragCompleteListener() {
@Override
public void onVehicleDragComplete() {
showVictoryDialog();
......
......@@ -4,11 +4,12 @@ package cz.nic.tablexia.game.games.pursuit.assets;
* Created by Václav Tarantík on 18.6.15.
*/
public class PursuitAssets {
public static final String SOUNDS_PATH = "common/sfx/";
public static final String MP3_EXTENSION = ".mp3";
public static final String MAPS_DIR = "maps/";
public static final String VEHICLES_DIR = "vehicles/";
public static final String BACKGROUND = "background2";
public static final String SOUNDS_PATH = "common/sfx/";
public static final String MP3_EXTENSION = ".mp3";
public static final String MAPS_DIR = "excluded/";
public static final String VEHICLES_DIR = "vehicles/";
public static final String BACKGROUND = "background2";
public static final String FINISH_FLAG = VEHICLES_DIR + "flag";
......
......@@ -6,16 +6,19 @@ import java.util.Random;
import cz.nic.tablexia.game.games.pursuit.assets.PursuitAssets;
import cz.nic.tablexia.game.games.pursuit.model.Maps;
import cz.nic.tablexia.util.Point;
import cz.nic.tablexia.game.games.pursuit.model.VehicleType;
import cz.nic.tablexia.util.Point;
/**
* Created by Václav Tarantík on 18.6.15.
*/
public class TextureHelper {
private static final Maps maps [] = new Maps[]{Maps.MAP1, Maps.MAP5, Maps.MAP3, Maps.MAP4, Maps.MAP2,Maps.MAP6, Maps.MAP7, Maps.MAP8, Maps.MAP9, Maps.MAP10, Maps.MAP11, Maps.MAP12, Maps.MAP13, Maps.MAP14};
public static final Point FLAG_BLACK_DOT_RELATIVE_POSITION = new Point(0.295f,0.129f);
public static final Point FINISH_FLAG_SIZE = new Point(75, 60);
private static final Maps maps [] = new Maps[]{Maps.MAP1, Maps.MAP5, Maps.MAP3, Maps.MAP4, Maps.MAP2,Maps.MAP6, Maps.MAP7, Maps.MAP8, Maps.MAP9, Maps.MAP10, Maps.MAP11, Maps.MAP12, Maps.MAP13, Maps.MAP14};
public static final Point FLAG_BLACK_DOT_RELATIVE_POSITION = new Point(0.295f,0.129f);
public static final Point FINISH_FLAG_SIZE = new Point(75, 60);
private static final String PNG_SUFFIX = ".png";
private static final String RED_MAP_NAME = "red";
public static String getBgTexturePath() {
return PursuitAssets.BACKGROUND;
......@@ -30,11 +33,15 @@ public class TextureHelper {
}
public static String getMapFullName(int mapNumber) {
return PursuitAssets.MAPS_DIR + maps[mapNumber].getTextureRegionName();
return getMapRegionName(mapNumber) + PNG_SUFFIX;
}
public static String getClickMapPath(int mapNumber) {
return PursuitAssets.MAPS_DIR + maps[mapNumber].getTextureRegionName() + "red";
return getMapRegionName(mapNumber) + RED_MAP_NAME + PNG_SUFFIX;
}
private static String getMapRegionName(int mapNumber) {
return PursuitAssets.MAPS_DIR + maps[mapNumber].getTextureRegionName();
}
public static VehicleType getVehicleTextureName(Random random,int mapNumber) {
......
package cz.nic.tablexia.game.games.pursuit.model;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle;
......@@ -27,17 +28,17 @@ public class Grid extends Group {
private int numberOfColumns;//number of rows respectively columns
private Map<Integer, PuzzlePiece> piecesMap;
private TextureRegion textureRegion;
private Texture texture;
private Random random;
public Grid(float x, float y, float size, int numberOfColumns, TextureRegion textureRegion,Random random) {
public Grid(float x, float y, float size, int numberOfColumns, Texture texture, Random random) {
super();
setPosition(x, y);
setSize(size, size);
setDebug(TablexiaSettings.getInstance().isShowBoundingBoxes());
this.textureRegion = textureRegion;
this.texture = texture;
this.numberOfColumns = numberOfColumns;
this.random = random;
......@@ -52,7 +53,7 @@ public class Grid extends Group {
private void placePieces() {
float pieceSize = getWidth() / numberOfColumns;
TextureRegion[][] split = textureRegion.split(textureRegion.getRegionWidth() / numberOfColumns, textureRegion.getRegionHeight() / numberOfColumns);
TextureRegion[][] split = new TextureRegion(texture).split(texture.getWidth() / numberOfColumns, texture.getHeight() / numberOfColumns);
int i = 0;
for (TextureRegion[] splitX : split) {
for (TextureRegion splitXY : splitX) {
......
package cz.nic.tablexia.game.games.pursuit.model;
import cz.nic.tablexia.util.Point;
/**
* Created by Václav Tarantík on 10.8.15.
*/
public enum Maps {
MAP1("map1",new cz.nic.tablexia.util.Point(0.866f,0.1f),new cz.nic.tablexia.util.Point(0.26f,0.85f)),
MAP2("map2",new cz.nic.tablexia.util.Point(0.64f,0.11f),new cz.nic.tablexia.util.Point(0.22f,0.75f)),
MAP3("map3",new cz.nic.tablexia.util.Point(0.08f,0.41f),new cz.nic.tablexia.util.Point(0.79f,0.71f)),// TODO add car initial rotation
MAP4("map4",new cz.nic.tablexia.util.Point(0.95f,0.33f),new cz.nic.tablexia.util.Point(0.18f,0.57f)),
MAP5("map5",new cz.nic.tablexia.util.Point(0.94f,0.12f),new cz.nic.tablexia.util.Point(0.86f,0.82f)),
MAP6("map6",new cz.nic.tablexia.util.Point(0.95f,0.17f),new cz.nic.tablexia.util.Point(0.45f,0.32f)),
MAP7("map7",new cz.nic.tablexia.util.Point(0.56f,0.07f),new cz.nic.tablexia.util.Point(0.36f,0.83f)),
MAP8("map8",new cz.nic.tablexia.util.Point(0.16f,0.19f),new cz.nic.tablexia.util.Point(0.83f,0.79f)),
MAP9("map9",new cz.nic.tablexia.util.Point(0.15f,0.11f),new cz.nic.tablexia.util.Point(0.81f,0.83f)),
MAP10("map10",new cz.nic.tablexia.util.Point(0.22f,0.07f),new cz.nic.tablexia.util.Point(0.76f,0.84f)),
MAP11("map11",new cz.nic.tablexia.util.Point(0.61f,0.11f),new cz.nic.tablexia.util.Point(0.21f,0.69f)),
MAP12("map12",new cz.nic.tablexia.util.Point(0.89f,0.17f),new cz.nic.tablexia.util.Point(0.2f,0.85f)),
MAP13("map13",new cz.nic.tablexia.util.Point(0.08f,0.06f),new cz.nic.tablexia.util.Point(0.88f,0.73f)),
MAP14("map14",new cz.nic.tablexia.util.Point(0.18f,0.08f),new cz.nic.tablexia.util.Point(0.32f,0.84f));
MAP1("map1", new Point(0.866f, 0.1f), new Point(0.26f, 0.85f)),
MAP2("map2", new Point(0.64f, 0.11f), new Point(0.22f, 0.75f)),
MAP3("map3", new Point(0.08f, 0.41f), new Point(0.79f, 0.71f)),// TODO add car initial rotation
MAP4("map4", new Point(0.95f, 0.33f), new Point(0.18f, 0.57f)),
MAP5("map5", new Point(0.94f, 0.12f), new Point(0.86f, 0.82f)),
MAP6("map6", new Point(0.95f, 0.17f), new Point(0.45f, 0.32f)),
MAP7("map7", new Point(0.56f, 0.07f), new Point(0.36f, 0.83f)),
MAP8("map8", new Point(0.16f, 0.19f), new Point(0.83f, 0.79f)),
MAP9("map9", new Point(0.15f, 0.11f), new Point(0.81f, 0.83f)),
MAP10("map10", new Point(0.22f, 0.07f), new Point(0.76f, 0.84f)),
MAP11("map11", new Point(0.61f, 0.11f), new Point(0.21f, 0.69f)),
MAP12("map12", new Point(0.89f, 0.17f), new Point(0.2f, 0.85f)),
MAP13("map13", new Point(0.08f, 0.06f), new Point(0.88f, 0.73f)),
MAP14("map14", new Point(0.18f, 0.08f), new Point(0.32f, 0.84f));
private String textureRegionName;
//relatives position of checkpoints on map
private cz.nic.tablexia.util.Point startPointCoords;
private cz.nic.tablexia.util.Point endPointCoords;
private Point startPointCoords;
private Point endPointCoords;
Maps(String textureRegionName, cz.nic.tablexia.util.Point startPointCoords, cz.nic.tablexia.util.Point endPointCoords){
Maps(String textureRegionName, Point startPointCoords, Point endPointCoords){
this.textureRegionName = textureRegionName;
this.startPointCoords = startPointCoords;
this.endPointCoords = endPointCoords;
......
package cz.nic.tablexia.util;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.reflect.ClassReflection;
import com.badlogic.gdx.utils.reflect.ReflectionException;
......@@ -53,4 +54,8 @@ public class Utility {
return colors;
}
public static int[][] createColorMap(Texture clickmap) {
return createColorMap(new TextureRegion(clickmap));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment