Main Menu
  • Welcome to The RPG Maker Resource Kit.

[XP] Tileset Merger

Started by game_guy, October 08, 2009, 05:04:59 AM

0 Members and 1 Guest are viewing this topic.

game_guy

Tileset Merger
Authors: game_guy
Version: 1.0
Type: Tileset Merger
Key Term: Misc System


Introduction

Ever needed a few tilesets merged for mapping? This script will merge any tilesets for you into one!


Features


  • Merges any amount of tilesets into one tileset!


Screenshots

Video


Demo

http://www.sendspace.com/file/ufkvn9


Script

[SPOILER]
#===============================================================================
# Tileset Merger
# Version 1.0
# Author game_guy
#-------------------------------------------------------------------------------
# Intro:
# Ever needed a few tilesets merged for mapping? This script will merge any
# tileset for you into one!
#
# Features:
# Merges any amount of tilesets into one tileset!
#
# Instructions:
# Import any tileset into the Tilesets folder that you want merged together.
# Then run the game and it'll merge it for you.
# Make sure all the tilesets have the same background color.
#
# Credits:
# game_guy ~ making it
# Fantasist ~ giving me a neat piece of code
# 66rpg ~ Bitmap to Png code
# GAX72 ~ Requesting merged tilesets
#===============================================================================

=begin
==============================================================================
                       Bitmap to PNG By ???
==============================================================================

?Bitmap??????

bitmap_obj.make_png(name[, path])

name:?????
path:????

??66??????????????
 
==============================================================================
=end

module Zlib
 class Png_File < GzipWriter
   #--------------------------------------------------------------------------
   # ? ???
   #--------------------------------------------------------------------------
   def make_png(bitmap_Fx,mode)
     @mode = mode
     @bitmap_Fx = bitmap_Fx
     self.write(make_header)
     self.write(make_ihdr)
     self.write(make_idat)
     self.write(make_iend)
   end
   #--------------------------------------------------------------------------
   # ? PNG??????
   #--------------------------------------------------------------------------
   def make_header
     return [0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a].pack("C*")
   end
   #--------------------------------------------------------------------------
   # ? PNG????????(IHDR)
   #--------------------------------------------------------------------------
   def make_ihdr
     ih_size = [13].pack("N")
     ih_sign = "IHDR"
     ih_width = [@bitmap_Fx.width].pack("N")
     ih_height = [@bitmap_Fx.height].pack("N")
     ih_bit_depth = [8].pack("C")
     ih_color_type = [6].pack("C")
     ih_compression_method = [0].pack("C")
     ih_filter_method = [0].pack("C")
     ih_interlace_method = [0].pack("C")
     string = ih_sign + ih_width + ih_height + ih_bit_depth + ih_color_type +
              ih_compression_method + ih_filter_method + ih_interlace_method
     ih_crc = [Zlib.crc32(string)].pack("N")
     return ih_size + string + ih_crc
   end
   #--------------------------------------------------------------------------
   # ? ??????(IDAT)
   #--------------------------------------------------------------------------
   def make_idat
     header = "\x49\x44\x41\x54"
     case @mode # ?54~
     when 1
       data = make_bitmap_data#1
     else
       data = make_bitmap_data
     end
     data = Zlib::Deflate.deflate(data, 8)
     crc = [Zlib.crc32(header + data)].pack("N")
     size = [data.length].pack("N")
     return size + header + data + crc
   end
   #--------------------------------------------------------------------------
   # ? ?Bitmap????????? mode 1(?54~)
   #--------------------------------------------------------------------------
   def make_bitmap_data1
     w = @bitmap_Fx.width
     h = @bitmap_Fx.height
     data = []
     for y in 0...h
       data.push(0)
       for x in 0...w
         color = @bitmap_Fx.get_pixel(x, y)
         red = color.red
         green = color.green
         blue = color.blue
         alpha = color.alpha
         data.push(red)
         data.push(green)
         data.push(blue)
         data.push(alpha)
       end
     end
     return data.pack("C*")
   end
   #--------------------------------------------------------------------------
   # ? ?Bitmap????????? mode 0
   #--------------------------------------------------------------------------
   def make_bitmap_data
     gz = Zlib::GzipWriter.open('hoge.gz')
     t_Fx = 0
     w = @bitmap_Fx.width
     h = @bitmap_Fx.height
     data = []
     for y in 0...h
       data.push(0)
       for x in 0...w
         t_Fx += 1
         if t_Fx % 10000 == 0
           Graphics.update
         end
         if t_Fx % 100000 == 0
           s = data.pack("C*")
           gz.write(s)
           data.clear
           #GC.start
         end
         color = @bitmap_Fx.get_pixel(x, y)
         red = color.red
         green = color.green
         blue = color.blue
         alpha = color.alpha
         data.push(red)
         data.push(green)
         data.push(blue)
         data.push(alpha)
       end
     end
     s = data.pack("C*")
     gz.write(s)
     gz.close    
     data.clear
     gz = Zlib::GzipReader.open('hoge.gz')
     data = gz.read
     gz.close
     File.delete('hoge.gz')
     return data
   end
   #--------------------------------------------------------------------------
   # ? PNG??????(IEND)
   #--------------------------------------------------------------------------
   def make_iend
     ie_size = [0].pack("N")
     ie_sign = "IEND"
     ie_crc = [Zlib.crc32(ie_sign)].pack("N")
     return ie_size + ie_sign + ie_crc
   end
 end
