gamefic 1.7.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +12 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +13 -0
  5. data/.solargraph.yml +5 -0
  6. data/Gemfile +7 -0
  7. data/LICENSE +20 -0
  8. data/README.md +28 -0
  9. data/Rakefile +10 -0
  10. data/gamefic.gemspec +27 -0
  11. data/lib/gamefic.rb +7 -6
  12. data/lib/gamefic/action.rb +38 -28
  13. data/lib/gamefic/active.rb +325 -280
  14. data/lib/gamefic/actor.rb +8 -5
  15. data/lib/gamefic/command.rb +9 -7
  16. data/lib/gamefic/core_ext/array.rb +24 -49
  17. data/lib/gamefic/core_ext/string.rb +25 -16
  18. data/lib/gamefic/describable.rb +21 -23
  19. data/lib/gamefic/element.rb +43 -31
  20. data/lib/gamefic/entity.rb +6 -12
  21. data/lib/gamefic/index.rb +121 -0
  22. data/lib/gamefic/{matchable.rb → keywords.rb} +52 -50
  23. data/lib/gamefic/messaging.rb +43 -44
  24. data/lib/gamefic/node.rb +14 -5
  25. data/lib/gamefic/plot.rb +69 -89
  26. data/lib/gamefic/plot/darkroom.rb +92 -264
  27. data/lib/gamefic/plot/host.rb +42 -48
  28. data/lib/gamefic/plot/snapshot.rb +5 -18
  29. data/lib/gamefic/query.rb +14 -18
  30. data/lib/gamefic/query/base.rb +30 -18
  31. data/lib/gamefic/query/children.rb +0 -0
  32. data/lib/gamefic/query/external.rb +18 -14
  33. data/lib/gamefic/query/family.rb +1 -7
  34. data/lib/gamefic/query/matches.rb +75 -67
  35. data/lib/gamefic/query/parent.rb +0 -0
  36. data/lib/gamefic/query/siblings.rb +0 -0
  37. data/lib/gamefic/query/text.rb +2 -1
  38. data/lib/gamefic/scene.rb +0 -2
  39. data/lib/gamefic/scene/activity.rb +24 -26
  40. data/lib/gamefic/scene/base.rb +64 -8
  41. data/lib/gamefic/scene/conclusion.rb +0 -2
  42. data/lib/gamefic/scene/custom.rb +0 -2
  43. data/lib/gamefic/scene/multiple_choice.rb +18 -3
  44. data/lib/gamefic/scene/multiple_scene.rb +29 -20
  45. data/lib/gamefic/scene/pause.rb +7 -2
  46. data/lib/gamefic/scene/yes_or_no.rb +21 -9
  47. data/lib/gamefic/scriptable.rb +87 -0
  48. data/lib/gamefic/serialize.rb +68 -0
  49. data/lib/gamefic/subplot.rb +29 -35
  50. data/lib/gamefic/syntax.rb +14 -13
  51. data/lib/gamefic/version.rb +3 -3
  52. data/lib/gamefic/world.rb +16 -0
  53. data/lib/gamefic/world/callbacks.rb +135 -0
  54. data/lib/gamefic/world/commands.rb +184 -0
  55. data/lib/gamefic/{plot → world}/entities.rb +30 -29
  56. data/lib/gamefic/{plot → world}/playbook.rb +255 -240
  57. data/lib/gamefic/world/players.rb +21 -0
  58. data/lib/gamefic/world/scenes.rb +226 -0
  59. metadata +41 -92
  60. data/bin/gamefic +0 -9
  61. data/lib/gamefic/engine.rb +0 -7
  62. data/lib/gamefic/engine/base.rb +0 -59
  63. data/lib/gamefic/engine/tty.rb +0 -24
  64. data/lib/gamefic/grammar.rb +0 -13
  65. data/lib/gamefic/grammar/conjugator.rb +0 -20
  66. data/lib/gamefic/grammar/gender.rb +0 -11
  67. data/lib/gamefic/grammar/person.rb +0 -10
  68. data/lib/gamefic/grammar/plural.rb +0 -13
  69. data/lib/gamefic/grammar/pronouns.rb +0 -106
  70. data/lib/gamefic/grammar/tense.rb +0 -6
  71. data/lib/gamefic/grammar/verb_set.rb +0 -43
  72. data/lib/gamefic/grammar/verbs.rb +0 -26
  73. data/lib/gamefic/grammar/word_adapter.rb +0 -49
  74. data/lib/gamefic/plot/articles.rb +0 -22
  75. data/lib/gamefic/plot/callbacks.rb +0 -126
  76. data/lib/gamefic/plot/commands.rb +0 -120
  77. data/lib/gamefic/plot/players.rb +0 -15
  78. data/lib/gamefic/plot/scenes.rb +0 -187
  79. data/lib/gamefic/plot/theater.rb +0 -73
  80. data/lib/gamefic/plot/you_mount.rb +0 -22
  81. data/lib/gamefic/script.rb +0 -13
  82. data/lib/gamefic/script/base.rb +0 -42
  83. data/lib/gamefic/script/file.rb +0 -14
  84. data/lib/gamefic/script/text.rb +0 -14
  85. data/lib/gamefic/shell.rb +0 -76
  86. data/lib/gamefic/source.rb +0 -14
  87. data/lib/gamefic/source/base.rb +0 -12
  88. data/lib/gamefic/source/file.rb +0 -23
  89. data/lib/gamefic/source/text.rb +0 -16
  90. data/lib/gamefic/tester.rb +0 -19
  91. data/lib/gamefic/text.rb +0 -8
  92. data/lib/gamefic/text/ansi.rb +0 -53
  93. data/lib/gamefic/text/html.rb +0 -68
  94. data/lib/gamefic/text/html/conversions.rb +0 -250
  95. data/lib/gamefic/text/html/entities.rb +0 -9
  96. data/lib/gamefic/tty.rb +0 -10
  97. data/lib/gamefic/user.rb +0 -7
  98. data/lib/gamefic/user/base.rb +0 -29
  99. data/lib/gamefic/user/tty.rb +0 -38
