ID:1860450
 
Ok so I'm trying to make some code that will be run from inside the project folder that will convert all 32x32 icons in the project to 64x64, but I get this 1 error that stops it from working. Here is the code and the error. Why is it going wrong?

It starts at the top directory and loops through all subdirectories finding icon files then attempting to convert them to 64x64. It loops through subdirectories fine but fails when trying to instantiate an icon from the file.
Code:
mob/verb/start_conversion()
convert_icons("./")

var/icons_converted=0

mob/proc/convert_icons(d="./")
for(var/f in flist(d))
if(copytext(f,length(f),length(f)+1)=="/")
var/next_path=f
if(d!="./") next_path=d+f
convert_icons(next_path)
else if(findtext(f,".dmi"))

while(findtext(f,"/"))
var/pos=findtext(f,"/")
f=copytext(f,pos,pos+1)

var/icon/dmi=new(file(f)) //THIS LINE CAUSES THE ERROR
if(Get_Width(dmi)==32 && Get_Height(dmi)==32)
dmi=Scaled_Icon(dmi,64,64)
icons_converted++
src<<"icons converted = [icons_converted]"
sleep(world.tick_lag)

proc/Scaled_Icon(O,X,Y)
var/icon/I=new(O)
I.Scale(X,Y)
return I

proc/Get_Width(O)
var/icon/I=new(O)
return I.Width()

proc/Get_Height(O)
var/icon/I=new(O)
return I.Height()


Problem description:
runtime error: bad icon operation
proc name: New (/icon/New)
usr: Guest-1768931727 (/mob)
src: /icon (/icon)
call stack:
/icon (/icon): New(Black Hole for space.dmi, null, null, null, null)
Guest-1768931727 (/mob): convert icons("Icons/")
Guest-1768931727 (/mob): convert icons("./")
Guest-1768931727 (/mob): start conversion()
Mind outputting f? I'm pretty sure it needs to be the complete path from the project directory. For example, this code should work on icons in the same folder as the .dmb.
Wow you're right thanks, I changed it to new(file(d+f)) instead of new(file(f)) and it now works.

But now I'm having a new problem, I made the oversight of not saving the converted icon back to disk, overwriting the original.

How do I do that?
Oh a simple fcopy nevermind. And all done, 1043 icons converted. Thanks