Class: TyranoDsl::Elements::World

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

Overview

The game world

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWorld

Returns a new instance of World.



24
25
26
27
28
29
30
31
32
# File 'lib/tyrano_dsl/elements/world.rb', line 24

def initialize
  @characters = {}
  @backgrounds = {}
  @labels = {}
  @jump_targets = []
  @scenes = {}
  @variables = {}
  @title_screen = TyranoDsl::Elements::TitleScreen.new
end

Instance Attribute Details

#backgroundsHash{String => TyranoDsl::Elements::Background} (readonly)

Returns:



10
11
12
# File 'lib/tyrano_dsl/elements/world.rb', line 10

def backgrounds
  @backgrounds
end

#charactersHash{String => TyranoDsl::Elements::Character} (readonly)

Returns:



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

def characters
  @characters
end

#jump_targetsArray<TyranoDsl::Elements::JumpTarget> (readonly)



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

def jump_targets
  @jump_targets
end

#labelsHash{String => TyranoDsl::Elements::Label} (readonly)

Returns:



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

def labels
  @labels
end

#scenesHash{String => TyranoDsl::Elements::Scene} (readonly)

Returns:



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

def scenes
  @scenes
end

#title_screenTyranoDsl::Elements::TitleScreen (readonly)



20
21
22
# File 'lib/tyrano_dsl/elements/world.rb', line 20

def title_screen
  @title_screen
end

#variablesHash{String => TyranoDsl::Elements::Variable} (readonly)

Returns:



22
23
24
# File 'lib/tyrano_dsl/elements/world.rb', line 22

def variables
  @variables
end

Instance Method Details

#label_value(label_name) ⇒ TyranoDsl::Elements::Label

Parameters:

  • label_name (String, nil)

Returns:



51
52
53
54
55
56
57
58
59
60
# File 'lib/tyrano_dsl/elements/world.rb', line 51

def label_value(label_name)
  if @labels.key? label_name
    @labels[label_name]
  else
    technical_name = label_name ? "label_#{@labels.length}" : nil
    label = TyranoDsl::Elements::Label.new(label_name, technical_name)
    @labels[label_name] = label
    label
  end
end

#validatevoid

This method returns an undefined value.



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/tyrano_dsl/elements/world.rb', line 36

def validate
  @jump_targets.each do |jump_target|
    scene = @scenes[jump_target.scene]
    unless scene
      raise TyranoDsl::TyranoException, "Unknown scene [#{jump_target.scene}] declared in label"
    end
    jump_target_label = jump_target.label
    if jump_target_label && (!scene.labels.include?(jump_target_label.name))
      raise TyranoDsl::TyranoException, "Unknown label [#{jump_target_label.name}] declared in label"
    end
  end
end