gamefic-what 1.0.0 → 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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +70 -70
- data/lib/gamefic/what/askable.rb +26 -1
- data/lib/gamefic/what/version.rb +1 -1
- data/lib/gamefic/what.rb +22 -25
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d9e9905a8d2e90f47f0e908036b534ceb215f25d819691d9cda6c924c3cd43b
|
4
|
+
data.tar.gz: 99ce298f2dff13991b9389b7b2954e513b419cfc333b3a84282659dfff42aceb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 799be61910dcdb1ed0835019152eb0f066becc5b167a68a6bc61388a1b180900eb46ef48aa029b766f3e1c16c9ca4a15472ba7cf2937416e3f29ca2c932cb9f9
|
7
|
+
data.tar.gz: 586b62b7d239c541e15b47d5672171a47f26ddedf67bbf1afc3c86ead1e981d830f3b94fe4722dbf767d4b3d4ca00fe9a15002cbe2b78acbfda6a897f581a7e9
|
data/CHANGELOG.md
CHANGED
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/lib/gamefic/what/askable.rb
CHANGED
@@ -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
|
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
|
data/lib/gamefic/what/version.rb
CHANGED
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(&:
|
13
|
-
|
14
|
-
respond nil, plaintext do |actor, text|
|
15
|
-
if actor.
|
16
|
-
actor.perform
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gamefic-what
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
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-
|
11
|
+
date: 2024-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gamefic
|