Skip to content

Commit

Permalink
Initial sketch of Ruby-based preset idea
Browse files Browse the repository at this point in the history
  • Loading branch information
andymeneely committed Mar 11, 2017
1 parent a55300f commit 4b806bb
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
27 changes: 25 additions & 2 deletions lib/squib/deck.rb
Expand Up @@ -8,9 +8,9 @@
require_relative 'graphics/hand'
require_relative 'graphics/showcase'
require_relative 'layout_parser'
require_relative 'presets/tgc_poker'
require_relative 'progress'


# The project module
#
# @api public
Expand Down Expand Up @@ -58,7 +58,9 @@ class Deck
# @param layout [String, Array] load a YML file of custom layouts. Multiple files are merged sequentially, redefining collisons. See README and sample for details.
# @param block [Block] the main body of the script.
# @api public
def initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml', layout: nil, &block)
def initialize(width: 825, height: 1125, cards: 1, dpi: 300,
config: 'config.yml', layout: nil, preset: :none,
&block)
@dpi = dpi
@font = DEFAULT_FONT
@cards = []
Expand All @@ -68,11 +70,14 @@ def initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml
@width = Args::UnitConversion.parse width, dpi
@height = Args::UnitConversion.parse height, dpi
cards.times{ |i| @cards << Squib::Card.new(self, @width, @height, i) }
# presetter = apply_preset!(preset) unless preset == :none # just sketching code for now
@layout = LayoutParser.new(dpi).load_layout(layout)
enable_groups_from_env!
# presetter.before(self) # just sketching code for now
if block_given?
instance_eval(&block) # here we go. wheeeee!
end
# presetter.after(self) # just sketching code for now
@cards.each { |c| c.finish! }
end

Expand All @@ -99,6 +104,24 @@ def show_info(config, layout)
Squib::logger.info " using #{@backend}"
end

# Load the preset template
# @api private
#
def apply_preset!(file)
Preset.new()
end

# DSL method
def safe # delegate to presetter
end

def cut # delegate to presetter
end

def proof # delegate to presetter
end


##################
### PUBLIC API ###
##################
Expand Down
48 changes: 48 additions & 0 deletions lib/squib/presets/tgc_poker.rb
@@ -0,0 +1,48 @@
module Squib
module Presets
class TgcPoker

def initialize(deck)
@deck = deck
end

# The width of the deck to set, unless overridden in Squib.new
def width
825
end

# The height of the deck to set, unless overridden in Squib.new
def height
1125
end

# The DPI of the deck to set, unless overridden in Squib.new
def dpi
300
end

# Executed before the main block
def before
@deck.use_layout('tgc_poker.yml')
end

def after
# Nothing here that I can think of yet
end

def safe
@deck.rect layout: :safe
end

def cut
@deck.rect layout: :cut
end

def proof
safe
cut
end

end
end
end

0 comments on commit 4b806bb

Please sign in to comment.