Search in sources :

Example 1 with Map

use of com.faforever.api.data.domain.Map in project faf-java-api by FAForever.

the class MapService method updateMapEntities.

private void updateMapEntities(MapUploadData progressData) {
    LuaValue scenarioInfo = progressData.getLuaScenarioInfo();
    Map map = progressData.getMapEntity();
    if (map == null) {
        map = new Map();
    }
    map.setDisplayName(scenarioInfo.get(ScenarioMapInfo.NAME).toString()).setMapType(scenarioInfo.get(ScenarioMapInfo.TYPE).tojstring()).setBattleType(scenarioInfo.get(ScenarioMapInfo.CONFIGURATIONS).get(ScenarioMapInfo.CONFIGURATION_STANDARD).get(ScenarioMapInfo.CONFIGURATION_STANDARD_TEAMS).get(1).get(ScenarioMapInfo.CONFIGURATION_STANDARD_TEAMS_NAME).tojstring()).setAuthor(progressData.getAuthorEntity());
    LuaValue size = scenarioInfo.get(ScenarioMapInfo.SIZE);
    MapVersion version = new MapVersion().setDescription(scenarioInfo.get(ScenarioMapInfo.DESCRIPTION).tojstring().replaceAll("<LOC .*?>", "")).setWidth(size.get(1).toint()).setHeight(size.get(2).toint()).setHidden(false).setRanked(progressData.isRanked()).setMaxPlayers(scenarioInfo.get(ScenarioMapInfo.CONFIGURATIONS).get(ScenarioMapInfo.CONFIGURATION_STANDARD).get(ScenarioMapInfo.CONFIGURATION_STANDARD_TEAMS).get(1).get(ScenarioMapInfo.CONFIGURATION_STANDARD_TEAMS_ARMIES).length()).setVersion(scenarioInfo.get(ScenarioMapInfo.MAP_VERSION).toint());
    map.getVersions().add(version);
    version.setMap(map);
    progressData.setMapEntity(map);
    progressData.setMapVersionEntity(version);
    version.setFilename(STUPID_MAP_FOLDER_PREFIX + progressData.getFinalZipName());
    progressData.setFinalZipFile(this.fafApiProperties.getMap().getTargetDirectory().resolve(progressData.getFinalZipName()));
    if (Files.exists(progressData.getFinalZipFile())) {
        throw new ApiException(new Error(ErrorCode.MAP_NAME_CONFLICT, progressData.getFinalZipName()));
    }
    // this triggers validation
    mapRepository.save(map);
}
Also used : ProgrammingError(com.faforever.api.error.ProgrammingError) Error(com.faforever.api.error.Error) MapVersion(com.faforever.api.data.domain.MapVersion) LuaValue(org.luaj.vm2.LuaValue) Map(com.faforever.api.data.domain.Map) ApiException(com.faforever.api.error.ApiException)

Example 2 with Map

use of com.faforever.api.data.domain.Map in project faf-java-api by FAForever.

the class MapService method postProcessLuaFile.

private void postProcessLuaFile(MapUploadData progressData) {
    LuaValue scenarioInfo = progressData.getLuaScenarioInfo();
    Optional<Map> mapEntity = mapRepository.findOneByDisplayName(scenarioInfo.get(ScenarioMapInfo.NAME).toString());
    if (!mapEntity.isPresent()) {
        return;
    }
    Player author = mapEntity.get().getAuthor();
    if (author == null) {
        return;
    }
    if (author.getId() != progressData.getAuthorEntity().getId()) {
        throw new ApiException(new Error(ErrorCode.MAP_NOT_ORIGINAL_AUTHOR, mapEntity.get().getDisplayName()));
    }
    int newVersion = scenarioInfo.get(ScenarioMapInfo.MAP_VERSION).toint();
    if (mapEntity.get().getVersions().stream().anyMatch(mapVersion -> mapVersion.getVersion() == newVersion)) {
        throw new ApiException(new Error(ErrorCode.MAP_VERSION_EXISTS, mapEntity.get().getDisplayName(), newVersion));
    }
    progressData.setMapEntity(mapEntity.get());
}
Also used : Player(com.faforever.api.data.domain.Player) ProgrammingError(com.faforever.api.error.ProgrammingError) Error(com.faforever.api.error.Error) LuaValue(org.luaj.vm2.LuaValue) Map(com.faforever.api.data.domain.Map) ApiException(com.faforever.api.error.ApiException)

Aggregations

Map (com.faforever.api.data.domain.Map)2 ApiException (com.faforever.api.error.ApiException)2 Error (com.faforever.api.error.Error)2 ProgrammingError (com.faforever.api.error.ProgrammingError)2 LuaValue (org.luaj.vm2.LuaValue)2 MapVersion (com.faforever.api.data.domain.MapVersion)1 Player (com.faforever.api.data.domain.Player)1