diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ad9ff0..483d065 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Squib CHANGELOG 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 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) diff --git a/lib/squib/sprues/sprue_schema.rb b/lib/squib/sprues/sprue_schema.rb index 1c011fd..74c2186 100644 --- a/lib/squib/sprues/sprue_schema.rb +++ b/lib/squib/sprues/sprue_schema.rb @@ -1,7 +1,8 @@ module Squib module Sprues 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 = { 'sheet_width' => UNIT_REGEX, 'sheet_height' => UNIT_REGEX, @@ -35,8 +36,8 @@ module Squib }]] }, 'cards' => [[{ - 'x' => UNIT_REGEX, - 'y' => UNIT_REGEX, + 'x' => COORD_REGEX, + 'y' => COORD_REGEX, 'rotate' => [ :optional, Numeric, ClassyHash::G.enum(:clockwise, :counterclockwise, :turnaround), diff --git a/samples/sprues/_negative_coords.rb b/samples/sprues/_negative_coords.rb new file mode 100644 index 0000000..cc22aeb --- /dev/null +++ b/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 \ No newline at end of file diff --git a/samples/sprues/my_sprues/negatives.yml b/samples/sprues/my_sprues/negatives.yml new file mode 100644 index 0000000..1eeaf5f --- /dev/null +++ b/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 diff --git a/samples/sprues/sprue_negatives_00_expected.png b/samples/sprues/sprue_negatives_00_expected.png new file mode 100644 index 0000000..8ae9688 Binary files /dev/null and b/samples/sprues/sprue_negatives_00_expected.png differ diff --git a/spec/data/sprues/negatives.yml b/spec/data/sprues/negatives.yml new file mode 100644 index 0000000..69de482 --- /dev/null +++ b/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 diff --git a/spec/sprue_spec.rb b/spec/sprue_spec.rb index b8c2a61..fd0b857 100644 --- a/spec/sprue_spec.rb +++ b/spec/sprue_spec.rb @@ -158,6 +158,13 @@ describe Squib::Sprue do expect(tmpl.cards.map { |card| card['flip_horizontal'] }) .to eq( [false, false, true] ) 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 expect do