@@ -0,0 +1,21 @@
1
+ module Gamefic
2
+ module World
3
+ module Players
4
+ include Gamefic::World::Entities
5
+
6
+ # An array of entities that are currently connected to users.
7
+ #
8
+ # @return [Array<Gamefic::Actor>]
9
+ def players
10
+ @players ||= []
11
+ end
12
+
13
+ # Get the character that the player will control on introduction.
14
+ #
15
+ # @return [Gamefic::Actor]
16
+ def get_player_character
17
+ cast player_class, name: 'yourself', synonyms: 'self myself you me', proper_named: true
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,226 @@
1
+ module Gamefic
2
+ module World
3
+ module Scenes
4
+ # @return [Class<Gamefic::Scene::Activity>]
5
+ def default_scene
6
+ @default_scene ||= Scene::Activity
7
+ end
8
+
9
+ # @return [Class<Gamefic::Scene::Conclusion>]
10
+ def default_conclusion
11
+ @default_conclusion ||= Scene::Conclusion
12
+ end
13
+
14
+ # Add a block to be executed when a player is added to the game.
15
+ # Each Plot can only have one introduction. Subsequent calls will
16
+ # overwrite the existing one.
17
+ #
18
+ # @example Welcome the player to the game
19
+ # introduction do |actor|
20
+ # actor.tell "Welcome to the game!"
21
+ # end
22
+ #
23
+ # @yieldparam [Gamefic::Actor]
24
+ def introduction(&proc)
25
+ @introduction = proc
26
+ end
27
+
28
+ # Introduce a player to the game.
29
+ # This method is typically called by the Engine that manages game execution.
30
+ #
31
+ # @param [Gamefic::Actor]
32
+ def introduce(player)
33
+ player.playbooks.push playbook unless player.playbooks.include?(playbook)
34
+ player.cue default_scene
35
+ players.push player
36
+ @introduction.call(player) unless @introduction.nil?
37
+ # @todo Find a better way to persist player characters
38
+ Gamefic::Index.stick
39
+ end
40
+
41
+ # Create a multiple-choice scene.
42
+ # The user will be required to make a valid choice to continue.
43
+ #
44
+ # @example
45
+ # @scene = multiple_choice 'Go to work', 'Go to school' do |actor, scene|
46
+ # # Assuming user selected the first choice:
47
+ # scene.selection #=> 'Go to work'
48
+ # scene.index #=> 0
49
+ # scene.number #=> 1
50
+ # end
51
+ #
52
+ # @yieldparam [Gamefic::Actor]
53
+ # @yieldparam [Gamefic::Scene::MultipleChoice]
54
+ # @return [Class<Gamefic::Scene::MultipleChoice>]
55
+ def multiple_choice *choices, &block
56
+ s = Scene::MultipleChoice.subclass do |actor, scene|
57
+ scene.options.concat choices
58
+ scene.on_finish &block
59
+ end
60
+ scene_classes.push s
61
+ s
62
+ end
63
+
64
+ # Create a yes-or-no scene.
65
+ # The user will be required to answer Yes or No to continue.
66
+ #
67
+ # @example
68
+ # @scene = yes_or_no 'What is your answer?' do |actor, scene|
69
+ # if scene.yes?
70
+ # actor.tell "You said yes."
71
+ # else
72
+ # actor.tell "You said no."
73
+ # end
74
+ # end
75
+ #
76
+ # @param prompt [String]
77
+ # @yieldparam [Gamefic::Actor]
78
+ # @yieldparam [Gamefic::Scene::YesOrNo]
79
+ # @return [Class<Gamefic::Scene::YesOrNo>]
80
+ def yes_or_no prompt = nil, &block
81
+ s = Scene::YesOrNo.subclass do |actor, scene|
82
+ scene.prompt = prompt
83
+ scene.on_finish &block
84
+ end
85
+ scene_classes.push s
86
+ s
87
+ end
88
+
89
+ # Create a scene with custom processing on user input.
90
+ #
91
+ # @example Echo the user's response
92
+ # @scene = question 'What do you say?' do |actor, scene|
93
+ # actor.tell "You said #{scene.input}"
94
+ # end
95
+ #
96
+ # @param prompt [String]
97
+ # @yieldparam [Gamefic::Actor]
98
+ # @yieldparam [Gamefic::Scene::Custom]
99
+ # @return [Class<Gamefic::Scene::Custom>]
100
+ def question prompt = 'What is your answer?', &block
101
+ s = Scene::Custom.subclass do |actor, scene|
102
+ scene.prompt = prompt
103
+ scene.on_finish &block
104
+ end
105
+ scene_classes.push s
106
+ s
107
+ end
108
+
109
+ # Create a scene that pauses the game.
110
+ # This scene will execute the specified block and wait for input from the
111
+ # the user (e.g., pressing Enter) to continue.
112
+ #
113
+ # @example
114
+ # @scene = pause 'Continue' do |actor|
115
+ # actor.tell "After you continue, you will be prompted for a command."
116
+ # actor.prepare default_scene
117
+ # end
118
+ #
119
+ # @param prompt [String] The text to display when prompting the user to continue.
120
+ # @yieldparam [Gamefic::Actor]
121
+ # @return [Class<Gamefic::Scene::Pause>]
122
+ def pause prompt = nil, &block
123
+ s = Scene::Pause.subclass do |actor, scene|
124
+ scene.prompt = prompt unless prompt.nil?
125
+ block.call(actor, scene) unless block.nil?
126
+ end
127
+ scene_classes.push s
128
+ s
129
+ end
130
+
131
+ # Create a conclusion.
132
+ # The game (or the character's participation in it) will end after this
133
+ # scene is complete.
134
+ #
135
+ # @example
136
+ # @scene = conclusion do |actor|
137
+ # actor.tell 'Game over'
138
+ # end
139
+ #
140
+ # @yieldparam [Gamefic::Actor]
141
+ # @return [Class<Gamefic::Scene::Conclusion>]
142
+ def conclusion &block
143
+ s = Scene::Conclusion.subclass &block
144
+ scene_classes.push s
145
+ s
146
+ end
147
+
148
+ # Create a custom scene.
149
+ #
150
+ # Custom scenes should always specify the next scene to be cued or
151
+ # prepared. If not, the scene will get repeated on the next turn.
152
+ #
153
+ # This method creates a Scene::Custom by default. You can customize other
154
+ # scene types by specifying the class to create.
155
+ #
156
+ # @example Ask the user for a name
157
+ # @scene = custom do |scene|
158
+ # data.prompt = "What's your name?"
159
+ # scene.on_finish do |actor, data|
160
+ # actor.name = data.input
161
+ # actor.tell "Hello, #{actor.name}!"
162
+ # actor.cue :active
163
+ # end
164
+ # end
165
+ #
166
+ # @param cls [Class] The class of scene to be instantiated.
167
+ # @yieldparam [Gamefic::Actor]
168
+ # @return [Class<Gamefic::Scene::Custom>]
169
+ def custom cls = Scene::Custom, &block
170
+ s = cls.subclass &block
171
+ scene_classes.push s
172
+ s
173
+ end
174
+
175
+ # Choose a new scene based on a list of options.
176
+ # This is a specialized type of multiple-choice scene that determines
177
+ # which scene to cue based on a Hash of choices and scene keys.
178
+ #
179
+ # @example Select a scene
180
+ # scene_one = pause do |actor|
181
+ # actor.tell "You went to scene one"
182
+ # end
183
+ #
184
+ # scene_two = pause do |actor|
185
+ # actor.tell "You went to scene two"
186
+ # end
187
+ #
188
+ # select_one_or_two = multiple_scene "One" => scene_one, "Two" => scene_two
189
+ #
190
+ # introduction do |actor|
191
+ # actor.cue select_one_or_two # The actor will be prompted to select "one" or "two" and get sent to the corresponding scene
192
+ # end
193
+ #
194
+ # @example Customize options
195
+ # scene_one = pause # do...
196
+ # scene_two = pause # do...
197
+ #
198
+ # # Some event in the game sets actor[:can_go_to_scene_two] to true
199
+ #
200
+ # select_one_or_two = multiple_scene do |actor, scene|
201
+ # scene.map "Go to scene one", scene_one
202
+ # scene.map "Go to scene two", scene_two if actor[:can_go_to_scene_two]
203
+ # end
204
+ #
205
+ # @param map [Hash] A Hash of options and associated scenes.
206
+ # @yieldparam [Gamefic::Actor]
207
+ # @yieldparam [Gamefic::Scene::MultipleScene]
208
+ # @return [Class<Gamefic::Scene::MultipleScene>]
209
+ def multiple_scene map = {}, &block
210
+ s = Scene::MultipleScene.subclass do |actor, scene|
211
+ map.each_pair { |k, v|
212
+ scene.map k, v
213
+ }
214
+ block.call actor, scene unless block.nil?
215
+ end
216
+ scene_classes.push s
217
+ s
218
+ end
219
+
220
+ # @return [Array<Class<Gamefic::Scene::Base>>]
221
+ def scene_classes
222
+ @scene_classes ||= []
223
+ end
224
+ end
225
+ end
226
+ end
metadata CHANGED
@@ -1,103 +1,84 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamefic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-01 00:00:00.000000000 Z
11
+ date: 2020-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: thor
14
+ name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '0.19'
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
- version: 0.19.4
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
19
+ version: '12.3'
27
20
  - - "~>"
