class MCDotArtMaker::SchematicHelper

.schematicを処理するためのクラス

nbt_utilsをラップして書き込み機能を追加する

Attributes

blocks[R]

include Singleton

data[R]

include Singleton

height[R]
length[R]
modified[R]
weOffsetX[R]
weOffsetY[R]
weOffsetZ[R]
weOriginX[R]
weOriginY[R]
weOriginZ[R]
width[R]

Public Class Methods

new() click to toggle source

@blocks: ブロックのIDデータ ブロックの並び順は -Xから +X方向 次に+Z方向に進んで -Xから +X方向 XZ平面のブロックを記述し終えたら +Y方向に1進む

# File lib/mc_dot_art_maker/schematic_helper.rb, line 17
def initialize
  @file = NBTUtils::File.new
end

Public Instance Methods

blocks=(other) click to toggle source
# File lib/mc_dot_art_maker/schematic_helper.rb, line 33
def blocks=(other)
  # - other - BlockID の配列
  @blocks = other
  @modified = true
end
data=(other) click to toggle source
# File lib/mc_dot_art_maker/schematic_helper.rb, line 38
def data=(other)
  # - other - Data の配列
  @data = other
  @modified = true
end
height=(other) click to toggle source
# File lib/mc_dot_art_maker/schematic_helper.rb, line 67
def height=(other)
  @height = other
  @modified = true
end
length=(other) click to toggle source
# File lib/mc_dot_art_maker/schematic_helper.rb, line 75
def length=(other)
  @length = other
  @modified = true
end
read(filename) click to toggle source
# File lib/mc_dot_art_maker/schematic_helper.rb, line 20
def read(filename)
  @filename = filename
  init
  @modified = false
end
refresh() click to toggle source
# File lib/mc_dot_art_maker/schematic_helper.rb, line 25
def refresh
  init
  @modified = false
end
to_s() click to toggle source
# File lib/mc_dot_art_maker/schematic_helper.rb, line 29
def to_s
  @tag.to_s
end
weOffsetX=(other) click to toggle source
# File lib/mc_dot_art_maker/schematic_helper.rb, line 43
def weOffsetX=(other)
  @weOffsetX = other
  @modified = true
end
weOffsetY=(other) click to toggle source
# File lib/mc_dot_art_maker/schematic_helper.rb, line 47
def weOffsetY=(other)
  @weOffsetY = other
  @modified = true
end
weOffsetZ=(other) click to toggle source
# File lib/mc_dot_art_maker/schematic_helper.rb, line 51
def weOffsetZ=(other)
  @weOffsetZ = other
  @modified = true
end
weOriginX=(other) click to toggle source
# File lib/mc_dot_art_maker/schematic_helper.rb, line 55
def weOriginX=(other)
  @weOriginX = other
  @modified = true
end
weOriginY=(other) click to toggle source
# File lib/mc_dot_art_maker/schematic_helper.rb, line 59
def weOriginY=(other)
  @weOriginY = other
  @modified = true
end
weOriginZ=(other) click to toggle source
# File lib/mc_dot_art_maker/schematic_helper.rb, line 63
def weOriginZ=(other)
  @weOriginZ = other
  @modified = true
end
width=(other) click to toggle source
# File lib/mc_dot_art_maker/schematic_helper.rb, line 71
def width=(other)
  @width = other
  @modified = true
end
write(name) click to toggle source
# File lib/mc_dot_art_maker/schematic_helper.rb, line 79
def write(name)
  raise(IllegalBlockSizeError,"Blocks or Data size doesn't match length*width*height: Block size #{@blocks.size}, width #{@width}, height #{@height}, length #{@length}") unless verify

  @tag.find_tag("Blocks").payload = to_nbt_block
  @tag.find_tag("Data").payload = to_nbt_data
  @tag.find_tag("WEOffsetX").payload = @weOffsetX
  @tag.find_tag("WEOffsetY").payload = @weOffsetY
  @tag.find_tag("WEOffsetZ").payload = @weOffsetZ
  @tag.find_tag("WEOriginX").payload = @weOriginX
  @tag.find_tag("WEOriginY").payload = @weOriginY
  @tag.find_tag("WEOriginZ").payload = @weOriginZ

  @tag.find_tag("Height").payload = @height
  @tag.find_tag("Width").payload = @width
  @tag.find_tag("Length").payload = @length

  @file.write(name, @tag, true)
  @modified = false
end

Private Instance Methods

init() click to toggle source
# File lib/mc_dot_art_maker/schematic_helper.rb, line 100
def init
  # .schematicを読みこんで、プロパティを初期化
  @tag = @file.read(@filename)

  @blocks = []
  @tag.find_tag("Blocks").payload.to_s.split("").each do |s|
    # p blockdata[s.unpack("H*")[0].hex]
    @blocks << s.unpack("H*")[0].hex
  end
  @data = []
  @tag.find_tag("Data").payload.to_s.split("").each do |s|
    # p blockdata[s.unpack("H*")[0].hex]
    @data << s.unpack("H*")[0].hex
  end

  @weOffsetX = @tag.find_tag("WEOffsetX").payload
  @weOffsetY = @tag.find_tag("WEOffsetY").payload
  @weOffsetZ = @tag.find_tag("WEOffsetZ").payload
  @weOriginX = @tag.find_tag("WEOriginX").payload
  @weOriginY = @tag.find_tag("WEOriginY").payload
  @weOriginZ = @tag.find_tag("WEOriginZ").payload

  @height = @tag.find_tag("Height").payload
  @width = @tag.find_tag("Width").payload
  @length = @tag.find_tag("Length").payload
end
to_nbt_block() click to toggle source
# File lib/mc_dot_art_maker/schematic_helper.rb, line 126
def to_nbt_block
  [@blocks.map{|b| b.to_s(16).rjust(2,"0") }.join].pack("H*")
end
to_nbt_data() click to toggle source
# File lib/mc_dot_art_maker/schematic_helper.rb, line 129
def to_nbt_data
  [@data.map{|d| d.to_s(16).rjust(2,"0") }.join].pack("H*")
end
verify() click to toggle source
# File lib/mc_dot_art_maker/schematic_helper.rb, line 132
def verify
  # ブロック数とデータ数が等しいか、Width * Length * height がブロック数と等しいか計算
  size = @width * @height * @length
  (@blocks.size == size) && (@data.size == size)
end