gamefic 4.2.0 → 4.2.2

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: 923f92309b7fcac0e2ed6aa4e691e2feea39521f15f19c7b7a560ddb7583b365
4
- data.tar.gz: 858516d0d245300605612517d833e858b84b8a40473f6e9bf7d8670c5589cd77
3
+ metadata.gz: 59bd1690879679cdd45c163968253a1fbc72b31f01cc96dbadcae33ef91b2ff4
4
+ data.tar.gz: 8cb18e1eb8322c6174fd313636f18937a03ffdc87e5b546e2619ced95fe54521
5
5
  SHA512:
6
- metadata.gz: d3d3aa37745380138eb41ed6bee89231e96b385a1c5b8fffc42eb90bb23e9fdcb5d9ea0466fe7f5e1b2d9d459609ec002c3f80d6d6ab324658cbdea4fce1aee2
7
- data.tar.gz: 16a1c623c7fc6173f306f43ca080b668b72fdef3700469a6b421abcf88df04c405137f1458727754fce9706107502d7bc0f1dd4cf6c91115784e14de38a6af5e
6
+ metadata.gz: fb9dc7e48fdae91f4ec59c9969353083367c6bd8706e2dde4dd45aeefbe49631d4789b285945ed78ad1f0094282bc54ea276e1448942e64a571bdcdb137dd971
7
+ data.tar.gz: 0c09e76fa4d56e7b36109cebf438679feb7aaffa61a82b49f12f3c0795df2a976176783d07f8ee796ca3d93f7c382adb5e426752e605deb2daff3ce8b2c418e5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 4.2.2 - May 18, 2026
2
+ - Freeze output raw data
3
+ - Seeds#construct macro
4
+
5
+ ## 4.2.1 - February 1, 2026
6
+ - Correct Scenes#introduction documentation
7
+ - Fix parsing of piped verbs
8
+ - Binding documentation
9
+
1
10
  ## 4.2.0 - November 27, 2025
2
11
  - Syntaxes support variable (piped) words
3
12
  - Props::MultipleChoice#index_of
@@ -1,22 +1,45 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gamefic
4
+ # A lightweight wrapper around a `Proc` that executes it in the context of a
5
+ # specific narrative.
6
+ #
7
+ # Gamefic stores most author-written blocks (responses, callbacks, etc.) as
8
+ # plain Ruby procs. Those blocks are intended to run within the context of
9
+ # their parent narrative so they can call the narrative's methods.
10
+ # Gamefic::Binding pairs the proc with its narrative and provides a safe way
11
+ # to execute it.
12
+ #
4
13
  class Binding
5
14
  class << self
15
+ # A map of objects and the stack of narratives in which they're currently
16
+ # involved.
17
+ #
6
18
  def registry
7
19
  @registry ||= {}
8
20
  end
9
21
 
22
+ # Push a narrative to the top of an object's stack.
23
+ #
24
+ # @param object [Object]
25
+ # @param narrative [Narrative]
10
26
  def push(object, narrative)
11
27
  registry[object] ||= []
12
28
  registry[object].push narrative
13
29
  end
14
30
 
31
+ # Remove a narrative from the top of an object's stack.
32
+ #
33
+ # @param object [Object]
15
34
  def pop(object)
16
35
  registry[object].pop
17
36
  registry.delete(object) if registry[object].empty?
18
37
  end
19
38
 
39
+ # Fetch the narrative at the top of an object's stack.
40
+ #
41
+ # @param object [Object]
42
+ # @return [Narrative, nil]
20
43
  def for(object)
21
44
  registry.fetch(object, []).last
22
45
  end
@@ -35,6 +58,9 @@ module Gamefic
35
58
  @code = code
36
59
  end
37
60
 
61
+ # Execute the binding's code within the context of the narrative.
62
+ #
63
+ # @return [void]
38
64
  def call(*args)
39
65
  args.each { |arg| Binding.push arg, @narrative }
40
66
  @narrative.instance_exec(*args, &@code)
@@ -88,6 +88,7 @@ module Gamefic
88
88
 
89
89
  def freeze
90
90
  raw_data.freeze
91
+ raw_data.each_value(&:freeze)
91
92
  super
92
93
  end
93
94
 
@@ -52,15 +52,12 @@ module Gamefic
52
52
  end
53
53
 
54
54
  # Add a block to be executed when a player is added to the game.
55
- # Each Plot should only have one introduction.
56
55
  #
57
56
  # @example Welcome the player to the game
58
57
  # introduction do |actor|
59
58
  # actor.tell "Welcome to the game!"
60
59
  # end
61
60
  #
62
- # @raise [ArgumentError] if an introduction already exists
63
- #
64
61
  # @yieldparam [Gamefic::Actor]
65
62
  # @yieldparam [Props::Default]
66
63
  # @yieldreceiver [Object<self>]
@@ -29,6 +29,11 @@ module Gamefic
29
29
  # This method adds an instance method for the entity and a class method to
30
30
  # reference it with a proxy.
31
31
  #
32
+ # @!macro gamefic.construct
33
+ # @!method $1
34
+ # @return [$2]
35
+ # @!method self.$1
36
+ # @return [Proxy]
32
37
  # @param name [Symbol, String] The method name for the entity
33
38
  # @param klass [Class<Gamefic::Entity>]
34
39
  # @return [void]
@@ -20,7 +20,7 @@ module Gamefic
20
20
  def interpret(command, translation)
21
21
  parts = Syntax.split(command)
22
22
  additions = if parts.first.include?('|')
23
- parts.first.split('|').map { |verb| Syntax.new("#{verb} #{verb[1..].join(' ')}", translation) }
23
+ parts.first.split('|').map { |verb| Syntax.new("#{verb} #{parts[1..].join(' ')}", translation) }
24
24
  else
25
25
  [Syntax.new(command, translation)]
26
26
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gamefic
4
- VERSION = '4.2.0'
4
+ VERSION = '4.2.2'
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamefic
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-11-27 00:00:00.000000000 Z
10
+ date: 2026-05-18 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: base64
@@ -253,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
253
253
  - !ruby/object:Gem::Version
254
254
  version: '0'
255
255
  requirements: []
256
- rubygems_version: 3.6.7
256
+ rubygems_version: 4.0.6
257
257
  specification_version: 4
258
258
  summary: Gamefic
259
259
  test_files: []