28
21
  - !ruby/object:Gem::Version
29
- version: '0.19'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 0.19.4
33
- - !ruby/object:Gem::Dependency
34
- name: rubyzip
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '1.2'
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: 1.2.0
43
- type: :runtime
22
+ version: '12.3'
23
+ type: :development
44
24
  prerelease: false
45
25
  version_requirements: !ruby/object:Gem::Requirement
46
26
  requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '1.2'
50
27
  - - ">="
51
28
  - !ruby/object:Gem::Version
52
- version: 1.2.0
29
+ version: '12.3'
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '12.3'
53
33
  - !ruby/object:Gem::Dependency
54
34
  name: rspec
55
35
  requirement: !ruby/object:Gem::Requirement
56
36
  requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '3.5'
60
37
  - - ">="
61
38
  - !ruby/object:Gem::Version
62
39
  version: 3.5.0
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '3.5'
63
43
  type: :development
64
44
  prerelease: false
65
45
  version_requirements: !ruby/object:Gem::Requirement
66
46
  requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '3.5'
70
47
  - - ">="
71
48
  - !ruby/object:Gem::Version
72
49
  version: 3.5.0
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '3.5'
73
53
  - !ruby/object:Gem::Dependency
74
- name: rake
54
+ name: simplecov
75
55
  requirement: !ruby/object:Gem::Requirement
