gamefic-standard 2.4.0 → 3.0.0

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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rspec.yml +41 -40
  3. data/.rspec-opal +2 -0
  4. data/CHANGELOG.md +3 -0
  5. data/Gemfile +2 -0
  6. data/README.md +64 -60
  7. data/Rakefile +14 -6
  8. data/gamefic-standard.gemspec +6 -3
  9. data/lib/gamefic-standard/actions/attack.rb +28 -0
  10. data/lib/gamefic-standard/actions/close.rb +14 -10
  11. data/lib/gamefic-standard/actions/drop.rb +20 -16
  12. data/lib/gamefic-standard/actions/enter.rb +29 -19
  13. data/lib/gamefic-standard/actions/go.rb +51 -47
  14. data/lib/gamefic-standard/actions/help.rb +52 -0
  15. data/lib/gamefic-standard/actions/insert.rb +33 -29
  16. data/lib/gamefic-standard/actions/inventory.rb +12 -8
  17. data/lib/gamefic-standard/actions/leave.rb +43 -39
  18. data/lib/gamefic-standard/actions/lock.rb +21 -17
  19. data/lib/gamefic-standard/actions/look.rb +117 -96
  20. data/lib/gamefic-standard/actions/move.rb +24 -0
  21. data/lib/gamefic-standard/actions/nil.rb +16 -15
  22. data/lib/gamefic-standard/actions/open.rb +5 -5
  23. data/lib/gamefic-standard/actions/place.rb +4 -4
  24. data/lib/gamefic-standard/actions/quit.rb +4 -8
  25. data/lib/gamefic-standard/actions/repeat.rb +14 -0
  26. data/lib/gamefic-standard/actions/save-restore-undo.rb +18 -0
  27. data/lib/gamefic-standard/actions/search.rb +5 -5
  28. data/lib/gamefic-standard/actions/take.rb +15 -4
  29. data/lib/gamefic-standard/actions/talk.rb +16 -4
  30. data/lib/gamefic-standard/actions/unlock.rb +10 -6
  31. data/lib/gamefic-standard/actions/wait.rb +3 -1
  32. data/lib/gamefic-standard/actions.rb +5 -0
  33. data/lib/gamefic-standard/articles.rb +2 -7
  34. data/lib/gamefic-standard/direction.rb +2 -3
  35. data/lib/gamefic-standard/entities/container.rb +2 -0
  36. data/lib/gamefic-standard/entities/door.rb +2 -0
  37. data/lib/gamefic-standard/entities/fixture.rb +2 -1
  38. data/lib/gamefic-standard/entities/item.rb +2 -0
  39. data/lib/gamefic-standard/entities/portal.rb +2 -0
  40. data/lib/gamefic-standard/entities/receptacle.rb +2 -0
  41. data/lib/gamefic-standard/entities/room.rb +21 -36
  42. data/lib/gamefic-standard/entities/rubble.rb +2 -1
  43. data/lib/gamefic-standard/entities/scenery.rb +2 -0
  44. data/lib/gamefic-standard/entities/supporter.rb +2 -0
  45. data/lib/gamefic-standard/entities/thing.rb +2 -0
  46. data/lib/gamefic-standard/give.rb +15 -14
  47. data/lib/gamefic-standard/grammar/pronoun.rb +80 -80
  48. data/lib/gamefic-standard/introduction.rb +8 -0
  49. data/lib/gamefic-standard/modules/enterable.rb +2 -0
  50. data/lib/gamefic-standard/modules/lockable.rb +3 -1
  51. data/lib/gamefic-standard/modules/standardized.rb +10 -12
  52. data/lib/gamefic-standard/modules.rb +0 -1
  53. data/lib/gamefic-standard/queries.rb +7 -20
  54. data/lib/gamefic-standard/version.rb +1 -1
  55. data/lib/gamefic-standard.rb +26 -8
  56. data/spec-opal/spec_helper.rb +32 -0
  57. metadata +33 -13
  58. data/lib/gamefic-standard/modules/use.rb +0 -45
  59. data/lib/gamefic-standard/test.rb +0 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6abba8f34782d5cfb4beee5d43dc31f155b535da326b385d7404e939d3920c6e
4
- data.tar.gz: 938d1bdcdbf488ee44531fcc00df5de29c4979869986c5ddbc3e7e479ae8e6bf
3
+ metadata.gz: 6c2ec7dc0f67d10c0539b74d735051ea02a42971a758b73b86ed393cfa9208e1
4
+ data.tar.gz: 8843dd046b42baac0c495a1da403bc4f5b6992f324360b4c66623aa2e3ae8e2a
5
5
  SHA512:
