gamefic 1.6.0 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +16 -0
- data/.solargraph.yml +5 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +7 -0
- data/LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +10 -0
- data/gamefic.gemspec +27 -0
- data/lib/gamefic.rb +11 -8
- data/lib/gamefic/action.rb +68 -58
- data/lib/gamefic/active.rb +331 -0
- data/lib/gamefic/actor.rb +8 -0
- data/lib/gamefic/command.rb +9 -7
- data/lib/gamefic/core_ext/array.rb +27 -49
- data/lib/gamefic/core_ext/string.rb +25 -16
- data/lib/gamefic/describable.rb +37 -22
- data/lib/gamefic/element.rb +47 -0
- data/lib/gamefic/entity.rb +24 -48
- data/lib/gamefic/{matchable.rb → keywords.rb} +52 -50
- data/lib/gamefic/messaging.rb +43 -45
- data/lib/gamefic/node.rb +14 -5
- data/lib/gamefic/plot.rb +73 -85
- data/lib/gamefic/plot/darkroom.rb +80 -0
- data/lib/gamefic/plot/host.rb +42 -46
- data/lib/gamefic/plot/snapshot.rb +14 -214
- data/lib/gamefic/query.rb +15 -17
- data/lib/gamefic/query/base.rb +51 -42
- data/lib/gamefic/query/children.rb +0 -0
- data/lib/gamefic/query/descendants.rb +2 -2
- data/lib/gamefic/query/external.rb +18 -0
- data/lib/gamefic/query/family.rb +3 -7
- data/lib/gamefic/query/matches.rb +75 -67
- data/lib/gamefic/query/parent.rb +0 -0
- data/lib/gamefic/query/siblings.rb +0 -0
- data/lib/gamefic/query/text.rb +12 -12
- data/lib/gamefic/query/tree.rb +17 -0
- data/lib/gamefic/scene.rb +1 -5
- data/lib/gamefic/scene/{active.rb → activity.rb} +4 -6
- data/lib/gamefic/scene/base.rb +77 -13
- data/lib/gamefic/scene/conclusion.rb +0 -2
- data/lib/gamefic/scene/custom.rb +0 -2
- data/lib/gamefic/scene/multiple_choice.rb +18 -16
- data/lib/gamefic/scene/multiple_scene.rb +29 -20
- data/lib/gamefic/scene/pause.rb +7 -2
- data/lib/gamefic/scene/yes_or_no.rb +21 -9
- data/lib/gamefic/scriptable.rb +88 -0
- data/lib/gamefic/serialize.rb +223 -0
- data/lib/gamefic/subplot.rb +47 -51
- data/lib/gamefic/syntax.rb +15 -13
- data/lib/gamefic/version.rb +3 -3
- data/lib/gamefic/world.rb +18 -0
- data/lib/gamefic/world/callbacks.rb +135 -0
- data/lib/gamefic/world/commands.rb +184 -0
- data/lib/gamefic/world/entities.rb +98 -0
- data/lib/gamefic/{plot → world}/playbook.rb +245 -236
- data/lib/gamefic/world/players.rb +37 -0
- data/lib/gamefic/world/scenes.rb +226 -0
- metadata +40 -108
- data/bin/gamefic +0 -9
- data/lib/gamefic/character.rb +0 -232
- data/lib/gamefic/character/state.rb +0 -12
- data/lib/gamefic/engine.rb +0 -7
- data/lib/gamefic/engine/base.rb +0 -66
- data/lib/gamefic/engine/tty.rb +0 -24
- data/lib/gamefic/grammar.rb +0 -13
- data/lib/gamefic/grammar/conjugator.rb +0 -20
- data/lib/gamefic/grammar/gender.rb +0 -11
- data/lib/gamefic/grammar/person.rb +0 -10
- data/lib/gamefic/grammar/plural.rb +0 -13
- data/lib/gamefic/grammar/pronouns.rb +0 -105
- data/lib/gamefic/grammar/tense.rb +0 -6
- data/lib/gamefic/grammar/verb_set.rb +0 -43
- data/lib/gamefic/grammar/verbs.rb +0 -26
- data/lib/gamefic/grammar/word_adapter.rb +0 -49
- data/lib/gamefic/plot/articles.rb +0 -22
- data/lib/gamefic/plot/callbacks.rb +0 -127
- data/lib/gamefic/plot/commands.rb +0 -121
- data/lib/gamefic/plot/entities.rb +0 -88
- data/lib/gamefic/plot/players.rb +0 -15
- data/lib/gamefic/plot/scenes.rb +0 -149
- data/lib/gamefic/plot/theater.rb +0 -73
- data/lib/gamefic/plot/you_mount.rb +0 -22
- data/lib/gamefic/script.rb +0 -13
- data/lib/gamefic/script/base.rb +0 -42
- data/lib/gamefic/script/file.rb +0 -14
- data/lib/gamefic/script/text.rb +0 -14
- data/lib/gamefic/shell.rb +0 -76
- data/lib/gamefic/source.rb +0 -14
- data/lib/gamefic/source/base.rb +0 -12
- data/lib/gamefic/source/file.rb +0 -23
- data/lib/gamefic/source/text.rb +0 -16
- data/lib/gamefic/tester.rb +0 -19
- data/lib/gamefic/text.rb +0 -8
- data/lib/gamefic/text/ansi.rb +0 -53
- data/lib/gamefic/text/html.rb +0 -68
- data/lib/gamefic/text/html/conversions.rb +0 -250
- data/lib/gamefic/text/html/entities.rb +0 -9
- data/lib/gamefic/tty.rb +0 -10
- data/lib/gamefic/user.rb +0 -8
- data/lib/gamefic/user/base.rb +0 -15
- data/lib/gamefic/user/buffer.rb +0 -32
- data/lib/gamefic/user/tty.rb +0 -54
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'gamefic/grammar'
|
2
|
-
|
3
|
-
module Gamefic::Grammar
|
4
|
-
class VerbSet
|
5
|
-
def initialize infinitive, *forms
|
6
|
-
# TODO what to do with the tense?
|
7
|
-
@infinitive = infinitive.to_s
|
8
|
-
@forms = {}
|
9
|
-
form = forms[0]
|
10
|
-
@forms["1:singular"] = form.nil? ? @infinitive.to_s : form.to_s
|
11
|
-
form = forms[1]
|
12
|
-
@forms["2:singular"] = form.nil? ? @infinitive.to_s : form.to_s
|
13
|
-
form = forms[2]
|
14
|
-
@forms["3:singular"] = form.nil? ? generate_third_singular : form.to_s
|
15
|
-
form = forms[3]
|
16
|
-
@forms["1:plural"] = form.nil? ? @infinitive.to_s : form.to_s
|
17
|
-
form = forms[4]
|
18
|
-
@forms["2:plural"] = form.nil? ? @forms["1:plural"] : form.to_s
|
19
|
-
form = forms[5]
|
20
|
-
@forms["3:plural"] = form.nil? ? @forms["1:plural"] : form.to_s
|
21
|
-
end
|
22
|
-
def conjugate pronoun
|
23
|
-
form = @forms["#{pronoun.person}"]
|
24
|
-
if form.nil?
|
25
|
-
form = @forms["#{pronoun.person}:#{pronoun.plural? ? 'plural' : 'singular'}"]
|
26
|
-
end
|
27
|
-
if form.nil?
|
28
|
-
raise "Unable to conjugate #{@infinitive}"
|
29
|
-
end
|
30
|
-
form
|
31
|
-
end
|
32
|
-
private
|
33
|
-
def generate_third_singular
|
34
|
-
if @infinitive.end_with?('o')
|
35
|
-
@infinitive + "es"
|
36
|
-
elsif @infinitive.end_with?('ry')
|
37
|
-
@infinitive[0..-2] + "ies"
|
38
|
-
else
|
39
|
-
@infinitive + "s"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'gamefic'
|
2
|
-
require 'gamefic/grammar'
|
3
|
-
|
4
|
-
module Gamefic::Grammar
|
5
|
-
class Verbs
|
6
|
-
extend Gamefic::Grammar::Conjugator::ClassMethods
|
7
|
-
def initialize obj
|
8
|
-
@pronoun = obj
|
9
|
-
self.class.conjugated_verbs.each_pair { |infinitive, verbset|
|
10
|
-
define_singleton_method infinitive do
|
11
|
-
verbset[:present].conjugate @pronoun
|
12
|
-
end
|
13
|
-
}
|
14
|
-
end
|
15
|
-
def method_missing infinitive, *args, &block
|
16
|
-
Gamefic::Grammar::VerbSet.new(infinitive, nil, *args).conjugate(@pronoun)
|
17
|
-
end
|
18
|
-
def [] infinitive
|
19
|
-
words = infinitive.split_words
|
20
|
-
Gamefic::Grammar::VerbSet.new(words[0], nil).conjugate(@pronoun) + (words.length > 1 ? ' ' + words[1..-1].join(' ') : '')
|
21
|
-
end
|
22
|
-
conjugate :be, :present, :am, :are, :is, :are
|
23
|
-
conjugate :have, :present, :have, :have, :has, :have
|
24
|
-
conjugate :can, :present, :can, :can, :can
|
25
|
-
end
|
26
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'gamefic/grammar'
|
2
|
-
require 'gamefic/grammar/gender'
|
3
|
-
|
4
|
-
module Gamefic::Grammar
|
5
|
-
module WordAdapter
|
6
|
-
include Gender
|
7
|
-
include Person
|
8
|
-
include Plural
|
9
|
-
# @return [Gamefic::Grammar::Pronouns]
|
10
|
-
def pronoun
|
11
|
-
@pronoun ||= Gamefic::Grammar::Pronouns.new(self)
|
12
|
-
end
|
13
|
-
# @return [Gamefic::Grammar::Verbs]
|
14
|
-
def verb
|
15
|
-
@verb ||= Gamefic::Grammar::Verbs.new(self)
|
16
|
-
end
|
17
|
-
def contract words
|
18
|
-
contractions[words] || words
|
19
|
-
end
|
20
|
-
private
|
21
|
-
def contractions
|
22
|
-
if @contractions.nil?
|
23
|
-
@contractions ||= {
|
24
|
-
"I am" => "I'm",
|
25
|
-
"you are" => "you're",
|
26
|
-
"he is" => "he's",
|
27
|
-
"she is" => "she's",
|
28
|
-
"it is" => "it's",
|
29
|
-
"we are" => "we're",
|
30
|
-
"they are" => "they're",
|
31
|
-
"am not" => "am not",
|
32
|
-
"are not" => "aren't",
|
33
|
-
"is not" => "isn't",
|
34
|
-
"do not" => "don't",
|
35
|
-
"does not" => "doesn't",
|
36
|
-
"can not" => "can't"
|
37
|
-
}
|
38
|
-
capitalized = {}
|
39
|
-
@contractions.each_pair { |k,v |
|
40
|
-
if k[0] != k[0].capitalize
|
41
|
-
capitalized[k.cap_first] = v.cap_first
|
42
|
-
end
|
43
|
-
}
|
44
|
-
@contractions.merge! capitalized
|
45
|
-
end
|
46
|
-
@contractions
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Gamefic
|
2
|
-
module Plot::Articles
|
3
|
-
def a(entity)
|
4
|
-
entity.indefinitely
|
5
|
-
end
|
6
|
-
def an(entity)
|
7
|
-
entity.indefinitely
|
8
|
-
end
|
9
|
-
def the(entity)
|
10
|
-
entity.definitely
|
11
|
-
end
|
12
|
-
def A(entity)
|
13
|
-
entity.indefinitely.cap_first
|
14
|
-
end
|
15
|
-
def An(entity)
|
16
|
-
entity.indefinitely.cap_first
|
17
|
-
end
|
18
|
-
def The(entity)
|
19
|
-
entity.definitely.cap_first
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,127 +0,0 @@
|
|
1
|
-
module Gamefic
|
2
|
-
|
3
|
-
module Plot::Callbacks
|
4
|
-
# Add a block to be executed on preparation of every turn.
|
5
|
-
#
|
6
|
-
# @example Increment a turn counter
|
7
|
-
# turn = 0
|
8
|
-
# on_ready do
|
9
|
-
# turn += 1
|
10
|
-
# end
|
11
|
-
#
|
12
|
-
def on_ready &block
|
13
|
-
p_ready_procs.push block
|
14
|
-
end
|
15
|
-
|
16
|
-
# Add a block to be executed after the Plot is finished updating a turn.
|
17
|
-
#
|
18
|
-
def on_update &block
|
19
|
-
p_update_procs.push block
|
20
|
-
end
|
21
|
-
|
22
|
-
# Add a block to be executed for each player at the beginning of a turn.
|
23
|
-
#
|
24
|
-
# @example Tell the player how many turns they've played.
|
25
|
-
# on_player_ready do |player|
|
26
|
-
# player[:turns] ||= 0
|
27
|
-
# if player[:turns] > 0
|
28
|
-
# player.tell "Turn #{player[:turns]}"
|
29
|
-
# end
|
30
|
-
# player[:turns] += 1
|
31
|
-
# end
|
32
|
-
#
|
33
|
-
# @yieldparam [Character]
|
34
|
-
def on_player_ready &block
|
35
|
-
p_player_ready_procs.push block
|
36
|
-
end
|
37
|
-
|
38
|
-
# Add a block to be executed for each player before an update.
|
39
|
-
#
|
40
|
-
# @yieldparam[Character]
|
41
|
-
def before_player_update &block
|
42
|
-
p_before_player_update_procs.push block
|
43
|
-
end
|
44
|
-
|
45
|
-
# Add a block to be executed for each player at the end of a turn.
|
46
|
-
#
|
47
|
-
# @yieldparam [Character]
|
48
|
-
def on_player_update &block
|
49
|
-
p_player_update_procs.push block
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
# Execute the on_ready blocks. This method is typically called by the
|
55
|
-
# Plot while beginning a turn.
|
56
|
-
#
|
57
|
-
def call_ready
|
58
|
-
p_ready_procs.each { |p| p.call }
|
59
|
-
end
|
60
|
-
|
61
|
-
# Execute the on_update blocks. This method is typically called by the
|
62
|
-
# Plot while ending a turn.
|
63
|
-
#
|
64
|
-
def call_update
|
65
|
-
p_update_procs.each { |p| p.call }
|
66
|
-
end
|
67
|
-
|
68
|
-
# Execute the before_player_update blocks for each player. This method is
|
69
|
-
# typically called by the Plot while updating a turn, immediately before
|
70
|
-
# processing player input.
|
71
|
-
#
|
72
|
-
def call_before_player_update
|
73
|
-
p_players.each { |player|
|
74
|
-
player.flush
|
75
|
-
p_before_player_update_procs.each { |block| block.call player }
|
76
|
-
}
|
77
|
-
end
|
78
|
-
|
79
|
-
# Execute the on_player_ready blocks for each player. This method is
|
80
|
-
# typically called by the Plot while beginning a turn, immediately after
|
81
|
-
# the on_ready blocks.
|
82
|
-
#
|
83
|
-
def call_player_ready
|
84
|
-
p_players.each { |player|
|
85
|
-
unless player.next_scene.nil?
|
86
|
-
player.cue player.next_scene
|
87
|
-
end
|
88
|
-
player.cue default_scene if player.scene.nil?
|
89
|
-
#player.prepare nil
|
90
|
-
#player.cue this_scene #unless player.scene.class == this_scene
|
91
|
-
p_player_ready_procs.each { |block| block.call player }
|
92
|
-
}
|
93
|
-
end
|
94
|
-
|
95
|
-
# Execute the on_player_update blocks for each player. This method is
|
96
|
-
# typically called by the Plot while ending a turn, immediately before the
|
97
|
-
# on_ready blocks.
|
98
|
-
#
|
99
|
-
def call_player_update
|
100
|
-
p_players.each { |player|
|
101
|
-
#player.performed nil
|
102
|
-
p_player_update_procs.each { |block| block.call player }
|
103
|
-
}
|
104
|
-
end
|
105
|
-
|
106
|
-
def p_ready_procs
|
107
|
-
@p_ready_procs ||= []
|
108
|
-
end
|
109
|
-
|
110
|
-
def p_update_procs
|
111
|
-
@p_update_procs ||= []
|
112
|
-
end
|
113
|
-
|
114
|
-
def p_before_player_update_procs
|
115
|
-
@p_before_player_update_procs ||= []
|
116
|
-
end
|
117
|
-
|
118
|
-
def p_player_ready_procs
|
119
|
-
@p_player_ready_procs ||= []
|
120
|
-
end
|
121
|
-
|
122
|
-
def p_player_update_procs
|
123
|
-
@p_player_update_procs ||= []
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
end
|
@@ -1,121 +0,0 @@
|
|
1
|
-
require 'gamefic/action'
|
2
|
-
|
3
|
-
module Gamefic
|
4
|
-
|
5
|
-
module Plot::Commands
|
6
|
-
# Create an Action that responds to a command.
|
7
|
-
# An Action uses the command argument to identify the imperative verb that
|
8
|
-
# triggers the action.
|
9
|
-
# It can also accept queries to tokenize the remainder of the input and
|
10
|
-
# filter for particular entities or properties.
|
11
|
-
# The block argument contains the code to be executed when the input
|
12
|
-
# matches all of the Action's criteria (i.e., verb and queries).
|
13
|
-
#
|
14
|
-
# @example A simple Action.
|
15
|
-
# respond :salute do |actor|
|
16
|
-
# actor.tell "Hello, sir!"
|
17
|
-
# end
|
18
|
-
# # The command "salute" will respond "Hello, sir!"
|
19
|
-
#
|
20
|
-
# @example An Action that accepts a Character
|
21
|
-
# respond :salute, Use.visible(Character) do |actor, character|
|
22
|
-
# actor.tell "#{The character} returns your salute."
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# @param command [Symbol] An imperative verb for the command
|
26
|
-
# @param queries [Array<Query::Base>] Filters for the command's tokens
|
27
|
-
# @yieldparam [Character]
|
28
|
-
def respond(command, *queries, &proc)
|
29
|
-
playbook.respond(command, *queries, &proc)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Create a Meta Action that responds to a command.
|
33
|
-
# Meta Actions are very similar to standard Actions, except the Plot
|
34
|
-
# understands them to be commands that operate above and/or outside of the
|
35
|
-
# actual game world. Examples of Meta Actions are commands that report the
|
36
|
-
# player's current score, save and restore saved games, or list the game's
|
37
|
-
# credits.
|
38
|
-
#
|
39
|
-
# @example A simple Meta Action
|
40
|
-
# meta :credits do |actor|
|
41
|
-
# actor.tell "This game was written by John Smith."
|
42
|
-
# end
|
43
|
-
#
|
44
|
-
# @param command [Symbol] An imperative verb for the command
|
45
|
-
# @param queries [Array<Query::Base>] Filters for the command's tokens
|
46
|
-
# @yieldparam [Character]
|
47
|
-
def meta(command, *queries, &proc)
|
48
|
-
playbook.meta command, *queries, &proc
|
49
|
-
end
|
50
|
-
|
51
|
-
# @deprecated
|
52
|
-
def action(command, *queries, &proc)
|
53
|
-
respond command, *queries, &proc
|
54
|
-
end
|
55
|
-
|
56
|
-
# Declare a dismabiguation response for actions.
|
57
|
-
# The disambigurator is executed when an action expects an argument to
|
58
|
-
# reference a specific entity but its query matched more than one. For
|
59
|
-
# example, "red" might refer to either a red key or a red book.
|
60
|
-
#
|
61
|
-
# If a disambiguator is not defined, the playbook will use its default
|
62
|
-
# implementation.
|
63
|
-
#
|
64
|
-
# @example Tell the player the list of ambiguous entities.
|
65
|
-
# disambiguate do |actor, entities|
|
66
|
-
# actor.tell "I don't know which you mean: #{entities.join_or}."
|
67
|
-
# end
|
68
|
-
#
|
69
|
-
# @yieldparam [Gamefic::Character]
|
70
|
-
# @yieldparam [Array<Gamefic::Entity>]
|
71
|
-
def disambiguate &block
|
72
|
-
playbook.disambiguate &block
|
73
|
-
end
|
74
|
-
|
75
|
-
# Validate an order before a character can execute its command.
|
76
|
-
#
|
77
|
-
# @yieldparam [Gamefic::Director::Order]
|
78
|
-
def validate &block
|
79
|
-
playbook.validate &block
|
80
|
-
end
|
81
|
-
|
82
|
-
# Create an alternate Syntax for an Action.
|
83
|
-
# The command and its translation can be parameterized.
|
84
|
-
#
|
85
|
-
# @example Create a synonym for the Inventory Action.
|
86
|
-
# interpret "catalogue", "inventory"
|
87
|
-
# # The command "catalogue" will be translated to "inventory"
|
88
|
-
#
|
89
|
-
# @example Create a parameterized synonym for the Look Action.
|
90
|
-
# interpret "scrutinize :entity", "look :entity"
|
91
|
-
# # The command "scrutinize chair" will be translated to "look chair"
|
92
|
-
#
|
93
|
-
# @param command [String] The format of the original command
|
94
|
-
# @param translation [String] The format of the translated command
|
95
|
-
# @return [Syntax] the Syntax object
|
96
|
-
def interpret command, translation
|
97
|
-
playbook.interpret command, translation
|
98
|
-
end
|
99
|
-
|
100
|
-
# @deprecated
|
101
|
-
def xlate command, translation
|
102
|
-
interpret command, translation
|
103
|
-
end
|
104
|
-
|
105
|
-
# Get an Array of available verbs.
|
106
|
-
# If the to_s parameter is true, convert Symbols to Strings.
|
107
|
-
#
|
108
|
-
# @return [Array<Symbol|String>]
|
109
|
-
def verbs to_s: false
|
110
|
-
to_s ? playbook.verbs.map { |v| v.to_s } : playbook.verbs
|
111
|
-
end
|
112
|
-
|
113
|
-
# Get an Array of all Actions defined in the Plot.
|
114
|
-
#
|
115
|
-
# @return [Array<Action>]
|
116
|
-
def actions
|
117
|
-
playbook.actions
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
module Gamefic
|
2
|
-
|
3
|
-
class Plot
|
4
|
-
module Entities
|
5
|
-
# Make a new Entity with the provided properties.
|
6
|
-
#
|
7
|
-
# @example Create an Entity
|
8
|
-
# chair = make Entity, name: 'red chair'
|
9
|
-
# chair.name #=> 'red chair'
|
10
|
-
#
|
11
|
-
# @param cls [Class] The Class of the Entity to be created.
|
12
|
-
# @param args [Hash] The entity's properties.
|
13
|
-
# @return [Gamefic::Entity]
|
14
|
-
def make cls, args = {}, &block
|
15
|
-
ent = cls.new args, &block
|
16
|
-
if ent.kind_of?(Entity) == false
|
17
|
-
raise "Invalid entity class"
|
18
|
-
end
|
19
|
-
p_entities.push ent
|
20
|
-
p_dynamic.push ent if running?
|
21
|
-
ent.playbook = playbook if ent.kind_of?(Character)
|
22
|
-
ent
|
23
|
-
end
|
24
|
-
|
25
|
-
def destroy entity
|
26
|
-
if p_dynamic.include?(entity)
|
27
|
-
p_entities.delete entity
|
28
|
-
p_dynamic.delete entity
|
29
|
-
p_players.delete entity
|
30
|
-
end
|
31
|
-
entity.parent = nil
|
32
|
-
end
|
33
|
-
|
34
|
-
# Pick an entity based on its description.
|
35
|
-
# The description provided must match exactly one entity; otherwise
|
36
|
-
# an error is raised.
|
37
|
-
#
|
38
|
-
# @example Select the Entity that matches the description
|
39
|
-
# red_chair = make Entity, :name => 'red chair'
|
40
|
-
# blue_chair make Entity, :name => 'blue chair'
|
41
|
-
# pick "red chair" #=> red_chair
|
42
|
-
# pick "blue chair" #=> blue_chair
|
43
|
-
# pick "chair" #=> IndexError: description is ambiguous
|
44
|
-
#
|
45
|
-
# @param description [String] The description of the entity
|
46
|
-
# @return [Gamefic::Entity] The entity that matches the description
|
47
|
-
def pick(description)
|
48
|
-
query = Gamefic::Query::Base.new
|
49
|
-
result = query.match(description, entities)
|
50
|
-
if result.objects.length == 0
|
51
|
-
raise IndexError.new("Unable to find entity from '#{description}'")
|
52
|
-
elsif result.objects.length > 1
|
53
|
-
raise IndexError.new("Ambiguous entities found from '#{description}'")
|
54
|
-
end
|
55
|
-
result.objects[0]
|
56
|
-
end
|
57
|
-
|
58
|
-
# Get an array of entities associated with this plot.
|
59
|
-
#
|
60
|
-
# @return [Array<Entity>]
|
61
|
-
def entities
|
62
|
-
p_entities.clone
|
63
|
-
end
|
64
|
-
|
65
|
-
# Get an array of players associated with this plot.
|
66
|
-
#
|
67
|
-
# @return [Array<Character>]
|
68
|
-
def players
|
69
|
-
p_players.clone
|
70
|
-
end
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
|
-
def p_entities
|
75
|
-
@p_entities ||= []
|
76
|
-
end
|
77
|
-
|
78
|
-
def p_players
|
79
|
-
@p_players ||= []
|
80
|
-
end
|
81
|
-
|
82
|
-
def p_dynamic
|
83
|
-
@p_dynamic ||= []
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|