end
#==============================================================================
# ? Bitmap
#------------------------------------------------------------------------------
# ????Bitmap?
#==============================================================================
class Bitmap
 #--------------------------------------------------------------------------
 # ? ??
 #--------------------------------------------------------------------------
 def make_png(name="like", path="",mode=0)
   make_dir(path) if path != ""
   Zlib::Png_File.open("temp.gz") {|gz|
     gz.make_png(self,mode)
   }
   Zlib::GzipReader.open("temp.gz") {|gz|
     $read = gz.read
   }
   f = File.open(path + name + ".png","wb")
   f.write($read)
   f.close
   File.delete('temp.gz')
   end
 #--------------------------------------------------------------------------
 # ? ??????
 #--------------------------------------------------------------------------
 def make_dir(path)
   dir = path.split("/")
   for i in 0...dir.size
     unless dir == "."
       add_dir = dir[0..i].join("/")
       begin
         Dir.mkdir(add_dir)
       rescue
       end
     end
   end
 end
end
begin
 @time = Time.now
 @height = 0
 @names = []
 dir = Dir.new('Graphics/Tilesets/')
 dir.entries.each {|file| next unless file.include?('.png')
 @names.push(file); RPG::Cache.tileset(file)}
 for i in 0...@names.size
   @tile = RPG::Cache.tileset(@names[i])
   @height += @tile.height
 end
 @bitmap = Bitmap.new(256, @height)
 @height = 0
 for i in 0...@names.size
   @tile = RPG::Cache.tileset(@names[i])
   @rect = Rect.new(0, 0, @tile.width, @tile.height)
   @bitmap.blt(0, @height, @tile, @rect)
   @height += @tile.height
 end
 @bitmap.make_png("MergedTile")
 print "Merged #{@names.size} tilesets together in \n#{Time.now - @time} seconds."
 exit
end
[/SPOILER]


Instructions

Import any tileset into the Tilesets folder that you want merged together.
Then run the game and it'll merge it for you.
Make sure all the tilesets have the same background color.
Merged tilesets will appear in the root of the game folder.


Compatibility

Should work with anything
Not tested with SDK


Credits and Thanks


  • game_guy ~ for making it
  • Fantasist ~ giving me a neat piece of code
  • 66rpg ~ BitmapToPng code
  • GAX72 ~ requesting a few merged tilesets


Author's Notes

Give credits and enjoy!

game_guy

Yea it supports transparency, the blue bg is my transparency color I changed it.

modern algebra


nayrz

Ello, this is my first time using this site, I mean I used it before for scripts but never posted on anything, anyways, I just used the tileset merger, great stuff, just one thing bugs me, if you take all 50 tilesets that come with rpgxp, they merge great but when your going down Through to use any of the ones on the bottom it freezes and sends you back up to the top, u gotta stop half way Through and slowly use the wheel on the mouse and hope it doesn't send u back up again also sometimes it says "script hanging", besides that i love it, i think I'm using a few other scripts of yours also, except maybe a bank, i had to use a Spanish bank script and just make the words that show in-game English lol

Lazer Ki

I'm trying this out tommorow
Hi

nayrz

Ah, well, at least it works X]