76
56
  requirements:
77
57
  - - "~>"
78
58
  - !ruby/object:Gem::Version
79
- version: '11.3'
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: 11.3.0
59
+ version: '0.14'
83
60
  type: :development
84
61
  prerelease: false
85
62
  version_requirements: !ruby/object:Gem::Requirement
86
63
  requirements:
87
64
  - - "~>"
88
65
  - !ruby/object:Gem::Version
89
- version: '11.3'
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: 11.3.0
66
+ version: '0.14'
93
67
  description: An adventure game and interactive fiction framework
94
68
  email: fsnyder@gamefic.com
95
- executables:
96
- - gamefic
69
+ executables: []
97
70
  extensions: []
98
71
  extra_rdoc_files: []
99
72
  files:
100
- - bin/gamefic
73
+ - ".gitignore"
74
+ - ".rspec"
75
+ - ".rubocop.yml"
76
+ - ".solargraph.yml"
77
+ - Gemfile
78
+ - LICENSE
79
+ - README.md
80
+ - Rakefile
81
+ - gamefic.gemspec
101
82
  - lib/gamefic.rb
102
83
  - lib/gamefic/action.rb
103
84
  - lib/gamefic/active.rb
@@ -107,36 +88,15 @@ files:
107
88
  - lib/gamefic/core_ext/string.rb
