hdeck 0.1.3 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d410e99074b9e1c4028b98441646544cde0f44e52feafa7da3ab717339388301
4
- data.tar.gz: 531e3387fda2332150c29e098f34daa8aced505e359428179aba81e4c53c949a
3
+ metadata.gz: baa027c771a491c6a5dc729f3b7d11a39420543087eb4ae621b66deb9dae1684
4
+ data.tar.gz: c13ecc315be7024d3df2928ac2e29a848abe341956d15a5aefe5d0460123f829
5
5
  SHA512:
6
- metadata.gz: d5915a31f734a3a690c2f7656a03ac6823366948c9b52222a2630366b3a0b5f1bb2031ff2eebc4437c83e5c75645f0aa1651093b4ae99bd17509f79a24fc0651
7
- data.tar.gz: 416387984ade1cb887a2214ed3c0395f94b3017da95ef4179245d781ec974026648cc4da19406fbe66d6101d7d8fee4c1174062d29bb7f3639a28bd72f91daae
6
+ metadata.gz: 2f91315a02582e68d62862120d4e837f5c9e6c519a46cb71b16085dd79b1ed04a9f841c5353f407a34cf1affd4d4dc28a3ead56a5beaf98e0001965cd0dc9128
7
+ data.tar.gz: 6e1da908f61398a133f495d47251e5e84e6f4bf6c2bbcf62ece22e401265dd3ee11b13de93ac72ef21e589c9476f12cf6afde596d036f7d82b25cb32255ddd00
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ hdeck.store
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /_yardoc/
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
6
 
5
7
  # Specify your gem's dependencies in hdeck.gemspec
6
8
  gemspec
@@ -1,13 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hdeck (0.1.0)
4
+ hdeck (1.0.0)
5
5
  thor
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
+ ast (2.4.0)
11
+ coderay (1.1.2)
10
12
  diff-lcs (1.3)
13
+ jaro_winkler (1.5.3)
14
+ method_source (0.9.2)
15
+ parallel (1.17.0)
16
+ parser (2.6.3.0)
17
+ ast (~> 2.4.0)
18
+ pry (0.12.2)
19
+ coderay (~> 1.1.0)
20
+ method_source (~> 0.9.0)
21
+ rainbow (3.0.0)
11
22
  rake (10.5.0)
12
23
  rspec (3.8.0)
13
24
  rspec-core (~> 3.8.0)
@@ -22,7 +33,16 @@ GEM
22
33
  diff-lcs (>= 1.2.0, < 2.0)
23
34
  rspec-support (~> 3.8.0)
24
35
  rspec-support (3.8.0)
36
+ rubocop (0.74.0)
37
+ jaro_winkler (~> 1.5.1)
38
+ parallel (~> 1.10)
39
+ parser (>= 2.6)
40
+ rainbow (>= 2.2.2, < 4.0)
41
+ ruby-progressbar (~> 1.7)
42
+ unicode-display_width (>= 1.4.0, < 1.7)
43
+ ruby-progressbar (1.10.1)
25
44
  thor (0.20.3)
45
+ unicode-display_width (1.6.0)
26
46
 
27
47
  PLATFORMS
28
48
  ruby
@@ -31,8 +51,10 @@ PLATFORMS
31
51
  DEPENDENCIES
32
52
  bundler (~> 1.17)
33
53
  hdeck!
54
+ pry
34
55
  rake (~> 10.0)
35
56
  rspec (~> 3.0)
57
+ rubocop
36
58
 
37
59
  BUNDLED WITH
38
60
  1.17.2
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # HDeck
2
2
 
