Module: StoryTeller::Engine

Defined in:
lib/story_teller/engine.rb,
lib/story_teller/version.rb

Overview

module Engine

Defined Under Namespace

Modules: Config, Library

Constant Summary collapse

VERSION =
'1.3.2'.freeze

Class Method Summary collapse

Class Method Details

.bind_managed_library(inform_library) ⇒ Object

Raises:

  • (ManagedLibraryError)


90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/story_teller/engine.rb', line 90

def bind_managed_library(inform_library)
  raise ManagedLibraryError, "InformLibrary is nil" if inform_library.nil?

  selfobj = inform_library.selfobj
  raise ManagedLibraryError, "InformLibrary selfobj is nil" if selfobj.nil?

  libraries[selfobj] = inform_library
  selfobj.inflib = inform_library if selfobj.respond_to?(:inflib=)

  seed_library_location(inform_library) if location_unset?(inform_library)

  inform_library
end

.default_configObject



129
130
131
# File 'lib/story_teller/engine.rb', line 129

def default_config
  @default_config ||= StoryTeller::Engine::Config::DEFAULTS
end

.default_environmentObject



153
154
155
# File 'lib/story_teller/engine.rb', line 153

def default_environment
  StoryTeller::Engine.default_config[:environment]
end

.default_invocation_propertiesObject



157
158
159
# File 'lib/story_teller/engine.rb', line 157

def default_invocation_properties
  StoryTeller::Engine.default_config.fetch(:properties, '').split.map(&:to_sym).freeze
end

.executableObject



149
150
151
# File 'lib/story_teller/engine.rb', line 149

def executable
  @executable
end

.executable=(executable) ⇒ Object



145
146
147
# File 'lib/story_teller/engine.rb', line 145

def executable=(executable)
  @executable = executable
end

.inform_code_prefixObject



133
134
135
# File 'lib/story_teller/engine.rb', line 133

def inform_code_prefix
  StoryTeller::Engine.default_config[:inform6lib_gem_code_prefix]
end

.invocation_contextObject



170
171
172
# File 'lib/story_teller/engine.rb', line 170

def invocation_context
  @invocation_context ||= Struct.new(*invocation_properties)
end

.invocation_propertiesObject



161
162
163
# File 'lib/story_teller/engine.rb', line 161

def invocation_properties
  @invocation_properties ||= default_invocation_properties
end

.invocation_properties=(properties) ⇒ Object



165
166
167
168
# File 'lib/story_teller/engine.rb', line 165

def invocation_properties=(properties)
  @invocation_properties = properties
  @invocation_context = nil
end

.language_nameObject



174
175
176
# File 'lib/story_teller/engine.rb', line 174

def language_name
  StoryTeller::Engine.default_config[:language]
end

.librariesObject



58
59
60
# File 'lib/story_teller/engine.rb', line 58

def libraries
  @libraries ||= {}
end

.library(selfobj = player_object) ⇒ Object



74
75
76
77
78
79
# File 'lib/story_teller/engine.rb', line 74

def library(selfobj = player_object)
  return libraries[selfobj] if !selfobj.nil? && libraries.key?(selfobj)

  inflib = InformLibrary.new.tap { |inflib| inflib.selfobj = selfobj }
  bind_managed_library(inflib)
end

.location_unset?(inflib) ⇒ Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/story_teller/engine.rb', line 111

def location_unset?(inflib)
  inflib&.instance_variable_get(:@location).nil?
end

.main_objectObject



125
126
127
# File 'lib/story_teller/engine.rb', line 125

def main_object
  @main_object
end

.main_object=(obj) ⇒ Object



121
122
123
# File 'lib/story_teller/engine.rb', line 121

def main_object=(obj)
  @main_object = obj
end

.parser_selfobjObject



115
116
117
118
119
# File 'lib/story_teller/engine.rb', line 115

def parser_selfobj
  return nil unless defined?(Inform::Parser::SelfObj)

  Inform::Parser::SelfObj
end

.player?(obj) ⇒ Boolean

Returns:

  • (Boolean)


178
179
180
181
# File 'lib/story_teller/engine.rb', line 178

def player?(obj)
  return false unless defined?(StoryTeller::IO::Session) && StoryTeller::IO::Session.respond_to?(:players)
  StoryTeller::IO::Session.players.include?(obj)
end

.player_objectObject



62
63
64
# File 'lib/story_teller/engine.rb', line 62

def player_object
  @player_object || parser_selfobj
end

.player_object=(object) ⇒ Object

Raises:

  • (ManagedLibraryError)


66
67
68
69
70
71
72
# File 'lib/story_teller/engine.rb', line 66

def player_object=(object)
  raise ManagedLibraryError, "player object is nil" if object.nil?

  @player_object = object
  replace_parser_selfobj(object)
  libraries.clear
end

.prime_dictionaryObject



183
184
185
186
187
188
189
# File 'lib/story_teller/engine.rb', line 183

def prime_dictionary
  Inform::Object.select_map(:name).compact.each do |n|
    Array(n).join(' ').split(/[,\s]+/).grep_v(/[^a-z]/i).map(&:downcase).map(&:to_sym).each do |word|
      StoryTeller::Dictionary.merge([word])
    end
  end
end

.project_dir_pathObject



137
138
139
140
141
142
143
# File 'lib/story_teller/engine.rb', line 137

def project_dir_path
  @project_dir_path ||= begin
    story_dir_path = File.expand_path(__dir__)
    lib_dir_path = File.expand_path(File.dirname(story_dir_path))
    File.expand_path(File.dirname(lib_dir_path))
  end
end

.replace_parser_selfobj(object) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/story_teller/engine.rb', line 81

def replace_parser_selfobj(object)
  return object unless defined?(Inform::Parser)

  Inform::Parser.send(:remove_const, :SelfObj) if Inform::Parser.const_defined?(:SelfObj, false)
  Inform::Parser.const_set(:SelfObj, object)

  object
end

.seed_library_location(inflib) ⇒ Object



104
105
106
107
108
109
# File 'lib/story_teller/engine.rb', line 104

def seed_library_location(inflib)
  player_obj = inflib.selfobj
  location = player_obj.location if player_obj.respond_to?(:location)

  inflib.instance_variable_set(:@location, location) unless location.nil?
end