Author Topic: Re: [Players] to image? [Solved]  (Read 561 times)

jedione

  • Sr. Member
  • ****
  • Posts: 311
  • punktoe
    • View Profile
Re: [Players] to image? [Solved]
« on: June 10, 2017, 07:55:11 AM »
does any one know how to make a different image pop up for
one, two, players using magic token.

local players = fe.add_text("[Players]", -8, 210, 200, 200 );

thanks....
« Last Edit: June 13, 2017, 06:50:48 PM by jedione »
help a friend....

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 404
    • View Profile
Re: [Players] to image?
« Reply #1 on: June 10, 2017, 09:01:04 AM »
It's as easy as:

Code: [Select]
local image = fe.add_image("[!players]", 50, 50, 100, 100)
function players( index_offset ) {
   local info = fe.game_info( Info.Players, index_offset ).tolower()
   if ( info.len() >= 1 ) return "players-" + info.slice(0, 1) + ".png"
   return "players-unknown.png"
}

this looks at just the first character from Info.Players, so it will return something like "players-1.png" or "players-2.png". If your player info doesn't start with that ( i.e. 1p, 2p, 4p ) or you want the full thing ( 2p sim ), you can just not slice info in the function.

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 404
    • View Profile
Re: [Players] to image?
« Reply #2 on: June 10, 2017, 09:38:18 AM »
While I was at it, you inspired me to rewrite my icon class as a magic-images.nut and include players! :)

This will cover system, genre, region, players and esrb icons.

System icons are found based on the display name
Genre icons need the categories filled in, usually by included catver.ini
Region icons require you to tag your games with 'ASIA, BRAZIL, EUROPE, JAPAN, SPAIN, USA, or WORLD'
Players icons need players info filled in and are found based on the first character of [Players] - i.e. 1, 2, 3 or 4
ESRB icons require you to tag your games with 'ESRB-C, ESRB-E, ESRB-T, ESRB-M, ESRB-A, or ESRB-RP'

Here is the code:
https://github.com/liquid8d/attract-extra/tree/master/layouts/sample_magic_images

I've attached a zip as well.

Here's the result:

« Last Edit: June 10, 2017, 11:48:03 AM by liquid8d »

BOXXMAN

  • Full Member
  • ***
  • Posts: 38
    • View Profile
Re: [Players] to image?
« Reply #3 on: June 10, 2017, 10:03:53 AM »
I had already done this in a much simpler way. Drop a folder called "Icons" into layout folder with the images you want to use and make sure they are named "1","2","3","4", ect., then set size and coordinates to your liking (x,y,w,h).


Code: [Select]
local playericon = fe.add_image("Icons/[Players]" , flx*,fly*flw*,flh*);
playericon.trigger = Transition.EndNavigation;

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 404
    • View Profile
Re: [Players] to image?
« Reply #4 on: June 10, 2017, 11:33:49 AM »
I had already done this in a much simpler way. Drop a folder called "Icons" into layout folder with the images you want to use and make sure they are named "1","2","3","4", ect., then set size and coordinates to your liking (x,y,w,h).


Code: [Select]
local playericon = fe.add_image("Icons/[Players]" , flx*,fly*flw*,flh*);
playericon.trigger = Transition.EndNavigation;

Oh, that's great, I forgot you can include the tokens in there directly! But if you use a function you have more control over the image names. In your case, you have to have exact matches for all possible player text, like '2', '2P', '2 Players', '2P SIM'. Using a function, you have control over the filename outcome. By default, it just looks at the first character - i.e. 1, 2, 3 or 4. But you  could also do something like have different images for 'SIM' or 'ALT'.

BOXXMAN

  • Full Member
  • ***
  • Posts: 38
    • View Profile
Re: [Players] to image?
« Reply #5 on: June 10, 2017, 11:48:55 AM »
I agree, and I use your code for the genre icons because there are far more possibilities of things you have to match. However, when you just need 1,2,3,4, as possible matches, it was a no brainer to just use two lines to basically accomplish the same thing.

jedione

  • Sr. Member
  • ****
  • Posts: 311
  • punktoe
    • View Profile
Re: [Players] to image?
« Reply #6 on: June 10, 2017, 12:47:04 PM »
wow....thank's guys.  big big help....

now i continue on with my new theme..
help a friend....

bjose2345

  • Sr. Member
  • ****
  • Posts: 107
    • View Profile
Re: [Players] to image?
« Reply #7 on: June 10, 2017, 04:02:12 PM »
Wow, this help me a lot, I Had a similar problem but didn't remember there was the magic token [Players], anyway thanks guys

jedione

  • Sr. Member
  • ****
  • Posts: 311
  • punktoe
    • View Profile
Re: [Players] to image? [Solved]
« Reply #8 on: June 13, 2017, 06:50:32 PM »
thanks everyone,,,solved...
help a friend....

BOXXMAN

  • Full Member
  • ***
  • Posts: 38
    • View Profile
Re: [Players] to image?
« Reply #9 on: June 14, 2017, 01:06:32 PM »
While I was at it, you inspired me to rewrite my icon class as a magic-images.nut and include players! :)

This will cover system, genre, region, players and esrb icons.

