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.2.3'.freeze

Class Method Summary collapse

Class Method Details

.bind_managed_library(inform_library) ⇒ Object

Raises:

  • (ManagedLibraryError)


71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/story_teller/engine.rb', line 71

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=)

  ensure_location(inform_library)

  inform_library
end

.default_configObject



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

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

.default_environmentObject



136
137
138
# File 'lib/story_teller/engine.rb', line 136

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

.default_invocation_propertiesObject



140
141
142
# File 'lib/story_teller/engine.rb', line 140

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

.ensure_location(inflib) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/story_teller/engine.rb', line 85

def ensure_location(inflib)
  return if inflib.nil?

  existing_location = inflib.instance_variable_get(:@location)
  return unless existing_location.nil?

  player = inflib.selfobj
  location = player.location if player.respond_to?(:location)
  location ||= player.spawn_point if player.respond_to?(:spawn_point)

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

.executableObject



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

def executable
  @executable
end

.executable=(executable) ⇒ Object



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

def executable=(executable)
  @executable = executable
end

.inform_code_prefixObject



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

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

.invocation_contextObject



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

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

.invocation_propertiesObject



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

def invocation_properties
  @invocation_properties ||= default_invocation_properties
end

.invocation_properties=(properties) ⇒ Object



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

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

.language_nameObject



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

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

.librariesObject



60
61
62
# File 'lib/story_teller/engine.rb', line 60

def libraries
  @libraries ||= {}
end

.libraryObject



64
65
66
67
68
69
# File 'lib/story_teller/engine.rb', line 64

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

  bind_managed_library(InformLibrary.new)
end

.main_objectObject



108
109
110
# File 'lib/story_teller/engine.rb', line 108

def main_object
  @main_object
end

.main_object=(obj) ⇒ Object



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

def main_object=(obj)
  @main_object = obj
end

.parser_selfobjObject



98
99
100
101
102
# File 'lib/story_teller/engine.rb', line 98

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

  Inform::Parser::SelfObj
end

.player?(obj) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.prime_dictionaryObject



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

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

.project_dir_pathObject



120
121
122
123
124
125
126
# File 'lib/story_teller/engine.rb', line 120

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