Batch Script to create .TAML files
by giovanni erazo · in Torque 2D Beginner · 09/24/2014 (10:12 pm) · 6 replies
I'm new learning game development using the MIT version of Torque 2D.
My game uses hundred's of .png files that need TAML files added (Hidden Objects). I thought that writing a script would be the best approach to solving this problem. I need some help/guidance as to how to go about writing a batch script that would help me accomplish this task.
Anyone have a script sample out there?
Example of the logic for the script assuming that there were only two files and three directories:
If I ran the script in a folder containing sub-folders and images let's call it the "assets" folder.
The batch file would run and first check the "assets" folder where the script resides.
If it found no images it would check all subfolders "images" and "backgrounds".
It would find the first file in a /images subfolder check.png...
assets/images/check.png
the batch file would than crate an .taml text file named: check.asset.taml
The XML file's content would look something like this:
<ImageAsset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../Torque2D.xsd"
AssetName="check"
ImageFile="check.png"/>
the batch script would continue and find the next file: (notice it found a new sub directory)
assets/images/backgrounds/background.png
and output a new .taml in the proper directory: background.asset.taml
The XML file Content:
<ImageAsset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../Torque2D.xsd"
AssetName="background"
ImageFile="background.png"/>
I would appreciate any help and direction on how to go about writing this script.
Thanks,
-Joe
My game uses hundred's of .png files that need TAML files added (Hidden Objects). I thought that writing a script would be the best approach to solving this problem. I need some help/guidance as to how to go about writing a batch script that would help me accomplish this task.
Anyone have a script sample out there?
Example of the logic for the script assuming that there were only two files and three directories:
If I ran the script in a folder containing sub-folders and images let's call it the "assets" folder.
The batch file would run and first check the "assets" folder where the script resides.
If it found no images it would check all subfolders "images" and "backgrounds".
It would find the first file in a /images subfolder check.png...
assets/images/check.png
the batch file would than crate an .taml text file named: check.asset.taml
The XML file's content would look something like this:
<ImageAsset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../Torque2D.xsd"
AssetName="check"
ImageFile="check.png"/>
the batch script would continue and find the next file: (notice it found a new sub directory)
assets/images/backgrounds/background.png
and output a new .taml in the proper directory: background.asset.taml
The XML file Content:
<ImageAsset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../Torque2D.xsd"
AssetName="background"
ImageFile="background.png"/>
I would appreciate any help and direction on how to go about writing this script.
Thanks,
-Joe
#2
I wrote a program that embedded Lua and added a few image format utilities so that you could use it to control Image Magic specifically for taking multiple individual images and making them into sprite sheets. There is nothing that would stop that same utility from adding a TAML image asset in the process. Maybe I should put that up on my GitHub account....
09/25/2014 (8:34 am)
This will need some slight dusting off, but here:/// <summary>
/// Call this function to scan a folder for images or sound files and create
/// asset files for them.
/// </summary>
/// <param name="path">The path to scan - "AssetModule/data/images/".</param>
/// <param name="type">The asset type - "image" or "sound".</param>
/// <param name="category">The asset category. If none, leave this blank.</param>
/// <param name="internal">Flag the asset as an internal asset.</param>
function makeAssetFiles(%path, %type, %category, %internal)
{
switch$(%type)
{
case "image":
%imageFile = findFirstFile(expandPath(%path @ "*.png"));
while (%imageFile !$= "")
{
createAsset(%imageFile, %path, %type, %category, %internal);
%imagefile = findNextFile(expandPath(%path @ "*.png"));
}
case "sound":
%audioFile = findFirstFile(expandPath(%path @ "*.ogg"));
while (%audioFile !$= "")
{
createAsset(%audioFile, %path, %type, %category, %internal);
%audioFile = findNextFile(expandPath(%path @ "*.ogg"));
}
%audioFile = findFirstFile(expandPath(%path @ "*.wav"));
while (%audioFile !$= "")
{
createAsset(%audioFile, %path, %type, %category, %internal);
%audioFile = findNextFile(expandPath(%path @ "*.wav"));
}
}
}
/// <summary>
/// This function creates an individual asset file for a particular image or sound.
/// </summary>
/// <param name="file">The file to create the asset for.</param>
/// <param name="path">The path to the file - "AssetModule/data/images/"</param>
/// <param name="type">The asset type - "image" or "sound"</param>
/// <param name="category">The asset category. If none, leave this blank</param>
function createAsset(%file, %path, %type, %category, %internal)
{
switch$(%type)
{
case "image":
%asset = new ImageAsset();
%asset.AssetName = fileBase(%file);
%asset.AssetInternal = %internal;
%asset.AssetAutoUnload = "0";
%asset.ImageFile = %file;
%asset.AssetCategory = %category;
case "sound":
%asset = new AudioAsset();
%asset.AssetName = fileBase(%file);
%asset.AssetInternal = %internal;
%asset.AssetAutoUnload = "0";
%asset.AudioFile = %file;
%asset.AssetCategory = %category;
}
%assetFileName = expandPath(%path @ fileBase(%file) @ ".asset.taml");
TamlWrite(%asset, %assetFileName);
}Then you call it like so:// comment these out after asset file generation
makeAssetFiles("^AssetModule/assets/images/", "image");
makeAssetFiles("^AssetModule/assets/audio/", "sound");This doesn't "cell up" sprite sheets - only generates single-frame image assets. You can go back and edit the TAML by hand if needed, but this should still save you a lot of time. Also, note that you have to restart your project after you generate your asset files (or reload the asset module, I guess).I wrote a program that embedded Lua and added a few image format utilities so that you could use it to control Image Magic specifically for taking multiple individual images and making them into sprite sheets. There is nothing that would stop that same utility from adding a TAML image asset in the process. Maybe I should put that up on my GitHub account....
#3
So, if you install Image Magick (http://www.imagemagick.org) you can script the above tool to:
a) Find individual images and use Image Magick's montage tool to combine them into a single sprite sheet.
b) In that same script, create and emit the TAML file for the new sprite sheet with all of the requisite cell data.
I'll probably write a script for this myself shortly. This does require a slightly different workflow than I personally prefer for sprite sheets - render each frame separately, then stitch them together.
09/25/2014 (1:28 pm)
Ok, I added that tool that I mentioned at the end of my last post: https://github.com/RichardRanft/imgmgrSo, if you install Image Magick (http://www.imagemagick.org) you can script the above tool to:
a) Find individual images and use Image Magick's montage tool to combine them into a single sprite sheet.
b) In that same script, create and emit the TAML file for the new sprite sheet with all of the requisite cell data.
I'll probably write a script for this myself shortly. This does require a slightly different workflow than I personally prefer for sprite sheets - render each frame separately, then stitch them together.
#4
09/27/2014 (12:59 pm)
And today I added a starter script for making complete sprite sheets from individual frame images using ImageMagick. It also generates a TAML asset file for the sprite sheet image and a quick pass at an animation asset file.
#5
09/27/2014 (1:52 pm)
I noticed in the source there's a PNGImage class - looks like some of the basic plumbing was put in for a Torque internal sprite sheet maker / texture packer. Always interesting finding stuff like this.
#6
Basically, I intended to use this for making sprite sheets. I put in png, jpg and bmp classes to use for gathering relevant statistics like image dimensions, etc. Other than that, the program just wraps Lua.
I was considering integrating ImageMagick itself, but then I decided to keep it simple....
09/27/2014 (1:56 pm)
In fact, it's from Torque's resource loader. It just reads the image file and gathers information, then abandons the actual image data. Most of the general "this is how to use libpng to load an image" information out there is lame - this we already know works.Basically, I intended to use this for making sprite sheets. I put in png, jpg and bmp classes to use for gathering relevant statistics like image dimensions, etc. Other than that, the program just wraps Lua.
I was considering integrating ImageMagick itself, but then I decided to keep it simple....
Employee Michael Perry
ZombieShortbus
If all the images are single cell, this would be a very simple script to write. Do you need any ImageAssets that contain multiple cells for animation?