# lib_iter function library

Dependencies: lib_2da, lib_anon, lib_array, lib_fn, lib_ini, lib_math, lib_sfo, lib_struct, lib_sugar, lib_tools, lib_ui

## Description

Contains the iter_resource function, used to recursively iterate through game resources by following references to other resources in a resource, and some other functions primarily used as helper functions for iter_resource.

## Public functions

iter_2da()=(array:a) patch

Return an array of the game resources contained in the current 2da file, assumed to be of type old-monster-summoning (prototype MONSUM01), new-monster-summoning (prototype MSUMMO1), or spell-selection (prototype SPCL621)

iter_ini()=(array:a) patch

Assuming the current file is an IWD-style area ini, return an array of the game resources it uses

iter_resource(start:s, ignore:s, spell_use_function:s, icon_function:s)=(array:a) action

Take as input the filename of a file. Return an array of filenames of resources used by that file, constructed recursively. Ignore any filenames for which the action function 'ignore', if set, returns true.

We don't currently recurse through or collect the following:

- Wish spell resources
- Familiars
- Tilesets
- The worldmap
- Creature animations

If 'spell_use_function' is set, apply it as a patch function to every spell resource referred to in an opcode. (We don't actually iterate through all of these since they're not actually a resource used by the spell.) The function should take as inputs 'source' (the resref of the resource being patched), 'source_ext' (the ext of the resource being patched), 'resref' (the resref of the resource being removed/protected from, 'ext' (the ext of that resource - in this setup, basically always spl, though we do log item uses from 318 etc).

iter_script()=(array:a) patch

Return an array of all in-game resources referenced in the currently-being-patched, assumed-decompiled, script.

iter_struct(arguments:s)=(array:a) action

Take as input the filename of a struct file. Return a k=>_ array of the filenames of all game resources referenced by it. (We don't check if the resources exist.)

iter_vef()=(array:a) patch

Return an array of the game resources contained in the current VEF file.

## Internal functions

These should not be called from outside the library itself.

iter_main(arguments:s, parameter:s)=(array:a) action

Take as input the filename of a file. Return a lowercased k=>_ array of the filenames of all game resources referenced by it, assuming they exist. Exclude any file that returns true when fed into the function 'parameter', if the latter is set

iter_main_helper(file:s, parameter:s)=(value:s) action

Check a file to see if it should be added to the list of resources generated by iter_main, or if it doesn't exist or is excluded by the ignore-func.

iter_opcode(opcode_offset:i, parameter2_offset:i, resref_offset:i, strtype:s)=(filename_array:a) patch

Read the opcode at opcode_offset and the parameter at parameter2_offset and, if appropriate, return the filename of the resource at resref_offset. Also log any icon uses Does not iterate through wish, familiars, or the core group of monsters summoned by opcode 127.

iter_struct_helper(struct:s, strtype:s)=(array:a) patch

Internal part of the iter_struct function