gamefic-standard 2.4.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +41 -40
- data/.rspec-opal +2 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +2 -0
- data/README.md +64 -60
- data/Rakefile +14 -6
- data/gamefic-standard.gemspec +6 -3
- data/lib/gamefic-standard/actions/attack.rb +28 -0
- data/lib/gamefic-standard/actions/close.rb +14 -10
- data/lib/gamefic-standard/actions/drop.rb +20 -16
- data/lib/gamefic-standard/actions/enter.rb +29 -19
- data/lib/gamefic-standard/actions/go.rb +51 -47
- data/lib/gamefic-standard/actions/help.rb +52 -0
- data/lib/gamefic-standard/actions/insert.rb +33 -29
- data/lib/gamefic-standard/actions/inventory.rb +12 -8
- data/lib/gamefic-standard/actions/leave.rb +43 -39
- data/lib/gamefic-standard/actions/lock.rb +21 -17
- data/lib/gamefic-standard/actions/look.rb +117 -96
- data/lib/gamefic-standard/actions/move.rb +24 -0
- data/lib/gamefic-standard/actions/nil.rb +16 -15
- data/lib/gamefic-standard/actions/open.rb +5 -5
- data/lib/gamefic-standard/actions/place.rb +4 -4
- data/lib/gamefic-standard/actions/quit.rb +4 -8
- data/lib/gamefic-standard/actions/repeat.rb +14 -0
- data/lib/gamefic-standard/actions/save-restore-undo.rb +18 -0
- data/lib/gamefic-standard/actions/search.rb +5 -5
- data/lib/gamefic-standard/actions/take.rb +15 -4
- data/lib/gamefic-standard/actions/talk.rb +16 -4
- data/lib/gamefic-standard/actions/unlock.rb +10 -6
- data/lib/gamefic-standard/actions/wait.rb +3 -1
- data/lib/gamefic-standard/actions.rb +5 -0
- data/lib/gamefic-standard/articles.rb +2 -7
- data/lib/gamefic-standard/direction.rb +2 -3
- data/lib/gamefic-standard/entities/container.rb +2 -0
- data/lib/gamefic-standard/entities/door.rb +2 -0
- data/lib/gamefic-standard/entities/fixture.rb +2 -1
- data/lib/gamefic-standard/entities/item.rb +2 -0
- data/lib/gamefic-standard/entities/portal.rb +2 -0
- data/lib/gamefic-standard/entities/receptacle.rb +2 -0
- data/lib/gamefic-standard/entities/room.rb +21 -36
- data/lib/gamefic-standard/entities/rubble.rb +2 -1
- data/lib/gamefic-standard/entities/scenery.rb +2 -0
- data/lib/gamefic-standard/entities/supporter.rb +2 -0
- data/lib/gamefic-standard/entities/thing.rb +2 -0
- data/lib/gamefic-standard/give.rb +15 -14
- data/lib/gamefic-standard/grammar/pronoun.rb +80 -80
- data/lib/gamefic-standard/introduction.rb +8 -0
- data/lib/gamefic-standard/modules/enterable.rb +2 -0
- data/lib/gamefic-standard/modules/lockable.rb +3 -1
- data/lib/gamefic-standard/modules/standardized.rb +10 -12
- data/lib/gamefic-standard/modules.rb +0 -1
- data/lib/gamefic-standard/queries.rb +7 -20
- data/lib/gamefic-standard/version.rb +1 -1
- data/lib/gamefic-standard.rb +26 -8
- data/spec-opal/spec_helper.rb +32 -0
- metadata +33 -13
- data/lib/gamefic-standard/modules/use.rb +0 -45
- data/lib/gamefic-standard/test.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c2ec7dc0f67d10c0539b74d735051ea02a42971a758b73b86ed393cfa9208e1
|
4
|
+
data.tar.gz: 8843dd046b42baac0c495a1da403bc4f5b6992f324360b4c66623aa2e3ae8e2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a4e56f9898345fa40c7b0743b5231fb4b18266644765e6e222c3aff884dc15f4f18707ae2cb0826c6cd1b6f5056f1347649a41a9480ec8601cefcbd6f1114d2
|
7
|
+
data.tar.gz: 3bfa5195316099738fe004bc29aec5f00782ccef7405324d452d0bcb644e2ea917866df37ef86a1879ec2fa68b8eae8c1ffeb0f181fe9aea1a648369232fcf73
|
data/.github/workflows/rspec.yml
CHANGED
@@ -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.
|
26
|
-
|
27
|
-
steps:
|
28
|
-
- uses: actions/checkout@v3
|
29
|
-
- name: Set up Ruby
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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.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
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
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
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
##
|
59
|
-
|
60
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
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
|
data/gamefic-standard.gemspec
CHANGED
@@ -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.
|
38
|
+
spec.required_ruby_version = '>= 2.7.0'
|
39
39
|
|
40
|
-
spec.
|
41
|
-
|
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
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
respond :drop, children do |actor, thing|
|
16
|
+
thing.parent = actor.parent
|
17
|
+
actor.tell "You drop #{the thing}."
|
18
|
+
end
|
17
19
|
|
18
|
-
|
19
|
-
|
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
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
13
|
+
respond :enter, parent do |actor, container|
|
14
|
+
actor.tell "You're already in #{the container}."
|
15
|
+
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
respond :enter, parent(Supporter) do |actor, supporter|
|
18
|
+
actor.tell "You're inside #{the supporter} already."
|
19
|
+
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
respond :enter, siblings(Container, proc(&:enterable?), proc(&:closed?)) do |actor, container|
|
22
|
+
actor.tell "#{The container} is closed."
|
23
|
+
end
|
22
24
|
|
23
|
-
|
24
|
-
|
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
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
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
|