Class TextureSet
java.lang.Object
net.mtrop.doom.texture.TextureSet
- All Implemented Interfaces:
Iterable<TextureSet.Texture>,Sizable
A helper class for the TEXTUREx and PNAMES setup that Doom Texture definitions use.
- Author:
- Matthew Tropiano
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classTexture patch.static classA class that represents a single composite Texture entry. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new blank TextureSet (no patches, no textures).TextureSet(PatchNames pnames, CommonTextureList<?>... textureLists) Creates a new TextureSet using an existing Patch Name lump and a series of Texture Lumps. -
Method Summary
Modifier and TypeMethodDescriptionaddTexture(TextureSet.Texture texture) Adds a texture.booleanChecks an entry for a texture exists.createTexture(String textureName) Creates a new entry for a texture, already added.<P extends CommonPatch, T extends CommonTexture<P>>
voidexport(PatchNames pnames, CommonTextureList<T> texture1) Exports thisTextureSet's contents into a PNAMES and TEXTUREx lump.<P extends CommonPatch, T extends CommonTexture<P>>
voidexport(PatchNames pnames, CommonTextureList<T> texture1, CommonTextureList<T> texture2, Set<String> texture1NameSet) Exports thisTextureSet's contents into a PNAMES and TEXTUREx lump.String[]getSequence(String firstName, String lastName) Returns a sequence of texture names.getTexture(int index) Returns a texture at a particular index.getTextureByName(String textureName) Returns an entry for a texture by name.booleanisEmpty()Returns if this object contains no objects.iterator()removeTexture(int index) Removes a texture at a particular index.removeTextureByName(String textureName) Removes a texture by name.replaceTextureByName(String textureName) Replaces a texture in the set with a new one, in-place without affecting texture order.voidshiftTexture(int index, int newIndex) Shifts the ordering of a texture.intsize()voidsort()Sorts the texture lumps in this set.voidsort(Comparator<TextureSet.Texture> comparator) Sorts the texture lumps in this set using a comparator.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
TextureSet
public TextureSet()Creates a new blank TextureSet (no patches, no textures).- Since:
- 2.6.0
-
TextureSet
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
Checks an entry for a texture exists.- Parameters:
textureName- the texture name to search for.- Returns:
- true if it exists, false otherwise.
-
addTexture
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
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
Returns a texture at a particular index.- Parameters:
index- the index of the texture to get.- Returns:
- the corresponding removed texture, or
nullif not removed.
-
getTextureByName
Returns an entry for a texture by name.- Parameters:
textureName- the texture name to search for.- Returns:
- a texture with the composite information, or
nullif the texture could not be found.
-
getSequence
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
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
nullif not found. - Since:
- 2.17.0
-
removeTexture
Removes a texture at a particular index.- Parameters:
index- the index of the texture to remove.- Returns:
- the corresponding removed texture, or
nullif not removed.
-
removeTextureByName
Removes a texture by name.- Parameters:
textureName- the name of the texture to remove.- Returns:
- the corresponding removed texture, or
nullif 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
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 thisTextureSet's contents into a PNAMES and TEXTUREx lump. This looks up patch indices as it exports - if a patch name does not exist inpnames, it is added.In the end,
pnamesandtexture1will 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 thisTextureSet's contents into a PNAMES and TEXTUREx lump. This looks up patch indices as it exports - if a patch name does not exist inpnames, it is added.In the end,
pnamesandtexture1/texture2will 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 totexture1).
-
size
-
isEmpty
public boolean isEmpty()Description copied from interface:SizableReturns if this object contains no objects. The general policy of this method is that this returns true if and only ifSizable.size()returns 0. -
iterator
- Specified by:
iteratorin interfaceIterable<TextureSet.Texture>
-