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