gamefic-what 1.1.0 → 2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +2 -6
- data/Rakefile +3 -2
- data/gamefic-what.gemspec +1 -1
- data/lib/gamefic/what/version.rb +1 -1
- data/lib/gamefic/what.rb +46 -8
- metadata +6 -7
- data/lib/gamefic/what/askable.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8f3c7e689ff251e6777f362bf424d493eb988cfccf47e95319fc0b216b2ddc5
|
4
|
+
data.tar.gz: 2cf0bfae41be0deb822d904f4745dd4270d4479fe782ee62052ae19e0c6d9fce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55f502bfbacb9b03c187b909f0197be357246810171fddc969499380c3c3472a7f9e68d27dd06c79476081723c841a59ddd2daa61379e3d9b57e590a88f320a2
|
7
|
+
data.tar.gz: 5cfa5f94b033640c715435fe39cbca5507e9bc656cf46a5656751c350a534ba254ccb654d40a32d552265a01094766eb698657fc9716fe8f62119da7aa0b72a6
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -25,10 +25,6 @@ require 'gamefic-what'
|
|
25
25
|
Example code:
|
26
26
|
|
27
27
|
```ruby
|
28
|
-
class Gamefic::Actor
|
29
|
-
include Gamefic::What::Askable
|
30
|
-
end
|
31
|
-
|
32
28
|
class MyPlot < Gamefic::Plot
|
33
29
|
include Gamefic::What
|
34
30
|
|
@@ -47,7 +43,7 @@ class MyPlot < Gamefic::Plot
|
|
47
43
|
|
48
44
|
respond :take do |actor|
|
49
45
|
actor.tell 'What do you want to take?'
|
50
|
-
actor.
|
46
|
+
actor.cue AskForWhat, template: 'take __what__'
|
51
47
|
end
|
52
48
|
end
|
53
49
|
```
|
@@ -57,7 +53,7 @@ Example gameplay:
|
|
57
53
|
> take
|
58
54
|
What do you want to take?
|
59
55
|
> the thing
|
60
|
-
You take
|
56
|
+
You take the thing.
|
61
57
|
|
62
58
|
## Development
|
63
59
|
|
data/Rakefile
CHANGED
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', '
|
36
|
+
spec.add_dependency 'gamefic', '~> 4.0'
|
37
37
|
|
38
38
|
spec.add_development_dependency 'opal-rspec', '~> 1.0'
|
39
39
|
spec.add_development_dependency 'opal-sprockets', '~> 1.0'
|
data/lib/gamefic/what/version.rb
CHANGED
data/lib/gamefic/what.rb
CHANGED
@@ -1,21 +1,59 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'gamefic/what/askable'
|
4
3
|
require 'gamefic/what/version'
|
5
4
|
|
6
5
|
module Gamefic
|
7
6
|
# A Gamefic extension for expanding commands with an additional argument.
|
8
7
|
#
|
9
8
|
module What
|
10
|
-
|
9
|
+
# Perform a command based on the player's answer for what an object of the
|
10
|
+
# previous command should be.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# class MyPlot < Gamefic::Plot
|
14
|
+
# include Gamefic::What
|
15
|
+
#
|
16
|
+
# construct :room, Gamefic::Entity, name: 'room'
|
17
|
+
# construct :thing, Gamefic::Entity, name: 'thing', parent: room
|
18
|
+
#
|
19
|
+
# introduction do |actor|
|
20
|
+
# actor.parent = room
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# respond :take, Gamefic::Entity do |actor, thing|
|
24
|
+
# thing.parent = actor
|
25
|
+
# actor.tell "You take it."
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# respond :take do |actor|
|
29
|
+
# actor.tell 'What do you want to take?'
|
30
|
+
# actor.cue AskForWhat, template: 'take __what__'
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
class AskForWhat < Gamefic::Scene::Base
|
35
|
+
def finish
|
36
|
+
if command_with_answer_actions.empty? && actor.can?(props.input.keywords.first)
|
37
|
+
actor.perform(props.input)
|
38
|
+
else
|
39
|
+
actor.perform command_with_answer
|
40
|
+
end
|
41
|
+
super
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
11
45
|
|
12
|
-
|
46
|
+
def command_with_answer
|
47
|
+
return nil unless props.input
|
48
|
+
|
49
|
+
@command_with_answer ||= context[:template].to_s
|
50
|
+
.gsub('__what__', props.input)
|
51
|
+
end
|
13
52
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
actor.proceed
|
53
|
+
def command_with_answer_actions
|
54
|
+
Gamefic::Request.new(actor, command_with_answer)
|
55
|
+
.to_actions
|
56
|
+
.select(&:verb)
|
19
57
|
end
|
20
58
|
end
|
21
59
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gamefic-what
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.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:
|
11
|
+
date: 2025-01-25 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
|
-
version: '
|
19
|
+
version: '4.0'
|
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
|
-
version: '
|
26
|
+
version: '4.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: opal-rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,7 +108,6 @@ files:
|
|
108
108
|
- gamefic-what.gemspec
|
109
109
|
- lib/gamefic-what.rb
|
110
110
|
- lib/gamefic/what.rb
|
111
|
-
- lib/gamefic/what/askable.rb
|
112
111
|
- lib/gamefic/what/version.rb
|
113
112
|
- sig/gamefic/what.rbs
|
114
113
|
homepage: https://gamefic.com
|
data/lib/gamefic/what/askable.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Gamefic
|
4
|
-
module What
|
5
|
-
# A mixin for Active entities that enables
|
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
|
-
#
|
25
|
-
# @param tokens [String, Array<String, nil>]
|
26
|
-
def ask_for_what(*tokens)
|
27
|
-
@asking_for_what = [tokens].flatten
|
28
|
-
end
|
29
|
-
|
30
|
-
attr_reader :asked_for_what
|
31
|
-
|
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)
|
37
|
-
@asked_for_what = @asking_for_what
|
38
|
-
@asking_for_what = nil
|
39
|
-
command
|
40
|
-
end
|
41
|
-
alias set_asked_for_what answer_for_what
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|