Module: Inform

Includes:
StoryTeller::Builtins
Defined in:
lib/story_teller/tree.rb,
lib/story_teller/events.rb,
lib/story_teller/events.rb,
lib/story_teller/events.rb,
lib/story_teller/stdlib.rb,
lib/story_teller/stdlib.rb,
lib/story_teller/stdlib.rb,
lib/story_teller/stdlib.rb,
lib/story_teller/context.rb,
lib/story_teller/helpers.rb,
lib/story_teller/helpers.rb,
lib/story_teller/helpers.rb,
lib/story_teller/helpers.rb,
lib/story_teller/history.rb,
lib/story_teller/version.rb,
lib/story_teller/articles.rb,
lib/story_teller/prototype.rb,
lib/story_teller/world_tree.rb,
lib/story_teller/grammar_parser.rb,
lib/story_teller/grammar_parser.rb,
lib/story_teller/grammar_parser.rb,
lib/story_teller/grammar_parser.rb,
lib/story_teller/inform/ephemeral/tag.rb,
lib/story_teller/inform/ephemeral/tag.rb,
lib/story_teller/inform/ephemeral/tag.rb,
lib/story_teller/inform/ephemeral/tag.rb,
lib/story_teller/inform/ephemeral/tag.rb,
lib/story_teller/inform/ephemeral/tag.rb,
lib/story_teller/inform/ephemeral/tag.rb,
lib/story_teller/inform/ephemeral/link.rb,
lib/story_teller/inform/ephemeral/link.rb,
lib/story_teller/inform/ephemeral/module.rb,
lib/story_teller/inform/ephemeral/module.rb,
lib/story_teller/inform/ephemeral/module.rb,
lib/story_teller/inform/ephemeral/object.rb,
lib/story_teller/inform/ephemeral/object.rb,
lib/story_teller/experimental/handler_dsl.rb

Overview

The Inform module

Defined Under Namespace

Modules: Behavior, BuilderInstanceMethods, Context, Ephemeral, Events, Genealogical, Grammar, History, Linkable, Matchers, Modular, NilClassObjectHelpers, NilClassSetHelpers, ObjectHelpers, Parser, Prototypical, Rules, SetHelpers, StdLib, TagHelpers, Taggable, Verbs Classes: BehaviorError, DuplicateVerb, Event, EventCauseRecordNotFoundError, TagRegistry, UnexpectedToken, Verb

Constant Summary collapse

NONANIMATE_BIT =

Support WriteListFrom implementations that prefer to skip animate objects

0x8000
VERSION =
StoryTeller::Engine::VERSION
VN_1610 =
'1610'.freeze
Dictionary =
Set.new
EphemeralObjects =
if defined?(Java)
  java.util.concurrent.ConcurrentHashMap.new
else
  {}
end
EphemeralObjectsChildren =
if defined?(Java)
  java.util.concurrent.ConcurrentHashMap.new
else
  {}
end

Constants included from StoryTeller::Builtins

StoryTeller::Builtins::MethodDefinitionPattern, StoryTeller::Builtins::MethodTerminationPattern, StoryTeller::Builtins::NOUN, StoryTeller::Builtins::PLURAL, StoryTeller::Builtins::PREPOSITION, StoryTeller::Builtins::VERB

Constants included from StoryTeller::Color

StoryTeller::Color::BackgroundColorCodes, StoryTeller::Color::ColorCodes, StoryTeller::Color::NearestColor, StoryTeller::Color::StyleCodes

Constants included from StoryTeller::Articles

StoryTeller::Articles::LowercaseASpaceString, StoryTeller::Articles::LowercaseSomeSpaceString, StoryTeller::Articles::LowercaseTheSpaceString

Class Method Summary collapse

Instance Method Summary collapse

Methods included from StoryTeller::Builtins

#__quit, #__read, #__restart, #__restore, #__save, #__verify, #apply_instance_behavior!, #classification, #compass, #content, #current_word, #deadflag, #deadflag=, #dict_par1, #dictionary, #disrobe, #drop, #emote, #findobject, #getobject, #go, #inform_object_class, #inform_object_collection, #inform_object_fetch, #initial, #language_descriptors, #language_pronouns, #library_method?, #life?, #light_adjusted, #method_source, #nothing, #num_words, #number, #object_name_matches?, #objectloop, #ofclass, #pause, #provides?, #randomly, #react_after?, #react_before?, #remaining_words, #resembles_method?, #say, #score, #score=, #search, #sequel_model?, #special, #the_time, #the_time=, #things_score, #things_score=, #to_s, #topic, #visibility_ceiling=, #workflags

