Tileset Combiner Version 1.0
by Neo-Bahamut aka Wurstinator
Hi,
I won't spend much time on this description since it just took me about half an hour to write the one above the script.
Ever thought "Oh wow, this tileset looks totally awesome. But this one does as well. I wish, I could use them both together but all this passages-terraintag-priority-options are too annoying D:"
Now, here comes my Tileset Combiner !!!
It automatically copies most of the tileset options from two or more tilesets together. All you have to set yourself are the autotiles, the fog, the panorama and the battleback.
Script:
Download:
http://www.multiupload.com/RMK8OKLZY2
by Neo-Bahamut aka Wurstinator
Hi,
I won't spend much time on this description since it just took me about half an hour to write the one above the script.
Ever thought "Oh wow, this tileset looks totally awesome. But this one does as well. I wish, I could use them both together but all this passages-terraintag-priority-options are too annoying D:"
Now, here comes my Tileset Combiner !!!
It automatically copies most of the tileset options from two or more tilesets together. All you have to set yourself are the autotiles, the fog, the panorama and the battleback.
Script:
- #============================================================================
- # ** Tileset Combiner
- #----------------------------------------------------------------------------
- # by Neo-Bahamut (also known as Wurstinator)
- # V 1.0
- # 04.09.2010 (DD.MM.YYYY)
- #----------------------------------------------------------------------------
- # This script combines two or more tilesets from the database for you.
- # All you have to do yourself is setting the Autotiles, the fog, the panorama
- # and the battleback. The tileset graphic, the tile's passabilities, priorities
- # and all the other stuff are set by the script.
- # This script require the "Bitmap to PNG" script by http://www.66rpg.com which is
- # included in this demo.
- #----------------------------------------------------------------------------
- # Script Usage:
- # You do not have to change anything in the code. If you know what you do,
- # you can change the constant variables at the beginning.
- # To start the process use the following line:
- # Tileset_Combiner.start_combine(ids)
- # It is not important whether you do this in a call script or in the script
- # editor somewhere below this script.
- # You have to replace "ids" with (obviously) the IDs of the tilesets.
- # You can find them in the Database at the "Tilesets" tab. On the left side
- # there is the list of all tilesets. They are listed like "ID: Name".
- # When you got the IDs you can start it like this (e.g. IDs 1, 2, 3, 5 and 9):
- # Tileset_Combiner.start_combine(1, 2, 3, 5, 9)
- # This is the easiest way to use it.
- # For those, who know what that means: You can also pass an Array or a Range.
- #----------------------------------------------------------------------------
- # Conditions:
- # If you use this script it would be nice to put me somewhere on your
- # credits list. As I can't check if you created your tilesets with this script
- # or you did by hand, I can't force you to do so.
- # But since putting me in the credits doesn't harm you, it would be pretty
- # inglorious to "betray" me :P
- # You may publish this script somewhere else, as long as you do not put
- # yourself into the authors list or remove me from it.
- # You may modify this script as long as you do not claim its ownership.
- #============================================================================
- module Tileset_Combiner
- TILESET_FILE = "./Data/Tilesets.rxdata"
- TILESET_DIRECTORY = "./Graphics/Tilesets/"
- PRINT_MESSAGE_WHEN_DONE = true
- USE_ANTI_FREEZE_THREAD = true
- ERROR_DETECTION = true
- def Tileset_Combiner.start_combine(*args)
- # Start Anti Freeze
- if USE_ANTI_FREEZE_THREAD
- anti_freeze = Thread.new {loop {self.update_anti_freeze}}
- end
- # Can give an Array or Range of Integers as argument
- if args[0].is_a?(Range)
- args[0] = args[0].to_a
- end
- if args[0].is_a?(Array)
- args = args[0]
- end
- # Load Data
- data = load_data(TILESET_FILE)
- used_data = args.collect {|id| data[id]}
- # Error if used_data contains nil
- if ERROR_DETECTION
- if used_data.include?(nil)
- p "Error occured. You tried to combine tilesets which do not exist." +
- "Their IDs will be removed from the list and the combination will continue."
- used_data = used_data.compact
- end
- end
- # Combine Bitmap
- new_bitmap = self.combine_bitmap(used_data)
- # Combine RPG::Tilesets
- new_tileset = self.combine_data(used_data)
- # Add Tileset
- new_tileset.id = data.size - 1
- data.push(new_tileset)
- # Save Data
- save_data(data, TILESET_FILE)
- # End Anti Freeze
- if USE_ANTI_FREEZE_THREAD
- anti_freeze.exit
- anti_freeze = nil
- end
- # Save Bitmap
- self.save_bitmap(new_bitmap, used_data)
- # Print Message
- if PRINT_MESSAGE_WHEN_DONE
- p 'Finished!'
- end
- end
- def Tileset_Combiner.make_tilesetname(data)
- string = "Combined Tileset ("
- data.each_with_index do |i, n|
- if i.is_a?(RPG::Tileset)
- string << i.id.to_s
- else
- string << i.to_s
- end
- if n < data.size - 1
- string << ','
- end
- end
- string << ')'
- return string
- end
- private
- def self.combine_bitmap(data)
- # Get Bitmaps
- bitmaps = data.collect do |tileset|
- Bitmap.new(TILESET_DIRECTORY + tileset.tileset_name)
- end
- # Create new Bitmap
- height = 0
- bitmaps.each {|i| height += i.height}
- combined = Bitmap.new(256, (height / 32.0).ceil * 32)
- # Copy content
- y = 0
- bitmaps.each do |i|
- combined.blt(0, y, i, i.rect)
- y += i.height
- end
- # Return
- return combined
- end
- def self.combine_data(data)
- # Create new Tileset and set the simple parameters
- new_tileset = RPG::Tileset.new
- new_tileset.name = Tileset_Combiner.make_tilesetname(data)
- new_tileset.tileset_name = new_tileset.name
- # Create new Tables
- tile_num = 0
- data.each {|tileset| tile_num += tileset.passages.xsize-384}
- table = Table.new(tile_num + 384)
- new_tileset.passages, new_tileset.priorities, new_tileset.terrain_tags =
- table.dup, table.dup, table.dup
- # Copy the data
- index = 383
- data.each do |tileset|
- size = tileset.passages.xsize - 384
- size.times do |n|
- index += 1
- new_tileset.passages[index] = tileset.passages[n + 384]
- new_tileset.priorities[index] = tileset.priorities[n + 384]
- new_tileset.terrain_tags[index] = tileset.terrain_tags[n + 384]
- end
- end
- # Return
- return new_tileset
- end
- def self.save_bitmap(bitmap, data)
- # Get name
- name = Tileset_Combiner.make_tilesetname(data)
- # Make dirs
- dir = ''
- TILESET_DIRECTORY.split('/').each do |d|
- dir << d << '/'
- if !FileTest.exist?(dir)
- Dir.mkdir(dir)
- end
- end
- # Save
- bitmap.make_png(TILESET_DIRECTORY + name)
- end
- def self.update_anti_freeze
- Graphics.update
- Graphics.frame_count -= 1
- sleep(3)
- end
- end
Expand to see the code.
Download:
http://www.multiupload.com/RMK8OKLZY2