gamefic-what 1.0.0 → 1.1.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: 26184e189b91fc9cb8e92ac66c9c26d3f76366128bfaab70a2e5c45ad48578ff
4
- data.tar.gz: 5d3c2424dbca05c0c97547972f4fd1d5243e437ba89d7d06427f7d9181edf384
3
+ metadata.gz: f40f2ea9dca315b67d9a59a7daa003655694a8f2bb0a218fb0779952c2e5f302
4
+ data.tar.gz: d5115b517c1f57c01b2c031f9f9e234814b376831bba9dd120ad585cb209957a
5
5
  SHA512:
6
- metadata.gz: 9dcf9bc8d1d9e7774846bc62343eb97bdae62f59f5999e01126e480bdc04fd169ffb42616700f1643ba7ad2ae0691c192c8ebf364dfd0c297691628c8805bd62
7
- data.tar.gz: eb07db1e55f4875bc34d0080e3dbac8df9b5e40ba14ce4747e53c38b610ebafad5f4065f6ce80ce8e576d0aa184f475261190bd77bfda43a3401676d7d48c23a
6
+ metadata.gz: 98cce3c727eb1e3fdc062894addd61b5e8e0df068b4182c1900bf3deb28747ded743258dde999ddc67b6b7e4905ad717afdb5f6cf370e4b47cae2361c353b46b
7
+ data.tar.gz: a89ab4ed46ec39098d1ae0ea2263c6036c3ec99cfb6eafa55cce52fcb74677365bcfc31f548807a1a435c5c21ff65d60fc281fc90e9288717d0f2a548987ba1a
data/CHANGELOG.md CHANGED
@@ -1,2 +1,9 @@
1
+ ## 1.1.0 - October 15, 2024
2
+ - Allow gamefic-4.0
3
+
4
+ ## 1.0.1 - October 7, 2024
5
+ - Answers reset asked_for_what
6
+ - Sanitize input
7
+
1
8
  ## 1.0.0 - September 24, 2024
2
9
  - First release
