module RBStarbound::SBVJ01

Public Class Methods

dump(io, player_data) click to toggle source
# File lib/rbstarbound/sbvj01.rb, line 14
def self.dump(io, player_data)
  sbvj01_header(io)
  write_player_data(io, player_data)
end
parse(io) click to toggle source
# File lib/rbstarbound/sbvj01.rb, line 7
def self.parse(io)
  unless sbvj01_header?(io)
    raise RBStarbound::SBVJ01Error, 'Not a SBVJ01 file'
  end
  read_player_data(io)
end

Private Class Methods

read_player_data(io) click to toggle source
# File lib/rbstarbound/sbvj01.rb, line 19
def self.read_player_data(io)
  name = RBStarbound::SBON.read_string(io)
  version = nil
  version = io.read(4).unpack('i>').first unless io.readchar.ord.zero?
  data = RBStarbound::SBON.read_dynamic(io)
  RBStarbound::Player::Data.new(name, version, data)
end
sbvj01_header(io) click to toggle source
# File lib/rbstarbound/sbvj01.rb, line 41
def self.sbvj01_header(io)
  io.write('SBVJ01')
end
sbvj01_header?(io) click to toggle source
# File lib/rbstarbound/sbvj01.rb, line 37
def self.sbvj01_header?(io)
  io.read(6) == 'SBVJ01'
end
write_player_data(io, player_data) click to toggle source
# File lib/rbstarbound/sbvj01.rb, line 27
def self.write_player_data(io, player_data)
  RBStarbound::SBON.write_string(io, player_data.name)
  if player_data.version.nil?
    io.write([0].pack('c'))
  else
    io.write([1, player_data.version].pack('ci>'))
  end
  RBStarbound::SBON.write_dynamic(io, player_data.data)
end