AnimaEngine  1.0.0
Nintendo DS Pokemon Black, White, Black 2, and White 2 sprite extraction and preview toolchain
Functions
gui_state.c File Reference

Implementations of GUI application state handlers. More...

#include "gui_state.h"
#include "file_util.h"
#include "gif_writer.h"
#include "nds_header.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Functions

void GuiState_Init (GuiState *state)
 Initializes default options inside a GuiState structure. More...
 
int GuiState_LoadAndValidateRom (GuiState *state, const char *path)
 Validates NDS ROM header and initializes internal directory mappings. More...
 
void GuiState_SetStatus (GuiState *state, const char *text)
 Sets statusbar notification message. More...
 
void GuiState_CopyText (char *dst, size_t dst_size, const char *src)
 Helper utility to safely copy a string with bounding limit constraints. More...
 
const char * GuiState_BaseName (const char *path)
 Extracts file basename from full absolute or relative path. More...
 
void GuiState_SanitizePath (const char *name, char *out, size_t out_size)
 Sanitizes folder name by stripping out illegal character blocks. More...
 
static void GuiState_SanitizeDisplayPath (const char *name, char *out, size_t out_size)
 Sanitizes species name for building camel-cased display output path strings. More...
 
void GuiState_BuildOutputDir (const PokemonCatalogEntry *entry, char *buf, size_t sz)
 Builds directory path where current species assets will be written. More...
 
static int StrContainsInsensitive (const char *hay, const char *needle)
 Checks if a string contains another string case-insensitively. More...
 
int GuiState_EntryMatchesQuery (const PokemonCatalogEntry *entry, const char *query)
 Checks if a Pokemon species matches the search filtering text query. More...
 
const PokemonCatalogEntryGuiState_SelectedEntry (int dex_id)
 Retrieves the species catalog entry matching index. More...
 
int GuiState_GetFormCount (const GuiState *state, int dex_id)
 Retrieves form count for a species. More...
 
const char * GuiState_GetFormName (const GuiState *state, int dex_id, int form_idx)
 Retrieves user-friendly label name of alternate form index. More...
 
static void GuiState_BuildPreviewOptions (GuiState *state, AnimaPreviewOptions *opts)
 Constructs option query filters matching current UI selected states. More...
 
static const AnimaPreviewAssetInfoGuiState_CurrentAsset (const GuiState *state)
 Gets the currently selected preview asset info descriptor. More...
 
int GuiState_RefreshAssets (GuiState *state, const PokemonCatalogEntry *entry)
 Scans ROM files to discover all asset variants for selected species. More...
 
void GuiState_UpdatePreview (GuiPreview *p)
 Advances active viewport frame index based on real-world elapsed frame delta time. More...
 
int GuiState_GifDelayCs (const GuiState *state)
 Retrieves the current custom GIF frame delay. More...
 
void GuiState_SetGifDelayCs (GuiState *state, int delay_cs)
 Sets the custom GIF frame delay. More...
 
void GuiState_UnloadPreview (GuiPreview *p)
 Deallocates texture cache and color frames stored inside preview struct. More...
 
static void GuiState_SetPreviewContentBounds (GuiPreview *p)
 Computes a tight bounding box encapsulating all non-transparent pixels in the preview animation frames. More...
 
static int LoadPreviewFromBackend (GuiState *state, const PokemonCatalogEntry *entry)
 Loads the default idle animation preview frames from the backend. More...
 
static int LoadPngPreview (GuiState *state, const PokemonCatalogEntry *entry, int backend_func(GuiState *, const PokemonCatalogEntry *, AnimaIdlePreview *))
 Helper for wrapping static single-frame PNG preview loaders. More...
 
static int LoadAnimatedPreview (GuiState *state, const PokemonCatalogEntry *entry, int backend_func(GuiState *, const PokemonCatalogEntry *, AnimaIdlePreview *))
 Helper for wrapping multi-frame animated preview loaders. More...
 
static int LoadSpritesheet (GuiState *state, const PokemonCatalogEntry *entry, AnimaIdlePreview *out)
 Direct callback for loading spritesheet asset frames. More...
 
static int LoadStaticIdle (GuiState *state, const PokemonCatalogEntry *entry, AnimaIdlePreview *out)
 Direct callback for loading static idle preview frame. More...
 
