ID:121083
 
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
This has been semi-suggested several times before (see "Access resource files dynamically" here and the second paragraph of Lummox JR's second comment here), but there doesn't appear to be a formal request.

It would be helpful if files in the cache could be accessed at runtime by filename. This would allow for storing file names in savefiles, instead of saving the entire file or hard-coding an associative-list of file cache references ("turfs.dmi"='turfs.dmi', "dragon.dmi"='dragon.dmi', ect).

For my purposes, I'm working on a map saver/loader, and would like to be able save any non-initial icon values without saving the entire icon or forcing the user to put together and maintain the aforementioned cache reference list. It would also allow for developers to write a clean process to save overlay data without flattening and saving the icon.

It has been suggested that file() be given a second parameter to specify if it's from the cache, but I think file_rsc(filename) would also be appropriate (and in-line with fcopy/fcopy_rsc).

Simple example use-case:
mob
icon='mob.dmi'
verb
SaveIcon()
var/savefile/S = new/savefile("test.sav")
S<<"[icon]"
LoadIcon()
var/savefile/S = new/savefile("test.sav")
var/filename
var/icon/I
S>>filename
I = file_rsc(filename)
if(I)
src.icon = I
else
src<<"File '[filename]' no longer in cache!"


In the above example, I assume file_rsc() would return null if the file could not be found in the cache. I think this makes more sense then throwing an error, because files disappearing from the cache may be a common occurrence (ie for old savefiles), and there's no real way for a developer to avoid the error.
I'd absolutely love to see this feature since it could be great for games that use a lot of user-uploaded content.
+1 this should of been available a long long time ago IMO ...