gamefic-commodities 0.1.0 → 1.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 +4 -0
- data/README.md +13 -4
- data/Rakefile +3 -2
- data/gamefic-commodities.gemspec +2 -2
- data/lib/gamefic/commodities/actions.rb +31 -42
- data/lib/gamefic/commodities/commodity.rb +1 -3
- data/lib/gamefic/commodities/quantity_scanner.rb +26 -0
- data/lib/gamefic/commodities/utils.rb +17 -9
- data/lib/gamefic/commodities/version.rb +1 -1
- data/lib/gamefic/commodities.rb +2 -2
- metadata +8 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2f8318cc02457f9206f71ea84788b5ecd36353cefa24a8a5ba00f3dc0a964574
|
|
4
|
+
data.tar.gz: 0eb3639a2a1e6cfb7e36adb064e1ca889bb2f0a900dec8d82538590cdd8206a5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b3606bf2ee4760ddbdbf48f2d3653082b403e0bb0e0c818b17fdecacd06e645978744981aa77e9dc61f8f976c0d8209ba691756ed527e108f46edf8a85a0d157
|
|
7
|
+
data.tar.gz: cdb59be4c8f1ddef105fd04bc9490e507617fd0d6d4673118f69b18a2d042d279d66786b8ae30d8f97f8729a078c0b5005d7b41c6ad8205ed9009234755ff439
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -13,7 +13,7 @@ Players can specify quantities in commands, e.g., `take 1 coin`.
|
|
|
13
13
|
|
|
14
14
|
Add the library to your Gamefic project's Gemfile:
|
|
15
15
|
|
|
16
|
-
```
|
|
16
|
+
```ruby
|
|
17
17
|
gem 'gamefic-commodities'
|
|
18
18
|
```
|
|
19
19
|
|
|
@@ -21,10 +21,19 @@ Run `bundle install`.
|
|
|
21
21
|
|
|
22
22
|
Add the requirement to your project's code (typically in `main.rb`):
|
|
23
23
|
|
|
24
|
-
```
|
|
24
|
+
```ruby
|
|
25
25
|
require 'gamefic-commodities'
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
Include the module in your project's plot:
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
class Example < Gamefic::Plot
|
|
32
|
+
include Gamefic::Standard
|
|
33
|
+
include Gamefic::Commodities
|
|
34
|
+
end
|
|
35
|
+
```
|
|
36
|
+
|
|
28
37
|
## Usage
|
|
29
38
|
|
|
30
39
|
The `Commodity` entity and related actions are automatically imported into `Gamefic::Standard`.
|
|
@@ -35,13 +44,13 @@ Example of adding a commodity:
|
|
|
35
44
|
class Example::Plot < Gamefic::Plot
|
|
36
45
|
include Gamefic::Standard
|
|
37
46
|
|
|
38
|
-
|
|
47
|
+
construct :room, Room,
|
|
39
48
|
name: 'room'
|
|
40
49
|
|
|
41
50
|
make_seed Commodity,
|
|
42
51
|
name: 'coin',
|
|
43
52
|
quantity: 2,
|
|
44
|
-
parent:
|
|
53
|
+
parent: room
|
|
45
54
|
|
|
46
55
|
introduction do |actor|
|
|
47
56
|
actor.parent = room
|
data/Rakefile
CHANGED
data/gamefic-commodities.gemspec
CHANGED
|
@@ -33,8 +33,8 @@ 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', '~>
|
|
37
|
-
spec.add_dependency 'gamefic-standard', '~>
|
|
36
|
+
spec.add_dependency 'gamefic', '~> 4.0'
|
|
37
|
+
spec.add_dependency 'gamefic-standard', '~> 4.0'
|
|
38
38
|
|
|
39
39
|
spec.add_development_dependency 'opal', '~> 1.7'
|
|
40
40
|
spec.add_development_dependency 'opal-rspec', '~> 1.0'
|
|
@@ -5,7 +5,9 @@ module Gamefic
|
|
|
5
5
|
module Actions
|
|
6
6
|
extend Gamefic::Scriptable
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
include Gamefic::What
|
|
9
|
+
|
|
10
|
+
respond :look, Commodity do |actor, thing|
|
|
9
11
|
actor.proceed
|
|
10
12
|
next unless thing.plural?
|
|
11
13
|
|
|
@@ -16,46 +18,26 @@ module Gamefic
|
|
|
16
18
|
end
|
|
17
19
|
end
|
|
18
20
|
|
|
19
|
-
respond :take,
|
|
20
|
-
actor
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
respond :place, siblings(::Commodity), available do |actor, _|
|
|
24
|
-
actor.proceed
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
respond :place, children(::Commodity), available do |actor, _|
|
|
28
|
-
actor.proceed
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
respond :insert, siblings(::Commodity), available do |actor, _|
|
|
32
|
-
actor.proceed
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
respond :insert, children(::Commodity), available do |actor, _|
|
|
36
|
-
actor.proceed
|
|
37
|
-
end
|
|
21
|
+
respond :take, plaintext do |actor, text|
|
|
22
|
+
commodities = Utils.match_nearby_commodities(actor, text)
|
|
23
|
+
next actor.proceed if commodities.empty?
|
|
38
24
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if comms.one?
|
|
42
|
-
actor.execute :take, comms.first
|
|
25
|
+
if commodities.one?
|
|
26
|
+
actor.execute :take, commodities.first
|
|
43
27
|
else
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
else
|
|
48
|
-
places = filtered.map { |object| object.parent.definitely }
|
|
49
|
-
actor.tell "Where do you want to take one from, #{places.join_or}?"
|
|
50
|
-
actor.ask_for_what "take #{filtered.first.name} from __what__"
|
|
51
|
-
end
|
|
28
|
+
places = commodities.map { |object| object.parent.definitely }
|
|
29
|
+
actor.tell "Where do you want to take one from, #{places.join_or}?"
|
|
30
|
+
actor.cue AskForWhat, template: "take #{commodities.first.name} from __what__"
|
|
52
31
|
end
|
|
53
32
|
end
|
|
54
33
|
|
|
55
|
-
respond :collect,
|
|
56
|
-
|
|
57
|
-
|
|
34
|
+
respond :collect, plaintext do |actor, text|
|
|
35
|
+
commodities = Utils.match_nearby_commodities(actor, text)
|
|
36
|
+
next actor.proceed if commodities.empty?
|
|
37
|
+
|
|
38
|
+
commodities.each { |com| actor.perform "take #{com.plural_name} from #{com.parent}" }
|
|
58
39
|
end
|
|
40
|
+
|
|
59
41
|
interpret 'collect all', 'take all'
|
|
60
42
|
interpret 'collect :thing', 'take :thing'
|
|
61
43
|
interpret 'collect all :commodity', 'collect :commodity'
|
|
@@ -67,17 +49,24 @@ module Gamefic
|
|
|
67
49
|
interpret 'take every :commodity', 'collect :commodity'
|
|
68
50
|
interpret 'take each :commodity', 'collect :commodity'
|
|
69
51
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
52
|
+
respond :take, integer, siblings(Commodity) do |actor, quantity, commodity|
|
|
53
|
+
Utils.try_quantity(actor, :take, quantity, commodity)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
respond :drop, integer, children(Commodity) do |actor, quantity, commodity|
|
|
57
|
+
Utils.try_quantity(actor, :drop, quantity, commodity)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
respond :insert, integer, children(Commodity), available do |actor, quantity, commodity, other|
|
|
61
|
+
Utils.try_quantity(actor, :insert, quantity, commodity, other)
|
|
62
|
+
end
|
|
74
63
|
|
|
75
|
-
|
|
76
|
-
Utils.try_quantity(actor,
|
|
64
|
+
respond :place, integer, children(Commodity), available do |actor, quantity, commodity, other|
|
|
65
|
+
Utils.try_quantity(actor, :place, quantity, commodity, other)
|
|
77
66
|
end
|
|
78
67
|
|
|
79
68
|
on_update do
|
|
80
|
-
entities.that_are(
|
|
69
|
+
entities.that_are(Commodity)
|
|
81
70
|
.reject(&:parent)
|
|
82
71
|
.each { |entity| destroy entity }
|
|
83
72
|
end
|
|
@@ -9,7 +9,7 @@ module Gamefic
|
|
|
9
9
|
# combined, i.e., the existing commodity's quantity is increased by the new
|
|
10
10
|
# commodity's quantity, and the other commodity is destroyed.
|
|
11
11
|
#
|
|
12
|
-
class Commodity < Item
|
|
12
|
+
class Commodity < Gamefic::Standard::Item
|
|
13
13
|
class CommodityError < ArgumentError; end
|
|
14
14
|
|
|
15
15
|
# @return [Integer]
|
|
@@ -101,5 +101,3 @@ module Gamefic
|
|
|
101
101
|
end
|
|
102
102
|
end
|
|
103
103
|
end
|
|
104
|
-
|
|
105
|
-
Commodity = Gamefic::Commodities::Commodity
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Gamefic
|
|
2
|
+
module Commodities
|
|
3
|
+
class QuantityScanner < Gamefic::Scanner::Base
|
|
4
|
+
def scan
|
|
5
|
+
words = token.keywords
|
|
6
|
+
first = words.shift
|
|
7
|
+
return unmatched_result unless first&.match(/\d+/)
|
|
8
|
+
|
|
9
|
+
result = subprocess(words.join(' '))
|
|
10
|
+
# @todo So we know the token might reference a quantity of a commodity. Now what?
|
|
11
|
+
Gamefic::Scanner::Result.new(result.scanned, result.token. result.matched, result.remainder, self)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def subprocess token_wo_number
|
|
17
|
+
Gamefic::Scanner::DEFAULT_PROCESSORS.each do |scanner|
|
|
18
|
+
result = scanner.scan(selection, token_wo_number)
|
|
19
|
+
return result unless result.matched.empty?
|
|
20
|
+
|
|
21
|
+
next result
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -6,18 +6,26 @@ module Gamefic
|
|
|
6
6
|
module_function
|
|
7
7
|
|
|
8
8
|
# @param actor [Gamefic::Actor]
|
|
9
|
-
# @param
|
|
10
|
-
# @param
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
command.arguments.first.count(number) do
|
|
16
|
-
actor.execute command.verb, *command.arguments
|
|
17
|
-
end
|
|
9
|
+
# @param verb [Symbol]
|
|
10
|
+
# @param quantity [Integer]
|
|
11
|
+
# @param commodity [Commodity]
|
|
12
|
+
def try_quantity(actor, verb, quantity, commodity, *args)
|
|
13
|
+
commodity.count(quantity) { actor.execute verb, commodity, *args }
|
|
18
14
|
rescue Commodity::CommodityError => e
|
|
19
15
|
actor.tell e.message
|
|
20
16
|
end
|
|
17
|
+
|
|
18
|
+
def match_nearby_commodities(actor, text)
|
|
19
|
+
available = Gamefic::Query::Family.span(actor)
|
|
20
|
+
result = Gamefic::Scanner.scan(available, text)
|
|
21
|
+
if result.remainder.empty? && result.matched.all? do |ent|
|
|
22
|
+
ent.is_a?(Commodity)
|
|
23
|
+
end && result.matched.uniq(&:name).one?
|
|
24
|
+
result.matched.reject { |com| actor.flatten.include?(com) }
|
|
25
|
+
else
|
|
26
|
+
[]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
21
29
|
end
|
|
22
30
|
end
|
|
23
31
|
end
|
data/lib/gamefic/commodities.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gamefic-commodities
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Fred Snyder
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: gamefic
|
|
@@ -16,28 +15,28 @@ dependencies:
|
|
|
16
15
|
requirements:
|
|
17
16
|
- - "~>"
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
18
|
+
version: '4.0'
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
23
|
- - "~>"
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
25
|
+
version: '4.0'
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
28
27
|
name: gamefic-standard
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
30
29
|
requirements:
|
|
31
30
|
- - "~>"
|
|
32
31
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
32
|
+
version: '4.0'
|
|
34
33
|
type: :runtime
|
|
35
34
|
prerelease: false
|
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
36
|
requirements:
|
|
38
37
|
- - "~>"
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
39
|
+
version: '4.0'
|
|
41
40
|
- !ruby/object:Gem::Dependency
|
|
42
41
|
name: opal
|
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -108,7 +107,6 @@ dependencies:
|
|
|
108
107
|
- - "~>"
|
|
109
108
|
- !ruby/object:Gem::Version
|
|
110
109
|
version: '0.14'
|
|
111
|
-
description:
|
|
112
110
|
email:
|
|
113
111
|
- fsnyder@castwide.com
|
|
114
112
|
executables: []
|
|
@@ -124,12 +122,11 @@ files:
|
|
|
124
122
|
- lib/gamefic/commodities.rb
|
|
125
123
|
- lib/gamefic/commodities/actions.rb
|
|
126
124
|
- lib/gamefic/commodities/commodity.rb
|
|
125
|
+
- lib/gamefic/commodities/quantity_scanner.rb
|
|
127
126
|
- lib/gamefic/commodities/utils.rb
|
|
128
127
|
- lib/gamefic/commodities/version.rb
|
|
129
|
-
homepage:
|
|
130
128
|
licenses: []
|
|
131
129
|
metadata: {}
|
|
132
|
-
post_install_message:
|
|
133
130
|
rdoc_options: []
|
|
134
131
|
require_paths:
|
|
135
132
|
- lib
|
|
@@ -144,8 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
144
141
|
- !ruby/object:Gem::Version
|
|
145
142
|
version: '0'
|
|
146
143
|
requirements: []
|
|
147
|
-
rubygems_version: 3.
|
|
148
|
-
signing_key:
|
|
144
|
+
rubygems_version: 3.6.7
|
|
149
145
|
specification_version: 4
|
|
150
146
|
summary: A Commodity entity for Gamefic.
|
|
151
147
|
test_files: []
|