@Override public String toString() { return "MapLoader: mapName: " + file.getFileName() + " mapId: " + getMapId(); }
/** * * @return Returns a stream of the file without the header. So you can directly start reading the data of the map. * @throws IOException */ public final InputStream getMapDataStream() throws IOException { InputStream inputStream = getMapInputStream(file); MapFileHeader.readFromStream(inputStream); return inputStream; }
@Override public MainGridWithUiSettings loadMainGrid(PlayerSetting[] playerSettings) throws MapLoadException { return loadMainGrid(playerSettings, EMapStartResources.HIGH_GOODS); }
@Override public MainGridWithUiSettings loadMainGrid(PlayerSetting[] playerSettings, EMapStartResources startResources) throws MapLoadException { MilliStopWatch watch = new MilliStopWatch(); IMapData mapData = getMapData(); watch.stop("Loading map data required"); byte numberOfPlayers = (byte) getMaxPlayers(); if (playerSettings == null || CommonConstants.ACTIVATE_ALL_PLAYERS) { playerSettings = new PlayerSetting[numberOfPlayers]; for (int i = 0; i < numberOfPlayers; i++) { playerSettings[i] = new PlayerSetting((byte) i); } } MainGrid mainGrid = new MainGrid(getMapId(), getMapName(), mapData, playerSettings); PlayerState[] playerStates = new PlayerState[numberOfPlayers]; for (byte playerId = 0; playerId < numberOfPlayers; playerId++) { playerStates[playerId] = new PlayerState(playerId, new UIState(mapData.getStartPoint(playerId))); } return new MainGridWithUiSettings(mainGrid, playerStates); }
@Override public IMapData getMapData() throws MapLoadException { if (data != null) { return data; } try (InputStream stream = super.getMapDataStream()) { data = new FreshMapData(); FreshMapSerializer.deserialize(data, stream); return data; } catch (IOException ex) { throw new MapLoadException(ex); } }
public static MapLoader getLoaderForListedMap(IListedMap listedMap) throws MapLoadException { if ((checkExtention(listedMap.getFileName(), MapLoader.MAP_EXTENSION_ORIGINAL)) || (checkExtention(listedMap.getFileName(), MapLoader.MAP_EXTENSION_ORIGINAL_MAP_EDITOR))) { // - original Siedler 3 Map return new OriginalMapLoader(listedMap); } else { // - Siedler 3 Remake Savegame or Map MapFileHeader header = RemakeMapLoader.loadHeader(listedMap); switch (header.getType()) { case NORMAL: return new FreshMapLoader(listedMap, header); case SAVED_SINGLE: return new SavegameLoader(listedMap, header); default: throw new MapLoadException("Unkown EMapType: " + header.getType()); } } }
@Override public MainGridWithUiSettings loadMainGrid(PlayerSetting[] playerSettings, EMapStartResources startResources) throws MapLoadException { try (ObjectInputStream ois = new ObjectInputStream(super.getMapDataStream())) { MatchConstants.deserialize(ois); PlayerState[] playerStates = (PlayerState[]) ois.readObject(); GameSerializer gameSerializer = new GameSerializer(); MainGrid mainGrid = gameSerializer.load(ois); mainGrid.initWithPlayerSettings(playerSettings); RescheduleTimer.loadFrom(ois); ois.close(); return new MainGridWithUiSettings(mainGrid, playerStates); } catch (IOException | ClassNotFoundException ex) { throw new MapLoadException(ex); } }
public static MapFileHeader loadHeader(IListedMap file) throws MapLoadException { try (InputStream stream = getMapInputStream(file)) { return MapFileHeader.readFromStream(stream); } catch (IOException e) { throw new MapLoadException("Error during header request for map " + file + " exception: ", e); } }