108
89
  - lib/gamefic/describable.rb
109
90
  - lib/gamefic/element.rb
110
- - lib/gamefic/engine.rb
111
- - lib/gamefic/engine/base.rb
112
- - lib/gamefic/engine/tty.rb
113
91
  - lib/gamefic/entity.rb
114
- - lib/gamefic/grammar.rb
115
- - lib/gamefic/grammar/conjugator.rb
116
- - lib/gamefic/grammar/gender.rb
117
- - lib/gamefic/grammar/person.rb
118
- - lib/gamefic/grammar/plural.rb
119
- - lib/gamefic/grammar/pronouns.rb
120
- - lib/gamefic/grammar/tense.rb
121
- - lib/gamefic/grammar/verb_set.rb
122
- - lib/gamefic/grammar/verbs.rb
123
- - lib/gamefic/grammar/word_adapter.rb
124
- - lib/gamefic/matchable.rb
92
+ - lib/gamefic/index.rb
93
+ - lib/gamefic/keywords.rb
125
94
  - lib/gamefic/messaging.rb
126
95
  - lib/gamefic/node.rb
127
96
  - lib/gamefic/plot.rb
128
- - lib/gamefic/plot/articles.rb
129
- - lib/gamefic/plot/callbacks.rb
130
- - lib/gamefic/plot/commands.rb
131
97
  - lib/gamefic/plot/darkroom.rb
132
- - lib/gamefic/plot/entities.rb
133
98
  - lib/gamefic/plot/host.rb
134
- - lib/gamefic/plot/playbook.rb
135
- - lib/gamefic/plot/players.rb
136
- - lib/gamefic/plot/scenes.rb
137
99
  - lib/gamefic/plot/snapshot.rb
138
- - lib/gamefic/plot/theater.rb
139
- - lib/gamefic/plot/you_mount.rb
140
100
  - lib/gamefic/query.rb
141
101
  - lib/gamefic/query/base.rb
142
102
  - lib/gamefic/query/children.rb
@@ -157,28 +117,18 @@ files:
157
117
  - lib/gamefic/scene/multiple_scene.rb
158
118
  - lib/gamefic/scene/pause.rb
159
119
  - lib/gamefic/scene/yes_or_no.rb
160
- - lib/gamefic/script.rb
161
- - lib/gamefic/script/base.rb
162
- - lib/gamefic/script/file.rb
163
- - lib/gamefic/script/text.rb
164
- - lib/gamefic/shell.rb
165
- - lib/gamefic/source.rb
166
- - lib/gamefic/source/base.rb
167
- - lib/gamefic/source/file.rb
168
- - lib/gamefic/source/text.rb
120
+ - lib/gamefic/scriptable.rb
121
+ - lib/gamefic/serialize.rb
169
122
  - lib/gamefic/subplot.rb
170
123
  - lib/gamefic/syntax.rb
171
- - lib/gamefic/tester.rb
172
- - lib/gamefic/text.rb
173
- - lib/gamefic/text/ansi.rb
174
- - lib/gamefic/text/html.rb
175
- - lib/gamefic/text/html/conversions.rb
176
- - lib/gamefic/text/html/entities.rb
177
- - lib/gamefic/tty.rb
178
- - lib/gamefic/user.rb
179
- - lib/gamefic/user/base.rb
180
- - lib/gamefic/user/tty.rb
181
124
  - lib/gamefic/version.rb
125
+ - lib/gamefic/world.rb
126
+ - lib/gamefic/world/callbacks.rb
127
+ - lib/gamefic/world/commands.rb
128
+ - lib/gamefic/world/entities.rb
129
+ - lib/gamefic/world/playbook.rb
130
+ - lib/gamefic/world/players.rb
131
+ - lib/gamefic/world/scenes.rb
182
132
  homepage: http://gamefic.com
183
133
  licenses:
184
134
  - MIT
@@ -198,8 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
148
  - !ruby/object:Gem::Version
199
149
  version: '0'
200
150
  requirements: []
201
- rubyforge_project:
202
- rubygems_version: 2.5.1
151
+ rubygems_version: 3.0.3
203
152
  signing_key:
204
153
  specification_version: 4
205
154
  summary: Gamefic