6
- metadata.gz: 8b21f6722f5247b3881bc3d056e77838de488f3d907114234a6c3737a9b37f6a7373d62dc1337a83a5c1e46f022e1cc7dd90f5c55c09043010e07ac814d01a97
7
- data.tar.gz: 3ea46e35b5f526854c8666f1dee03a5d72f77995dc2cdf803ae6f5b26b07bc619e698b9fc14b1f2c8082924d10cbe4a4ca219ac3db8b08210668c46a5b4cf1e9
6
+ metadata.gz: 6a4e56f9898345fa40c7b0743b5231fb4b18266644765e6e222c3aff884dc15f4f18707ae2cb0826c6cd1b6f5056f1347649a41a9480ec8601cefcbd6f1114d2
7
+ data.tar.gz: 3bfa5195316099738fe004bc29aec5f00782ccef7405324d452d0bcb644e2ea917866df37ef86a1879ec2fa68b8eae8c1ffeb0f181fe9aea1a648369232fcf73
@@ -1,40 +1,41 @@
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
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.7', '3.0', '3.1']
26
+
27
+ steps:
28
+ - uses: actions/checkout@v3
29
+ - name: Set up Ruby
30
+ uses: ruby/setup-ruby@v1
31
+ with:
32
+ ruby-version: ${{ matrix.ruby-version }}
33
+ bundler-cache: false
34
+ - name: Set up Node
35
+ uses: actions/setup-node@v3
36
+ - name: Install dependencies
37
+ run: bundle install
38
+ - name: Run tests
39
+ run: bundle exec rspec
40
+ - name: Run tests
41
+ run: bundle exec rake opal
data/.rspec-opal ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 3.0.0 - January 27, 2024
2
+ - Updates for Gamefic 3.0
3
+
1
4
  ## 2.4.0 - February 11, 2023
2
5
  - Change Actor#perform to Actor#execute
3
6
  - Update gamefic dependency
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in gamefic-standard.gemspec
4
4
  gemspec
