Change json cell class name

Signed-off-by: Chris Cromer <chris@cromer.cl>
This commit is contained in:
Chris Cromer 2019-10-11 11:20:20 -03:00
parent f7adc8551e
commit 0d2d95f216
3 changed files with 23 additions and 22 deletions

View File

@ -18,6 +18,7 @@ package cl.cromer.azaraka;
import cl.cromer.azaraka.ai.BreadthFirstSearch;
import cl.cromer.azaraka.ai.State;
import cl.cromer.azaraka.json.Json;
import cl.cromer.azaraka.json.JsonCell;
import cl.cromer.azaraka.object.Object;
import cl.cromer.azaraka.object.*;
import cl.cromer.azaraka.sound.Sound;
@ -113,37 +114,37 @@ public class Scene extends JComponent implements Constants {
private void loadScene(String json) {
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
cl.cromer.azaraka.json.Cell[][] cells = gson.fromJson(json, cl.cromer.azaraka.json.Cell[][].class);
JsonCell[][] jsonCells = gson.fromJson(json, JsonCell[][].class);
for (int x = 0; x < cells.length; x++) {
for (int y = 0; y < cells[x].length; y++) {
for (int x = 0; x < jsonCells.length; x++) {
for (int y = 0; y < jsonCells[x].length; y++) {
this.cells[x][y] = new Cell((x * CELL_PIXELS) + canvas.getLeftMargin(), (y * CELL_PIXELS) + canvas.getTopMargin(), x, y);
if (cells[x][y].type.equals(Player.class.getName())) {
if (jsonCells[x][y].type.equals(Player.class.getName())) {
this.cells[x][y].setObject(new Player(null, this.cells[x][y]));
}
else if (cells[x][y].type.equals(Enemy.class.getName())) {
else if (jsonCells[x][y].type.equals(Enemy.class.getName())) {
this.cells[x][y].setObject(new Enemy(null, this.cells[x][y], null));
}
else if (cells[x][y].type.equals(Chest.class.getName())) {
else if (jsonCells[x][y].type.equals(Chest.class.getName())) {
this.cells[x][y].setObject(new Chest(null, this.cells[x][y]));
}
else if (cells[x][y].type.equals(Gem.class.getName())) {
else if (jsonCells[x][y].type.equals(Gem.class.getName())) {
this.cells[x][y].setObject(new Gem(null, this.cells[x][y]));
}
else if (cells[x][y].type.equals(Key.class.getName())) {
else if (jsonCells[x][y].type.equals(Key.class.getName())) {
this.cells[x][y].setObject(new Key(null, this.cells[x][y]));
}
else if (cells[x][y].type.equals(Obstacle.class.getName())) {
else if (jsonCells[x][y].type.equals(Obstacle.class.getName())) {
this.cells[x][y].setObject(new Obstacle(null, this.cells[x][y]));
}
else if (cells[x][y].type.equals(Portal.class.getName())) {
else if (jsonCells[x][y].type.equals(Portal.class.getName())) {
this.cells[x][y].setObject(new Portal(null, this.cells[x][y]));
}
for (int k = 0; k < cells[x][y].textures.size(); k++) {
for (int k = 0; k < jsonCells[x][y].textures.size(); k++) {
try {
this.cells[x][y].addTexture(textureSheet.getTexture(cells[x][y].textures.get(k)), cells[x][y].textures.get(k));
this.cells[x][y].addTexture(textureSheet.getTexture(jsonCells[x][y].textures.get(k)), jsonCells[x][y].textures.get(k));
}
catch (SheetException e) {
logger.warning(e.getMessage());

View File

@ -47,28 +47,28 @@ public class Json implements Constants {
* @param celdas The cells of the scene to export
*/
public void exportScene(Cell[][] celdas) {
cl.cromer.azaraka.json.Cell[][] cells = new cl.cromer.azaraka.json.Cell[celdas.length][celdas[0].length];
JsonCell[][] jsonCells = new JsonCell[celdas.length][celdas[0].length];
for (int x = 0; x < celdas.length; x++) {
for (int y = 0; y < celdas[x].length; y++) {
cells[x][y] = new cl.cromer.azaraka.json.Cell();
jsonCells[x][y] = new JsonCell();
if (celdas[x][y].getObject() != null) {
cells[x][y].type = celdas[x][y].getObject().getClass().getName();
jsonCells[x][y].type = celdas[x][y].getObject().getClass().getName();
}
else {
cells[x][y].type = "null";
jsonCells[x][y].type = "null";
}
cells[x][y].textures = celdas[x][y].getTextureNumbers();
jsonCells[x][y].textures = celdas[x][y].getTextureNumbers();
}
}
writeScene(cells);
writeScene(jsonCells);
}
/**
* Write the JSON scene to a file
*
* @param cells The JSON cells object
* @param jsonCells The JSON cells object
*/
private void writeScene(cl.cromer.azaraka.json.Cell[][] cells) {
private void writeScene(JsonCell[][] jsonCells) {
GsonBuilder gsonBuilder;
if (PRETTY_JSON) {
gsonBuilder = new GsonBuilder().setPrettyPrinting();
@ -77,7 +77,7 @@ public class Json implements Constants {
gsonBuilder = new GsonBuilder();
}
Gson gson = gsonBuilder.create();
String json = gson.toJson(cells);
String json = gson.toJson(jsonCells);
File file = new File("src/main/resources/scene.json");
try {

View File

@ -20,7 +20,7 @@ import java.util.ArrayList;
/**
* This class represents the structure of a cell in JSON
*/
public class Cell {
public class JsonCell {
/**
* The type of cell, e.g. player, chest, enemy, etc
*/