Attract-Mode Support Forum

Attract-Mode Support => Scripting => Topic started by: jedione on June 10, 2017, 07:55:11 AM

Title: Re: [Players] to image? [Solved]
Post by: jedione 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....
Title: Re: [Players] to image?
Post by: liquid8d 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.
Title: Re: [Players] to image?
Post by: liquid8d 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:
(http://i.imgur.com/kxAWNXZ.png)
Title: Re: [Players] to image?
Post by: BOXXMAN 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;
Title: Re: [Players] to image?
Post by: liquid8d 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'.
Title: Re: [Players] to image?
Post by: BOXXMAN 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.
Title: Re: [Players] to image?
Post by: jedione on June 10, 2017, 12:47:04 PM
wow....thank's guys.  big big help....

now i continue on with my new theme..
Title: Re: [Players] to image?
Post by: bjose2345 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
Title: Re: [Players] to image? [Solved]
Post by: jedione on June 13, 2017, 06:50:32 PM
thanks everyone,,,solved...
Title: Re: [Players] to image?
Post by: BOXXMAN 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:
(http://i.imgur.com/kxAWNXZ.png)
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.
Title: Re: [Players] to image?
Post by: liquid8d on June 14, 2017, 10:03:36 PM
I discovered a small bug...

Thanks, I'll add in the hyphenated version.
Title: Re: [Players] to image? [Solved]
Post by: BOXXMAN 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.
Title: Re: Re: [Players] to image? [Solved]
Post by: qqplayer 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.
Title: Re: [Players] to image? [Solved]
Post by: BOXXMAN 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.
Title: Re: [Players] to image? [Solved]
Post by: liquid8d 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.
Title: Re: [Players] to image? [Solved]
Post by: liquid8d on June 17, 2017, 03:11:17 PM
I found an issue in the code "magic-images.nut"

As Boxxman said, that isn't a bug, it was intentionally using tags to find region. You could use name to save time from manually tagging, but matching might not be accurate for all types of roms ( U, US, USA, W, WORLD, EUR, EUROPE, etc..) - same for ESRB, you will need to add tags (ESRB-E, ESRB-M, etc) as there is no info on that being scraped
Title: Re: [Players] to image? [Solved]
Post by: Favdeacon on June 18, 2017, 04:02:13 AM
Hi.

Code: [Select]
   local info = fe.game_info( Info.Players, index_offset ).tolower()
   if ( info.len() >= 1 ) return "players-" + info.slice(0, 1) + ".png"

Nice code. It fails on two-digit player numbers, though. A very seldom but nevertheless existing case, e.g. Royal Ascot II with 12 players. Perfectionists like me may that find unsettling. :)

Two friends who know their RegEx helped me write this function:

Code: [Select]
function plnum()
 {
  local ex = regexp(@"(\d+)P(?: (alt|sim))?");
local plinfo = fe.game_info(Info.Players);
  local plex = ex.capture(plinfo);
local plnum = plinfo.slice(plex[1].begin,plex[1].end);
local mpmode = plinfo.slice(plex[2].begin,plex[2].end);
return plnum;
 }

Given fe.game_info(Info.Players) in the format "2P alt" etc. it returns the number of players with one or more digits. As a bonus, the multiplayer mode "alt" or "sim" will be stored in the variable mpmode.

Because I am very new at Squirrel and coding overall, it may be not very optimized. Feel free to tinker with it.
Title: Re: [Players] to image? [Solved]
Post by: qqplayer on June 21, 2017, 10:13:57 AM
@BOXXMAN @liquid8d thanks for the info.