andymeneely / squib

A Ruby DSL for prototyping card games.
http://squib.rocks
MIT License
917 stars 67 forks source link

Extent with a decimal in the font size brings an error, not with an integer font size. #390

Open gabuzom opened 2 months ago

gabuzom commented 2 months ago

Describe the bug

(DISCLAIMER: Sorry if it is my lack of knowledge of Ruby that is at fault here. It is actually very likely. Please accept my apologies in advance if it's the case.)

Ruby crashes with a strange error, like if the extent array was empty or such, whenever the font size in my extent is 6.7. it doesnt when the size is 7.

To Reproduce

WHAT WORKS:

extents = text(str: cards['desc'], font: 'TradeGothic 7', x:100, width:570, height: 235, color: '#0000') puts extents ws = extents.inject([]) do |arr, ext| case ext[:height] when 0..80 arr << ext[:height]+640 ; arr ...etc.

(later:) text str: cards['context'], y: ws, layout: "context"

WHAT DOESNT:

extents = text(str: cards['desc'], font: 'TradeGothic 6.7', x:100, width:570, height: 235, color: '#0000') puts extents ws = extents.inject([]) do |arr, ext| case ext[:height] when 0..80 arr << ext[:height]+640 ; arr ...etc.

(only 7 is changed by 6.7. tried with 6.8 and other values to the same... extent < pun intended)

error is:

peoject.rb:83:in block (2 levels) in <main>': undefined method<<' for nil (NoMethodError)

arr << ext[:height]+620 ; arr 
    ^^
from project.rb:78:in `each'
from project.rb:78:in `inject'
from project.rb:78:in `block in <main>'
from /usr/local/bundle/gems/squib-0.19.0/lib/squib/deck.rb:75:in `instance_eval'
from /usr/local/bundle/gems/squib-0.19.0/lib/squib/deck.rb:75:in `initialize'
from project.rb:12:in `new'
from project.rb:12:in `<main>'

I tried escaping the string with " " and with ' '

Expected behavior

not crashing! :)

Environment

Additional context none

Check the following: