gamefic 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa8d74d06ad87105050c1ca487acd976d293f4ca52fa6cc760061ccdbb3a14e7
4
- data.tar.gz: f791519291a168cf31045d6bc2f136d4829f5ddce2fa7c370d6c4887f83f560e
3
+ metadata.gz: 2288262e86ac4a5cf259b3a37e80ba56a3a4ed334b8842770109e1930799585d
4
+ data.tar.gz: 542aaff9c3f4d0aae1a4471fba5d52ff35b569971c861af006ddc78f0d1cc568
5
5
  SHA512:
6
- metadata.gz: e8abcf0f9ca24db9b8bc3f61be5d0d28dcd86c24f047e420eb117bd09411b70d5f3ae7e9c2c5d2277062c4c72a970d2c9144eb0990a46872eb80b7a7bd75369e
7
- data.tar.gz: 2bdec46fe7d946a05c3d9bf258314db25c61f32459993f03f1c2096dd31b0056917332fcd5c05ee011e3c352e373a1dcaa74f670d069398e481334ff64c07f1d
6
+ metadata.gz: 6a89c7fb5978047517827e3cc2de5f172da5e6905a7e7efe0725763b4ce01d56725df46a443b903906effd962cebdbd238d81719b315eb26f3b8bf289d337089
7
+ data.tar.gz: 9976d0c58957309ba605e645a8c7e214d798c12e114b71e5d5fa2bb4b6d39878537612e670da6e42168dfd31ee5fce7304eee9983d1177d878262af630e6e582
@@ -0,0 +1,40 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with rspec.
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: RSpec
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ test:
21
+
22
+ runs-on: ubuntu-latest
23
+ strategy:
24
+ matrix:
25
+ ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1']
26
+
27
+ steps:
28
+ - uses: actions/checkout@v3
29
+ - name: Set up Ruby
30
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
31
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
32
+ uses: ruby/setup-ruby@v1
33
+ # uses: ruby/setup-ruby@2b019609e2b0f1ea1a2bc8ca11cb82ab46ada124
34
+ with:
35
+ ruby-version: ${{ matrix.ruby-version }}
36
+ bundler-cache: false
37
+ - name: Install dependencies
38
+ run: bundle install
39
+ - name: Run tests
40
+ run: bundle exec rspec
data/.rubocop.yml CHANGED
@@ -10,4 +10,7 @@ Style/StringLiterals:
10
10
 
11
11
  Style/Documentation:
12
12
  Description: 'Document classes and non-namespace modules.'
13
- Enabled: false
13
+ Enabled: false
14
+
15
+ Style/MethodDefParentheses:
16
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 2.4.0 - February 11, 2023
2
+ - Fix arity of delegated methods in scripts
3
+ - Action hooks accept verb filters
4
+ - Opal exception for delegated methods
5
+ - Support separation of kwargs in Ruby >= 2.7
6
+
1
7
  ## 2.3.0 - January 25, 2023
2
8
  - Remove unused Active#actions method
3
9
  - Add before_action and after_action hooks
data/Gemfile CHANGED
@@ -1,7 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
-
5
- group :test do
6
- gem "simplecov"
7
- end
data/gamefic.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  end
20
20
  s.require_paths = ['lib']
21
21
 
22
- s.required_ruby_version = '>= 2.1.0'
22
+ s.required_ruby_version = '>= 2.3.0'
23
23
 
24
24
  s.add_development_dependency 'rake', '~> 12.3', '>= 12.3'
25
25
  s.add_development_dependency 'rspec', '~> 3.5', '>= 3.5.0'
@@ -32,8 +32,11 @@ module Gamefic
32
32
 
33
33
  # Cancel an action. This method can be called in a before_action hook to
34
34
  # prevent subsequent hooks and the action itself from being executed.
35
+ # Cancelling an action in an after_action hook has no effect.
35
36
  #
36
37
  def cancel
38
+ # @todo Emit a warning for attempts to cancel an action after it's been
39
+ # executed
37
40
  @cancelled = true
38
41
  end
39
42
 
@@ -44,6 +47,10 @@ module Gamefic
44
47
  @executed
45
48
  end
46
49
 
50
+ def cancelled?
51
+ !@executed && @cancelled
52
+ end
53
+
47
54
  # The verb associated with this action.
48
55
  #
49
56
  # @return [Symbol] The symbol representing the verb
@@ -91,8 +98,9 @@ module Gamefic
91
98
  return unless @with_callbacks
92
99
  @actor.playbooks
93
100
  .flat_map(&:before_actions)
94
- .each do |block|
95
- block.call(self)
101
+ .each do |hook|
102
+ next unless hook.verb.nil? || hook.verb == verb
103
+ hook.block.call(self)
96
104
  break if @cancelled
97
105
  end
98
106
  end
@@ -101,7 +109,10 @@ module Gamefic
101
109
  return unless @with_callbacks
102
110
  @actor.playbooks
103
111
  .flat_map(&:after_actions)
104
- .each { |block| block.call(self) }
112
+ .each do |hook|
113
+ next unless hook.verb.nil? || hook.verb == verb
114
+ hook.block.call(self)
115
+ end
105
116
  end
106
117
 
107
118
  class << self
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'set'
2
4
 
3
5
  module Gamefic
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gamefic
2
4
  # The action selector for character commands.
3
5
  #
@@ -12,11 +14,16 @@ module Gamefic
12
14
  @started = false
13
15
  end
14
16
 
17
+ # @param dispatcher [Dispatcher]
18
+ # @return [void]
15
19
  def merge dispatcher
16
20
  commands.concat dispatcher.commands
17
21
  actions.concat dispatcher.actions
18
22
  end
19
23
 
24
+ # Get the next executable action.
25
+ #
26
+ # @return [Action]
20
27
  def next
21
28
  instance = nil
22
29
  while instance.nil? && !@actions.empty?
@@ -76,9 +76,14 @@ Gamefic::Scriptable.module_exec do
76
76
  instance = self
77
77
  theater ||= Object.new
78
78
  theater.instance_exec do
79
- define_singleton_method :method_missing do |symbol, *args, **splat, &block|
80
- result = instance.public_send :public_send, symbol, *args, **splat, &block
81
- result
79
+ if RUBY_ENGINE == 'opal' || RUBY_VERSION =~ /^2\.[456]\./
80
+ define_singleton_method :method_missing do |symbol, *args, &block|
81
+ instance.public_send :public_send, symbol, *args, &block
82
+ end
83
+ else
84
+ define_singleton_method :method_missing do |symbol, *args, **splat, &block|
85
+ instance.public_send :public_send, symbol, *args, **splat, &block
86
+ end
82
87
  end
83
88
  end
84
89
  theater.extend Gamefic::Serialize
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gamefic
2
- VERSION = '2.3.0'
4
+ VERSION = '2.4.0'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'gamefic/action'
2
4
 
3
5
  module Gamefic
@@ -91,23 +93,29 @@ module Gamefic
91
93
  # @param command [Symbol] An imperative verb for the command
92
94
  # @param queries [Array<Query::Base>] Filters for the command's tokens
93
95
  # @yieldparam [Gamefic::Actor]
94
- def meta(command, *queries, &proc)
95
- playbook.meta command, *queries, &proc
96
+ def meta(command, *queries, &block)
97
+ playbook.meta command, *queries, &block
96
98
  end
97
99
 
98
100
  # Add a proc to be evaluated before a character executes an action.
101
+ # When a verb is specified, the proc will only be evaluated if the
102
+ # action's verb matches it.
99
103
  #
104
+ # @param verb [Symbol, nil]
100
105
  # @yieldparam [Gamefic::Action]
