Class: RubyToBlock::Block::Character

Inherits:
Base
  • Object
show all
Defined in:
app/models/concerns/ruby_to_block/block/character.rb

Overview

ソースコードに含まれるキャラクターを表現するクラス

Constant Summary

Constants inherited from Base

Base::STRING_RE

Instance Attribute Summary collapse

Attributes inherited from Base

#fields, #parent, #prev_sibling, #sibling, #statements, #values

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#[], #add_statement, #add_value, blocknize, indent?, #indent_level, inherited, inline?, #inline?, #null?, priority, process_else, process_end, process_value_string, regexp, statement?, #type, type, value?

Constructor Details

#initialize(options) ⇒ Character

Returns a new instance of Character.



43
44
45
46
47
48
49
50
51
# File 'app/models/concerns/ruby_to_block/block/character.rb', line 43

def initialize(options)
  @name = options[:name]
  @costumes = options[:costumes]
  @costume_index = options[:costume_index]
  @x = options[:x]
  @y = options[:y]
  @angle = options[:angle]
  @rotation_style = options[:rotation_style]
end

Instance Attribute Details

#angleObject

Returns the value of attribute angle.



25
26
27
# File 'app/models/concerns/ruby_to_block/block/character.rb', line 25

def angle
  @angle
end

#costume_indexObject

Returns the value of attribute costume_index.



22
23
24
# File 'app/models/concerns/ruby_to_block/block/character.rb', line 22

def costume_index
  @costume_index
end

#costumesObject

Returns the value of attribute costumes.



21
22
23
# File 'app/models/concerns/ruby_to_block/block/character.rb', line 21

def costumes
  @costumes
end

#nameObject

rubocop:enable LineLength



20
21
22
# File 'app/models/concerns/ruby_to_block/block/character.rb', line 20

def name
  @name
end

#rotation_styleObject

Returns the value of attribute rotation_style.



26
27
28
# File 'app/models/concerns/ruby_to_block/block/character.rb', line 26

def rotation_style
  @rotation_style
end

#xObject

Returns the value of attribute x.



23
24
25
# File 'app/models/concerns/ruby_to_block/block/character.rb', line 23

def x
  @x
end

#yObject

Returns the value of attribute y.



24
25
26
# File 'app/models/concerns/ruby_to_block/block/character.rb', line 24

def y
  @y
end

Class Method Details

.process_match_data(md, context) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/concerns/ruby_to_block/block/character.rb', line 28

def self.process_match_data(md, context)
  md2 = regexp.match(md[type])
  name = md2[1]
  costumes = md2[2].scan(/"([^"]+)"/).flatten
  context[:characters][name] = new(name: name,
                                   costumes: costumes,
                                   costume_index: md2[3] || "0",
                                   x: md2[4],
                                   y: md2[5],
                                   angle: md2[6],
                                   rotation_style: md2[7] || "free")

  true
end

Instance Method Details

#to_xml(parent) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/concerns/ruby_to_block/block/character.rb', line 53

def to_xml(parent)
  attrs = {
    "name" => @name,
    "x" => @x,
    "y" => @y,
    "angle" => @angle,
    "costumes" => @costumes.join(","),
  }
  if @costume_index != "0"
    attrs["costume_index"] = @costume_index
  end
  if @rotation_style != "free"
    attrs["rotation_style"] = @rotation_style
  end
  parent.add_element("character", attrs)
end