data/README.md CHANGED
@@ -1,70 +1,70 @@
1
- # Gamefic::What
2
-
3
- A Gamefic extension for expanding commands with an additional argument.
4
-
5
- This extension is included in `gamefic-standard`.
6
-
7
- ## Installation
8
-
9
- Add the library to your Gamefic project's Gemfile:
10
-
11
- ```
12
- gem 'gamefic-what'
13
- ```
14
-
15
- Run `bundle install`.
16
-
17
- Add the requirement to your project's code (typically in `main.rb`):
18
-
19
- ```
20
- require 'gamefic-what'
21
- ```
22
-
23
- ## Usage
24
-
25
- Example code:
26
-
27
- ```ruby
28
- class Gamefic::Actor
29
- include Gamefic::What::Askable
30
- end
31
-
32
- class MyPlot < Gamefic::Plot
33
- include Gamefic::What
34
-
35
- attr_seed :room, Gamefic::Entity, name: 'room'
36
- attr_seed :thing, Gamefic::Entity, name: 'thing'
37
-
38
- introduction do |actor|
39
- actor.parent = room
40
- thing.parent = room
41
- end
42
-
43
- respond :take, available do |actor, thing|
44
- thing.parent = actor
45
- actor.tell "You take #{thing}."
46
- end
47
-
48
- respond :take do |actor|
49
- actor.tell 'What do you want to take?'
50
- actor.ask_for_what 'take', nil
51
- end
52
- end
53
- ```
54
-
55
- Example gameplay:
56
-
57
- > take
58
- What do you want to take?
59
- > the thing
60
- You take a thing.
61
-
62
- ## Development
63
-
64
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
65
-
66
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
67
-
68
- ## Contributing
69
-
70
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gamefic-what.
1
+ # Gamefic::What
2
+
3
+ A Gamefic extension for expanding commands with an additional argument.
4
+
5
+ This extension is included in `gamefic-standard`.
6
+
7
+ ## Installation
8
+
9
+ Add the library to your Gamefic project's Gemfile:
10
+
11
+ ```
12
+ gem 'gamefic-what'
13
+ ```
14
+
15
+ Run `bundle install`.
16
+
17
+ Add the requirement to your project's code (typically in `main.rb`):
18
+
19
+ ```
20
+ require 'gamefic-what'
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ Example code:
26
+
27
+ ```ruby
28
+ class Gamefic::Actor
29
+ include Gamefic::What::Askable
30
+ end
31
+
32
+ class MyPlot < Gamefic::Plot
33
+ include Gamefic::What
34
+
35
+ attr_seed :room, Gamefic::Entity, name: 'room'
36
+ attr_seed :thing, Gamefic::Entity, name: 'thing'
37
+
38
+ introduction do |actor|
39
+ actor.parent = room
40
+ thing.parent = room
41
+ end
42
+
43
+ respond :take, available do |actor, thing|
44
+ thing.parent = actor
45
+ actor.tell "You take #{thing}."
46
+ end
47
+
48
+ respond :take do |actor|
49
+ actor.tell 'What do you want to take?'
50
+ actor.ask_for_what 'take', nil
51
+ end
52
+ end
53
+ ```
54
+
55
+ Example gameplay:
56
+
57
+ > take
58
+ What do you want to take?
59
+ > the thing
60
+ You take a thing.
61
+
62
+ ## Development
63
+
64
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
65
+
66
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gamefic-what.
data/gamefic-what.gemspec CHANGED
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
33
33
 
34
34
  # Uncomment to register a new dependency of your gem
35
35
  # spec.add_dependency "example-gem", "~> 1.0"
36
- spec.add_dependency 'gamefic', '~> 3.4'
36
+ spec.add_dependency 'gamefic', '>= 3.4'
37
37
 
38
38
  spec.add_development_dependency 'opal-rspec', '~> 1.0'
39
39
  spec.add_development_dependency 'opal-sprockets', '~> 1.0'
@@ -2,7 +2,26 @@
2
2
 
3
3
  module Gamefic
4
4
  module What
5
+ # A mixin for Active entities that enables
5
6
  module Askable
7
+ # Set a template to be populated with the player's answer.
8
+ #
9
+ # The template's placeholder for the answer can take two forms:
10
+ # 1. An array with a nil element: `ask_for_what :use, nil`
11
+ # 2. A `__what__` placeholder in a string: `ask_for_what "use __what__"`
12
+ #
13
+ # @example
14
+ # class Example::Plot < Gamefic::Plot
15
+ # respond :use, available do |actor, thing|
16
+ # actor.tell "You use #{the thing}."
17
+ # end
18
+ #
19
+ # respond :use do |actor|
20
+ # actor.tell "What do you want to use?"
21
+ # actor.ask_for_what :use, nil
22
+ # end
23
+ # end
24
+ #
6
25
  # @param tokens [String, Array<String, nil>]
7
26
  def ask_for_what(*tokens)
8
27
  @asking_for_what = [tokens].flatten
@@ -10,10 +29,16 @@ module Gamefic
10
29
 
11
30
  attr_reader :asked_for_what
12
31
 
13
- def set_asked_for_what
32
+ def answer_for_what(text = nil)
33
+ text = text&.gsub('__what__', 'what') # "Don't recurse" -- Heavy D.
34
+ command = text && asked_for_what&.map { |token| token || text }
35
+ &.join(' ')
36
+ &.gsub('__what__', text)
14
37
  @asked_for_what = @asking_for_what
15
38
  @asking_for_what = nil
39
+ command
16
40
  end
41
+ alias set_asked_for_what answer_for_what
17
42
  end
18
43
  end
19
44
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Gamefic
4
4
  module What
5
- VERSION = '1.0.0'
5
+ VERSION = '1.1.0'
6
6
  end
7
7
  end
data/lib/gamefic/what.rb CHANGED
@@ -1,25 +1,22 @@
1
- # frozen_string_literal: true
2
-
3
- require 'gamefic/what/askable'
4
- require 'gamefic/what/version'
5
-
6
- module Gamefic
7
- # A Gamefic extension for expanding commands with an additional argument.
8
- #
9
- module What
10
- extend Gamefic::Scriptable
11
-
12
- on_player_update(&:set_asked_for_what)
13
-
14
- respond nil, plaintext do |actor, text|
15
- if actor.asked_for_what
16
- actor.perform actor.asked_for_what
17
- .map { |part| part ? part.to_s : text }
18
- .join(' ')
19
- .gsub('__what__', text)
20
- else
21
- actor.proceed
22
- end
23
- end
24
- end
25
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'gamefic/what/askable'
4
+ require 'gamefic/what/version'
5
+
6
+ module Gamefic
7
+ # A Gamefic extension for expanding commands with an additional argument.
8
+ #
9
+ module What
10
+ extend Gamefic::Scriptable
11
+
12
+ on_player_update(&:answer_for_what)
13
+
14
+ respond nil, plaintext do |actor, text|
15
+ if (command = actor.answer_for_what(text))
16
+ actor.perform command
17
+ else
18
+ actor.proceed
19
+ end
20
+ end
21
+ end
22
+ end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamefic-what
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-24 00:00:00.000000000 Z
11
+ date: 2024-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gamefic
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.4'
27
27
  - !ruby/object:Gem::Dependency