101
- def before_action &block
102
- playbook.before_actions.push block
106
+ def before_action verb = nil, &block
107
+ playbook.before_action verb, &block
103
108
  end
104
109
  alias validate before_action
105
110
 
106
111
  # Add a proc to be evaluated after a character executes an action.
112
+ # When a verb is specified, the proc will only be evaluated if the
113
+ # action's verb matches it.
107
114
  #
115
+ # @param [Symbol, nil]
108
116
  # @yieldparam [Gamefic::Action]
109
- def after_action &block
110
- playbook.after_actions.push block
117
+ def after_action verb = nil, &block
118
+ playbook.after_action verb, &block
111
119
  end
112
120
 
113
121
  # Create an alternate Syntax for an Action.
@@ -164,7 +172,7 @@ module Gamefic
164
172
  elsif q.is_a?(Gamefic::Element) || (q.is_a?(Class) && q <= Gamefic::Element)
165
173
  get_default_query.new(q)
166
174
  else
167
- raise ArgumentError.new("Invalid argument for response: #{q}")
175
+ raise ArgumentError, "Invalid argument for response: #{q.inspect}"
168
176
  end
169
177
  end
170
178
  end
@@ -5,6 +5,8 @@ module Gamefic
5
5
  # A collection of rules for performing commands.
6
6
  #
7
7
  class Playbook
8
+ ActionHook = Struct.new(:verb, :block)
9
+
8
10
  # An array of available syntaxes.
9
11
  #
10
12
  # @return [Array<Gamefic::Syntax>]
@@ -47,18 +49,24 @@ module Gamefic
47
49
  end
48
50
 
49
51
  # Add a proc to be evaluated before a character executes an action.
52
+ # When a verb is specified, the proc will only be evaluated if the
53
+ # action's verb matches it.
50
54
  #
55
+ # @param verb [Symbol, nil]
51
56
  # @yieldparam [Gamefic::Action]
52
- def before_action &block
53
- @before_actions.push block
57
+ def before_action verb = nil, &block
58
+ @before_actions.push ActionHook.new(verb, block)
54
59
  end
55
60
  alias validate before_action
56
61
 
57
62
  # Add a proc to be evaluated after a character executes an action.
63
+ # When a verb is specified, the proc will only be evaluated if the
64
+ # action's verb matches it.
58
65
  #
66
+ # @param verb [Symbol, nil]
59
67
  # @yieldparam [Gamefic::Action]
60
- def after_action &block
61
- @after_actions.push block
68
+ def after_action verb = nil, &block
69
+ @after_actions.push ActionHook.new(verb, block)
62
70
  end
63
71
 
64
72
  # Get an Array of all Actions associated with the specified verb.
@@ -1,6 +1,9 @@
1
1
  module Gamefic
2
2
  module World
3
3
  module Scenes
4
+ include Commands
5
+ include Players
6
+
4
7
  # @return [Class<Gamefic::Scene::Activity>]
5
8
  def default_scene
6
9
  @default_scene ||= Scene::Activity
@@ -29,13 +32,12 @@ module Gamefic
29
32
  # This method is typically called by the Engine that manages game execution.
30
33
  #
31
34
  # @param [Gamefic::Actor]
35
+ # @return [void]
32
36
  def introduce(player)
33
37
  player.playbooks.push playbook unless player.playbooks.include?(playbook)
34
38
  player.cue default_scene
35
39
  players.push player
36
- @introduction.call(player) unless @introduction.nil?
37
- # @todo Find a better way to persist player characters
38
- # Gamefic::Index.stick
40
+ @introduction&.call(player)
39
41
  end
40
42
 
41
43
  # Create a multiple-choice scene.
@@ -53,7 +55,7 @@ module Gamefic
53
55
  # @yieldparam [Gamefic::Scene::MultipleChoice]
54
56
  # @return [Class<Gamefic::Scene::MultipleChoice>]
55
57
  def multiple_choice *choices, &block
