Tileset Merger
Authors: game_guy
Version: 1.0
Type: Tileset Merger
Key Term: Misc System
IntroductionEver 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!
ScreenshotsVideo (http://www.youtube.com/watch?v=PC2MhWlibs4)
Demohttp://www.sendspace.com/file/ufkvn9
Script
#===============================================================================
# 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
InstructionsImport 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.
CompatibilityShould 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 NotesGive credits and enjoy!
any thoughts on it at all?
It can definitely save some time and nerves that merging usually requires. xD
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 :)
Will it work with default tilesets?
game_guy made it... ofc it works on the default tiles
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
add ons?
*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
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...
You don't use this in a game... O.o
It's a graphics tool
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.
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"
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.
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...
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
Hey, how do i make it to merge all fify def. rtp tiles?
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.
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.
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"
I tried it with a new project, but it told me the script was hanging... So, i´ll try again, but i imported the RTP ones and ran it, and that´s when it hanged...
Try downloading the demo, another thing it is a ton of tilesets in there...Not sure how to fix it my friends done it before.
EDIT:
The screen needs to be active at all times so pretty much you need to stare at the screen until its done sorry =\ that might take 1-3 minutes with all those tilesets. I just now tested it with 32 it took 46 seconds.
Ok, so my firewall bugged at me, and it caused it to...
Ok, i´ll try it now, thanks