static int LoadBreak (GuiState *state, const PokemonCatalogEntry *entry, AnimaIdlePreview *out)
 Direct callback for loading idle break preview frame loop. More...
 
static int LoadComposed (GuiState *state, const PokemonCatalogEntry *entry, AnimaIdlePreview *out)
 Direct callback for loading composed animation frame loop. More...
 
static int LoadNmarAnimation (GuiState *state, const PokemonCatalogEntry *entry, AnimaIdlePreview *out)
 Direct callback for loading NMAR timeline-driven animation. More...
 
static int LoadNmcrMap (GuiState *state, const PokemonCatalogEntry *entry, AnimaIdlePreview *out)
 Direct callback for loading NMCR layout map composition. More...
 
int GuiState_TryLoadPreview (GuiState *state, const PokemonCatalogEntry *entry)
 Attempts to load the preview for a Pokemon catalog entry. More...
 
void GuiState_RunExport (GuiState *state, const PokemonCatalogEntry *entry, int export_spritesheets, int export_static, int export_gif, int export_idle_break, int export_composed)
 Performs batch export run for currently selected Pokemon. More...
 
void GuiState_ExportDsFiles (GuiState *state, const PokemonCatalogEntry *entry)
 Raw dumps individual compressed Nitro NARC blocks for selected species to disk. More...
 
void GuiState_ExportAllAssets (GuiState *state, const PokemonCatalogEntry *entry)
 Recursively renders and writes all assets discovered for species. More...
 
static int GuiState_ExportLoadedPreviewGif (const GuiState *state, const char *out_path)
 Exports currently loaded preview frame buffer directly to a custom GIF file. More...
 
void GuiState_ExportCurrent (GuiState *state, const PokemonCatalogEntry *entry)
 Exports the currently active preview asset view to its default output file path. More...
 

Detailed Description

Implementations of GUI application state handlers.

Function Documentation

◆ GuiState_BaseName()

const char* GuiState_BaseName ( const char *  path)

Extracts file basename from full absolute or relative path.

Parameters
pathFile path.
Returns
Pointer to start of basename within path string.

◆ GuiState_BuildOutputDir()

void GuiState_BuildOutputDir ( const PokemonCatalogEntry entry,
char *  buf,
size_t  sz 
)

Builds directory path where current species assets will be written.

Parameters
entryPointer to Pokemon catalog entry.
bufOutput path buffer.
szSize of output path buffer.

◆ GuiState_BuildPreviewOptions()

static void GuiState_BuildPreviewOptions ( GuiState state,
AnimaPreviewOptions opts 
)
static

Constructs option query filters matching current UI selected states.

Parameters
stateGUI state context.
optsDestination options.

◆ GuiState_CopyText()

void GuiState_CopyText ( char *  dst,
size_t  dst_size,
const char *  src 
)

Helper utility to safely copy a string with bounding limit constraints.

Parameters
dstDestination buffer.
dst_sizeDestination capacity limit in bytes.
srcSource string.

◆ GuiState_CurrentAsset()

static const AnimaPreviewAssetInfo* GuiState_CurrentAsset ( const GuiState state)
static

Gets the currently selected preview asset info descriptor.

Parameters
stateGUI state.
Returns
Asset info pointer, or NULL if invalid or none loaded.

◆ GuiState_EntryMatchesQuery()

int GuiState_EntryMatchesQuery ( const PokemonCatalogEntry entry,
const char *  query 
)

Checks if a Pokemon species matches the search filtering text query.

Parameters
entryPointer to Pokemon catalog entry.
querySearch query text filter.
Returns
1 on match; 0 otherwise.

◆ GuiState_ExportAllAssets()

void GuiState_ExportAllAssets ( GuiState state,
const PokemonCatalogEntry entry 
)

Recursively renders and writes all assets discovered for species.

Parameters
stateGlobal GUI state.
entryCatalog entry.

◆ GuiState_ExportCurrent()

void GuiState_ExportCurrent ( GuiState state,
const PokemonCatalogEntry entry 
)

Exports the currently active preview asset view to its default output file path.

Parameters
stateGlobal GUI state.
entryCatalog entry.

◆ GuiState_ExportDsFiles()

void GuiState_ExportDsFiles ( GuiState state,
const PokemonCatalogEntry entry 
)

