A bit of JS I wrote as a workaround as miniSphere has no function to save a spriteset thought I'd share it in case anyone else needs to edit and save spritesets with JS and wants to work in miniSphere. I haven't made a spriteset creation function as you can just have a template spriteset you open to start with. Note this is kinda slow for large spritesets (particularly the image saving) but I couldn't think of another way to do it.
function save_sprite(sprite, filename)
{
var file = OpenRawFile(filename,true);
//header data - commented where not self explanatory
file.write(CreateByteArrayFromString(".rss"));//file signiture
Write_16Word(3, file);//rss version number - always 3
Write_16Word(sprite.images.length, file);
Write_16Word(sprite.images[0].width, file);
Write_16Word(sprite.images[0].height, file);
Write_16Word(sprite.directions.length, file);
Write_16Word(sprite.base.x1, file);
Write_16Word(sprite.base.y1, file);
Write_16Word(sprite.base.x2, file);
Write_16Word(sprite.base.y2, file);
file.write(CreateByteArray(106));//blank space needed by format
/*this next bit is horrid (it works but it's super slow) the format
requires 4 bytes per colur in rgba order not aware of any other way
to do it with sphere's available functions:( */
var temp_s;
var col;
var temp_c = CreateByteArray(1);
for(var i = 0,x=0,y=0; i < sprite.images.length; ++ i)
{
temp_s = sprite.images[i].createSurface();
for(y=0;y<sprite.images[0].height;++y)
{
for(x=0;x<sprite.images[0].width;++x)
{
col = temp_s.getPixel(x,y);
temp_c[0] = col.red & 0xff;
file.write(temp_c);
temp_c[0] = col.green & 0xff;
file.write(temp_c);
temp_c[0] = col.blue & 0xff;
file.write(temp_c);
temp_c[0] = col.alpha & 0xff;
file.write(temp_c);
}
}
}
//Direction data - this is easier
//the CreateByteArray calls are for padding the format needs
for(i = 0; i<sprite.directions.length; ++ i)
{
Write_16Word(sprite.directions[i].frames.length,file);
file.write(CreateByteArray(6));
Write_16Word(CreateByteArrayFromString(sprite.directions[i].name).length,file);
file.write(CreateByteArrayFromString(sprite.directions[i].name));
for(x=0;x<sprite.directions[i].frames.length;++x)
{
Write_16Word(sprite.directions[i].frames[x].index,file);
Write_16Word(sprite.directions[i].frames[x].delay,file);
file.write(CreateByteArray(4));
}
}
file.close();
}
function Write_16Word(word, file)
{
var array_of_integer = new Array();
array_of_integer[0] = (word & 0xff00) >> 8;
array_of_integer[1] = (word & 0x00ff);
var byte_array_of_integer = CreateByteArray(2);
byte_array_of_integer[0] = array_of_integer[1];
byte_array_of_integer[1] = array_of_integer[0];
file.write(byte_array_of_integer);
}