Browse Source

Allow negative coordinates in sprue coordinates

Fixes #336
dev
Andy Meneely 4 years ago
parent
commit
c795852fa8
  1. 6
      CHANGELOG.md
  2. 7
      lib/squib/sprues/sprue_schema.rb
  3. 7
      samples/sprues/_negative_coords.rb
  4. 12
      samples/sprues/my_sprues/negatives.yml
  5. BIN
      samples/sprues/sprue_negatives_00_expected.png
  6. 7
      spec/data/sprues/negatives.yml
  7. 7
      spec/sprue_spec.rb

6
CHANGELOG.md

@ -1,6 +1,12 @@
# Squib CHANGELOG # Squib CHANGELOG
Squib follows [semantic versioning](http://semver.org). Squib follows [semantic versioning](http://semver.org).
## v0.17.1 / 2021-08-11
Bugs:
* Sprues now allow negative coordinates (#336)
* Documentation typos (#337)
## v0.17.0 / 2021-07-23 ## v0.17.0 / 2021-07-23
Features: Features:
* Drop shadows! The `save_png` method now supports a bunch of `shadow_` arguments that will add a drop shadow just before rendering. This is intended for using in rulebooks or marketing. Try it out by adding `shadow_radius: 8` to your save_png (#306, #264) * Drop shadows! The `save_png` method now supports a bunch of `shadow_` arguments that will add a drop shadow just before rendering. This is intended for using in rulebooks or marketing. Try it out by adding `shadow_radius: 8` to your save_png (#306, #264)

7
lib/squib/sprues/sprue_schema.rb

@ -1,7 +1,8 @@
module Squib module Squib
module Sprues module Sprues
UNIT_REGEX = /^(\d*[.])?\d+(in|cm|mm)$/ UNIT_REGEX = /^(\d*[.])?\d+(in|cm|mm)$/
ROTATE_REGEX = /^(\d*[.])?\d+(deg|rad)?$/ COORD_REGEX = /^\-?(\d*[.])?\d+(in|cm|mm)$/
ROTATE_REGEX = /^\-?(\d*[.])?\d+(deg|rad)?$/
SCHEMA = { SCHEMA = {
'sheet_width' => UNIT_REGEX, 'sheet_width' => UNIT_REGEX,
'sheet_height' => UNIT_REGEX, 'sheet_height' => UNIT_REGEX,
@ -35,8 +36,8 @@ module Squib
}]] }]]
}, },
'cards' => [[{ 'cards' => [[{
'x' => UNIT_REGEX, 'x' => COORD_REGEX,
'y' => UNIT_REGEX, 'y' => COORD_REGEX,
'rotate' => [ 'rotate' => [
:optional, Numeric, :optional, Numeric,
ClassyHash::G.enum(:clockwise, :counterclockwise, :turnaround), ClassyHash::G.enum(:clockwise, :counterclockwise, :turnaround),

7
samples/sprues/_negative_coords.rb

@ -0,0 +1,7 @@
require_relative '../../lib/squib'
Squib::Deck.new(width: 100, height: 100, cards: 3) do
background color: :grey
text str: 'Hello', font: 'Sans Bold 10'
save_sheet sprue: 'my_sprues/negatives.yml', prefix: 'sprue_negatives_'
end

12
samples/sprues/my_sprues/negatives.yml

@ -0,0 +1,12 @@
---
sheet_width: 3.0in
sheet_height: 3.0in
card_width: 1in
card_height: 1in
cards:
- x: -0.15in
y: -0.10in
- x: 1.5in
y: 0.5in
- x: 0.5in
y: 1.5in

BIN
samples/sprues/sprue_negatives_00_expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

7
spec/data/sprues/negatives.yml

@ -0,0 +1,7 @@
sheet_width: 8.5in
sheet_height: 11in
card_width: 2.5in
card_height: 3.5in
cards:
- x: -0.5in
y: -1in

7
spec/sprue_spec.rb

@ -158,6 +158,13 @@ describe Squib::Sprue do
expect(tmpl.cards.map { |card| card['flip_horizontal'] }) expect(tmpl.cards.map { |card| card['flip_horizontal'] })
.to eq( [false, false, true] ) .to eq( [false, false, true] )
end end
it 'parses negative coordinates' do
tmpl = Squib::Sprue.load(sprue_file('negatives.yml'), 100, 37.5)
expect(tmpl.cards.length).to eq(1)
expect(tmpl.cards.map { |card| card['x'] }) .to eq( [-50] )
expect(tmpl.cards.map { |card| card['y'] }) .to eq( [-100] )
end
it 'fails when sheet_width is not defined' do it 'fails when sheet_width is not defined' do
expect do expect do

Loading…
Cancel
Save