Beispiel #1
0
  public void removeEntity() {

    Position entityPosition = _map.getCell(_posSelected).getPrimaryEntity();

    int entityID = _map.getEntityID(entityPosition);

    EntityType entity = _map.getEntity(entityID).getType();

    Position[] posList =
        new Position[_preferences.getEntityHeight(entity) * _preferences.getEntityWidth(entity)];

    int i = 0;

    for (int x = entityPosition.getX();
        x < (entityPosition.getX() + _preferences.getEntityWidth(entity));
        x++)
      for (int y = entityPosition.getY();
          y < (entityPosition.getY() + _preferences.getEntityHeight(entity));
          y++) {

        posList[i] = new Position(x, y);

        i++;
      }

    if (_map.removeEntity(posList, entityID)) {

      notifyRemoveEntity(posList);
      notifyCellDeSelected();
    }
  }
Beispiel #2
0
 public void exportHeightmapImage(File file) {
   if (_map != null) {
     HeightMapExporter hm = new HeightMapExporter(_map.getMapWidth(), _map.getMapHeight());
     hm.ProcessMap(_map, _preferences);
     hm.SaveImageHeightmap(file);
   }
 }
Beispiel #3
0
  public void setEntityParameters(HashMap<String, String> parameters) {

    int entityID = _map.getEntityID(_posSelected);

    _map.removeAllEntityParameters(entityID);

    if (!parameters.isEmpty())
      for (String name : parameters.keySet()) {

        _map.newEntityParameter(entityID, name, parameters.get(name));
      }
  }
Beispiel #4
0
  public HashMap<String, String> getEntityParameters() {

    HashMap<String, String> parameters = new HashMap<String, String>();

    for (String name : _map.getEntity(_map.getEntityID(_posSelected)).getParamNames()) {

      if ((!name.equals(Map.ENTITY_TYPE))
          && (!name.equals(Map.ENTITY_DIMENSION))
          && (!name.equals(Map.ENTITY_POSITION)))
        parameters.put(name, _map.getEntity(_map.getEntityID(_posSelected)).getParameter(name));
    }

    return parameters;
  }
Beispiel #5
0
  private void newEntity(EntityType newType) {

    Position[] posList =
        new Position[_preferences.getEntityHeight(newType) * _preferences.getEntityWidth(newType)];

    int i = 0;

    for (int x = _posSelected.getX();
        x < (_posSelected.getX() + _preferences.getEntityWidth(newType));
        x++)
      for (int y = _posSelected.getY();
          y < (_posSelected.getY() + _preferences.getEntityHeight(newType));
          y++) {

        posList[i] = new Position(x, y);

        i++;
      }

    if (_map.newEntity(
        posList,
        new Entity(newType),
        _preferences.getEntityHeight(newType),
        _preferences.getEntityWidth(newType))) {

      notifyAllSelectChanges();
      notifyNewEntity(posList, newType);
    }
  }
Beispiel #6
0
  private void changeCellType(CellType newType) {

    _map.setCellType(_posSelected, newType);

    notifyAllSelectChanges();
    notifyCellChanged(_posSelected, newType);
  }
Beispiel #7
0
  private void notifyAllSelectChanges() {

    notifyCellSelected();
    notifyShowCellType();
    notifyShowEntityMessage();

    if (_map.getCell(_posSelected).getEntity() > 0) {

      Entity entity = _map.getEntity(_map.getEntityID(_posSelected));

      Set<String> paramNames = entity.getParamNames();

      for (String name : paramNames) {

        notifyShowEntityParameter(name, entity.getParameter(name));
      }
    }
  }
Beispiel #8
0
  public void exportMap(File file) {

    if (_map != null)
      try {
        file.createNewFile();
        if (file.canWrite()) {

          _fileHandler.initExportData(file);

          _fileHandler.exportData("Map = {\n\n");

          _fileHandler.exportData(_preferences.getGridAttributes());

          _fileHandler.exportData(_map.getGridAttributes());

          /*int width = _map.getMapWidth();
          int height = _map.getMapHeight();
          String s = "";

          for (int x = 0; x < width; x++)
          	for (int y = 0; y < height; y++) {

          		CellType cell = _map.getCell(new Position(x, y)).getType();
          		s = "\t" + cell.getType() + x + "_" + y + " = {\n";
          		s = s + "\t\ttype = \"" + cell.getType() + "\",\n";
          		s = s + "\t\t" + Map.CELL_POSITION + " = { " + x + ", " + y + " },\n";
          		s = s + _preferences.getCellAttributes(cell);
          		s = s + "\t},\n\n";
          		_fileHandler.exportData(s);

          	}*/

          _fileHandler.exportData(_map.getAllEntitiesAttributes());

          _fileHandler.exportData("}");

          _fileHandler.closeExportFile();
        }

      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
  }
Beispiel #9
0
  private void notifyShowEntityMessage() {

    String message;

    if (_map.getCell(_posSelected).getEntity() > 0) message = "Información de la entidad:";
    else message = "Casilla sin entidad";

    for (ControllerListener listener : _listeners) {
      listener.showEntityMessage(message);
    }
  }
Beispiel #10
0
  private void notifyNewMapLoaded() {

    notifyCellDeSelected();
    notifyNewMap(_map.getMapWidth(), _map.getMapHeight());

    _posSelected = null;

    Position pos = null;

    for (int x = 0; x < _map.getMapWidth(); x++)
      for (int y = 0; y < _map.getMapHeight(); y++) {

        pos = new Position(x, y);
        notifyCellChanged(pos, _map.getCell(pos).getType());

        int entityID = _map.getCell(pos).getEntity();

        if (entityID != 0) {

          Position entityPos = _map.getCell(pos).getPrimaryEntity();

          EntityType entityType = _map.getEntity(entityID).getType();

          Position[] posList =
              new Position
                  [_preferences.getEntityHeight(entityType)
                      * _preferences.getEntityWidth(entityType)];

          int i = 0;

          for (int xEntity = entityPos.getX();
              xEntity < (entityPos.getX() + _preferences.getEntityWidth(entityType));
              xEntity++)
            for (int yEntity = entityPos.getY();
                yEntity < (entityPos.getY() + _preferences.getEntityHeight(entityType));
                yEntity++) {

              posList[i] = new Position(xEntity, yEntity);
              i++;
            }

          notifyNewEntity(posList, entityType);
        }
      }
  }
Beispiel #11
0
  public void importMap(File file) {

    if (file.exists() && file.canRead()) {

      _fileHandler.initImportData(file);

      _map = new Map();

      String line = _fileHandler.importData();

      while (line != null) {

        _preferences.importData(line, 0, null, null);
        _map.importData(line, 0, _preferences.getCellTypes(), _preferences.getColorEntities());
        line = _fileHandler.importData();
      }

      _fileHandler.closeImportFile();

      notifyNewMapLoaded();
    }
  }
Beispiel #12
0
  private void notifyShowCellType() {

    for (ControllerListener listener : _listeners) {
      listener.showCellType(_map.getCell(_posSelected).getType().getType());
    }
  }
Beispiel #13
0
  public void setMapParameters(HashMap<String, String> parameters) {

    _map.setParameters(parameters);
  }
Beispiel #14
0
  public HashMap<String, String> getMapParameters() {

    return _map.getParameters();
  }