3
3
  [![Build Status](https://travis-ci.org/mgmarlow/hdeck.svg?branch=master)](https://travis-ci.org/mgmarlow/hdeck)
4
+ [![Gem Version](https://badge.fury.io/rb/hdeck.svg)](https://badge.fury.io/rb/hdeck)
4
5
 
5
6
  CLI tool to manage decks of [harrow cards](http://pathfinder.wikia.com/wiki/List_of_harrow_cards).
6
7
  Designed to make working with the
@@ -9,13 +10,8 @@ class easier.
9
10
 
10
11
  ## Installation
11
12
 
12
- Gem coming soon. For now,
13
-
14
13
  ```
15
- git clone https://github.com/mgmarlow/hdeck.git
16
- cd hdeck
17
- bundle
18
- ./bin/console new
14
+ gem install hdeck
19
15
  ```
20
16
 
21
17
  ## Examples
@@ -25,7 +21,7 @@ bundle
25
21
  Begin the CLI by running the console:
26
22
 
27
23
  ```
28
- ./bin/console new
24
+ hdeck new
29
25
  ```
30
26
 
31
27
  Follow the commands to manage your harrow deck.
@@ -45,13 +41,14 @@ Dealer feat. You can configure alignment with the `--alignment`
45
41
  flag. Defaults to CN.
46
42
 
47
43
  ```
48
- ./bin/console new --alignment LG
44
+ hdeck new --alignment LG
49
45
  ```
50
46
 
51
47
  ## Roadmap
52
48
 
49
+ - [x] Publish gem
53
50
  - [ ] Better CLI formatting
54
51
  - [ ] Better error handling
55
52
  - [ ] Save & Load decks
56
53
  - [ ] More deck management options (# cards, shuffling)
57
- - [ ] Publish gem
54
+
data/bin/hdeck CHANGED
@@ -1,30 +1,69 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'bundler/setup'
3
4
  require 'thor'
4
- require_relative '../lib/hdeck'
5
+ require 'yaml/store'
6
+ require 'hdeck'
5
7
 
6
8
  class CLI < Thor
7
9
  package_name "hdeck"
8
10
 
11
+ # TODO: Make this nonsesnse relative to gem's directory
9
12
  desc "new", "create a new harrow deck"
10
13
  option :alignment, default: 'CN'
11
- def new()
12
- puts 'Creating a new Harrow Deck.'
13
- # TODO: validate alignment
14
+ def new
15
+ store = YAML::Store.new pathname
14
16
  player = HDeck::CardCaster.new(alignment: options[:alignment])
15
- active = true
16
-
17
- while active do
18
- action = ask("What would you like to do? (draw) (throw) (quit)\n")
19
-
20
- if action == 'draw'
21
- player.draw_card(shuffle_before: true, replace: true)
22
- elsif action == 'throw'
23
- player.draw_card(shuffle_before: true, replace: false, calculate_match: true)
24
- elsif action == 'quit' || action == 'q'
25
- active = false
26
- else
27
- puts 'did not recognize command'
17
+
18
+ store.transaction do
19
+ store[:player] = player
20
+ end
21
+ end
22
+
23
+ desc "draw", "draw from harrow deck (with replacement)"
24
+ option :n, default: 1, desc: 'draw amount', type: :numeric
25
+ def draw
26
+ player = get_player
27
+ player.draw_card(amount: options[:n])
28
+ end
29
+
30
+ desc "throw", "throw card from harrow deck (no replacement)"
31
+ option :n, default: 1, desc: 'throw amount', type: :numeric
32
+ def throw
33
+ player = get_player
34
+ player.throw_card(amount: options[:n])
35
+ save(player)
36
+ end
37
+
38
+ desc "length", "number of cards left in the deck"
39
+ def length
40
+ player = get_player
41
+ puts player.deck.length
42
+ end
43
+
44
+ desc "shuffle", "shuffle the active harrow deck"
45
+ def shuffle
46
+ player = get_player
47
+ player.deck.shuffle
48
+ puts "Shuffled #{player.deck.length} cards."
49
+ save(player)
50
+ end
51
+
52
+ no_commands do
53
+ def pathname
54
+ File.join(File.dirname(__FILE__), 'hdeck.store')
55
+ end
56
+
57
+ # TODO: Clean up store instantiation pattern
58
+ def get_player
59
+ store = YAML::Store.new pathname
60
+ store.transaction { store[:player] }
61
+ end
62
+
63
+ def save(player)
64
+ store = YAML::Store.new pathname
65
+ store.transaction do
66
+ store[:player] = player
28
67
  end
29
68
  end
30
69
  end
data/cards.json CHANGED
@@ -108,21 +108,21 @@
108
108
  "ability": "Dexterity",
109
109
  "symbol": "key",
110
110
  "name": "The Avalanche",
111
- "desc": "Disaster: an unthinking panic and destruction that overruns all.[",
111
+ "desc": "Disaster: an unthinking panic and destruction that overruns all.",
112
112
  "morality": "LE"
113
113
  },
114
114
  {
115
115
  "ability": "Dexterity",
116
116
  "symbol": "key",
117
117
  "name": "The Crows",
118
- "desc": "Murder, theft, and the violent loss of that which is loved.[",
118
+ "desc": "Murder, theft, and the violent loss of that which is loved.",
119
119
  "morality": "NE"
120
120
  },
121
121
  {
122
122
  "ability": "Dexterity",
123
123
  "symbol": "key",
124
124
  "name": "The Demon's Lantern",
125
- "desc": "An impossible situation of traps, mind tricks, and sleight of hand.[",
125
+ "desc": "An impossible situation of traps, mind tricks, and sleight of hand.",
126
126
  "morality": "CE"
127
127
  },
128
128
  {
@@ -1,30 +1,33 @@
1
+ # frozen_string_literal: true
1
2
 
2
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "hdeck/version"
5
+ require 'hdeck/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "hdeck"
8
+ spec.name = 'hdeck'
8
9
  spec.version = HDeck::VERSION
9
- spec.authors = ["Graham Marlow"]
10
- spec.email = ["mgmarlow@gmail.com"]
10
+ spec.authors = ['Graham Marlow']
11
+ spec.email = ['mgmarlow@gmail.com']
11
12
 
12
- spec.summary = "CLI tool to manage decks of harrow cards."
13
- spec.homepage = "https://github.com/mgmarlow/hdeck"
14
- spec.license = "MIT"
13
+ spec.summary = 'CLI tool to manage decks of harrow cards.'
14
+ spec.homepage = 'https://github.com/mgmarlow/hdeck'
15
+ spec.license = 'MIT'
15
16
 
16
17
  # Specify which files should be added to the gem when it is released.
17
18
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
19
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
20
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
21
  end
21
- spec.bindir = "bin"
22
+ spec.bindir = 'bin'
22
23
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
- spec.require_paths = ["lib"]
24
+ spec.require_paths = ['lib']
24
25
 
25
- spec.add_dependency "thor"
26
+ spec.add_dependency 'thor'
26
27
 
27
- spec.add_development_dependency "bundler", "~> 1.17"
28
- spec.add_development_dependency "rake", "~> 10.0"
29
- spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency 'bundler', '~> 1.17'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.0'
31
+ spec.add_development_dependency 'pry'
32
+ spec.add_development_dependency 'rubocop'
30
33
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
- require_relative 'hdeck/version'
3
- require_relative 'hdeck/card_caster'
4
- require_relative 'hdeck/card'
5
- require_relative 'hdeck/deck'
4
+ require 'hdeck/version'
5
+ require 'hdeck/card_caster'
6
+ require 'hdeck/card'
7
+ require 'hdeck/deck'
6
8
 
7
9
  module HDeck
8
10
  class Error < StandardError; end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HDeck
2
4
  # An individual Harrow card unit, described on this page:
3
5
  # https://pathfinder.fandom.com/wiki/List_of_harrow_cards
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HDeck
2
4
  # Manager class for Card Caster
3
5
  class CardCaster
@@ -8,19 +10,30 @@ module HDeck
8
10
  @deck = Deck.new
9
11
  end
10
12
 
11
- def draw_card(shuffle_before: true, replace: false, calculate_match: false)
12
- if deck.length <= 0
13
- puts 'Deck is out of cards'
14
- return
15
- end
13
+ def draw_card(amount: 1)
14
+ copy = Marshal.load(Marshal.dump(deck))
16
15
 
17
- deck.shuffle if shuffle_before
16
+ (0...amount).each do |_|
17
+ card = copy.draw
18
+ if card.nil?
19
+ puts "Out of cards. Create a new deck with 'hdeck new'"
20
+ return
21
+ end
18
22
 
19
- drawn_card = deck.draw(replace: replace)
23
+ puts "\n#{card}\n\n"
24
+ end
25
+ end
26
+
27
+ def throw_card(amount: 1)
28
+ (0...amount).each do |_|
29
+ card = deck.draw
30
+ if card.nil?
31
+ puts "Out of cards. Create a new deck with 'hdeck new'"
32
+ return
33
+ end
20
34
 
21
- if calculate_match
22
35
  # Bonuses applied via Role Dealer feat
23
- case detect_alignment_match(drawn_card)
36
+ case detect_alignment_match(card)
24
37
  when :full
25
38
  puts "Full alignment match!\n"\
26
39
  "--------------------\n"\
@@ -32,9 +45,9 @@ module HDeck
32
45
  "--------------------\n"\
33
46
  "crit range: 19-20\n"
34
47
  end
35
- end
36
48
 
37
- puts("\n#{drawn_card.to_s}\n\n")
49
+ puts "\n#{card}\n\n"
50
+ end
38
51
  end
39
52
 
40
53
  def detect_alignment_match(card)
@@ -1,10 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HDeck
2
4
  # Provides a Harrow deck for a Card Caster to interact with
3
5
  class Deck
6
+ class OutOfCardsError < StandardError; end
4
7
  include Enumerable
5
8
 
6
9
  def initialize
7
- card_data = JSON.parse(File.read('cards.json'))
10
+ card_path = File.expand_path('../../cards.json', File.dirname(__FILE__))
11
+ card_data = JSON.parse(File.read(card_path))
8
12
  @cards = get_cards(card_data)
9
13
  end
10
14
 
@@ -16,8 +20,10 @@ module HDeck
16
20
  @cards.each(&block)
17
21
  end
18
22
 
19
- def draw(replace: true)
20
- replace ? @cards.last : @cards.pop
23
+ def draw
24
+ return if @cards.length <= 0
25
+
26
+ @cards.shift
21
27
  end
22
28
 
23
29
  def shuffle
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HDeck
2
- VERSION = "0.1.3"
4
+ VERSION = '1.0.1'
3
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hdeck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Graham Marlow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-25 00:00:00.000000000 Z
11
+ date: 2019-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  description:
70
98
  email:
71
99
  - mgmarlow@gmail.com