package scdbpf
Provides methods for accessing and modifying the contents of DBPF formatted files. Currently, only DBPF version 1.0 is supported (used by SimCity 4).
DBPF files are accessed via DbpfFiles, a container of
DbpfEntries. The content of a DbpfEntry can be accessed from
BufferedEntries in decoded form as DbpfType, such as
Exemplar, Fsh or Sc4Path.
This package object provides additional type aliases for DbpfExceptions.
Examples
To get started, it is easiest to start the REPL via sbt console, which
loads all the dependencies and useful initial import statements. Reading a
DBPF file, sorting its entries by TGI and writing back to the same file
could be achieved like this:
val dbpf = DbpfFile.read(new File("foobar.dat")) dbpf.write(dbpf.entries.sortBy(_.tgi))
This example shifts the GIDs of all LTexts by +3:
dbpf.write(dbpf.entries.map { e =>
if (e.tgi matches Tgi.LText)
e.copy(e.tgi.copy(gid = e.tgi.gid + 3))
else
e
})Another example: This decodes all the Sc4Path entries and rotates
them by 90 degree.
val writeList = for (e <- dbpf.entries) yield { if (e.tgi matches Tgi.Sc4Path) { val be = e.toBufferedEntry.convertContentTo(Sc4Path) be.copy(content = be.content * RotFlip.R1F0) } else { e } } dbpf.write(writeList)
The following example finds the first entry that is an exemplar and
contains a property with a specific ID. (Note the view to avoid
unnecessary decoding if the exemplar is already among the first entries.)
val id = UInt(0x12345678) dbpf.entries.view. filter(_.tgi matches Tgi.Exemplar). map(_.toBufferedEntry.convertContentTo(Exemplar)). find(_.content.properties.contains(id))
- Source
- package.scala
- Alphabetic
- By Inheritance
- scdbpf
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- final case class BufferedEntry[+A <: DbpfType](tgi: Tgi, content: A, compressed: Boolean) extends DbpfEntry with Product with Serializable
A buffered entry whose data is held in memory in uncompressed form.
A buffered entry whose data is held in memory in uncompressed form. The actual data will be held by the
contenttype. As such, this entry will be immutable, if itscontentis immutable.- A
the type of the content
- tgi
the TGI of this entry
- content
the actual content of this entry
- compressed
true, if the input should try to return the data in compressed form. If compression fails (if the compressed data would be larger than the compressed one, for instance), the data may be uncompressed nevertheless.
- See also
- type DbpfDecodeFailedException = scdbpf.DbpfExceptions.DbpfDecodeFailedException
- trait DbpfEntry extends AnyRef
The base trait for entries of a DBPF file.
- type DbpfException = scdbpf.DbpfExceptions.DbpfException
- class DbpfFile extends AnyRef
A container for
DbpfEntriesthat are read from and written to a file.A container for
DbpfEntriesthat are read from and written to a file. Instances of this class may be obtained via the DbpfFile.read method. Thewritemethods may be used for writing entries back to a file.A
DbpfFileis immutable, but the entries of this file might not be. - type DbpfFileFormatException = scdbpf.DbpfExceptions.DbpfFileFormatException
- type DbpfIoException = scdbpf.DbpfExceptions.DbpfIoException
- type DbpfStreamOutOfDateException = scdbpf.DbpfExceptions.DbpfStreamOutOfDateException
- trait DbpfType extends AnyRef
The base trait for the content type of
DbpfEntries.The base trait for the content type of
DbpfEntries.- See also
- trait DbpfTypeCompanion[B <: DbpfType] extends WithContentConverter[B]
This trait defines the converters that should be implemented by companion objects of
DbpfTypes. - type ExceptionHandler = scdbpf.compat.ExceptionHandler
- sealed trait Exemplar extends DbpfType
- trait Fsh extends DbpfType
- sealed trait LText extends DbpfType
- final class RawEntry extends DbpfEntry
A buffered entry whose raw byte data is held in an array, that is, the exact data that would be written to a file (compressed or uncompressed).
A buffered entry whose raw byte data is held in an array, that is, the exact data that would be written to a file (compressed or uncompressed).
This differs from a BufferedEntry in that the latter always holds the uncompressed data. Thus, a
BufferedEntryis suited for access and modification of the content, but aRawEntryis usually suitable for just holding the data in memory, as creating the input does not require an intermediate compression. If the data is not compressed, this distinction is not as important.Instances of this class are immutable, if the data it was created from was. Note that conversion between
RawEntriesandBufferedEntriesreferences the same backing array if possible. If created from a StreamedEntry, a new data array will be created, hence, the entry will be immutable.- See also
- class RawType extends DbpfType
A raw type that does not represent any specific format.
A raw type that does not represent any specific format. Its data is backed by an array. As such, it is also suited as a super class of specialized types which are backed by an array.
Instances of this class my be obtained via the companion object.
- Note
This is one of the few spots where the raw backing array gets exposed. If instances of this class or created from instances of this class are meant to be immutable, it is required to ensure that this array does not get modified.
- trait S3d extends DbpfType
- trait Sc4Path extends DbpfType
- final class StreamedEntry extends DbpfEntry
A lightweight entry that reads its data as stream from a file without holding all the data constantly in memory.
A lightweight entry that reads its data as stream from a file without holding all the data constantly in memory.
Usually, it is not necessary to load all the entries into memory, especially when processing large files, so instances of this class can be directly read from and written to files. Note that this is sensitive to changes of the source file: If the source file has been modified since this entry had been created, a DbpfStreamOutOfDateException will be thrown upon calling input so as to preclude malformed data.
- See also
- sealed trait Tgi extends LabeledTgi
Represents Type, Group, Instance identifiers of
DbpfEntries.Represents Type, Group, Instance identifiers of
DbpfEntries.Tgiobjects are immutable.Instances of this class may be obtained via the companion object's
applymethod, for example:val tgi = Tgi(0, 0, 0x12345678)
Alternatively, the
copymethods can be used to create modified copies.tgi.copy(iid = 0x87654321) tgi.copy(Tgi.Sc4Path)The matches method is used to test whether a
Tgimatches anotherTgiobject orTgiMask. - sealed trait TgiMask extends TgiLike
Represents masks of TGIs that are used for the
matchmethod of Tgi.Represents masks of TGIs that are used for the
matchmethod of Tgi.Instances of this class may be obtained via the companion object's
applymethods. - trait WithContentConverter[B <: DbpfType] extends AnyRef
This trait is used for companion objects of
DbpfTypes and is needed in particular for Exemplars.
Value Members
- implicit def genericConverter[A <: DbpfType](implicit conv: Converter[DbpfType, A]): Converter[BufferedEntry[DbpfType], BufferedEntry[A]]
provides a converter for
BufferedEntries, given a converter ofDbpfTypes - implicit def noopConverter[A <: DbpfType]: Converter[BufferedEntry[A], BufferedEntry[A]]
resolves generalizing conversions from specialized types to general ones
- val strategy: scdbpf.compat.strategy.type
- object DbpfExceptions
- object DbpfFile
Provides factory methods for reading and writing DBPF files.
- object DbpfPackager
Provides method for QFS compressing and decompressing.
- object DbpfProperty
- object DbpfUtil
- object Exemplar extends WithContentConverter[Exemplar]
- object Experimental
Provides a few experimental functions that are useful, but which may still be changed in the future.
- object Fsh extends DbpfTypeCompanion[Fsh]
- object LText extends DbpfTypeCompanion[LText]
- object RawType
- object S3d extends DbpfTypeCompanion[S3d]
- object Sc4Path extends DbpfTypeCompanion[Sc4Path]
- object Tgi
Provides various masks that
Tgis can be matched against. - object TgiMask
Provides factory methods for creating
TgiMasks.