From c795852fa82e7e5a9eec67d2cd19a15d30bacc81 Mon Sep 17 00:00:00 2001 From: Andy Meneely Date: Wed, 11 Aug 2021 15:00:54 -0400 Subject: [PATCH] Allow negative coordinates in sprue coordinates Fixes #336 --- CHANGELOG.md | 6 ++++++ lib/squib/sprues/sprue_schema.rb | 7 ++++--- samples/sprues/_negative_coords.rb | 7 +++++++ samples/sprues/my_sprues/negatives.yml | 12 ++++++++++++ samples/sprues/sprue_negatives_00_expected.png | Bin 0 -> 6342 bytes spec/data/sprues/negatives.yml | 7 +++++++ spec/sprue_spec.rb | 7 +++++++ 7 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 samples/sprues/_negative_coords.rb create mode 100644 samples/sprues/my_sprues/negatives.yml create mode 100644 samples/sprues/sprue_negatives_00_expected.png create mode 100644 spec/data/sprues/negatives.yml 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 0000000000000000000000000000000000000000..8ae9688dc6a7a9a86d84511640b8f39199f3a678 GIT binary patch literal 6342 zcmeHMYfw{X8vcS6teRr$4dm7?qd22QK?Na%VAaG6qIMiu5lui8rO2HCNeIz&7Zot= z1QwB-Y&yg>q9_U?mxM*2F+dtpZXyJTA%uW|+(<$$d$ijhyHmT)&g|?sGH1@5Iqx~& zIp@86&-*;zxpE{317EssDF6Vzf8U<30a*0y>wSq8WWjGf7XuxvBMxHr0L$y`W+Rgh zfE{uFo?XY%il>L}#hw@#riAmEbyguO&raO_I(**`2U@>?wO$;p`%^{j3TL~p74bQk zb=(m<^z8_IhwtsUa+jUb4p|`nhMJ~&E|l)7lsH*NSdX-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Qn?S(cUbhS8BmDO z%VJ6KiBIx}ypg^G-AAl}|KS|v-ZmkFUM&=xxKv@B=K#t-BW3IG%VP}7x5`nkzj%Tf z`(N7V#W>}E&sPBHn$2}xv{sYhu5gef^)_ke<$^;C*?xybh=np)D3gUU`5%MmxCOR9V6TnyEa4^eV*>2o M8?@){SGY_60N%oD`v3p{ literal 0 HcmV?d00001 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