[XP] Tileset Merger

Started by G_G, August 18, 2009, 12:08:38 pm

Previous topic - Next topic

G_G

August 18, 2009, 12:08:38 pm Last Edit: September 22, 2009, 10:48:06 am by 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: ShowHide

#===============================================================================
# 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



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!

G_G


Blizzard

It can definitely save some time and nerves that merging usually requires. xD
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Fantasist

QuoteMake sure all the tilesets have the same background color.


Well, that's not needed if the tilesets already have the background transparent. The PNG script takes care of the transparencies too. That means you can just use the script directly on RTP tilesets :)
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




rpgmakerfanhaha

Will it work with default tilesets?

Jackolas

game_guy made it... ofc it works on the default tiles

Aqua

September 04, 2009, 10:49:03 am #6 Last Edit: September 04, 2009, 11:25:03 am by Aqua
You should run it in a new game - that way, there'll be sure to have no conflicting scripts.


Or... if you want it without error...
Get the demo xD

RoseSkye


G_G

*adds video*

Okay so theres no confusion I added a video to the screenshots so people can get a better idea on what it does

Holyrapid

This is cool. I´ll use this in my game, Rozarias Tale. With this i can create world maps with just the default RTP tiles, and so on...

Aqua

You don't use this in a game... O.o
It's a graphics tool

winkio

Quote from: Pyhankoski on September 30, 2009, 04:37:38 am
This is cool. I´ll use this in my game, Rozarias Tale. With this i can create world maps with just the default RTP tiles, and so on...
Quote from: Aqua on September 30, 2009, 04:50:54 pm
You don't use this in a game... O.o
It's a graphics tool


Aqua, he said he was going to use it to merge tilesets in his game.  He made it clear that he didn't expect it to be a script IN the game, or anything like that.

Aqua

Quote from: Pyhankoski on September 30, 2009, 04:37:38 am
This is cool. I´ll use this in my game, Rozarias Tale. With this i can create world maps with just the default RTP tiles, and so on...


The "in" makes it seem as if it's IN the game... :p
A better word would have been "for"

Starrodkirby86

Nazi-ing English when you already know what he intended to say doesn't make you look cool...>.>

Unless he wants improvement on his English or something.

What's osu!? It's a rhythm game. Thought I should have a signature with a working rank. ;P It's now clickable!
Still Aqua's biggest fan (Or am I?).




Holyrapid

October 05, 2009, 04:50:33 am #14 Last Edit: October 06, 2009, 01:28:11 am by Pyhankoski
Blah... I wasn´t thinking straight since i was at the time and also i´m also at the moment in school...
BTW... now that i downloaded this, i noticed that there were japanese kanji-symbols in it, so would G_G or someone explain this to me...

Jackolas

QuoteCredits and Thanks

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


66rpg probably put them in there

Holyrapid

Hey, how do i make it to merge all fify def. rtp tiles?

Jackolas

one by one.
so first merge 2 with each other.
than add another 1, and  another 1, etc

just remember if you load all in 1 it will get a slow game with loads of loading times.
and kinda make your game crap.
so only merge tiles that you need per map. and make multiple tiles.

Calintz

It's a good system, but I would never use it myself.
A very long time ago, Blizzard and I discussed the practicability of larger tilesets as opposed to the time they consume to create the everyday maps for your game. I prefer standard size tilesets. Everything included in the originals is all that you need. It really is. If you want to make your game more original, then sure ... add a couple tiles, but you don't really need the mergers.

G_G

Quote from: Pyhankoski on October 17, 2009, 07:19:22 am
Hey, how do i make it to merge all fify def. rtp tiles?

Easy but first
Quote from: Jackolas on October 17, 2009, 08:00:35 am
one by one.
so first merge 2 with each other.
than add another 1, and  another 1, etc

just remember if you load all in 1 it will get a slow game with loads of loading times.
and kinda make your game crap.
so only merge tiles that you need per map. and make multiple tiles.


Nope just place all tilesets you want merged together in tilesets folder it'll merge them all. So if you have 7 tilesets in there it'll merge it together then export it into the file "MergedTileset"