Author Topic: Genre Display from Magic Token Category  (Read 13458 times)

bionictoothpick

  • Sr. Member
  • ****
  • Posts: 325
  • He who laughs lasts.
    • View Profile
Genre Display from Magic Token Category
« on: April 25, 2016, 03:17:25 AM »
If the magic token for Category is: Shooter / Flying Vertical
I am not able to use a slash for naming the desired image. I started doing a find/replace for "Shooter /Flying Vertical" to Shooter_Flying_Vertical.png to display the images.

The code is simple for displaying using this renaming method, but I would prefer if the code would work with the original Category:
// Genre
local genre = PreserveImage("genre/[Category]",400,1075,368,368);
genre.set_fit_or_fill( "fit");
genre.set_anchor( ::Anchor.Center );

If you've read this far: Can I use something like if CATEGORY CONTAINS Flying Vertical then X=Shooter_Flying_Vertical

ArcadeBliss

  • Sr. Member
  • ****
  • Posts: 195
    • View Profile
Re: Genre Display from Magic Token Category
« Reply #1 on: April 25, 2016, 03:36:15 AM »
This is issue that liquid8's code solves to have pictures change using the catagory information. I changed it a little to be more generic and included my genre changing code below:

class to change an image based upon "fe.game_info()" possibilities
Code: [Select]
//////////////////////////////////////////////////
//
// a class that displays images according to
// data found in the emulator game list e.g: ersb
// graphic based upon name in a game list
//
//////////////////////////////////////////////////
class changingImage
{
mode = 1;       //0 = first match, 1 = last match, 2 = random
supported = null;
folder=null;
infoType=null;
ref = null;

constructor( image, sup, f, i  )
{
supported = sup;
folder= f;
infoType= i;
ref = image;
fe.add_transition_callback( this, "imagetransition" );


}
   
function imagetransition( ttype, var, ttime )
{

if ( ttype == Transition.ToNewSelection || ttype == Transition.ToNewList )
{
local cat = null;
if (infoType==Info.Tags)
{
cat = " " + fe.game_info(infoType, var);
} else {
cat = " " + fe.game_info(infoType, var).tolower();
}
local matches = [];

foreach( key, val in supported )
{
foreach( nickname in val )
{
if ( cat.find(nickname, 0) ) matches.push(key);
}
}
if ( matches.len() > 0 )
{
switch( mode )
{
case 0:
ref.file_name = "images/" + folder + "/" + matches[0] + ".png";
break;
case 1:
ref.file_name = "images/" + folder + "/" + matches[matches.len() - 1] + ".png";
break;
case 2:
local random_num = floor(((rand() % 1000 ) / 1000.0) * ((matches.len() - 1) - (0 - 1)) + 0);
ref.file_name = "images/" + folder + "/" + matches[random_num] + ".png";
break;
}
} else {
ref.file_name = "images/" + folder + "/unknown.png";
}
}
}
}

Initilizing the class with your own info
Code: [Select]
   
// Change Genre based upon game catagory
local genre = {
        //filename : [ match1, match2 ]
        "action": [ "action" ],
        "adventure": [ "adventure" ],
        "fighter": [ "fighting", "fighter", "beat'em up" ],
        "platform": [ "platformer", "platform" ],
        "puzzle": [ "puzzle" ],
        "racing": [ "racing", "driving" ],
        "rpg": [ "rpg", "role playing", "role playing game" ],
        "shooter": [ "shooter", "shmup" ],
        "sports": [ "sports", "boxing", "golf", "baseball", "football", "soccer" ],
"maze": [ "maze" ],
        "strategy": [ "strategy"]
    }
local genre_image = fe.add_image("images/genre/unknown.png");
genre_image.x = detailsNewX;
genre_image.y= DETAILS_BOTTOM_ALIGNMENT;
changingImage( genre_image, genre, "genre", Info.Category );
« Last Edit: April 25, 2016, 03:38:59 AM by ArcadeBliss »

bionictoothpick

  • Sr. Member
  • ****
  • Posts: 325
  • He who laughs lasts.
    • View Profile
Re: Genre Display from Magic Token Category
« Reply #2 on: April 25, 2016, 04:44:51 AM »
I didn't realize liquid's code would show a different image for golf and baseball with that code, I thought it was defaulting to sports if any of the sports were included.

ArcadeBliss

  • Sr. Member
  • ****
  • Posts: 195
    • View Profile
Re: Genre Display from Magic Token Category
« Reply #3 on: April 25, 2016, 05:35:22 AM »
you can set it up any way you like. For example in my example, you would just change the initialization code to the following:

Code: [Select]
// Change Genre based upon game category
local genre = {
        //filename : [ match1, match2 ]
        "action": [ "action" ],
        "adventure": [ "adventure" ],
        "fighter": [ "fighting", "fighter", "beat'em up" ],
        "platform": [ "platformer", "platform" ],
        "puzzle": [ "puzzle" ],
        "racing": [ "racing", "driving" ],
        "rpg": [ "rpg", "role playing", "role playing game" ],
        "shooter": [ "shooter", "shmup" ],
        "sports": [ "sports", "boxing", "football", "soccer" ],
"maze": [ "maze" ],
         "golf": ["golf"],
         "baseball": ["baseball"],
        "strategy": [ "strategy"]
    }
local genre_image = fe.add_image("images/genre/unknown.png");
genre_image.x = detailsNewX;
genre_image.y= DETAILS_BOTTOM_ALIGNMENT;
changingImage( genre_image, genre, "genre", Info.Category );

In the initilization code, I added "golf" as an array with the value "golf", and I removed "golf" from the array "sports". When a category is found having "golf", it will look for an image that is the same as the name of the array. In this case "golf.png".

Hope that helps

bionictoothpick

  • Sr. Member
  • ****
  • Posts: 325
  • He who laughs lasts.
    • View Profile
Re: Genre Display from Magic Token Category
« Reply #4 on: April 25, 2016, 05:42:08 AM »
Yes it does!