Spaces to tabs

This commit is contained in:
Olof Larsson 2015-01-12 08:47:03 +01:00
parent d4e42e3b33
commit eeb0344d9c

48
s2b.rb
View file

@ -1,12 +1,12 @@
# Massconverter from .schematic files to .bo2 files
# Usage: ruby s2b.rb
# This will convert all schematics in the sibling folder "in".
# The results will be placed in the folder "out".
# Air and magenta colored wool is ignored.
# If the file name is ending with R5 the z will use a -5 offset
# This will convert all schematics in the sibling folder "in".
# The results will be placed in the folder "out".
# Air and magenta colored wool is ignored.
# If the file name is ending with R5 the z will use a -5 offset
#
# See: http://www.minecraftwiki.net/wiki/Schematic_File_Format
# https://github.com/Wickth/TerrainControll/blob/master/bo2spec.txt
# https://github.com/Wickth/TerrainControll/blob/master/bo2spec.txt
#
# Lisence: MIT
@ -15,11 +15,11 @@ require 'rbconfig'
# Detect whether script is running on a Mac, change 'require' accordingly.
hostOs = RbConfig::CONFIG['host_os']
if /darwin|mac/.match(hostOs)
if ! require "/Library/Ruby/Gems/1.8/gems/nbtfile-0.2.0/lib/nbtfile.rb"
require "nbtfile"
end
if ! require "/Library/Ruby/Gems/1.8/gems/nbtfile-0.2.0/lib/nbtfile.rb"
require "nbtfile"
end
else
require "nbtfile"
require "nbtfile"
end
# Needy blocks are items like torches and doors, which require other blocks to
@ -107,12 +107,12 @@ def schematicToBO2(schematic, zoffset)
data = data.each_slice(schematic["Length"]).to_a
layers = blocks.zip(data).map { |blocks, data| blocks.zip(data).map { |blocks, data| blocks.zip(data) } }
deferred = []
# Utility function that converts lines into strings.
def stringifyLine(lineArray)
return stringified = "#{lineArray[0]},#{lineArray[1]},#{lineArray[2]}:#{lineArray[3]}.#{lineArray[4]}"
end
# Utility function that converts lines into strings.
def stringifyLine(lineArray)
return stringified = "#{lineArray[0]},#{lineArray[1]},#{lineArray[2]}:#{lineArray[3]}.#{lineArray[4]}"
end
ret.push(*FILE_HEADER)
layers.each_with_index do |rows, z|
z += zoffset
@ -123,11 +123,11 @@ def schematicToBO2(schematic, zoffset)
next
end
y -= schematic["Length"] / 2 # Center the object on the Y axis
line = [y, x, z, block, data]
line = [y, x, z, block, data]
if NEEDY_BLOCKS.include?(block)
deferred << line
else
ret << stringifyLine(line)
ret << stringifyLine(line)
end
end
end
@ -135,13 +135,13 @@ def schematicToBO2(schematic, zoffset)
# Write needy blocks to the end of the BOB file, respecting the order of
# NEEDY_BLOCKS, in case some blocks are needier than others.
deferred.sort! { |a, b| NEEDY_BLOCKS.index(a[3]) <=> NEEDY_BLOCKS.index(b[3]) }
deferredStringified = []
deferred.each do |lineToStringify|
deferredStringified << stringifyLine(lineToStringify)
end
deferredStringified.reverse.each { |line| ret << line }
deferred.sort! { |a, b| NEEDY_BLOCKS.index(a[3]) <=> NEEDY_BLOCKS.index(b[3]) }
deferredStringified = []
deferred.each do |lineToStringify|
deferredStringified << stringifyLine(lineToStringify)
end
deferredStringified.reverse.each { |line| ret << line }
return ret
end