Module: RBStarbound::SBVJ01
- Defined in:
- lib/rbstarbound/sbvj01.rb
Class Method Summary collapse
- .dump(io, player_data) ⇒ Object
- .parse(io) ⇒ Object
- .read_player_data(io) ⇒ Object
- .sbvj01_header(io) ⇒ Object
- .sbvj01_header?(io) ⇒ Boolean
- .write_player_data(io, player_data) ⇒ Object
Class Method Details
.dump(io, player_data) ⇒ Object
14 15 16 17 |
# 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) ⇒ Object
7 8 9 10 11 12 |
# 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 |
.read_player_data(io) ⇒ Object
19 20 21 22 23 24 25 |
# 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) ⇒ Object
41 42 43 |
# File 'lib/rbstarbound/sbvj01.rb', line 41 def self.sbvj01_header(io) io.write('SBVJ01') end |
.sbvj01_header?(io) ⇒ Boolean
37 38 39 |
# File 'lib/rbstarbound/sbvj01.rb', line 37 def self.sbvj01_header?(io) io.read(6) == 'SBVJ01' end |
.write_player_data(io, player_data) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# 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 |