Methods included from StoryTeller::Plurals

#apply_inflections, #plural?, #pluralize, #singular?, #singularize

Methods included from StoryTeller::Color

#background_color, #color, #nearest_color, #style, #un_background_color, #un_color, #un_style

Methods included from StoryTeller::Articles

#A, #Cthatorthose, #Ctheyreorthats, #The, #a, #cthatorthose, #ctheyreorthats, #defart, #indefart, #isorare, #itorthem, #thatorthose, #the

Class Method Details

.attributesObject



136
137
138
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 136

def attributes
  TagRegistry::SINGLETON.memo ||= TagRegistry.new
end

.Grammar(src) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/story_teller/grammar_parser.rb', line 33

def Grammar(src)
  source_location = caller_locations(1, 1).first
  mod_name = File.basename(source_location.path, '.*').gsub(/\W+/, '_').to_sym
  Inform::Grammar::Parser.new.parse_grammar(mod_name, src.each_line,
    origin_path: source_location.path, origin_line: source_location.lineno)
  self
end


69
70
71
# File 'lib/story_teller/inform/ephemeral/link.rb', line 69

def link_klass
  Inform::Ephemeral::Link
end

.tag_klassObject



132
133
134
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 132

def tag_klass
  Inform::Ephemeral::Tag
end

Instance Method Details

#builder(target, behavior, context) ⇒ Object



140
141
142
143
144
145
146
147
# File 'lib/story_teller/experimental/handler_dsl.rb', line 140

def builder(target, behavior, context)
  Class.new do
    def initialize(target, behavior, context)
      @target, @behavior, @context = target, behavior, context
      self.extend(BuilderInstanceMethods)
    end
  end.new(target, behavior, context)
end

#context_proxy(target, context, proxy = Object.new) ⇒ Object

rubocop: disable Metrics/MethodLength



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/story_teller/experimental/handler_dsl.rb', line 82

def context_proxy(target, context, proxy = Object.new)
  return target if context.nil?

  proxy.define_singleton_method(:method_missing) do |method_name, *args, &block|
    if context.local_variable_defined?(method_name)
      context.local_variable_get(method_name)
    elsif target.respond_to?(method_name)
      target.public_send(method_name, *args, &block)
    else
      super(method_name, *args, &block)
    end
  end

  proxy.define_singleton_method(:respond_to_missing?) do |method_name, include_private = false|
    context.local_variable_defined?(method_name) || target.respond_to?(method_name, include_private)
  end

  proxy
end

#ensure_behavior_module!(key, behavior) ⇒ Object

Raises:



109
110
111
# File 'lib/story_teller/experimental/handler_dsl.rb', line 109

def ensure_behavior_module!(key, behavior)
  raise BehaviorError.new(key, behavior) unless behavior.is_a?(::Module)
end

#extend_and_persist(behavior) ⇒ Object

rubocop: enable Metrics/MethodLength



103
104
105
106
107
# File 'lib/story_teller/experimental/handler_dsl.rb', line 103

def extend_and_persist(behavior)
  self.extend(behavior)
  self.save_changes if self.respond_to?(:save_changes)
  self
end

#with(context = nil, key = Inform::Behavior.key_for(self), &block) ⇒ Object

rubocop: disable Metrics/AbcSize rubocop: disable Metrics/MethodLength



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/story_teller/experimental/handler_dsl.rb', line 57

def with(context = nil, key = Inform::Behavior.key_for(self), &block)
  log.debug "with.self=#{self.inspect} (#{self.identity})"
  behavior = Inform::Behavior::REGISTRY[key] ||= ::Module.new
  ensure_behavior_module!(key, behavior)

  unless block.nil?
    proxy = context_proxy(context || self, block.binding)
    b = builder(self, behavior, proxy)
    klass = b.class
    before = klass.instance_methods(false)

    b.instance_exec(proxy, &block)

    added = klass.instance_methods(false) - before
    added.each do |m|
      behavior.define_method(m, klass.instance_method(m))
    end
  end

  extend_and_persist(behavior)
end