Class TextureSet

java.lang.Object
net.mtrop.doom.texture.TextureSet
All Implemented Interfaces:
Iterable<TextureSet.Texture>, Sizable

public class TextureSet extends Object implements Iterable<TextureSet.Texture>, Sizable
A helper class for the TEXTUREx and PNAMES setup that Doom Texture definitions use.
Author:
Matthew Tropiano
  • Constructor Details

    • TextureSet

      public TextureSet()
      Creates a new blank TextureSet (no patches, no textures).
      Since:
      2.6.0
    • TextureSet

      @SafeVarargs public TextureSet(PatchNames pnames, CommonTextureList<?>... textureLists)
      Creates a new TextureSet using an existing Patch Name lump and a series of Texture Lumps.
      Parameters:
      pnames - the patch name lump.
      textureLists - the list of texture lists.
      Throws:
      TextureException - if a texture references an invalid index in pnames.
  • Method Details

    • contains

      public boolean contains(String textureName)
      Checks an entry for a texture exists.
      Parameters:
      textureName - the texture name to search for.
      Returns:
      true if it exists, false otherwise.
    • addTexture

      public TextureSet.Texture addTexture(TextureSet.Texture texture)
      Adds a texture. The texture being added is deep-copied, such that altering the texture being added will not affect the one in this set.
      Parameters:
      texture - the texture to add.
      Returns:
      (since 2.6.0) the reference to the copy of the texture added to this set.
      Throws:
      IllegalArgumentException - if the texture to add is null.
    • createTexture

      public TextureSet.Texture createTexture(String textureName)
      Creates a new entry for a texture, already added.
      Parameters:
      textureName - the name of the texture to add.
      Returns:
      a new, empty texture.
      Throws:
      IllegalArgumentException - if the texture name is empty or not a valid texture name.
      See Also:
    • getTexture

      public TextureSet.Texture getTexture(int index)
      Returns a texture at a particular index.
      Parameters:
      index - the index of the texture to get.
      Returns:
      the corresponding removed texture, or null if not removed.
    • getTextureByName

      public TextureSet.Texture getTextureByName(String textureName)
      Returns an entry for a texture by name.
      Parameters:
      textureName - the texture name to search for.
      Returns:
      a texture with the composite information, or null if the texture could not be found.
    • getSequence

      public String[] getSequence(String firstName, String lastName)
      Returns a sequence of texture names. Order and list of entries are dependent on the order of all of the textures in this set.
      Parameters:
      firstName - the first texture name in the sequence.
      lastName - the last texture name in the sequence.
      Returns:
      an array of all of the textures in the sequence, including the provided textures, or null, if either texture does not exist.
    • replaceTextureByName

      public TextureSet.Texture replaceTextureByName(String textureName)
      Replaces a texture in the set with a new one, in-place without affecting texture order.
      Parameters:
      textureName - the name of the texture to replace.
      Returns:
      a new, empty texture to serve as the replacement entry, or null if not found.
      Since:
      2.17.0
    • removeTexture

      public TextureSet.Texture removeTexture(int index)
      Removes a texture at a particular index.
      Parameters:
      index - the index of the texture to remove.
      Returns:
      the corresponding removed texture, or null if not removed.
    • removeTextureByName

      public TextureSet.Texture removeTextureByName(String textureName)
      Removes a texture by name.
      Parameters:
      textureName - the name of the texture to remove.
      Returns:
      the corresponding removed texture, or null if not removed.
    • shiftTexture

      public void shiftTexture(int index, int newIndex)
      Shifts the ordering of a texture.
      Parameters:
      index - the old index.
      newIndex - the new index.
      See Also:
    • sort

      public void sort()
      Sorts the texture lumps in this set.
    • sort

      public void sort(Comparator<TextureSet.Texture> comparator)
      Sorts the texture lumps in this set using a comparator.
      Parameters:
      comparator - the comparator to use.
    • export

      public <P extends CommonPatch, T extends CommonTexture<P>> void export(PatchNames pnames, CommonTextureList<T> texture1)
      Exports this TextureSet's contents into a PNAMES and TEXTUREx lump. This looks up patch indices as it exports - if a patch name does not exist in pnames, it is added.

      In the end, pnames and texture1 will be the objects whose contents will change.

      Type Parameters:
      P - the inferred patch type of the provided TextureLists.
      T - the inferred texture type of the provided TextureLists.
      Parameters:
      pnames - the patch names lump to add names to.
      texture1 - the first texture list to write to.
    • export

      public <P extends CommonPatch, T extends CommonTexture<P>> void export(PatchNames pnames, CommonTextureList<T> texture1, CommonTextureList<T> texture2, Set<String> texture1NameSet)
      Exports this TextureSet's contents into a PNAMES and TEXTUREx lump. This looks up patch indices as it exports - if a patch name does not exist in pnames, it is added.

      In the end, pnames and texture1/texture2 will be the objects whose contents will change.

      Type Parameters:
      P - the inferred patch type of the provided TextureLists.
      T - the inferred texture type of the provided TextureLists.
      Parameters:
      pnames - the patch names lump to add names to.
      texture1 - the first texture list to write to.
      texture2 - the second texture list to write to. Can be null.
      texture1NameSet - the set of texture names that will be written to the first texture list. Can be null (exports all names to texture1).
    • size

      public int size()
      Specified by:
      size in interface Sizable
      Returns:
      the amount of individual objects that this object contains.
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Sizable
      Returns if this object contains no objects. The general policy of this method is that this returns true if and only if Sizable.size() returns 0.
      Specified by:
      isEmpty in interface Sizable
      Returns:
      true if so, false otherwise.
    • iterator

      public Iterator<TextureSet.Texture> iterator()
      Specified by:
      iterator in interface Iterable<TextureSet.Texture>