squib 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +29 -29
- data/.travis.yml +6 -6
- data/.yardopts +7 -5
- data/Gemfile +2 -2
- data/LICENSE.txt +22 -22
- data/README.md +245 -92
- data/Rakefile +11 -11
- data/bin/squib +18 -18
- data/lib/squib.rb +31 -18
- data/lib/squib/api/background.rb +18 -16
- data/lib/squib/api/data.rb +52 -52
- data/lib/squib/api/image.rb +66 -48
- data/lib/squib/api/save.rb +43 -37
- data/lib/squib/api/settings.rb +38 -35
- data/lib/squib/api/shapes.rb +116 -106
- data/lib/squib/api/text.rb +50 -45
- data/lib/squib/api/units.rb +16 -16
- data/lib/squib/card.rb +42 -36
- data/lib/squib/commands/new.rb +43 -39
- data/lib/squib/constants.rb +104 -39
- data/lib/squib/deck.rb +116 -113
- data/lib/squib/graphics/background.rb +13 -12
- data/lib/squib/graphics/image.rb +47 -28
- data/lib/squib/graphics/save_doc.rb +54 -50
- data/lib/squib/graphics/save_images.rb +32 -10
- data/lib/squib/graphics/shapes.rb +59 -55
- data/lib/squib/graphics/text.rb +113 -107
- data/lib/squib/input_helpers.rb +193 -139
- data/lib/squib/progress.rb +38 -0
- data/lib/squib/project_template/.gitignore +4 -3
- data/lib/squib/project_template/ABOUT.md +19 -19
- data/lib/squib/project_template/Gemfile +2 -2
- data/lib/squib/project_template/PNP NOTES.md +3 -3
- data/lib/squib/project_template/config.yml +20 -2
- data/lib/squib/project_template/deck.rb +5 -5
- data/lib/squib/version.rb +6 -6
- data/samples/ball.png +0 -0
- data/samples/basic.rb +19 -19
- data/samples/colors.rb +15 -16
- data/samples/custom-config.yml +6 -1
- data/samples/custom-layout.yml +39 -34
- data/samples/custom_config.rb +18 -5
- data/samples/customconfig-imgdir/shiny-purse2.png +0 -0
- data/samples/customconfig-imgdir/spanner2.svg +91 -0
- data/samples/draw_shapes.rb +18 -18
- data/samples/excel.rb +19 -19
- data/samples/grit.png +0 -0
- data/samples/hello_world.rb +6 -6
- data/samples/load_images.rb +29 -19
- data/samples/offset.svg +71 -0
- data/samples/portrait-landscape.rb +23 -0
- data/samples/ranges.rb +55 -47
- data/samples/save_pdf.rb +14 -14
- data/samples/shiny-purse.png +0 -0
- data/samples/spanner.svg +91 -91
- data/samples/text_options.rb +60 -58
- data/samples/tgc_proofs.rb +19 -19
- data/samples/units.rb +12 -12
- data/samples/use_layout.rb +28 -28
- data/spec/api/api_text_spec.rb +42 -36
- data/spec/commands/new_spec.rb +47 -47
- data/spec/data/multi-extends-single-entry.yml +13 -0
- data/spec/data/multi-level-extends.yml +10 -0
- data/spec/data/no-extends.yml +5 -0
- data/spec/data/single-extends.yml +7 -0
- data/spec/data/single-level-multi-extends.yml +12 -0
- data/spec/deck_spec.rb +147 -49
- data/spec/input_helpers_spec.rb +117 -0
- data/spec/samples_run_spec.rb +19 -14
- data/spec/spec_helper.rb +3 -0
- data/squib.gemspec +46 -42
- metadata +78 -4
- data/API.md +0 -59
data/lib/squib/commands/new.rb
CHANGED
@@ -1,40 +1,44 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Squib
|
4
|
+
# Squib's command-line options
|
5
|
+
module Commands
|
6
|
+
|
7
|
+
# Generate a new Squib project into a fresh directory.
|
8
|
+
#
|
9
|
+
# Provides conventions for using Git (you are using version control, right??).
|
10
|
+
# Also provides some basic layout and config files to start from, along with templates for instructions and other notes you don't want to forget.
|
11
|
+
#
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# squib new foo-blasters
|
15
|
+
# cd foo-blasters
|
16
|
+
# ruby deck.rb
|
17
|
+
# git init
|
18
|
+
# git add .
|
19
|
+
# git commit -m "Starting my cool new game using Squib!"
|
20
|
+
#
|
21
|
+
# @api public
|
22
|
+
class New
|
23
|
+
|
24
|
+
# :nodoc:
|
25
|
+
# @api private
|
26
|
+
def process(args)
|
27
|
+
raise ArgumentError.new('Please specify a path.') if args.empty?
|
28
|
+
|
29
|
+
new_project_path = File.expand_path(args.join(" "), Dir.pwd)
|
30
|
+
template_path = File.expand_path('../project_template', File.dirname(__FILE__))
|
31
|
+
|
32
|
+
FileUtils.mkdir_p new_project_path
|
33
|
+
if !Dir["#{new_project_path}/**/*"].empty?
|
34
|
+
$stderr.puts "#{new_project_path} exists and is not empty. Doing nothing and quitting."
|
35
|
+
else
|
36
|
+
Dir.chdir(new_project_path) do
|
37
|
+
FileUtils.cp_r template_path + '/.', new_project_path
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
40
44
|
end
|
data/lib/squib/constants.rb
CHANGED
@@ -1,40 +1,105 @@
|
|
1
|
-
module Squib
|
2
|
-
# Squib's defaults for when arguments are not specified in the command nor layouts.
|
3
|
-
#
|
4
|
-
# @api public
|
5
|
-
SYSTEM_DEFAULTS = {
|
6
|
-
:
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
37
|
-
:
|
38
|
-
|
39
|
-
|
1
|
+
module Squib
|
2
|
+
# Squib's defaults for when arguments are not specified in the command nor layouts.
|
3
|
+
#
|
4
|
+
# @api public
|
5
|
+
SYSTEM_DEFAULTS = {
|
6
|
+
:align => :left,
|
7
|
+
:alpha => 1.0,
|
8
|
+
:blend => :none,
|
9
|
+
:color => :black,
|
10
|
+
:default_font => 'Arial 36',
|
11
|
+
:dir => "_output",
|
12
|
+
:ellipsize => :end,
|
13
|
+
:fill_color => '#0000',
|
14
|
+
:force_id => false,
|
15
|
+
:font => :use_set,
|
16
|
+
:format => :png,
|
17
|
+
:gap => 0,
|
18
|
+
:height => :native,
|
19
|
+
:hint => :off,
|
20
|
+
:img_dir => '.',
|
21
|
+
:justify => false,
|
22
|
+
:margin => 75,
|
23
|
+
:markup => false,
|
24
|
+
:prefix => "card_",
|
25
|
+
:progress_bar => false,
|
26
|
+
:range => :all,
|
27
|
+
:rotate => false,
|
28
|
+
:sheet => 0,
|
29
|
+
:spacing => 0,
|
30
|
+
:str => '',
|
31
|
+
:stroke_color => :black,
|
32
|
+
:stroke_width => 2.0,
|
33
|
+
:trim => 0,
|
34
|
+
:valign => :top,
|
35
|
+
:width => :native,
|
36
|
+
:wrap => true,
|
37
|
+
:x => 0,
|
38
|
+
:x1 => 100,
|
39
|
+
:x2 => 150,
|
40
|
+
:x3 => 100,
|
41
|
+
:x_radius => 0,
|
42
|
+
:y => 0,
|
43
|
+
:y1 => 100,
|
44
|
+
:y2 => 150,
|
45
|
+
:y3 => 150,
|
46
|
+
:y_radius => 0,
|
47
|
+
}
|
48
|
+
|
49
|
+
# Squib's configuration defaults
|
50
|
+
#
|
51
|
+
# @api public
|
52
|
+
CONFIG_DEFAULTS = {
|
53
|
+
'custom_colors' => {},
|
54
|
+
'dpi' => 300,
|
55
|
+
'hint' => :none,
|
56
|
+
'progress_bar' => false,
|
57
|
+
'img_dir' => '.',
|
58
|
+
}
|
59
|
+
|
60
|
+
# These are parameters that are intended to be "expanded" across
|
61
|
+
# range if they are singletons.
|
62
|
+
#
|
63
|
+
# For example, using a different font for each card, using one `text`
|
64
|
+
#
|
65
|
+
# key: the internal name of the param (e.g. :files)
|
66
|
+
# value: the user-facing API key (e.g. file: 'abc.png')
|
67
|
+
#
|
68
|
+
# @api private
|
69
|
+
EXPANDING_PARAMS = {
|
70
|
+
:align => :align,
|
71
|
+
:alpha => :alpha,
|
72
|
+
:blend => :blend,
|
73
|
+
:circle_radius => :radius,
|
74
|
+
:color => :color,
|
75
|
+
:ellipsize => :ellipsize,
|
76
|
+
:files => :file,
|
77
|
+
:fill_color => :fill_color,
|
78
|
+
:force_svgid => :force_id,
|
79
|
+
:font => :font,
|
80
|
+
:height => :height,
|
81
|
+
:hint => :hint,
|
82
|
+
:justify => :justify,
|
83
|
+
:layout => :layout,
|
84
|
+
:markup => :markup,
|
85
|
+
:rect_radius => :radius,
|
86
|
+
:spacing => :spacing,
|
87
|
+
:str => :str,
|
88
|
+
:stroke_color => :stroke_color,
|
89
|
+
:stroke_width => :stroke_width,
|
90
|
+
:svgid => :id,
|
91
|
+
:valign => :valign,
|
92
|
+
:width => :width,
|
93
|
+
:wrap => :wrap,
|
94
|
+
:x => :x,
|
95
|
+
:x1 => :x1,
|
96
|
+
:x2 => :x2,
|
97
|
+
:x3 => :x3,
|
98
|
+
:x_radius => :x_radius,
|
99
|
+
:y => :y,
|
100
|
+
:y1 => :y1,
|
101
|
+
:y2 => :y2,
|
102
|
+
:y2 => :y3,
|
103
|
+
:y_radius => :y_radius,
|
104
|
+
}
|
40
105
|
end
|
data/lib/squib/deck.rb
CHANGED
@@ -1,114 +1,117 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require 'pp'
|
3
|
-
require 'squib
|
4
|
-
require 'squib/
|
5
|
-
require 'squib/
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
#
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
# @
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
# @
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
@
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
#
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
require 'squib/api/
|
108
|
-
require 'squib/api/
|
109
|
-
require 'squib/api/
|
110
|
-
require 'squib/api/
|
111
|
-
require 'squib/api/
|
112
|
-
|
113
|
-
|
1
|
+
require 'yaml'
|
2
|
+
require 'pp'
|
3
|
+
require 'squib'
|
4
|
+
require 'squib/card'
|
5
|
+
require 'squib/progress'
|
6
|
+
require 'squib/input_helpers'
|
7
|
+
require 'squib/constants'
|
8
|
+
|
9
|
+
# The project module
|
10
|
+
#
|
11
|
+
# @api public
|
12
|
+
module Squib
|
13
|
+
|
14
|
+
# The main interface to Squib. Provides a front-end porcelain whereas the Card class interacts with the graphics plumbing.
|
15
|
+
#
|
16
|
+
# @api public
|
17
|
+
class Deck
|
18
|
+
include Enumerable
|
19
|
+
include Squib::InputHelpers
|
20
|
+
|
21
|
+
# :nodoc:
|
22
|
+
# @api private
|
23
|
+
attr_reader :width, :height
|
24
|
+
|
25
|
+
# :nodoc:
|
26
|
+
# @api private
|
27
|
+
attr_reader :cards
|
28
|
+
|
29
|
+
# :nodoc:
|
30
|
+
# @api private
|
31
|
+
attr_reader :text_hint
|
32
|
+
|
33
|
+
# :nodoc:
|
34
|
+
# @api private
|
35
|
+
attr_reader :layout, :config
|
36
|
+
|
37
|
+
# Squib's constructor that sets the immutable properties.
|
38
|
+
#
|
39
|
+
# This is the starting point for Squib. In providing a block to the constructor, you have access to all of Deck's instance methods.
|
40
|
+
# The documented methods in Deck are the ones intended for use by most users.
|
41
|
+
# 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.
|
42
|
+
# @example
|
43
|
+
# require 'squib'
|
44
|
+
# Squib::Deck.new do
|
45
|
+
# text str: 'Hello, World!'
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# @param width: [Integer] the width of each card in pixels
|
49
|
+
# @param height: [Integer] the height of each card in pixels
|
50
|
+
# @param cards: [Integer] the number of cards in the deck
|
51
|
+
# @param dpi: [Integer] the pixels per inch when rendering out to PDF or calculating using inches.
|
52
|
+
# @param config: [String] the Yaml file used for global settings of this deck
|
53
|
+
# @param layout: [String] the Yaml file used for layouts.
|
54
|
+
# @param block [Block] the main body of the script.
|
55
|
+
# @api public
|
56
|
+
def initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml', layout: nil, &block)
|
57
|
+
@width=width; @height=height
|
58
|
+
@dpi = dpi
|
59
|
+
@font = Squib::SYSTEM_DEFAULTS[:default_font]
|
60
|
+
@cards = []
|
61
|
+
@custom_colors = {}
|
62
|
+
@img_dir = '.'
|
63
|
+
@progress_bar = Squib::Progress.new(false)
|
64
|
+
cards.times{ @cards << Squib::Card.new(self, width, height) }
|
65
|
+
load_config(config)
|
66
|
+
@layout = YAML.load_file(layout) unless layout.nil?
|
67
|
+
if block_given?
|
68
|
+
instance_eval(&block)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Directly accesses the array of cards in the deck
|
73
|
+
#
|
74
|
+
# @api private
|
75
|
+
def [](key)
|
76
|
+
@cards[key]
|
77
|
+
end
|
78
|
+
|
79
|
+
# Iterates over each card in the deck
|
80
|
+
#
|
81
|
+
# @api private
|
82
|
+
def each(&block)
|
83
|
+
@cards.each { |card| block.call(card) }
|
84
|
+
end
|
85
|
+
|
86
|
+
# Shows a descriptive place of the location
|
87
|
+
def location(opts)
|
88
|
+
opts[:layout] || (" @ #{opts[:x]},#{opts[:y]}")
|
89
|
+
end
|
90
|
+
|
91
|
+
# Load the configuration file, if exists, overriding hardcoded defaults
|
92
|
+
# @api private
|
93
|
+
def load_config(file)
|
94
|
+
if File.exists?(file) && config = YAML.load_file(file)
|
95
|
+
config = Squib::CONFIG_DEFAULTS.merge(config)
|
96
|
+
@dpi = config['dpi'].to_i
|
97
|
+
@text_hint = config['text_hint']
|
98
|
+
@progress_bar.enabled = config['progress_bars']
|
99
|
+
@custom_colors = config['custom_colors']
|
100
|
+
@img_dir = config['img_dir']
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
##################
|
105
|
+
### PUBLIC API ###
|
106
|
+
##################
|
107
|
+
require 'squib/api/background'
|
108
|
+
require 'squib/api/data'
|
109
|
+
require 'squib/api/image'
|
110
|
+
require 'squib/api/save'
|
111
|
+
require 'squib/api/settings'
|
112
|
+
require 'squib/api/shapes'
|
113
|
+
require 'squib/api/text'
|
114
|
+
require 'squib/api/units'
|
115
|
+
|
116
|
+
end
|
114
117
|
end
|