56
- s = Scene::MultipleChoice.subclass do |actor, scene|
58
+ s = Scene::MultipleChoice.subclass do |_actor, scene|
57
59
  scene.options.concat choices
58
60
  scene.on_finish &block
59
61
  end
@@ -73,12 +75,12 @@ module Gamefic
73
75
  # end
74
76
  # end
75
77
  #
76
- # @param prompt [String]
78
+ # @param prompt [String, nil]
77
79
  # @yieldparam [Gamefic::Actor]
78
80
  # @yieldparam [Gamefic::Scene::YesOrNo]
79
81
  # @return [Class<Gamefic::Scene::YesOrNo>]
80
82
  def yes_or_no prompt = nil, &block
81
- s = Scene::YesOrNo.subclass do |actor, scene|
83
+ s = Scene::YesOrNo.subclass do |_actor, scene|
82
84
  scene.prompt = prompt
83
85
  scene.on_finish &block
84
86
  end
@@ -98,7 +100,7 @@ module Gamefic
98
100
  # @yieldparam [Gamefic::Scene::Base]
99
101
  # @return [Class<Gamefic::Scene::Base>]
100
102
  def question prompt = 'What is your answer?', &block
101
- s = Scene::Base.subclass do |actor, scene|
103
+ s = Scene::Base.subclass do |_actor, scene|
102
104
  scene.prompt = prompt
103
105
  scene.on_finish &block
104
106
  end
@@ -116,13 +118,13 @@ module Gamefic
116
118
  # actor.prepare default_scene
117
119
  # end
118
120
  #
119
- # @param prompt [String] The text to display when prompting the user to continue.
121
+ # @param prompt [String, nil] The text to display when prompting the user to continue
120
122
  # @yieldparam [Gamefic::Actor]
121
123
  # @return [Class<Gamefic::Scene::Pause>]
122
124
  def pause prompt = nil, &block
123
125
  s = Scene::Pause.subclass do |actor, scene|
124
126
  scene.prompt = prompt unless prompt.nil?
125
- block.call(actor, scene) unless block.nil?
127
+ block&.call(actor, scene)
126
128
  end
127
129
  scene_classes.push s
128
130
  s
@@ -163,7 +165,7 @@ module Gamefic
163
165
  # end
164
166
  # end
165
167
  #
166
- # @param cls [Class] The class of scene to be instantiated.
168
+ # @param cls [Class<Scene::Base>] The class of scene to be instantiated.
167
169
  # @yieldparam [Gamefic::Actor]
168
170
  # @return [Class<Gamefic::Scene::Base>]
169
171
  def custom cls = Scene::Base, &block
@@ -208,10 +210,10 @@ module Gamefic
208
210
  # @return [Class<Gamefic::Scene::MultipleScene>]
209
211
  def multiple_scene map = {}, &block
210
212
  s = Scene::MultipleScene.subclass do |actor, scene|
211
- map.each_pair { |k, v|
213
+ map.each_pair do |k, v|
212
214
  scene.map k, v
213
- }
214
- block.call actor, scene unless block.nil?
215
+ end
216
+ block&.call actor, scene
215
217
  end
216
218
  scene_classes.push s
217
219
  s
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamefic
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-25 00:00:00.000000000 Z
11
+ date: 2023-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -70,6 +70,7 @@ executables: []
70
70
  extensions: []
71
71
  extra_rdoc_files: []
72
72
  files:
73
+ - ".github/workflows/rspec.yml"
73
74
  - ".gitignore"
74
75
  - ".rspec"
75
76
  - ".rubocop.yml"
@@ -142,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
143
  requirements:
143
144
  - - ">="
144
145
  - !ruby/object:Gem::Version
145
- version: 2.1.0
146
+ version: 2.3.0
146
147
  required_rubygems_version: !ruby/object:Gem::Requirement
147
148
  requirements:
148
149
  - - ">="