gamefic 4.2.0 → 4.2.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 +5 -0
- data/lib/gamefic/binding.rb +26 -0
- data/lib/gamefic/scriptable/scenes.rb +0 -3
- data/lib/gamefic/scriptable/syntaxes.rb +1 -1
- data/lib/gamefic/version.rb +1 -1
- 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: 9800fd3de4b72b22f083edb20b4c9b74b58f306ce70266a1a9c2aa6b40b02d1e
|
|
4
|
+
data.tar.gz: 0ba0352e45dd1609d2070e915d6fcf3e41175fd7e52dafcdb4ed5151967241d9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1350f7c939581714ba21108e8376faf4091905a5a85e15ec2d7b4fdc0e44de9c6057698117b04abcf763cf4b3cc74d807383c609c23814973cca58b0a318a59e
|
|
7
|
+
data.tar.gz: fc2464dbfc163a53742af0e286623a08f67c70472acabd8bfb0176aadfd18431b3f7c41a340264cbf79c9b493b8cda0fcf4b13b91be086cf9442ec9b971f3a4e
|
data/CHANGELOG.md
CHANGED
data/lib/gamefic/binding.rb
CHANGED
|
@@ -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)
|
|
@@ -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>]
|
|
@@ -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} #{
|
|
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
|
data/lib/gamefic/version.rb
CHANGED
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.
|
|
4
|
+
version: 4.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Fred Snyder
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 2026-02-01 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: base64
|