gamefic 1.7.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +12 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +16 -0
  5. data/.solargraph.yml +5 -0
  6. data/CHANGELOG.md +10 -0
  7. data/Gemfile +7 -0
  8. data/LICENSE +20 -0
  9. data/README.md +28 -0
  10. data/Rakefile +10 -0
  11. data/gamefic.gemspec +27 -0
  12. data/lib/gamefic.rb +7 -7
  13. data/lib/gamefic/action.rb +66 -60
  14. data/lib/gamefic/active.rb +331 -280
  15. data/lib/gamefic/actor.rb +8 -5
  16. data/lib/gamefic/command.rb +9 -7
  17. data/lib/gamefic/core_ext/array.rb +27 -49
  18. data/lib/gamefic/core_ext/string.rb +25 -16
  19. data/lib/gamefic/describable.rb +21 -23
  20. data/lib/gamefic/element.rb +47 -31
  21. data/lib/gamefic/entity.rb +6 -12
  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 -91
  26. data/lib/gamefic/plot/darkroom.rb +80 -264
  27. data/lib/gamefic/plot/host.rb +42 -48
  28. data/lib/gamefic/plot/snapshot.rb +14 -19
  29. data/lib/gamefic/query.rb +15 -18
  30. data/lib/gamefic/query/base.rb +50 -37
  31. data/lib/gamefic/query/children.rb +0 -0
  32. data/lib/gamefic/query/descendants.rb +2 -2
  33. data/lib/gamefic/query/external.rb +18 -14
  34. data/lib/gamefic/query/family.rb +3 -7
  35. data/lib/gamefic/query/matches.rb +75 -67
  36. data/lib/gamefic/query/parent.rb +0 -0
  37. data/lib/gamefic/query/siblings.rb +0 -0
  38. data/lib/gamefic/query/text.rb +12 -12
  39. data/lib/gamefic/query/tree.rb +17 -0
  40. data/lib/gamefic/scene.rb +0 -2
  41. data/lib/gamefic/scene/activity.rb +24 -26
  42. data/lib/gamefic/scene/base.rb +71 -10
  43. data/lib/gamefic/scene/conclusion.rb +1 -3
  44. data/lib/gamefic/scene/multiple_choice.rb +19 -14
  45. data/lib/gamefic/scene/multiple_scene.rb +29 -20
  46. data/lib/gamefic/scene/pause.rb +8 -3
  47. data/lib/gamefic/scene/yes_or_no.rb +22 -10
  48. data/lib/gamefic/scriptable.rb +88 -0
  49. data/lib/gamefic/serialize.rb +223 -0
  50. data/lib/gamefic/subplot.rb +38 -35
  51. data/lib/gamefic/syntax.rb +15 -13
  52. data/lib/gamefic/version.rb +3 -3
  53. data/lib/gamefic/world.rb +18 -0
  54. data/lib/gamefic/world/callbacks.rb +135 -0
  55. data/lib/gamefic/world/commands.rb +184 -0
  56. data/lib/gamefic/{plot → world}/entities.rb +33 -35
  57. data/lib/gamefic/{plot → world}/playbook.rb +245 -240
  58. data/lib/gamefic/world/players.rb +37 -0
  59. data/lib/gamefic/world/scenes.rb +226 -0
  60. metadata +37 -88
  61. data/bin/gamefic +0 -9
  62. data/lib/gamefic/engine.rb +0 -7
  63. data/lib/gamefic/engine/base.rb +0 -59
  64. data/lib/gamefic/engine/tty.rb +0 -24
  65. data/lib/gamefic/grammar.rb +0 -13
  66. data/lib/gamefic/grammar/conjugator.rb +0 -20
  67. data/lib/gamefic/grammar/gender.rb +0 -11
  68. data/lib/gamefic/grammar/person.rb +0 -10
  69. data/lib/gamefic/grammar/plural.rb +0 -13
  70. data/lib/gamefic/grammar/pronouns.rb +0 -106
  71. data/lib/gamefic/grammar/tense.rb +0 -6
  72. data/lib/gamefic/grammar/verb_set.rb +0 -43
  73. data/lib/gamefic/grammar/verbs.rb +0 -26
  74. data/lib/gamefic/grammar/word_adapter.rb +0 -49
  75. data/lib/gamefic/plot/articles.rb +0 -22
  76. data/lib/gamefic/plot/callbacks.rb +0 -126
  77. data/lib/gamefic/plot/commands.rb +0 -120
  78. data/lib/gamefic/plot/players.rb +0 -15
  79. data/lib/gamefic/plot/scenes.rb +0 -187
  80. data/lib/gamefic/plot/theater.rb +0 -73
  81. data/lib/gamefic/plot/you_mount.rb +0 -22
  82. data/lib/gamefic/scene/custom.rb +0 -9
  83. data/lib/gamefic/script.rb +0 -13
  84. data/lib/gamefic/script/base.rb +0 -42
  85. data/lib/gamefic/script/file.rb +0 -14
  86. data/lib/gamefic/script/text.rb +0 -14
  87. data/lib/gamefic/shell.rb +0 -76
  88. data/lib/gamefic/source.rb +0 -14
  89. data/lib/gamefic/source/base.rb +0 -12
  90. data/lib/gamefic/source/file.rb +0 -23
  91. data/lib/gamefic/source/text.rb +0 -16
  92. data/lib/gamefic/tester.rb +0 -19
  93. data/lib/gamefic/text.rb +0 -8
  94. data/lib/gamefic/text/ansi.rb +0 -53
  95. data/lib/gamefic/text/html.rb +0 -68
  96. data/lib/gamefic/text/html/conversions.rb +0 -250
  97. data/lib/gamefic/text/html/entities.rb +0 -9
  98. data/lib/gamefic/tty.rb +0 -10
  99. data/lib/gamefic/user.rb +0 -7
  100. data/lib/gamefic/user/base.rb +0 -29
  101. data/lib/gamefic/user/tty.rb +0 -38
@@ -0,0 +1,37 @@
1
+ module Gamefic
2
+ module World
3
+ module Players
4
+ include Gamefic::World::Entities
5
+ include Gamefic::World::Commands
6
+
7
+ # An array of entities that are currently connected to users.
8
+ #
9
+ # @return [Array<Gamefic::Actor>]
10
+ def players
11
+ @players ||= []
12
+ end
13
+
14
+ def player_class cls = nil
15
+ STDERR.puts "Modifying player_class this way is deprecated. Use set_player_class instead" unless cls.nil?
16
+ @player_class = cls unless cls.nil?
17
+ @player_class ||= Gamefic::Actor
18
+ end
19
+
20
+ # @param cls [Class]
21
+ def set_player_class cls
22
+ unless cls < Gamefic::Active && cls <= Gamefic::Entity
23
+ raise ArgumentError, "Player class must be an active entity"
24
+ end
25
+ @player_class = cls
26
+ end
27
+
28
+ # Make a character that a player will control on introduction.
29
+ #
30
+ # @return [Gamefic::Actor]
31
+ def make_player_character
32
+ cast player_class, name: 'yourself', synonyms: 'self myself you me', proper_named: true
33
+ end
34
+ alias get_player_character make_player_character
35
+ end
36
+ end
37
+ 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::Base]
99
+ # @return [Class<Gamefic::Scene::Base>]
100
+ def question prompt = 'What is your answer?', &block
101
+ s = Scene::Base.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::Base 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 |actor, scene|
158
+ # scene.prompt = "What's your name?"
159
+ # scene.on_finish do
160
+ # actor.name = scene.input
161
+ # actor.tell "Hello, #{actor.name}!"
162
+ # actor.cue default_scene
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::Base>]
169
+ def custom cls = Scene::Base, &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,55 +1,35 @@
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.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-01 00:00:00.000000000 Z
11
+ date: 2021-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: thor
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '0.19'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 0.19.4
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - "~>"
28
- - !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
14
+ name: rake
35
15
  requirement: !ruby/object:Gem::Requirement
36
16
  requirements:
37
17
  - - "~>"
38
18
  - !ruby/object:Gem::Version
39
- version: '1.2'
19
+ version: '12.3'
40
20
  - - ">="
41
21
  - !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
27
  - - "~>"
48
28
  - !ruby/object:Gem::Version
49
- version: '1.2'
29
+ version: '12.3'
50
30
  - - ">="
51
31
  - !ruby/object:Gem::Version
52
- version: 1.2.0
32
+ version: '12.3'
53
33
  - !ruby/object:Gem::Dependency
54
34
  name: rspec
55
35
  requirement: !ruby/object:Gem::Requirement
@@ -71,33 +51,35 @@ dependencies:
71
51
  - !ruby/object:Gem::Version
72
52
  version: 3.5.0
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
+ - CHANGELOG.md
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - gamefic.gemspec
101
83
  - lib/gamefic.rb
102
84
  - lib/gamefic/action.rb
103
85
  - lib/gamefic/active.rb
@@ -107,36 +89,14 @@ files:
107
89
  - lib/gamefic/core_ext/string.rb
108
90
  - lib/gamefic/describable.rb
109
91
  - lib/gamefic/element.rb
110
- - lib/gamefic/engine.rb
111
- - lib/gamefic/engine/base.rb
112
- - lib/gamefic/engine/tty.rb
113
92
  - 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
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
@@ -148,42 +108,32 @@ files:
148
108
  - lib/gamefic/query/parent.rb
149
109
  - lib/gamefic/query/siblings.rb
150
110
  - lib/gamefic/query/text.rb
111
+ - lib/gamefic/query/tree.rb
151
112
  - lib/gamefic/scene.rb
152
113
  - lib/gamefic/scene/activity.rb
153
114
  - lib/gamefic/scene/base.rb
154
115
  - lib/gamefic/scene/conclusion.rb
155
- - lib/gamefic/scene/custom.rb
156
116
  - lib/gamefic/scene/multiple_choice.rb
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
185
135
  metadata: {}
186
- post_install_message:
136
+ post_install_message:
187
137
  rdoc_options: []
188
138
  require_paths:
189
139
  - lib
@@ -198,9 +148,8 @@ 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
203
- signing_key:
151
+ rubygems_version: 3.1.6
152
+ signing_key:
204
153
  specification_version: 4
205
154
  summary: Gamefic
206
155
  test_files: []