1
0

more robust and future-proof architecture

This commit is contained in:
Ninjananas
2024-09-03 20:05:42 +02:00
parent 7bdea04111
commit 677906b5a7
18 changed files with 416 additions and 84 deletions

70
src/deck.rb Normal file
View File

@@ -0,0 +1,70 @@
require 'squib'
data = Squib.xlsx file: 'data/cards.xlsx', explode: 'quantite'
def icon_to_svg(icon)
icon.nil? ? nil : "icone_#{icon}.svg"
end
def rank_to_banner_svg(rank)
rank.nil? ? nil : (rank.start_with?('+') || rank.start_with?('-')) ? "banniere_mod.svg" : "banniere_rang.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'
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
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'}
alt_icon_file = data['icone_alt'].map { |icon| icon_to_svg(icon) }
svg file: alt_icon_file, layout: 'alt_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'
build :debug do
save_pdf sprue: 'sprues/A4_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, 7, 15, 25, 38, 17], trim: inches(BLEED), trim_radius: inches(0.125), fill_color: 'black'
showcase range: [0, 7, 15, 25, 38, 17], trim: inches(BLEED), trim_radius: inches(0.125), fill_color: 'black'
end
build :full do
save_png dir: '_output/full/front'
end
end