1
0
Files
robolitik/src/deck.rb
2024-10-13 20:27:50 +02:00

139 lines
3.9 KiB
Ruby

require 'squib'
data = Squib.xlsx file: 'data/cards.xlsx', explode: 'quantite'
def icon_to_svg(icon)
icon.nil? ? nil : "icone_#{icon}.svg"
end
def ret_icon_to_svg(icon)
icon.nil? ? nil : "retourner_#{icon}.svg"
end
def banner_text_layout(rank)
if rank.nil?
nil
elsif rank.start_with?('+')
"banniere_bonus.svg"
elsif rank.start_with?('-')
"banniere_malus.svg"
else
"banniere_rang.svg"
end
end
def rank_to_banner_svg(rank)
if rank.nil?
nil
elsif rank.start_with?('+')
"banniere_bonus.svg"
elsif rank.start_with?('-')
"banniere_malus.svg"
else
"banniere_rang.svg"
end
end
def get_art(data, idx)
art = data['art'][idx]
unless art.nil?
return "#{art}.svg"
end
icon = data['icone'][idx]
icon_alt = data['icone_alt'][idx]
icon_alt = icon_alt.nil? ? '' : "_#{icon_alt}"
puts "default_art_#{icon}#{icon_alt}.svg"
return "default_art_#{icon}#{icon_alt}.svg"
end
def embed_custom(embed, id)
embed.svg width: '0.8c', height: '0.8c', dx: '0c', dy: '-0.7c', key: ":#{id}:", file: "._graphics/#{id}.svg"
end
DPI = 300
CELL_PX = DPI / 8.0
BLEED = 0.125 # In inches
WIDTH = (2.5 + 2*BLEED) * DPI
HEIGHT = (3.5 + 2*BLEED) * DPI
Squib.configure cell_px: CELL_PX
Squib::Deck.new(
cards: data['nom'].size,
layout: '._layouts/poker.yml',
width: WIDTH,
height: HEIGHT,
dpi: DPI,
) do
background color: 'white'
svg file: 'bg_numbers.svg', layout: 'background'
build :debug do
rect layout: 'border', stroke_color: 'black'
rect layout: 'cut', dash: '0.5mm 0.5mm', stroke_color: 'red'
rect layout: 'safe', dash: '0.5mm 0.5mm', stroke_color: 'green'
end
art_file = (0..data['icone'].length).map { |idx| get_art(data, idx) }
svg file: art_file, layout: 'art'
icon_file = data['icone'].map { |icon| icon_to_svg(icon) }
svg file: icon_file, layout: 'icon'
banner_file = data['rang'].map { |rank| rank_to_banner_svg(rank) }
svg file: banner_file, layout: 'banner'
text str: data['rang'], layout: 'banner_text'
text str: data['nom'], layout: banner_file.map { |banner| banner.nil? ? 'name' : 'name_with_banner'}
paparazzo_file = data['type'].map { |type| type=='action' ? 'paparazzo.svg' : nil }
svg file: paparazzo_file, layout: 'paparazzo'
alt_icon_file = data['icone_alt'].map { |icon| icon_to_svg(icon) }
svg file: alt_icon_file, layout: 'alt_icon'
ret_icon_file = data['icone_alt'].map { |icon| ret_icon_to_svg(icon) }
svg file: ret_icon_file, layout: 'ret_icon'
alt_ret_icon_file = data['icone'].zip(data['icone_alt']).map { |icon, alt_icon| alt_icon.nil? ? nil : ret_icon_to_svg(icon) }
svg file: alt_ret_icon_file, layout: 'alt_ret_icon'
alt_banner_file = data['rang_alt'].map { |rank| rank_to_banner_svg(rank) }
svg file: alt_banner_file, layout: 'alt_banner'
text str: data['rang_alt'], layout: 'alt_banner_text'
fill_color = data['effet'].map { |effet| effet.nil? ? '#0000': '#f7f7f7ff' }
stroke_color = data['effet'].map { |effet| effet.nil? ? '#0000': '#cca9' }
rect layout: 'effect_frame', fill_color: fill_color, stroke_color: stroke_color
text(str: data['effet'], layout: 'effect_text') do |embed|
embed_custom(embed, 'effet')
embed_custom(embed, 'magouille')
embed_custom(embed, 'pv')
embed_custom(embed, 'symbole_ind')
embed_custom(embed, 'symbole_gau')
embed_custom(embed, 'symbole_roy')
embed_custom(embed, 'symbole_ana')
embed_custom(embed, 'symbole_dro')
embed_custom(embed, 'symbole_eco')
end
build :debug do
save_pdf sprue: 'sprues/debug.yml', file: 'debug.pdf'
end
build :pnp do
rect layout: 'cut'
save_pdf sprue: 'sprues/A4_poker.yml', trim: inches(BLEED), file: 'pnp_A4.pdf'
end
build :showcase do
hand range: [0, 6, 13, 21, 38, 59, 65], trim_radius: inches(0.125), fill_color: 'black'
showcase range: [0, 6, 13, 21, 38, 59, 65], trim: inches(BLEED), trim_radius: inches(0.125), fill_color: 'black'
end
build :full do
save_png dir: '_output/full/front'
end
end