Class: TyranoDsl::WritingContext

Inherits:
Object
  • Object
show all
Defined in:
lib/tyrano_dsl/writing_context.rb

Overview

Context for writing

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(world) ⇒ WritingContext

Returns a new instance of WritingContext.

Parameters:



21
22
23
24
25
26
27
28
29
30
# File 'lib/tyrano_dsl/writing_context.rb', line 21

def initialize(world)
  @logger = Logger.new(STDOUT)
  @world = world
  @file_actions = []
  @current_scene_content = nil
  @current_scene_name = nil
  @current_scene_assets = nil
  @current_scene_labels = nil
  @scene_writer = TyranoDsl::ElementsWriters::SceneWriter.new
end

Instance Attribute Details

#current_scene_assetsArray<String> (readonly)

Returns:

  • (Array<String>)


12
13
14
# File 'lib/tyrano_dsl/writing_context.rb', line 12

def current_scene_assets
  @current_scene_assets
end

#current_scene_contentArray<String> (readonly)

Returns:

  • (Array<String>)


14
15
16
# File 'lib/tyrano_dsl/writing_context.rb', line 14

def current_scene_content
  @current_scene_content
end

#file_actionsHash{String => Object} (readonly)

Returns:

  • (Hash{String => Object})


16
17
18
# File 'lib/tyrano_dsl/writing_context.rb', line 16

def file_actions
  @file_actions
end

#worldTyranoDsl::Elements::World (readonly)



18
19
20
# File 'lib/tyrano_dsl/writing_context.rb', line 18

def world
  @world
end

Instance Method Details

#add_asset_loading(word_location, asset_content) ⇒ void

This method returns an undefined value.

Add an asset to be loaded in the current scene

Parameters:

  • word_location (Array<String>)
  • asset_content (String)

Raises:



49
50
51
52
# File 'lib/tyrano_dsl/writing_context.rb', line 49

def add_asset_loading(word_location, asset_content)
  check_in_scene(word_location)
  @current_scene_assets << asset_content
end

#add_label(word_location, label_name) ⇒ void

This method returns an undefined value.

Add an label in the current scene

Parameters:

  • word_location (Array<String>)
  • label_name (String)

Raises:



60
61
62
63
64
65
66
# File 'lib/tyrano_dsl/writing_context.rb', line 60

def add_label(word_location, label_name)
  check_in_scene(word_location)
  if @current_scene_labels.include? label_name
    raise TyranoDsl::TyranoException, "Duplicated label [#{label_name}]"
  end
  @current_scene_labels << label_name
end

#append_content(word_location, content) ⇒ void

This method returns an undefined value.

Append some content to the current scene

Parameters:

  • word_location (Array<String>)
  • content (Array<String>)

Raises:



38
39
40
41
# File 'lib/tyrano_dsl/writing_context.rb', line 38

def append_content(word_location, content)
  check_in_scene(word_location)
  @current_scene_content << content
end

#end_writingvoid

This method returns an undefined value.

Bookkeeping stuff to end the writing



82
83
84
85
86
87
88
89
90
# File 'lib/tyrano_dsl/writing_context.rb', line 82

def end_writing
  write_current_scene
  @current_scene_content = nil
  @current_scene_name = nil
  @current_scene_assets = nil
  @current_scene_labels = nil
  @world.validate
  log {"Writing is over, #{@file_actions.length} actions created"}
end

#init_new_scene(scene_name) ⇒ void

This method returns an undefined value.

Initialize a new scene

Parameters:

  • scene_name (String)

    the scene name



71
72
73
74
75
76
77
# File 'lib/tyrano_dsl/writing_context.rb', line 71

def init_new_scene(scene_name)
  write_current_scene
  @current_scene_content = []
  @current_scene_name = scene_name
  @current_scene_assets = Set.new
  @current_scene_labels = []
end