Game Development Community

TAML & Multiple Assets

by James Urquhart · in Torque 2D Beginner · 02/10/2013 (10:40 am) · 2 replies

While prototyping a T2D-MIT game I was disappointed to find out it's only possible to specify 1 asset per "asset.taml" file.

Looking at the code it makes sense since the assumption is the assets are created on-demand based on the contents of the taml, but from a user perspective its a little frustrating since if for example you have a game character with multiple animations you've got to create a file for each animation even though the animation may use the same base image and otherwise be 90% identical. If you need to change anything, you've got to play the "lets find the right file" game.

Are there any plans to allow common assets to be grouped into a single taml?

Of course if there was an editor this problem would likely be irrelevant, but still it feels like a bit of an oversight.

#1
02/10/2013 (12:55 pm)
No, I don't think so. However, I did write a script that will create the asset files for you to save myself having to hand-write the ones for Three Step....

/// <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 - "^{EditorAssets}/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 @ "*.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 - "^{EditorAssets}/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":
            %datablock = new ImageAsset();
            %datablock.AssetName = fileBase(%file);
            %datablock.AssetInternal = %internal;
            %datablock.AutoUnload = "0";
            %datablock.ImageFile = %file;
            %datablock.AssetCategory = %category;
            
        case "sound":
            %datablock = new AudioAsset();
            %datablock.AssetName = fileBase(%file);
            %datablock.AssetInternal = %internal;
            %datablock.AutoUnload = "0";
            %datablock.AudioFile = %file;
            %datablock.AssetCategory = %category;
            
    }
    %assetFileName = expandPath(%path @ fileBase(%file) @ ".asset.taml");

    TamlWrite(%datablock, %assetFileName);
}

Just fire it off somewhere (comments should explain it) and then comment it out or remove it. Sadly, you're still stuck editing multi-celled images and animations by hand once the generic asset file is generated.

Quite a bit of thought went into the decision to map one asset to one asset file. I think that the general consensus was that it would ease updates and project publishing at the time the decision was made.
#2
02/10/2013 (8:36 pm)
The system was set up with editors in mind. The approach of a single asset definition in a file worked well in 3SS, and also allowed us to think ahead about culling out unused assets when packaging game, porting modules, and so on. After using it for quite some time, I actually far prefer this way of managing assets compared to the old Torque 2D way. It's much easier for me to locate assets, manage them via the AssetDatabase, and hand off assets to others.