package de.geolykt.starloader.api.event.lifecycle; import java.util.Objects; import org.jetbrains.annotations.ApiStatus.AvailableSince; import org.jetbrains.annotations.ApiStatus.Internal; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import com.badlogic.gdx.graphics.g2d.PixmapPacker; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.g2d.TextureRegion; import de.geolykt.starloader.api.event.Event; import de.geolykt.starloader.api.gui.Drawing; import de.geolykt.starloader.api.gui.DrawingImpl; /** * Lifecycle event which is fired after the main texture atlas has been generated * via {@link PixmapPacker}. This {@link Event} will be fired after the {@link AtlasPackingEvent} * by necessity. However, the generated {@link TextureAtlas} will not be assigned * to its corresponding field in the game's 'GalFX' class (which in turn is used by * {@link Drawing} / {@link DrawingImpl}). This means that most graphical operations, * such as obtaining built-in fonts or specific texture regions, are only possible after * this event was fired. * *

The main usecase of this event is to preemptively store {@link TextureRegion}s * packed through {@link AtlasPackingEvent#packTexture(String, com.badlogic.gdx.graphics.Pixmap)} * via {@link TextureAtlas#findRegion(String)}. * *

For more information about the atlas packing process, see the documentation of * {@link AtlasPackingEvent}. * *

Like {@link AtlasPackingEvent}, this event should ideally only be fired once. * Changes to this behaviour will be considered an API compatibility break. * *

This event will be posted to the event bus immediately after * {@link PixmapPacker#generateTextureAtlas(com.badlogic.gdx.graphics.Texture.TextureFilter, com.badlogic.gdx.graphics.Texture.TextureFilter, boolean)} * is called. * * @since 2.0.0-a20260214 * @apiNote Keep in mind that the constructor of Event classes are in general not public APIs, * unless specified otherwise. This also means that subclassing this class is not supported when * it comes to preserving ABI constraints. */ @AvailableSince("2.0.0-a20260214") public class AtlasPackedEvent extends Event { @NotNull private final TextureAtlas atlas; /** * This constructor is not public API, do not invoke manually. * * @param atlas The {@link TextureAtlas} instance. * @since 2.0.0-a20260214 */ @Internal @Contract(pure = true, value = "null -> fail") public AtlasPackedEvent(@NotNull TextureAtlas atlas) { this.atlas = Objects.requireNonNull(atlas, "'atlas' may not be null"); } /** * Obtains the {@link TextureAtlas} instance that was generated by the {@link AtlasPackingEvent}. * * @return The {@link TextureAtlas} generated by {@link AtlasPackingEvent}. * @since 2.0.0-a20260214 */ @NotNull @Contract(pure = true) @AvailableSince("2.0.0-a20260214") public TextureAtlas getAtlas() { return this.atlas; } }