Support for built-in layouts, with examples
parent
cad197553b
commit
569464a575
|
|
@ -112,9 +112,16 @@ module Squib
|
||||||
@layout = {}
|
@layout = {}
|
||||||
Squib::logger.info { " using layout(s): #{files}" }
|
Squib::logger.info { " using layout(s): #{files}" }
|
||||||
Array(files).each do |file|
|
Array(files).each do |file|
|
||||||
yml = @layout.merge(YAML.load_file(file))
|
thefile = file
|
||||||
yml.each do |key, value|
|
thefile = "#{File.dirname(__FILE__)}/layouts/#{file}" unless File.exists?(file)
|
||||||
@layout[key] = recurse_extends(yml, key, {})
|
if File.exists? thefile
|
||||||
|
yml = @layout.merge(YAML.load_file(thefile))
|
||||||
|
yml.each do |key, value|
|
||||||
|
@layout[key] = recurse_extends(yml, key, {})
|
||||||
|
end
|
||||||
|
else
|
||||||
|
puts "the file: #{thefile}"
|
||||||
|
Squib::logger.error { "Layout file not found: #{file}" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
title:
|
||||||
|
x: 275
|
||||||
|
y: 75
|
||||||
|
width: 475
|
||||||
|
height: 125
|
||||||
|
art:
|
||||||
|
x: 275
|
||||||
|
y: 225
|
||||||
|
width: 475
|
||||||
|
height: 475
|
||||||
|
description:
|
||||||
|
x: 275
|
||||||
|
y: 725
|
||||||
|
width: 475
|
||||||
|
height: 200
|
||||||
|
snark:
|
||||||
|
x: 275
|
||||||
|
y: 950
|
||||||
|
width: 475
|
||||||
|
height: 100
|
||||||
|
bonus1:
|
||||||
|
x: 75
|
||||||
|
y: 75
|
||||||
|
width: 175
|
||||||
|
height: 175
|
||||||
|
bonus2:
|
||||||
|
extends: bonus1
|
||||||
|
y: += 198
|
||||||
|
bonus3:
|
||||||
|
extends: bonus2
|
||||||
|
y: += 198
|
||||||
|
bonus4:
|
||||||
|
extends: bonus3
|
||||||
|
y: += 198
|
||||||
|
bonus5:
|
||||||
|
extends: bonus4
|
||||||
|
y: += 198
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
bonus_ul:
|
||||||
|
x: 75
|
||||||
|
y: 75
|
||||||
|
width: 200
|
||||||
|
height: 200
|
||||||
|
bonus_lr:
|
||||||
|
extends: bonus_ul
|
||||||
|
x: 750
|
||||||
|
y: 1050
|
||||||
|
angle: 3.14159
|
||||||
|
art:
|
||||||
|
x: 150
|
||||||
|
y: 275
|
||||||
|
width: 525
|
||||||
|
height: 575
|
||||||
|
valign: middle
|
||||||
|
align: center
|
||||||
|
|
@ -14,9 +14,9 @@ Squib::Deck.new(layout: 'custom-layout.yml') do
|
||||||
text str: 'The Title', layout: :title
|
text str: 'The Title', layout: :title
|
||||||
|
|
||||||
# Layouts also support YAML merge keys toreuse settings
|
# Layouts also support YAML merge keys toreuse settings
|
||||||
svg file: 'spanner.svg', layout: :icon_left
|
svg file: 'spanner.svg', layout: :icon_left
|
||||||
png file: 'shiny-purse.png', layout: :icon_middle
|
png file: 'shiny-purse.png', layout: :icon_middle
|
||||||
svg file: 'spanner.svg', layout: :icon_right
|
svg file: 'spanner.svg', layout: :icon_right
|
||||||
|
|
||||||
# Squib has its own, richer merge key: "extends"
|
# Squib has its own, richer merge key: "extends"
|
||||||
rect fill_color: :black, layout: :bonus
|
rect fill_color: :black, layout: :bonus
|
||||||
|
|
@ -33,9 +33,28 @@ Squib::Deck.new(layout: 'custom-layout.yml') do
|
||||||
save_png prefix: 'layout_'
|
save_png prefix: 'layout_'
|
||||||
end
|
end
|
||||||
|
|
||||||
Squib::Deck.new(layout:['custom-layout.yml', 'custom-layout2.yml']) do
|
Squib::Deck.new(layout: ['custom-layout.yml', 'custom-layout2.yml']) do
|
||||||
text str: 'The Title', layout: :title # from custom-layout.yml
|
text str: 'The Title', layout: :title # from custom-layout.yml
|
||||||
text str: 'The Subtitle', layout: :subtitle # redefined in custom-layout2.yml
|
text str: 'The Subtitle', layout: :subtitle # redefined in custom-layout2.yml
|
||||||
text str: 'The Description', layout: :description # from custom-layout2.yml
|
text str: 'The Description', layout: :description # from custom-layout2.yml
|
||||||
save_png prefix: 'layout2_'
|
save_png prefix: 'layout2_'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Built-in layouts are easy to use and extend
|
||||||
|
Squib::Deck.new(layout: 'playing-card.yml') do
|
||||||
|
text str: "A\u2660", layout: :bonus_ul, font: 'Sans bold 100', hint: :red
|
||||||
|
text str: "A\u2660", layout: :bonus_lr, font: 'Sans bold 100', hint: :red
|
||||||
|
text str: "artwork here", layout: :art, hint: :red
|
||||||
|
save_png prefix: 'layout_builtin_playing_card_'
|
||||||
|
end
|
||||||
|
|
||||||
|
# Built-in layouts are easy to use and extend
|
||||||
|
Squib::Deck.new(layout: 'hand.yml') do
|
||||||
|
%w(title bonus1 bonus2 bonus3 bonus4 bonus5
|
||||||
|
description snark art).each do |icon|
|
||||||
|
text str: icon.capitalize, layout: icon,
|
||||||
|
hint: :red, valign: 'middle', align: 'center'
|
||||||
|
end
|
||||||
|
png file: 'pokercard.png', alpha: 0.5
|
||||||
|
save_png prefix: 'layout_builtin_hand_'
|
||||||
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue