Module: Inform::RuntimeInstanceMethods
Overview
The RuntimeInstanceMethods module
Constant Summary
Inform::RuntimeConstants::LibraryRegistry, Inform::RuntimeConstants::Registry, Inform::RuntimeConstants::UndefinedMainPattern
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#main_object ⇒ Object
Returns the value of attribute main_object.
133
134
135
|
# File 'lib/runtime/runtime.rb', line 133
def main_object
@main_object
end
|
Instance Method Details
#apply_preferences ⇒ Object
209
210
211
212
213
214
215
216
217
218
219
|
# File 'lib/runtime/runtime.rb', line 209
def apply_preferences
return if inform_library.nil?
player_obj = inform_library.player
preferences = player_obj.&:preferences
return if preferences.nil? || !preferences.respond_to?(:properties)
preferences.properties.each_pair do |key, value|
variable = :"@#{key}"
Parser.initial_state.delete(variable)
inform_library.instance_variable_set(variable, value)
end
end
|
#config_file_path ⇒ Object
135
136
137
|
# File 'lib/runtime/runtime.rb', line 135
def config_file_path
@config_file_path ||= File.join(game_path, @options[:game_config_file_name])
end
|
#ensure_location ⇒ Object
TODO: Ensuring the location of the player object requires that this method be invoked before the move @player, @location operation in the InformLibrary#play method. This means that ensuring the location must take place either in the game- defined Initialise() method, or else it can happen in a provided LibraryExtension method, but in that case it would be at risk of being overridden by a game-defined Initialise() method. TODO: Try to figure out what the best approach here is. I think that if a multi-player game is to supply an entrypoint module, it will have to handle the location ensurance itself.
185
186
187
188
189
190
191
192
|
# File 'lib/runtime/runtime.rb', line 185
def ensure_location
return if inform_library.nil?
return if inform_library.location
player_obj = inform_library.player
location = player_obj.location
location ||= player_obj.spawn_point if player_obj.respond_to?(:spawn_point)
inform_library.location = location
end
|
#game_components ⇒ Object
147
148
149
|
# File 'lib/runtime/runtime.rb', line 147
def game_components
@game_components ||= @options.fetch(:game_components, '').split.map(&:to_sym)
end
|
#game_dir_name ⇒ Object
139
140
141
|
# File 'lib/runtime/runtime.rb', line 139
def game_dir_name
@game_dir_name ||= @options[:game_dir_name]
end
|
#game_path ⇒ Object
143
144
145
|
# File 'lib/runtime/runtime.rb', line 143
def game_path
@game_path ||= File.expand_path(@options[:game_path])
end
|
#grammar_module_path ⇒ Object
151
152
153
|
# File 'lib/runtime/runtime.rb', line 151
def grammar_module_path
@grammar_module_path ||= File.join(game_path, @options[:game_grammar_module_name])
end
|
257
258
259
|
# File 'lib/runtime/runtime.rb', line 257
def inspect
to_s
end
|
#invocation_context ⇒ Object
159
160
161
|
# File 'lib/runtime/runtime.rb', line 159
def invocation_context
@invocation_context ||= Struct.new(*invocation_properties)
end
|
#invocation_properties ⇒ Object
155
156
157
|
# File 'lib/runtime/runtime.rb', line 155
def invocation_properties
@invocation_properties ||= @options.fetch(:properties, '').split.map(&:to_sym)
end
|
#invoke_main_method ⇒ Object
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/runtime/runtime.rb', line 163
def invoke_main_method
::Object.new.send(:Main)
rescue NameError => e
if UndefinedMainPattern.match?(e.message)
log.error "Main() definition is missing"
else
log.error e.message
e.backtrace.each { |t| log.error t } end
end
|
198
199
200
201
202
203
204
205
206
207
|
# File 'lib/runtime/runtime.rb', line 198
def manage_inform_library(key = Inform::Runtime)
Inform::Runtime.libraries[key] ||= begin
inform_library = InformLibrary.new
if self.respond_to?(:specialized_player)
inform_library.selfobj = specialized_player
end
inform_library.subscribe(inform_library.selfobj)
inform_library
end
end
|
#manage_privileges ⇒ Object
221
222
223
224
225
|
# File 'lib/runtime/runtime.rb', line 221
def manage_privileges
Inform::Object.include(Inform::Privileges)
return unless @options[:admin]
give inform_library.player, :admin
end
|
#play_game ⇒ Object
236
237
238
239
240
241
242
243
|
# File 'lib/runtime/runtime.rb', line 236
def play_game
log.debug "#{self}#play_game"
invoke_main_method
apply_preferences
manage_privileges
read_eval_print_loop
end
|
245
246
247
248
249
250
251
|
# File 'lib/runtime/runtime.rb', line 245
def quit
$stdout.print "[Hit enter to exit.]"
$stdin.getc
exit
end
|
#read_eval_print_loop ⇒ Object
227
228
229
230
231
232
233
234
|
# File 'lib/runtime/runtime.rb', line 227
def read_eval_print_loop
loop do
prompt
inform_library.send(inform_library.inform(read))
end
rescue Interrupt => e
$stdout.puts "\n#{e.class.name}"
end
|
253
254
255
|
# File 'lib/runtime/runtime.rb', line 253
def to_s
"#<#{self.class.name}:#{object_id}>"
end
|