@Override public DatFileMapping getDatFileMapping(int fileIndex) { IndexingDatFileMapping mapping = datFileMappings[fileIndex]; return mapping == null ? new DefaultGfxFolderMapping.DefaultDatFileMapping() : mapping; }
public static GfxFolderMapping getMappingForVersionId(String settlersVersionId) { try { SettlersVersionMapping mappingFile = readFromStream(SettlersVersionMapping.class.getResourceAsStream(MAPPING_FILE_NAME)); return mappingFile.getMapping(settlersVersionId); } catch (IOException e) { throw new RuntimeException(e); } } }
private GfxFolderMapping getMapping(String settlersVersionId) throws IOException { if (mappingFilesByVersionId.containsKey(settlersVersionId)) { String mappingFileName = mappingFilesByVersionId.get(settlersVersionId); InputStream mappingFileStream = getClass().getResourceAsStream(mappingFileName); return IndexingGfxFolderMapping.readFromStream(mappingFileStream); } else { return new DefaultGfxFolderMapping(); } }
/** * Sets the path to look for dat files. * * @param path * The directory. It may not exist, but must not be null. */ public static void setLookupPath(File path, String settlersVersionId) { ImageProvider.lookupPath = path; getInstance().gfxFolderMapping = SettlersVersionMapping.getMappingForVersionId(settlersVersionId); getInstance().startPreloading(); }
public static SettlersVersionMapping readFromDirectory(String directory) throws IOException { File file = new File(directory, MAPPING_FILE_NAME); if (file.exists()) { return readFromStream(new FileInputStream(file)); } else { return new SettlersVersionMapping(); } }
public void serializeToDirectory(String directory) throws IOException { serializeToStream(new FileOutputStream(new File(directory, MAPPING_FILE_NAME))); }
private void loadGuiImage(int goldIndex, String name) { try { int theseGraphicsFilesIndex = mapping.mapGuiImage(goldIndex); reader.skipTo(guiStarts[theseGraphicsFilesIndex]); SingleImage image = DatBitmapReader.getImage(guiTranslator, reader, name); guiImages[goldIndex] = image; } catch (IOException | ArrayIndexOutOfBoundsException e) { guiImages[goldIndex] = NullImage.getForGui(); } }
private DatFileReader createFileReader(int fileIndex) { String numberString = String.format(Locale.ENGLISH, "%02d", fileIndex); DatFileReader reader = EMPTY_DAT_FILE; for (DatFileType type : DatFileType.values()) { String fileName = FILE_PREFIX + numberString + type.getFileSuffix(); File file = findFileInPaths(fileName); if (file != null) { reader = new AdvancedDatFileReader(file, type, gfxFolderMapping.getDatFileMapping(fileIndex), "F" + fileIndex); break; } } return CustomGraphicsInterceptor.prependCustomGraphics(fileIndex, reader, this); }
private synchronized void loadSettlers(int goldIndex, String name) throws IOException { int theseGraphicsFilesIndex = mapping.mapSettlersSequence(goldIndex); int position = settlerStarts[theseGraphicsFilesIndex]; long[] framePositions = readSequenceHeader(position); SettlerImage[] images = new SettlerImage[framePositions.length]; for (int i = 0; i < framePositions.length; i++) { reader.skipTo(framePositions[i]); images[i] = DatBitmapReader.getImage(settlerTranslator, reader, name + "-S" + goldIndex + ":" + i); } int torsoPosition = torsoStarts[theseGraphicsFilesIndex]; if (torsoPosition >= 0) { long[] torsoPositions = readSequenceHeader(torsoPosition); for (int i = 0; i < torsoPositions.length && i < framePositions.length; i++) { reader.skipTo(torsoPositions[i]); SingleImage torso = DatBitmapReader.getImage(torsoTranslator, reader, name + "-T" + goldIndex + ":" + i); images[i].setTorso(torso); } } int shadowPosition = shadowStarts[theseGraphicsFilesIndex]; if (shadowPosition >= 0) { long[] shadowPositions = readSequenceHeader(shadowPosition); for (int i = 0; i < shadowPositions.length && i < framePositions.length; i++) { reader.skipTo(shadowPositions[i]); SingleImage shadow = DatBitmapReader.getImage(shadowTranslator, reader, name + "-SH" + goldIndex + ":" + i); images[i].setShadow(shadow); } } settlerSequences[goldIndex] = new ArraySequence<>(images); }
@Test public void testGetAmazonDemoMapping() { GfxFolderMapping mapping = SettlersVersionMapping.getMappingForVersionId(Long.toString(-1282419180527137435L)); assertNotNull(mapping); assertTrue(mapping instanceof IndexingGfxFolderMapping); }
@Override public DatFileMapping getDatFileMapping(int fileIndex) { return new DefaultDatFileMapping(); }
@Test public void testGetMappingForUnknownHash() { GfxFolderMapping mapping = SettlersVersionMapping.getMappingForVersionId(Long.toString(-1L)); assertNotNull(mapping); assertTrue(mapping instanceof DefaultGfxFolderMapping); } }
public AdvancedDatFileReader(File file, DatFileType type, String file_name) { this(file, type, new DefaultDatFileMapping(), file_name); }