dicebag 3.3.0 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/dicebag +12 -1
- data/lib/dicebag/normalize.rb +10 -2
- data/lib/dicebag/roll_part.rb +2 -2
- data/lib/dicebag/roll_part_string.rb +2 -2
- data/lib/dicebag/transform.rb +4 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c9b311916035f1eaf3e31fd09c0eba523bc426875ca25ea0929d131215df709
|
4
|
+
data.tar.gz: 3c7c973630fdc29c654f3b90009d32652da06763a2e6a44fc5d2edb643215b96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 735fae23c00f6c883f4370bd8ca2a9451b6747264664b820f6f2b36ea062c8f3167197be28e17c83978d82a887c2d71cf5236af5519865913f23a0773145d087
|
7
|
+
data.tar.gz: 8c9c8fbc7ad416cf954da26a9118e040863a8cfb8b2ca0e71b9e8b0248d282ef0ff17bb66646433e93c6d55d8c359fc95962ceaba0205f8889500319271cd479
|
data/bin/dicebag
CHANGED
@@ -18,14 +18,25 @@ class DiceBagCLI
|
|
18
18
|
|
19
19
|
def opts
|
20
20
|
@opts ||= OptionParser.new do |args|
|
21
|
+
args.banner = 'Usage: dicebag [-n | --notes] <dice string>'
|
22
|
+
|
21
23
|
args.on '-n', '--notes', 'Display any notes for the roll.'
|
24
|
+
|
25
|
+
args.on_head('-h', 'Displays this help.') do
|
26
|
+
puts args
|
27
|
+
|
28
|
+
exit
|
29
|
+
end
|
22
30
|
end
|
23
31
|
end
|
24
32
|
|
25
33
|
def perform
|
34
|
+
abort(opts.help) if ARGV.empty?
|
35
|
+
|
26
36
|
nonopts = opts.parse! into: params
|
27
37
|
|
28
|
-
|
38
|
+
dstr = nonopts.join(' ')
|
39
|
+
roll = DiceBag::Roll.new dstr
|
29
40
|
result = roll.roll
|
30
41
|
|
31
42
|
puts result
|
data/lib/dicebag/normalize.rb
CHANGED
@@ -101,13 +101,21 @@ module DiceBag
|
|
101
101
|
|
102
102
|
explode = hash[:options][:explode]
|
103
103
|
|
104
|
-
|
104
|
+
# If we did not come with a value, set it to dice sides, but no
|
105
|
+
# need to note this, as this is what no values means.
|
106
|
+
return __set_explode_to_sides(hash) if explode.negative?
|
105
107
|
|
106
|
-
|
108
|
+
# But we do want to note if the explode value was set to 1. >:|
|
109
|
+
__set_explode_to_sides if explode == 1
|
107
110
|
|
108
111
|
hash[:notes].push("Explode set to #{hash[:sides]}")
|
109
112
|
end
|
110
113
|
|
114
|
+
# :nodoc:
|
115
|
+
def __set_explode_to_sides(hash)
|
116
|
+
hash[:options][:explode] = hash[:sides]
|
117
|
+
end
|
118
|
+
|
111
119
|
# Prevent Reroll abuse.
|
112
120
|
def normalize_reroll(hash)
|
113
121
|
return unless hash[:options].key?(:reroll) &&
|
data/lib/dicebag/roll_part.rb
CHANGED
@@ -96,14 +96,14 @@ module DiceBag
|
|
96
96
|
def generate_results
|
97
97
|
@results = []
|
98
98
|
|
99
|
-
explode = @options
|
99
|
+
explode = @options[:explode]
|
100
100
|
|
101
101
|
count.times do
|
102
102
|
roll = roll_die
|
103
103
|
|
104
104
|
@results.push(roll)
|
105
105
|
|
106
|
-
handle_explode(roll)
|
106
|
+
handle_explode(roll) unless explode.nil?
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
@@ -34,9 +34,9 @@ module RollPartString
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def to_s_explode
|
37
|
-
return unless @options.key?(:explode)
|
37
|
+
return unless @options.key?(:explode) && @options[:explode].positive?
|
38
38
|
|
39
|
-
e =
|
39
|
+
e = format('e%s', @options[:explode])
|
40
40
|
|
41
41
|
@parts.push e
|
42
42
|
end
|
data/lib/dicebag/transform.rb
CHANGED
@@ -5,6 +5,8 @@ module DiceBag
|
|
5
5
|
# pass later.)
|
6
6
|
class Transform < Parslet::Transform
|
7
7
|
def self.hashify_options(options)
|
8
|
+
return options if options.is_a? Hash
|
9
|
+
|
8
10
|
opts = {}
|
9
11
|
|
10
12
|
options.each { |val| opts.update val } if options.respond_to?(:each)
|
@@ -40,9 +42,9 @@ module DiceBag
|
|
40
42
|
end
|
41
43
|
|
42
44
|
# Explode is special, in that if it is nil, then we set it to -1 to
|
43
|
-
# reflect that.
|
45
|
+
# reflect that, and it'll be updated in the normalization phase.
|
44
46
|
rule(explode: simple(:x)) do
|
45
|
-
{ explode: (x ? Integer(x) :
|
47
|
+
{ explode: (x ? Integer(x) : -1) }
|
46
48
|
end
|
47
49
|
|
48
50
|
# Match a label by itself.
|