5
+
6
+ gem 'gamefic', git: 'https://github.com/castwide/gamefic.git', branch: 'v3'
data/README.md CHANGED
@@ -1,60 +1,64 @@
1
- # Gamefic Standard
2
-
3
- The standard library for the Gamefic interactive fiction framework.
4
-
5
- Gamefic Standard provides common useful components for adventure games. [Inform](http://inform7.com/)
6
- developers should find it similar to Inform's Standard Rules. It defines common
7
- components like Rooms and Characters, along with in-game commands like `GO`,
8
- `GET`, and `DROP` to enable basic interactivity.
9
-
10
- ## Installation
11
-
12
- Add this line to your application's Gemfile:
13
-
14
- ```ruby
15
- gem 'gamefic-standard'
16
- ```
17
-
18
- And then execute:
19
-
20
- $ bundle
21
-
22
- Or install it yourself as:
23
-
24
- $ gem install gamefic-standard
25
-
26
- ## Usage
27
-
28
- Require the library in your game scripts:
29
-
30
- ```ruby
31
- require 'gamefic'
32
- require 'gamefic-standard'
33
-
34
- Gamefic.script do
35
- @office = make Room, name: 'office'
36
- @desk = make Fixture, name: 'desk', parent: @office
37
-
38
- introduction do |actor|
39
- actor.parent = @office
40
- actor.tell "You're in an office."
41
- end
42
- end
43
- ```
44
-
45
- Go to the [Gamefic website](https://gamefic.com) or the [SDK repo](https://github.com/castwide/gamefic-sdk)
46
- for more information about using Gamefic.
47
-
48
- ## Development
49
-
50
- 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.
51
-
52
- 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
53
-
54
- ## Contributing
55
-
56
- Bug reports and pull requests are welcome on GitHub at https://github.com/castwide/gamefic-standard.
57
-
58
- ## License
59
-
60
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
1
+ # Gamefic Standard
2
+
3
+ The standard library for the Gamefic interactive fiction framework.
4
+
5
+ Gamefic Standard provides common useful components for adventure games. [Inform](http://inform7.com/)
6
+ developers should find it similar to Inform's Standard Rules. It defines common
7
+ components like Rooms and Characters, along with in-game commands like `GO`,
8
+ `GET`, and `DROP` to enable basic interactivity.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'gamefic-standard'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install gamefic-standard
25
+
26
+ ## Usage
27
+
28
+ Require the library in your game scripts:
29
+
30
+ ```ruby
31
+ require 'gamefic'
32
+ require 'gamefic-standard'
33
+
34
+ class MyPlot < Gamefic::Plot
35
+ seed do
36
+ @office = make Room, name: 'office'
37
+ @desk = make Fixture, name: 'desk', parent: @office
38
+ end
39
+
40
+ script do
41
+ introduction do |actor|
42
+ actor.parent = @office
43
+ actor.tell "You're in an office."
44
+ end
45
+ end
46
+ end
47
+ ```
48
+
49
+ Go to the [Gamefic website](https://gamefic.com) or the [SDK repo](https://github.com/castwide/gamefic-sdk)
50
+ for more information about using Gamefic.
51
+
52
+ ## Development
53
+
54
+ 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.
55
+
56
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
57
+
58
+ ## Contributing
59
+
60
+ Bug reports and pull requests are welcome on GitHub at https://github.com/castwide/gamefic-standard.
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,6 +1,14 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require 'opal/rspec/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
8
+
9
+ Opal::RSpec::RakeTask.new(:opal) do |_, config|
10
+ Opal.append_path File.expand_path('../lib', __FILE__)
11
+ Opal.use_gem('gamefic')
12
+ config.pattern = 'spec/**/*_spec.rb'
13
+ config.requires = ['spec_helper']
14
+ end
@@ -35,10 +35,13 @@ Gem::Specification.new do |spec|
35
35
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
36
  spec.require_paths = ["lib"]
37
37
 
38
- spec.add_dependency 'gamefic', '~> 2.4'
38
+ spec.required_ruby_version = '>= 2.7.0'
39
39
 
40
- spec.add_development_dependency 'bundler', '~> 2.0'
41
- spec.add_development_dependency 'rake', '~> 10.0'
40
+ spec.add_dependency 'gamefic', '~> 3.0'
41
+
42
+ spec.add_development_dependency 'opal', '~> 1.7'
43
+ spec.add_development_dependency 'opal-rspec', '~> 1.0'
44
+ spec.add_development_dependency 'opal-sprockets', '~> 1.0'
42
45
  spec.add_development_dependency 'rspec', '~> 3.0'
43
46
  spec.add_development_dependency 'simplecov', '~> 0.14'
44
47
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gamefic
4
+ module Standard
5
+ script do
6
+ respond :attack do |actor, thing|
7
+ actor.tell "Violence is not the answer here."
8
+ end
9
+
10
+ respond :attack, Thing do |actor, _thing|
11
+ actor.execute :attack
12
+ end
13
+
14
+ interpret 'fight', 'attack'
15
+ interpret 'battle', 'attack'
16
+ interpret 'kill', 'attack'
17
+ interpret 'punch', 'attack'
18
+ interpret 'kick', 'attack'
19
+ interpret 'hit', 'attack'
20
+ interpret 'fight :thing', 'attack :thing'
21
+ interpret 'battle :thing', 'attack :thing'
22
+ interpret 'kill :thing', 'attack :thing'
23
+ interpret 'punch :thing', 'attack :thing'
24
+ interpret 'kick :thing', 'attack :thing'
25
+ interpret 'hit :thing', 'attack :thing'
26
+ end
27
+ end
28
+ end
@@ -1,14 +1,18 @@
1
- Gamefic.script do
2
- respond :close, Use.available do |actor, thing|
3
- actor.tell "You can't close #{the thing}."
4
- end
1
+ module Gamefic
2
+ module Standard
3
+ script do
4
+ respond :close, available do |actor, thing|
5
+ actor.tell "You can't close #{the thing}."
6
+ end
5
7
 
6
- respond :close, Use.available(Openable) do |actor, thing|
7
- if thing.open?
8
- actor.tell "You close #{the thing}."
9
- thing.open = false
10
- else
11
- actor.tell "#{The thing} is already closed."
8
+ respond :close, available(Openable) do |actor, thing|
9
+ if thing.open?
10
+ actor.tell "You close #{the thing}."
11
+ thing.open = false
12
+ else
13
+ actor.tell "#{The thing} is already closed."
14
+ end
15
+ end
12
16
  end
13
17
  end
14
18
  end
@@ -1,20 +1,24 @@
1
- Gamefic.script do
2
- respond :drop, Use.available do |actor, thing|
3
- actor.tell "You're not carrying #{the thing}."
4
- end
1
+ module Gamefic
2
+ module Standard
3
+ script do
4
+ respond :drop, available do |actor, thing|
5
+ actor.tell "You're not carrying #{the thing}."
6
+ end
5
7
 
6
- respond :drop, Gamefic::Query::Descendants.new do |actor, thing|
7
- actor.execute :take, thing
8
- next unless thing.parent == actor
9
- thing.parent = actor.parent
10
- actor.tell "You drop #{the thing}."
11
- end
8
+ respond :drop, children do |actor, thing|
9
+ actor.execute :take, thing
10
+ next unless thing.parent == actor
11
+ thing.parent = actor.parent
12
+ actor.tell "You drop #{the thing}."
13
+ end
12
14
 
13
- respond :drop, Use.children do |actor, thing|
14
- thing.parent = actor.parent
15
- actor.tell "You drop #{the thing}."
16
- end
15
+ respond :drop, children do |actor, thing|
16
+ thing.parent = actor.parent
17
+ actor.tell "You drop #{the thing}."
18
+ end
17
19
 
18
- interpret "put down :thing", "drop :thing"
19
- interpret "put :thing down", "drop :thing"
20
+ interpret "put down :thing", "drop :thing"
21
+ interpret "put :thing down", "drop :thing"
22
+ end
23
+ end
20
24
  end
@@ -1,25 +1,35 @@
1
- Gamefic.script do
2
- respond :enter, Use.siblings do |actor, thing|
3
- actor.tell "#{The thing} can't accommodate you."
4
- end
1
+ module Gamefic
2
+ module Standard
3
+ script do
4
+ respond :enter, siblings do |actor, thing|
5
+ actor.tell "#{The thing} can't accommodate you."
6
+ end
5
7
 
6
- respond :enter, Use.siblings(Enterable, :enterable?) do |actor, supporter|
7
- actor.parent = supporter
8
- actor.tell "You get in #{the supporter}."
9
- end
8
+ respond :enter, siblings(Enterable, proc(&:enterable?)) do |actor, supporter|
9
+ actor.parent = supporter
10
+ actor.tell "You get in #{the supporter}."
11
+ end
10
12
 
11
- respond :enter, Use.parent do |actor, container|
12
- actor.tell "You're already in #{the container}."
13
- end
13
+ respond :enter, parent do |actor, container|
14
+ actor.tell "You're already in #{the container}."
15
+ end
14
16
 
15
- respond :enter, Use.parent(Supporter) do |actor, supporter|
16
- actor.tell "You're inside #{the supporter} already."
17
- end
17
+ respond :enter, parent(Supporter) do |actor, supporter|
18
+ actor.tell "You're inside #{the supporter} already."
19
+ end
18
20
 
19
- respond :enter, Use.siblings(Container, :enterable?, :closed?) do |actor, container|
20
- actor.tell "#{The container} is closed."
21
- end
21
+ respond :enter, siblings(Container, proc(&:enterable?), proc(&:closed?)) do |actor, container|
22
+ actor.tell "#{The container} is closed."
23
+ end
22
24
 
23
- interpret "get on :thing", "enter :thing"
24
- interpret "get in :thing", "enter :thing"
25
+ interpret "get on :thing", "enter :thing"
26
+ interpret "get in :thing", "enter :thing"
27
+ interpret "sit on :thing", "enter :thing"
28
+ interpret "sit in :thing", "enter :thing"
29
+ interpret "lie on :thing", "enter :thing"
30
+ interpret "lie in :thing", "enter :thing"
31
+ interpret "stand on :thing", "enter :thing"
32
+ interpret "stand in :thing", "enter :thing"
33
+ end
34
+ end
25
35
  end
@@ -1,55 +1,59 @@
1
- Gamefic.script do
2
- respond :go, Use.siblings(Portal) do |actor, portal|
3
- if portal.destination.nil?
4
- actor.tell "That portal leads nowhere."
5
- else
6
- actor.parent = portal.destination
7
- if !portal.direction.nil?
8
- actor.tell "You go #{portal.direction}."
1
+ module Gamefic
2
+ module Standard
3
+ script do
4
+ respond :go, siblings(Portal) do |actor, portal|
5
+ if portal.destination.nil?
6
+ actor.tell "That portal leads nowhere."
7
+ else
8
+ actor.parent = portal.destination
9
+ if !portal.direction.nil?
10
+ actor.tell "You go #{portal.direction}."
11
+ end
12
+ actor.execute :look
13
+ end
9
14
  end
10
- actor.execute :look
11
- end
12
- end
13
15
 
14
- respond :go, Use.text do |actor, text|
15
- if actor.parent == actor.room
16
- actor.tell "I don't see any way to go \"#{text} from here."
17
- else
18
- actor.execute :leave
19
- if actor.parent == actor.room
20
- actor.perform "go #{text}"
21
- else
22
- actor.proceed
16
+ respond :go, plaintext do |actor, text|
17
+ if actor.parent == actor.room
18
+ actor.tell "I don't see any way to go \"#{text}\" from here."
19
+ else
20
+ actor.execute :leave
21
+ if actor.parent == actor.room
22
+ actor.perform "go #{text}"
23
+ else
24
+ actor.proceed
25
+ end
26
+ end
23
27
  end
24
- end
25
- end
26
28
 
27
- respond :go, Use.available(Door) do |actor, door|
28
- actor.execute :open, door unless door.open?
29
- actor.proceed if door.open?
30
- end
29
+ respond :go, available(Door) do |actor, door|
30
+ actor.execute :open, door unless door.open?
31
+ actor.proceed if door.open?
32
+ end
31
33
 
32
- interpret "north", "go north"
33
- interpret "south", "go south"
34
- interpret "west", "go west"
35
- interpret "east", "go east"
36
- interpret "up", "go up"
37
- interpret "down", "go down"
38
- interpret "northwest", "go northwest"
39
- interpret "northeast", "go northeast"
40
- interpret "southwest", "go southwest"
41
- interpret "southeast", "go southeast"
34
+ interpret "north", "go north"
35
+ interpret "south", "go south"
36
+ interpret "west", "go west"
37
+ interpret "east", "go east"
38
+ interpret "up", "go up"
39
+ interpret "down", "go down"
40
+ interpret "northwest", "go northwest"
41
+ interpret "northeast", "go northeast"
42
+ interpret "southwest", "go southwest"
43
+ interpret "southeast", "go southeast"
42
44
 
43
- interpret "n", "go north"
44
- interpret "s", "go south"
45
- interpret "w", "go west"
46
- interpret "e", "go east"
47
- interpret "u", "go up"
48
- interpret "d", "go down"
49
- interpret "nw", "go northwest"
50
- interpret "ne", "go northeast"
51
- interpret "sw", "go southwest"
52
- interpret "se", "go southeast"
45
+ interpret "n", "go north"
46
+ interpret "s", "go south"
47
+ interpret "w", "go west"
48
+ interpret "e", "go east"
49
+ interpret "u", "go up"
50
+ interpret "d", "go down"
51
+ interpret "nw", "go northwest"
52
+ interpret "ne", "go northeast"
53
+ interpret "sw", "go southwest"
54
+ interpret "se", "go southeast"
53
55
 
54
- interpret "go to :place", "go :place"
56
+ interpret "go to :place", "go :place"
57
+ end
58
+ end
55
59
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gamefic
4
+ module Standard
5
+ script do
6
+ respond :verbs do |actor|
7
+ list = rulebook.synonyms.reject { |syn| syn.to_s.start_with?('_') }
8
+ .map { |syn| "<kbd>#{syn}</kbd>"}
9
+ .join_and
10
+ actor.tell "I understand the following commands: #{list}."
11
+ actor.tell "Try using commands in plain sentences like <kbd>go north</kbd> or <kbd>take the coin</kbd>."
12
+ actor.tell "For more information about a specific command, try <kbd>help [command]</kbd>, e.g., <kbd>help go</kbd>."
13
+ end
14
+
15
+ interpret 'commands', 'verbs'
16
+ interpret 'help', 'verbs'
17
+
18
+ respond :help, plaintext do |actor, command|
19
+ if rulebook.synonyms.include?(command.to_sym) && !command.start_with?('_')
20
+ available = rulebook.syntaxes.select { |syntax| syntax.synonym == command.to_sym }
21
+ .uniq(&:signature)
22
+ examples = available.map(&:template)
23
+ .map do |tmpl|
24
+ tmpl.text
25
+ .gsub(/:character/i, '[someone]')
26
+ .gsub(/:var[0-9]?/i, '[something]')
27
+ .gsub(/:([a-z0-9]+)/i, "[\\1]")
28
+ end
29
+ .reject { |tmpl| tmpl.include?('[something] [something]') }
30
+ actor.tell 'Examples:'
31
+ actor.stream '<ul>'
32
+ examples.each do |xmpl|
33
+ actor.stream "<li><kbd>#{xmpl}</kbd></li>"
34
+ end
35
+ actor.stream '</ul>'
36
+ related = available.map(&:verb)
37
+ .uniq
38
+ .that_are_not(command.to_sym)
39
+ .sort
40
+ .map { |sym| "<kbd>#{sym}</kbd>"}
41
+ next if related.empty?
42
+
43
+ actor.tell "Related: #{related.join(', ')}"
44
+ elsif command =~ /[^a-z]/i
45
+ actor.tell "Try asking for help with a specific command, e.g., <kbd>help go</kbd>"
46
+ else
47
+ actor.tell "\"#{command.cap_first}\" is not a verb I understand."
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end