Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Sake

Pages: [1]
1
Scripting / Re: is it possible to check video artwork file exist or not
« on: February 22, 2022, 10:58:44 PM »
I'm working on a layout and needed something similar. Here's a modified version that could work for you. Note: I modified this from my original code and didn't test run it, I may have typos but the core logic is the same.
The function GetArtOfType() will return a filename if it matches your criteria or empty string if nothing is found for example:

local fileName = GetArtOfType(0, "");
fileName could equal an asset name found in the "video" subfolder with any extension .mp4, .avi, .mkv etc...

local fileName = GetArtOfType(0, ".mp4");
Performs the same search but only return a filename if it contains ".mp4" in the name.

Code:
// Configure the root art folder such as /emu/artwork you can get the value from UserConfig or hard code if you like
local g_baseArtFolder = my_config["baseArtFolder"];
// List of media folders that can be searched. The index parameter in GetArtOfType refers to this list
local g_mediaFolders = ["video","snap","flyer"];
// Store files in found in folders to avoid performing the directory search each time
local g_assetFileNames = [];

/////////////////////////////////////////////////////////////////////////
// Get the asset file of a given type if it exists
//
// \param mediaIndex - Index into your media folder list to use for lookup
// \param extension - Specific file extension if desired, otherwise first match will be returned
//
/////////////////////////////////////////////////////////////////////////
function GetArtOfType(mediaIndex, extension)
{
   // Note this assumes assets are stored in system folders such as /emu/artwork/atari2600/video
   // where the system name comes from the emulator name you use in AM. If you do not use that
   // structure edit below to match
   local baseName = g_baseArtFolder + "/" + fe.game_info(Info.Emulator) + "/" + g_mediaFolders[mediaIndex];
   local gameName = fe.game_info(Info.Name) + ".";
   
   // Only get the directory listing 1 time
   if (g_assetFileNames[mediaIndex] == null)
   {
      g_assetFileNames[mediaIndex] = DirectoryListing(baseName).results;
   }
   
   // Determine if a file in the target folder matches the active game and optionally the desired extension
   foreach (filename in g_assetFileNames[mediaIndex])
   {
      // Find any file that has the game name in it
      if (filename.find(gameName) != null)
      {
         if (extension.len() > 0)
         {
            if (filename.find(extension) != null)
            {
               return filename;
            }
         }
         else
         {
            return filename;
         }
      }
   }
   
   return "";
}

2
Scripting / Solution: class userconfig , not showing options in menu
« on: September 10, 2021, 12:49:28 AM »
I'm just getting started with layouts and ran into the same issue. Posting solution for anyone else that may run into this.

I have found two cases that cause UserConfig to break:

1) On a windows machine the problem was my "layout.nut" was named "Layout.nut" with a leading capital. The layout works BUT the configuration didn't show up. Renamed to lowercase and configs starting showing up again. Seems whatever populates configs is case sensitive.

2) Other than defining variables, try to place all code AFTER the UserConfig definition. Some code prior to the UserConfig definition will break it. Specifically saw this creating a table entry such as: MyTable.NewValue <- 1000;

Hope this saves someone from pulling their hair out.

Pages: [1]