andymeneely / squib

A Ruby DSL for prototyping card games.
http://squib.rocks
MIT License
918 stars 67 forks source link

svg data: gameicons not working properly for excel? #243

Closed TasmaniaKrama closed 5 years ago

TasmaniaKrama commented 6 years ago

Just as we can pull text data from excel like so text str: deck['Power'], layout: :PowerText why can't we simply use this code which works: svg data: GameIcons.get("ak47"). recolor(fg: '000000', bg: 'FFFFFF'). string, layout: :GovIcon and change it to svg data: GameIcons.get(deck['Power']). recolor(fg: '000000', bg: 'FFFFFF'). string, layout: :GovIcon and pull the ak47 icon from the excel column called Power. Am I missing something here?

andymeneely commented 6 years ago

Sorry I missed this for so long!

This has nothing to do with Excel or GameIcons - it's how Squib handles inputs. (See Squib Thinks in Arrays).

So when Squib sees svg data: 'string', it will apply 'string' to every single card. When you give deck['Power'] - that's an array so it gets mapped to every single card.

Now, if you want to map the Power column to various GameIcon recolorings, or even various GameIcons, you can do that like this:

# I'm assuming you have powers in your Excel sheet called 'melee' and 'ranged'
deck['PowerIcon'] = deck['Power'].map do |power|
  case power
  when 'ranged'
    GameIcons.get("ak47").recolor(fg: '000000', bg: 'FFFFFF').string
  when 'melee'
    GameIcons.get("lorc/fist").recolor(fg: '000000', bg: 'FFFFFF').string
  end 
end

svg data: deck['PowerIcon']

(Note: I haven't tested this code - so it might need some attention if you copy-paste)