lib/squib/deck.rb in squib-0.5.1 vs lib/squib/deck.rb in squib-0.6.0

- old
+ new

@@ -1,14 +1,18 @@ require 'yaml' require 'pp' +require 'forwardable' require 'squib' require 'squib/card' require 'squib/progress' require 'squib/input_helpers' require 'squib/constants' require 'squib/layout_parser' require 'squib/args/unit_conversion' +require 'squib/conf' +require 'squib/graphics/showcase' +require 'squib/graphics/hand' # The project module # # @api public module Squib @@ -17,29 +21,24 @@ # # @api public class Deck include Enumerable include Squib::InputHelpers + extend Forwardable - # :nodoc: + # Attributes for the width, height (in pixels) and number of cards + # These are expected to be immuatble for the life of Deck # @api private - attr_reader :width, :height + attr_reader :width, :height, :cards + # Delegate these configuration options to the Squib::Conf object + def_delegators :conf, :antialias, :backend, :count_format, :custom_colors, :dir, + :img_dir, :prefix, :text_hint, :typographer # :nodoc: # @api private - attr_reader :cards + attr_reader :layout, :conf - # :nodoc: - # @api private - attr_reader :text_hint, :antialias - - # :nodoc: - # @api private - attr_reader :layout, :config, :quote_chars - - attr_reader :dir, :prefix, :count_format - # Squib's constructor that sets the immutable properties. # # This is the starting point for Squib. In providing a block to the constructor, you have access to all of Deck's instance methods. # The documented methods in Deck are the ones intended for use by most users. # If your game requires multiple different sizes or orientations, I recommend using multiple `Squib::Deck`s in your `deck.rb`. You can modify the internals of `Squib::Deck` (e.g. `@cards`), but that's not recommended. @@ -56,28 +55,19 @@ # @param config [String] the file used for global settings of this 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) - @antialias = CONFIG_DEFAULTS['antialias'] @dpi = dpi @font = SYSTEM_DEFAULTS[:default_font] @cards = [] - @custom_colors = {} - @img_dir = '.' - @progress_bar = Progress.new(false) - @text_hint = :off - @backend = :memory - @dir = SYSTEM_DEFAULTS[:dir] - @prefix = SYSTEM_DEFAULTS[:prefix] - @count_format = SYSTEM_DEFAULTS[:count_format] - @quote_chars = CONFIG_DEFAULTS.select {|k,v| %w(lsquote rsquote ldquote rdquote em_dash en_dash ellipsis smart_quotes).include?(k) } + @conf = Conf.load(config) + @progress_bar = Progress.new(@conf.progress_bars) # FIXME this is evil. Using something different with @ and non-@ show_info(config, layout) - load_config(config) @width = Args::UnitConversion.parse width, dpi @height = Args::UnitConversion.parse height, dpi - cards.times{ |i| @cards << Squib::Card.new(self, @width, @height, @backend, i) } + cards.times{ |i| @cards << Squib::Card.new(self, @width, @height, i) } @layout = LayoutParser.load_layout(layout) if block_given? instance_eval(&block) # here we go. wheeeee! end end @@ -92,32 +82,9 @@ # Iterates over each card in the deck # # @api private def each(&block) @cards.each { |card| block.call(card) } - end - - # Load the configuration file, if exists, overriding hardcoded defaults - # @api private - def load_config(file) - if File.exists?(file) && config = YAML.load_file(file) - Squib::logger.info { " using config: #{file}" } - config = CONFIG_DEFAULTS.merge(config) - @dpi = config['dpi'].to_i - @text_hint = config['text_hint'] - @progress_bar.enabled = config['progress_bars'] - @custom_colors = config['custom_colors'] - @img_dir = config['img_dir'] - @backend = (config['backend'].to_s.downcase.strip == 'svg') ? :svg : :memory - @dir = config['dir'] - @prefix = config['prefix'] - @count_format = config['count_format'] - @antialias = config['antialias'] - @quote_chars ||= {} - %w(lsquote rsquote ldquote rdquote smart_quotes em_dash en_dash ellipsis).each do |key| - @quote_chars[key] = config[key] - end - end end # Use Logger to show more detail on the run # :nodoc: # @api private