ID:2777087
 
(See the best response by Xooxer.)
Code:
var list/imgs = new

proc/Icon2Browser(icon_file)
var list/states = icon_states(icon_file)
for(var/state in states)
imgs[state] = image(icon_file,null,state)

mob/proc/PreloadIcons2Browser()
world.name = "Loading [imgs.len] Images"
for(var/i in imgs)
src << browse_rsc(imgs[i],i)


Understanding
You'd call Icon2Browser() at worldstart as needed.
You'd call PreloadIcons2Browser() when connecting as to allow for icons in the browser.



Problem description:

Trying to take a .dmi file and grab all the current states from inside it, which works, and then I add them to a global variable "imgs" which stores a image created using the icon and state.

However this doesn't seem to work with browse_rsc() as I run into this issue
--> runtime error: bad resource file

-.-

Is there an easy way to load an entire icon file into the browse cache so that I can use multiple icon_states within it? Driving me crazy.





While it seems to work for the output, I thought that turning each state into its own /image object would allow to preload it via browse_rsc as it says it accepts images, but it's still only grabbing the 1st frame.

\icon[imgs[i.icon_state]]
This is how I'm displaying them in the browser.
After changing it from image() to icon() I no longer get the error "bad resource file".

I now get the error "Unable to open cache file.
Unable to open cache file.
Unable to open cache file.
Unable to open cache file."
Best response
id:149413 I think that has the info you want. Something about using /icon and perhaps f_copyrsc(). I'm not on my computer, so can't fiddle with it right now. Check out that thread, though. Seems Lummox already addressed a similar issue.
In response to Xooxer
Xooxer wrote:
id:149413 I think that has the info you want. Something about using /icon and perhaps f_copyrsc(). I'm not on my computer, so can't fiddle with it right now. Check out that thread, though. Seems Lummox already addressed a similar issue.

You're awesome, solved my issue.
For those curious.

var list/imgCACHE = new

proc/CacheIcon(icon_file)
for(var/state in icon_states(icon_file))
if(!(icon_file in imgCACHE))
imgCACHE[icon_file] = list()
imgCACHE[icon_file][state] = icon(icon_file,state)

mob/proc/PreloadBrowserCache()
var i,j,l = imgCACHE, p
for(i in l)
for(j in l[i]){src << browse_rsc(l[i][j],"[j].png")}


<img src='[i.state].png' width=32 height=32>