System icons are found based on the display name
Genre icons need the categories filled in, usually by included catver.ini
Region icons require you to tag your games with 'ASIA, BRAZIL, EUROPE, JAPAN, SPAIN, USA, or WORLD'
Players icons need players info filled in and are found based on the first character of [Players] - i.e. 1, 2, 3 or 4
ESRB icons require you to tag your games with 'ESRB-C, ESRB-E, ESRB-T, ESRB-M, ESRB-A, or ESRB-RP'

Here is the code:
https://github.com/liquid8d/attract-extra/tree/master/layouts/sample_magic_images

I've attached a zip as well.

Here's the result:

I discovered a small bug in the genre matching after finding all rpg are not showing rpg  icon and rather showing up as action. The way it is scraping the genre  from Gamesdb is "role-playing" with a hyphen,instead of "role playing", as you have it in the script. So,  if you just add the hyphenated version to the descriptors, it covers all bases and brings up the right icon.

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 404
    • View Profile
Re: [Players] to image?
« Reply #10 on: June 14, 2017, 10:03:36 PM »
I discovered a small bug...

Thanks, I'll add in the hyphenated version.

BOXXMAN

  • Full Member
  • ***
  • Posts: 38
    • View Profile
Re: [Players] to image? [Solved]
« Reply #11 on: June 15, 2017, 01:49:23 PM »
Do you know of a way to modify the genre function to include multiple matches? I was working on some icons for Action/Adventure, ect., but can't figure out how to use the function to output all matches rather than just first, last, or random. Is this even possible to do with the function, or could it be done some other way? I was going to do it the hard way by making every combination of genres I could come up with, and just create the icons named in the same fashion, then just using the magic tokens to call them. However, the "/" output between the genres screws that up because "/" can't be used in file naming in windows, so I'm back to trying it with the function. Is this possible? Thanks for any help.

qqplayer

  • Sr. Member
  • ****
  • Posts: 126
    • View Profile
Re: Re: [Players] to image? [Solved]
« Reply #12 on: June 16, 2017, 02:16:36 AM »
I love this , but how did you "scrape" esrb and region info?

I mean , my names include (USA), (Europe) ... but region flag isn´t showing.
And Esrb , I really don´t know where to include this tag.

UPDATE:

I found an issue in the code "magic-images.nut"

Code: [Select]
local tags = fe.game_info(Info.Tags, offset).tolower()
Changed to

Code: [Select]
local tags = fe.game_info(Info.Name, offset).tolower()
Code: [Select]
//return file_name for region
function region( offset ) {
   local supported = [ "usa", "japan", "brazil", "asia", "spain", "europe", "world", "unknown" ]
   local tags = fe.game_info(Info.Name, offset).tolower()
   local index = supported.find("unknown")
   foreach( item in supported )
      if ( tags.find(item) != null ) index = supported.find(item)
   return magic_image_settings.region.path + supported[index] + magic_image_settings.region.ext
}


So last thing I need is how to add Esrb ratings , where can I find this info to scrappe , thanks.
« Last Edit: June 16, 2017, 03:08:05 AM by qqplayer »

BOXXMAN

  • Full Member
  • ***
  • Posts: 38
    • View Profile
Re: [Players] to image? [Solved]
« Reply #13 on: June 16, 2017, 08:33:26 AM »
I love this , but how did you "scrape" esrb and region info?

I mean , my names include (USA), (Europe) ... but region flag isn´t showing.
And Esrb , I really don´t know where to include this tag.

UPDATE:

I found an issue in the code "magic-images.nut"

Code: [Select]
local tags = fe.game_info(Info.Tags, offset).tolower()
Changed to

Code: [Select]
local tags = fe.game_info(Info.Name, offset).tolower()
Code: [Select]
//return file_name for region
function region( offset ) {
   local supported = [ "usa", "japan", "brazil", "asia", "spain", "europe", "world", "unknown" ]
   local tags = fe.game_info(Info.Name, offset).tolower()
   local index = supported.find("unknown")
   foreach( item in supported )
      if ( tags.find(item) != null ) index = supported.find(item)
   return magic_image_settings.region.path + supported[index] + magic_image_settings.region.ext
}


So last thing I need is how to add Esrb ratings , where can I find this info to scrappe , thanks.

It is not an issue, it is done like that because it gets the region and esrb from tags not game info. You have to manually add your tags for that info, because there is no scraper for that. This script does not scrape, AM itself contains the scraper, which until it is updated to include ratings and region, will not scrape that info at the moment.

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 404
    • View Profile
Re: [Players] to image? [Solved]
« Reply #14 on: June 17, 2017, 03:06:15 PM »
Do you know of a way to modify the genre function to include multiple matches? I was working on some icons for Action/Adventure, ect., but can't figure out how to use the function to output all matches rather than just first, last, or random. Is this even possible to do with the function, or could it be done some other way? I was going to do it the hard way by making every combination of genres I could come up with, and just create the icons named in the same fashion, then just using the magic tokens to call them. However, the "/" output between the genres screws that up because "/" can't be used in file naming in windows, so I'm back to trying it with the function. Is this possible? Thanks for any help.

That's why I included a random option on multiple matches. It'd be a bit more involved to show multiple dynamically, the biggest issue being where you put it on the layout since you won't know how many will show. Otherwise like you said, coming up combos is another option - you could do a replace on the forward slashes to deal with that.