Raw dumps individual compressed Nitro NARC blocks for selected species to disk.

Parameters
stateGlobal GUI state.
entryCatalog entry.

◆ GuiState_ExportLoadedPreviewGif()

static int GuiState_ExportLoadedPreviewGif ( const GuiState state,
const char *  out_path 
)
static

Exports currently loaded preview frame buffer directly to a custom GIF file.

Parameters
stateGUI state context.
out_pathDestination file path.
Returns
0 on success; negative on failure.

◆ GuiState_GetFormCount()

int GuiState_GetFormCount ( const GuiState state,
int  dex_id 
)

Retrieves form count for a species.

Parameters
stateGlobal GUI state pointer.
dex_idNational Dex ID.
Returns
Amount of alternative forms (at least 1).

◆ GuiState_GetFormName()

const char* GuiState_GetFormName ( const GuiState state,
int  dex_id,
int  form_idx 
)

Retrieves user-friendly label name of alternate form index.

Parameters
stateGlobal GUI state pointer.
dex_idNational Dex ID.
form_idxForm index.
Returns
Read-only form name label.

◆ GuiState_GifDelayCs()

int GuiState_GifDelayCs ( const GuiState state)

Retrieves the current custom GIF frame delay.

Parameters
stateGlobal GUI state pointer.
Returns
Delay in centiseconds.

◆ GuiState_Init()

void GuiState_Init ( GuiState state)

Initializes default options inside a GuiState structure.

Parameters
statePointer to state to initialize.

◆ GuiState_LoadAndValidateRom()

int GuiState_LoadAndValidateRom ( GuiState state,
const char *  path 
)

Validates NDS ROM header and initializes internal directory mappings.

Parameters
stateGlobal GUI state pointer.
pathPath to NDS ROM file.
Returns
0 on success; negative value on validation or load error.

◆ GuiState_RefreshAssets()

int GuiState_RefreshAssets ( GuiState state,
const PokemonCatalogEntry entry 
)

Scans ROM files to discover all asset variants for selected species.

Parameters
stateGlobal GUI state pointer.
entryPokemon catalog entry.
Returns
0 on success; negative value on error.

◆ GuiState_RunExport()

void GuiState_RunExport ( GuiState state,
const PokemonCatalogEntry entry,
int  export_spritesheets,
int  export_static,
int  export_gif,
int  export_idle_break,
int  export_composed 
)

Performs batch export run for currently selected Pokemon.

Parameters
stateGlobal GUI state.
entryCatalog entry.
export_spritesheets1 to generate sheets.
export_static1 to generate static first-frame.
export_gif1 to write standard GIF.
export_idle_break1 to write break GIF.
export_composed1 to write merged loop.

◆ GuiState_SanitizeDisplayPath()

static void GuiState_SanitizeDisplayPath ( const char *  name,
char *  out,
size_t  out_size 
)
static

Sanitizes species name for building camel-cased display output path strings.

Parameters
nameSource string.
outOutput buffer.
out_sizeSize of output buffer.

◆ GuiState_SanitizePath()

void GuiState_SanitizePath ( const char *  name,
char *  out,
size_t  out_size 
)

Sanitizes folder name by stripping out illegal character blocks.

Parameters
nameSource directory folder name.
outDestination buffer.
out_sizeSize of destination buffer.

◆ GuiState_SelectedEntry()

const PokemonCatalogEntry* GuiState_SelectedEntry ( int  dex_id)

Retrieves the species catalog entry matching index.

Parameters
dex_idNational Dex ID (1 to 649).
Returns
Catalog entry pointer.

◆ GuiState_SetGifDelayCs()

void GuiState_SetGifDelayCs ( GuiState state,
int  delay_cs 
)

Sets the custom GIF frame delay.

Parameters
stateGlobal GUI state pointer.
delay_csCustom delay in centiseconds.

◆ GuiState_SetPreviewContentBounds()

static void GuiState_SetPreviewContentBounds ( GuiPreview p)
static

Computes a tight bounding box encapsulating all non-transparent pixels in the preview animation frames.

Parameters
pTarget preview.

◆ GuiState_SetStatus()

void GuiState_SetStatus ( GuiState state,
const char *  text 
)

Sets statusbar notification message.

