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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '08a734e8585509d12f97f384bcd5e7ff9081ee6500ea4f3eaaae6337bbaf0d98'
4
- data.tar.gz: 7c83ac167edba79d950397f919faeffe7c12ef76c0f0e82e4b4fbe8cda3d288a
3
+ metadata.gz: 2f8318cc02457f9206f71ea84788b5ecd36353cefa24a8a5ba00f3dc0a964574
4
+ data.tar.gz: 0eb3639a2a1e6cfb7e36adb064e1ca889bb2f0a900dec8d82538590cdd8206a5
5
5
  SHA512:
6
- metadata.gz: ff83060ddb98824b01c98a229697834e5d3448d4ceb8c22f8de11939439c48fae7cdda371c79dd5cc94f2347edc51dc98fca623d1f42ca7a14152e136756f440
7
- data.tar.gz: ada7030b38061a939c7ee47b010f67dbd039645f8bf2464a9a71658568fd9144a7c4f9072806d3fc377398aaa28e07c36eb4c3a12e9f770cfbafd42024da69ec
6
+ metadata.gz: b3606bf2ee4760ddbdbf48f2d3653082b403e0bb0e0c818b17fdecacd06e645978744981aa77e9dc61f8f976c0d8209ba691756ed527e108f46edf8a85a0d157
7
+ data.tar.gz: cdb59be4c8f1ddef105fd04bc9490e507617fd0d6d4673118f69b18a2d042d279d66786b8ae30d8f97f8729a078c0b5005d7b41c6ad8205ed9009234755ff439
data/CHANGELOG.md CHANGED
@@ -1,2 +1,6 @@
1
+ ## 1.0.0 - February 17, 2026
2
+ - Gamefic 4.0 updates
3
+ - Explicit inclusion
4
+
1
5
  ## 0.1.0 - October 5, 2024
2
6
  - First release
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
- attr_seed :room, Room,
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: _attr(:room)
53
+ parent: room
45
54
 
46
55
  introduction do |actor|
47
56
  actor.parent = room
data/Rakefile CHANGED
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/setup'
4
+ require 'bundler/gem_tasks'
5
+ require 'rspec/core/rake_task'
5
6
  require 'opal/rspec/rake_task'
6
7
 
7
8
  RSpec::Core::RakeTask.new(:spec)
@@ -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', '~> 3.5'
37
- spec.add_dependency 'gamefic-standard', '~> 3.0'
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
- respond :look, ::Commodity do |actor, thing|
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, siblings(::Commodity) do |actor, _|
20
- actor.proceed
21
- end
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
- respond :take, available(::Commodity, ambiguous: true) do |actor, comms|
40
- comms = comms.reject { |com| com.parent == actor }
41
- if comms.one?
42
- actor.execute :take, comms.first
25
+ if commodities.one?
26
+ actor.execute :take, commodities.first
43
27
  else
44
- filtered = comms.reject { |ent| actor.flatten.include?(ent) }
45
- if filtered.one?
46
- actor.execute :take, filtered.first
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, available(::Commodity, ambiguous: true) do |actor, comms|
56
- comms.reject { |com| com.parent == actor }
57
- .each { |com| actor.perform "take #{com.plural_name} from #{com.parent}" }
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
- meta nil, plaintext do |actor, text|
71
- words = text.keywords
72
- verb = words.shift
73
- next actor.proceed if words.empty? || words.first =~ /[^\d]+/
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
- number = words.shift.to_i
76
- Utils.try_quantity(actor, number, "#{verb} #{words.join(' ')}")
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(::Commodity)
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 number [Integer]
10
- # @param input [String]
11
- def try_quantity(actor, number, input)
12
- command = Gamefic::Command.compose(actor, input)
13
- return actor.proceed unless command.arguments.first.is_a?(Commodity)
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Gamefic
4
4
  module Commodities
5
- VERSION = '0.1.0'
5
+ VERSION = '1.0.0'
6
6
  end
7
7
  end
@@ -9,7 +9,7 @@ module Gamefic
9
9
  require 'gamefic/commodities/commodity'
10
10
  require 'gamefic/commodities/utils'
11
11
  require 'gamefic/commodities/actions'
12
+
13
+ include Gamefic::Commodities::Actions
12
14
  end
13
15
  end
14
-
15
- Gamefic::Standard.include Gamefic::Commodities::Actions
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: 0.1.0
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: 2024-10-05 00:00:00.000000000 Z
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: '3.5'
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: '3.5'
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: '3.0'
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: '3.0'
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.3.7
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: []