Package net.mtrop.doom.texture
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
Modifier and TypeClassDescriptionstatic class
Texture patch.static class
A class that represents a single composite Texture entry. -
Constructor Summary
ConstructorDescriptionCreates 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.boolean
Checks 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.boolean
isEmpty()
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.void
shiftTexture
(int index, int newIndex) Shifts the ordering of a texture.int
size()
void
sort()
Sorts the texture lumps in this set.void
sort
(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, wait
Methods 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
null
if 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
null
if 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
null
if 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
null
if not removed.
-
removeTextureByName
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
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,
pnames
andtexture1
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 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,
pnames
andtexture1
/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 totexture1
).
-
size
public int size() -
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 ifSizable.size()
returns 0. -
iterator
- Specified by:
iterator
in interfaceIterable<TextureSet.Texture>
-