Parameters
stateGlobal GUI state pointer.
textFormat string.

◆ GuiState_TryLoadPreview()

int GuiState_TryLoadPreview ( GuiState state,
const PokemonCatalogEntry entry 
)

Attempts to load the preview for a Pokemon catalog entry.

Parameters
stateGlobal GUI state pointer.
entryPokemon catalog entry.
Returns
0 on success; negative value on failure.

◆ GuiState_UnloadPreview()

void GuiState_UnloadPreview ( GuiPreview p)

Deallocates texture cache and color frames stored inside preview struct.

Parameters
pPointer to preview struct.

◆ GuiState_UpdatePreview()

void GuiState_UpdatePreview ( GuiPreview p)

Advances active viewport frame index based on real-world elapsed frame delta time.

Parameters
pPointer to active preview structure to advance.

◆ LoadAnimatedPreview()

static int LoadAnimatedPreview ( GuiState state,
const PokemonCatalogEntry entry,
int   backend_funcGuiState *, const PokemonCatalogEntry *, AnimaIdlePreview * 
)
static

Helper for wrapping multi-frame animated preview loaders.

Parameters
stateGUI state context.
entryPokemon catalog entry.
backend_funcSpecific backend load routine.
Returns
0 on success; negative on failure.

◆ LoadBreak()

static int LoadBreak ( GuiState state,
const PokemonCatalogEntry entry,
AnimaIdlePreview out 
)
static

Direct callback for loading idle break preview frame loop.

Parameters
stateGUI state.
entryPokemon entry.
outOutput preview structure.
Returns
0 on success; negative on failure.

◆ LoadComposed()

static int LoadComposed ( GuiState state,
const PokemonCatalogEntry entry,
AnimaIdlePreview out 
)
static

Direct callback for loading composed animation frame loop.

Parameters
stateGUI state.
entryPokemon entry.
outOutput preview structure.
Returns
0 on success; negative on failure.

◆ LoadNmarAnimation()

static int LoadNmarAnimation ( GuiState state,
const PokemonCatalogEntry entry,
AnimaIdlePreview out 
)
static

Direct callback for loading NMAR timeline-driven animation.

Parameters
stateGUI state.
entryPokemon entry.
outOutput preview structure.
Returns
0 on success; negative on failure.

◆ LoadNmcrMap()

static int LoadNmcrMap ( GuiState state,
const PokemonCatalogEntry entry,
AnimaIdlePreview out 
)
static

Direct callback for loading NMCR layout map composition.

Parameters
stateGUI state.
entryPokemon entry.
outOutput preview structure.
Returns
0 on success; negative on failure.

◆ LoadPngPreview()

static int LoadPngPreview ( GuiState state,
const PokemonCatalogEntry entry,
int   backend_funcGuiState *, const PokemonCatalogEntry *, AnimaIdlePreview * 
)
static

Helper for wrapping static single-frame PNG preview loaders.

Parameters
stateGUI state context.
entryPokemon catalog entry.
backend_funcSpecific backend load routine.
Returns
0 on success; negative on failure.

◆ LoadPreviewFromBackend()

static int LoadPreviewFromBackend ( GuiState state,
const PokemonCatalogEntry entry 
)
static

Loads the default idle animation preview frames from the backend.

Parameters
stateGUI state context.
entryTarget Pokemon entry.
Returns
0 on success; negative on failure.

◆ LoadSpritesheet()

static int LoadSpritesheet ( GuiState state,
const PokemonCatalogEntry entry,
AnimaIdlePreview out 
)
static

Direct callback for loading spritesheet asset frames.

Parameters
stateGUI state.
entryPokemon entry.
outOutput preview structure.
Returns
0 on success; negative on failure.

◆ LoadStaticIdle()

static int LoadStaticIdle ( GuiState state,
const PokemonCatalogEntry entry,
AnimaIdlePreview out 
)
static

Direct callback for loading static idle preview frame.

Parameters
stateGUI state.
entryPokemon entry.
outOutput preview structure.
Returns
0 on success; negative on failure.

◆ StrContainsInsensitive()

static int StrContainsInsensitive ( const char *  hay,
const char *  needle 
)
static

Checks if a string contains another string case-insensitively.

Parameters
hayString to search in.
needleSubstring to search for.
Returns
1 if found; 0 if not found.