@Override public Component getListCellRendererComponent(JList<? extends MapLoader> list, MapLoader value, int index, boolean isSelected, boolean cellHasFocus) { mapNameLabel.setText(value.getMapName()); String date = "???"; if (value.getCreationDate() != null) { date = df.format(value.getCreationDate()); mapIdLabel.setText(date + " / " + value.getMapId()); playerCountLabel.setText("Player: " + value.getMinPlayers() + " - " + value.getMaxPlayers()); if (value.getDescription() != null && !value.getDescription().isEmpty()) { descriptionLabel.setText(value.getDescription()); } else { descriptionLabel.setText("<no description>");
@Override public int compareTo(MapLoader other) { MapFileHeader myHeader = this.getFileHeader(); MapFileHeader otherHeader = other.getFileHeader(); if (myHeader.getType() == otherHeader.getType() && myHeader.getType() == MapType.SAVED_SINGLE) { return -this.getCreationDate().compareTo(other.getCreationDate()); // order by date descending } else { return this.getMapName().compareToIgnoreCase(other.getMapName()); // order by name ascending } }
/** * Load a map * * @param loader * Map to load * @throws MapLoadException */ public void loadMap(MapLoader loader) throws MapLoadException { MapData data = new MapData(loader.getMapData()); MapFileHeader header = loader.getFileHeader(); loadMap(header, data); }
/** * Checks if a map matches the search criteria * * @param m * Map * @param search * Criteria * @return true if yes, false if no */ private boolean matchesSearch(MapLoader m, String search) { if (m.getMapName().toLowerCase(Locale.ENGLISH).contains(search)) { return true; } if (m.getDescription().toLowerCase(Locale.ENGLISH).contains(search)) { return true; } return m.getMapId().toLowerCase(Locale.ENGLISH).contains(search); }
@Override public int getMaxPlayers() { return mapLoader.getMaxPlayers(); }
IStartingGame game; if (loadableReplayFile == null) { MapLoader mapLoader = MapLoader.getLoaderForListedMap(new DirectoryMapLister.ListedMapFile(new File(mapFile))); if (mapLoader.getFileHeader().getType() == MapFileHeader.MapType.NORMAL) { byte playerId = 0; PlayerSetting[] playerSettings = PlayerSetting.createDefaultSettings(playerId, (byte) mapLoader.getMaxPlayers()); game = new JSettlersGame(mapLoader, randomSeed, playerId, playerSettings).start(); } else { MapFileHeader header = mapLoader.getFileHeader(); game = new JSettlersGame(mapLoader, randomSeed, header.getPlayerId(), header.getPlayerSettings()).start();
private void buildPlayerSlots() { int maximumNumberOfPlayers = this.mapLoader.getMaxPlayers(); playerSlots.clear(); for (byte i = 0; i < maximumNumberOfPlayers; i++) { PlayerSlot playerSlot = playerSlotFactory.createPlayerSlot(i, this.mapLoader); playerSlots.add(playerSlot); } PlayerSetting[] playerSettings = mapLoader.getFileHeader().getPlayerSettings(); for (byte i = 0; i < playerSlots.size(); i++) { PlayerSlot playerSlot = playerSlots.get(i); PlayerSetting playerSetting = playerSettings[i]; playerSlot.setSlot(i); if (playerSetting.getTeamId() != null) { playerSlot.setTeam(playerSetting.getTeamId(), false); } else { playerSlot.setTeam(i); } if (playerSetting.getCivilisation() != null) { playerSlot.setCivilisation(playerSetting.getCivilisation(), false); } if (playerSetting.getPlayerType() != null) { playerSlot.setPlayerType(playerSetting.getPlayerType(), false); } } }
@Override public synchronized void foundMap(IListedMap map) { MapLoader loader; try { loader = MapLoader.getLoaderForListedMap(map); } catch (Exception e) { System.err.println("Cought exception while loading header for " + map.getFileName()); e.printStackTrace(); return; } MapFileHeader mapHead = loader.getFileHeader(); // - if the map can't be load (e.g. caused by wrong format) the mapHead gets NULL! -> hide/ignore this map from user if (mapHead != null) { MapType type = loader.getFileHeader().getType(); if ((type == MapType.SAVED_SINGLE)) { savedMaps.add((RemakeMapLoader) loader); } else { freshMaps.add(loader); } } }
private static void createReplayOfRemainingTasks(MapLoader newSavegame, ReplayStartInformation replayStartInformation, String newReplayFile, IGameClock gameClock) throws IOException { System.out.println("Creating new jsettlers.integration.replay file (" + newReplayFile + ")..."); ReplayStartInformation replayInfo = new ReplayStartInformation(0, newSavegame.getMapName(), newSavegame.getMapId(), replayStartInformation.getPlayerId(), replayStartInformation.getPlayerSettings() ); DataOutputStream dos = new DataOutputStream(ResourceManager.writeUserFile(newReplayFile)); replayInfo.serialize(dos); gameClock.saveRemainingTasks(dos); dos.close(); System.out.println("New jsettlers.integration.replay file successfully created!"); }
@Test public void testIfSavegameOfSavegameEqualsSavegame() throws IOException, MapLoadException, ClassNotFoundException, InterruptedException { final byte playerId = 0; final int targetTimeMinutes = 30; MapLoader map = MapUtils.getMountainlake(); ReplayUtils.PlayMapResult directSavegameReplay = ReplayUtils.playMapToTargetTimes(map, playerId, targetTimeMinutes); assertDirectSavegameReplay(1, directSavegameReplay); MapLoader savegame = directSavegameReplay.getSavegames()[0]; Thread.sleep(2000L); // loading + saving might happend in less than a second => make sure the next savegame is saved with a different name System.out.println("Loading savegame..."); MatchConstants.init(new NetworkTimer(true), 0L); MainGridWithUiSettings loadedMap = savegame.loadMainGrid(PlayerSetting.createDefaultSettings(playerId, (byte) savegame.getMaxPlayers())); MainGrid mainGrid = loadedMap.getMainGrid(); PlayerState playerState = loadedMap.getPlayerState(playerId); mainGrid.initForPlayer(playerId, playerState.getFogOfWar()); MapLoader savegameOfSavegame; try { System.out.println("Creating savegame of savegame..."); savegameOfSavegame = MapUtils.saveMainGrid(mainGrid, playerId, playerState.getUiState()); assertNotNull(savegameOfSavegame); } finally { mainGrid.stopThreads(); JSettlersGame.clearState(); } // compare direct savegame with replayed savegame. MapUtils.compareMapFiles(savegame, savegameOfSavegame); }
@Override public String getMapName() { return gameName + "(" + mapLoader.getMapName() + ")"; }
@Override public String getMapId() { return mapLoader.getMapId(); } }
@Override public IMapData getMapData() throws MapLoadException { return mapLoader.getMapData(); }
@Override public Date getCreationDate() { return mapLoader.getCreationDate(); }
@Override public MapFileHeader getFileHeader() { return mapLoader.getFileHeader(); }
@Override public short[] getImage() { return mapLoader.getImage(); }
/** * Main entry point * * @param args */ public static void main(String[] args) { try { ExceptionHandler.setupDefaultExceptionHandler(); final File file = new File(args[0]); JSettlersGame game = new JSettlersGame(MapLoader.getLoaderForListedMap(new DirectoryMapLister.ListedMapFile(file)), 123456L, (byte) 0, null); game.start(); } catch (Exception e) { ExceptionHandler.displayError(e, "Error launching game"); } } }
@Override public IListedMap getListedMap() { return mapLoader.getListedMap(); }
@Override public String getDescription() { return mapLoader.getDescription(); }
/** * Checks if a map matches the search criteria * * @param m * Map * @param search * Criteria * @return true if yes, false if no */ private boolean matchesSearch(MapLoader m, String search) { if (search.isEmpty()) { return true; } if (m.getMapName().toLowerCase(Locale.ENGLISH).contains(search)) { return true; } if (m.getDescription().toLowerCase(Locale.ENGLISH).contains(search)) { return true; } return m.getMapId().toLowerCase(Locale.ENGLISH).contains(search); }