#======================================================================
# ** Map Screenshot Maker
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 1.1
# 2007-07-21
# SDK : Version 2.0+, Part I
#------------------------------------------------------------------------------
# * Version History :
#
# Version 1 ---------------------------------------------------- (2007-07-20)
# Version 1.1 ------------------------------------------------- (2007-07-21)
# - Update : Made it so it saves multiple png files for bigger maps.
# Version 1.1.1 -Brew -------------------- (25Mar08)
# - Fixed sprite position. Added 'Q' button option with autoname
# 'mapname'.png, removed SDK dependence.
#------------------------------------------------------------------------------
# * Requirements :
#
# Method & Class Library (2.1+)
#------------------------------------------------------------------------------
# * Description :
#
# This script was designed to allow you to make a single screenshot of your
# entire map. In constructions a still image of the tilemap, panorama, fog,
# event and player sprites, weather, picture sprites and the timer. It then
# exports the files to a filename you specify, and saves it in PNG format.
#------------------------------------------------------------------------------
# * Instructions :
#
# Place The Script Below Scene_Debug and Above Main.
#
# To make a screenshot, use: MapScreenshotMaker.take(filename)
# Or hit the 'Q' button while on a map.
#
#------------------------------------------------------------------------------
# * Syntax :
#
# Taking Map Screenshot
# - MapScreenshotMaker.take(filename, dir)
#
# You do not need to specify filename, as it defaults to a 'Test.png'
# You do not need to specify dir, as it defaults to 'Graphics/Saved Images'
# The extension .png does not need to be included in the filename.
#------------------------------------------------------------------------------
# * Special Thanks :
#
# Prexus, for requesting and beta testing
#==============================================================================
#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
#SDK.log('Map Screenshot Maker', 'SephirothSpawn', 1.1, '2007-07-21')
#SDK.check_requirements(2.0, [], {'Method & Class Library' => 2.1})
#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
#if SDK.enabled?('Map Screenshot Maker')
#==============================================================================
# ** Spriteset_Map
#==============================================================================
class Spriteset_Map
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :tilemap
attr_reader :panorama
attr_reader :fog
attr_reader :character_sprites
attr_reader :weather
attr_reader :picture_sprites
attr_reader :timer_sprite
end
#==============================================================================
# ** Scene_Map
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :spriteset
alias screenshot_update update
def initialize
$data_mapinfo = load_data("Data/MapInfos.rxdata")
end
def update
if Input.trigger?(Input::L)
#make filename from map name
filename = $data_mapinfo[$game_map.map_id].name
#take the shot
MapScreenshotMaker.take(filename)
#show message that it finished
print "Saved " + filename + ".png"
end
screenshot_update
end
end
#==============================================================================
# ** RPG::Weather
#==============================================================================
class RPG::Weather
#--------------------------------------------------------------------------
# * Bitmap
#--------------------------------------------------------------------------
def bitmap
# Create Bitmap
bitmap = Bitmap.new(640, 480)
# Pass Through @sprites
@sprites.each do |sprite|
next unless sprite.visible
next if sprite.bitmap.nil?
bitmap.blt(sprite.x, sprite.y, sprite.bitmap, sprite.bitmap.rect)
end
# Return Bitmap
return bitmap
end
end
#==============================================================================
# ** MapScreenshotMaker
#==============================================================================
module MapScreenshotMaker
#--------------------------------------------------------------------------
# * Max Image Size
#--------------------------------------------------------------------------
Max_Image_Size = nil
#--------------------------------------------------------------------------
# * Take
#--------------------------------------------------------------------------
# def self.take(filename = 'Map Screenshot', dir = 'Graphics/Saved Images/')
def self.take(filename = 'Map Screenshot', dir = '')
# Return If Not Map Scene
return unless $scene.is_a?(Scene_Map)
# Gets Spriteset
spriteset = $scene.spriteset
# Create Bitmap
bitmap = Bitmap.new($game_map.width * 32, $game_map.height * 32)
# Draw Chracter Sprites
self.draw_character_sprites(bitmap, spriteset, 'sprite.z >= -1000')
# Draw Panorama
if spriteset.panorama.visible
if spriteset.panorama.bitmap != nil
b = spriteset.panorama.bitmap
opacity = spriteset.panorama.opacity
x_times = (bitmap.rect.width / b.rect.width.to_f)
x_times = x_times.ceil == x_times.to_i ?
x_times.to_i : x_times.to_i + 1
y_times = (bitmap.rect.width / b.rect.width.to_f)
y_times = y_times.ceil == y_times.to_i ?
y_times.to_i : y_times.to_i + 1
self.tile_bitmap(bitmap, b, x_times, y_times, opacity)
end
end
# Draw Chracter Sprites
c = '!sprite.z.between?(-1000, -1)'
self.draw_character_sprites(bitmap, spriteset, c)
# Draw Layer 1
self.draw_tilemap_layer(bitmap, spriteset, 0)
# Draw Chracter Sprites
c = '!sprite.z.between?(0, 149)'
self.draw_character_sprites(bitmap, spriteset, c)
# Draw Layer 2
self.draw_tilemap_layer(bitmap, spriteset, 1)
# Draw Chracter Sprites
c = '!sprite.z.between?(150, 299)'
self.draw_character_sprites(bitmap, spriteset, c)
# Draw Layer 3
self.draw_tilemap_layer(bitmap, spriteset, 2)
# Draw Chracter Sprites
c = '!sprite.z.between?(300, 999)'
self.draw_character_sprites(bitmap, spriteset, c)
# Draw Weather Sprite
x_times = (bitmap.rect.width / 640.0)
x_times = x_times.ceil == x_times.to_i ? x_times.to_i : x_times.to_i + 1
y_times = (bitmap.rect.width / 480.0)
y_times = y_times.ceil == y_times.to_i ? y_times.to_i : y_times.to_i + 1
self.tile_bitmap(bitmap, spriteset.weather.bitmap, x_times, y_times)
# Draw Chracter Sprites
c = '!sprite.z.between?(1000, 2999)'
self.draw_character_sprites(bitmap, spriteset, c)
# Draw Fog Sprite
if spriteset.fog.visible
if spriteset.fog.bitmap != nil
b = spriteset.fog.bitmap
opacity = spriteset.fog.opacity
x_times = (bitmap.rect.width / b.rect.width.to_f)
x_times = x_times.ceil == x_times.to_i ?
x_times.to_i : x_times.to_i + 1
y_times = (bitmap.rect.width / b.rect.width.to_f)
y_times = y_times.ceil == y_times.to_i ?
y_times.to_i : y_times.to_i + 1
self.tile_bitmap(bitmap, b, x_times, y_times, opacity)
end
end
# Draw Chracter Sprites
self.draw_character_sprites(bitmap, spriteset, 'sprite.z < 3000')
# Draw Picture Sprites
self.draw_picture_sprites(bitmap, spriteset, 'sprite.z >= 500')
# Draw Sprite Timer
if spriteset.timer_sprite.visible
if spriteset.timer_sprite.bitmap != nil
self.blt(spriteset.timer_sprite.x, spriteset.timer_sprite.y,
spriteset.timer_sprite.bitmap, spriteset.timer_sprite.opacity)
end
end
# Draw Picture Sprite
self.draw_picture_sprites(bitmap, spriteset, 'sprite.z < 500')
# Save Bitmap
if Max_Image_Size != nil && (bitmap.rect.width > Max_Image_Size ||
bitmap.rect.height > Max_Image_Size)
# Gets X & Y Max Times
x_times = (bitmap.rect.width / Max_Image_Size.to_f)
x_times = x_times.ceil == x_times.to_i ?
x_times.to_i : x_times.to_i + 1
y_times = (bitmap.rect.width / Max_Image_Size.to_f)
y_times = y_times.ceil == y_times.to_i ?
y_times.to_i : y_times.to_i + 1
# Split Up Bitmap Into Sections
for x in 0...x_times
for y in 0...y_times
# Get src rect
src_rect = Rect.new(x * Max_Image_Size, y * Max_Image_Size,
[bitmap.rect.width - x * Max_Image_Size, Max_Image_Size].min,
[bitmap.rect.height - y * Max_Image_Size, Max_Image_Size].min)
# Creates New Bitmap
b = Bitmap.new(src_rect.width, src_rect.height)
b.blt(0, 0, bitmap, src_rect)
# Saves Bitmap
b.make_png("#{filename}_#{x}-#{y}", dir)
# Update Graphics Module
Graphics.update
end
end
# If Within Max Size
else
# Saves Bitmap
bitmap.make_png(filename, dir)
end
end
#--------------------------------------------------------------------------
# * Tile Bitmap
#--------------------------------------------------------------------------
def self.tile_bitmap(main, sub, x_times, y_times, a = 255)
for x in 0...x_times
for y in 0...y_times
main.blt(x * sub.rect.width, y * sub.rect.height, sub, sub.rect, a)
end
end
end
#--------------------------------------------------------------------------
# * Draw Character Sprites
#--------------------------------------------------------------------------
def self.draw_character_sprites(bitmap, spriteset, c)
# Pass Through Character Sprites
spriteset.character_sprites.each do |sprite|
# Skip If Not Visible or Nil Bitmap
next if sprite.visible == false || sprite.bitmap.nil?
# Skip If Condition
next if (eval c)
# Draw Sprite On Bitmap
xoff = sprite.bitmap.width / 8 - ($game_map.display_x / 4)
yoff = sprite.bitmap.height / 4 - ($game_map.display_y / 4)
bitmap.blt(sprite.x - xoff, sprite.y - yoff, sprite.bitmap, sprite.src_rect,
sprite.opacity)
end
end
#--------------------------------------------------------------------------
# * Draw Picture Sprites
#--------------------------------------------------------------------------
def self.draw_picture_sprites(bitmap, spriteset, c)
# Pass Through Character Sprites
spriteset.picture_sprites.each do |sprite|
# Skip If Not Visible or Nil Bitmap
next if sprite.visible == false || sprite.bitmap.nil?
# Skip If Condition
next if (eval c)
# Draw Sprite On Bitmap
bitmap.blt(sprite.x, sprite.y, sprite.bitmap, sprite.src_rect,
sprite.opacity)
end
end
#--------------------------------------------------------------------------
# * Draw Tilemap Layer
#--------------------------------------------------------------------------
def self.draw_tilemap_layer(bitmap, spriteset, layer)
# Get Map Data & Priorities
map_data = $game_map.data
priorities = $game_map.priorities
tileset = $game_map.tileset_name
autotiles = $game_map.autotile_names
# Passes Through Layers
for z in 0...map_data.zsize
# Passes Through X Coordinates
for x in 0...map_data.xsize
# Passes Through Z Coordinates
for y in 0...map_data.ysize
# Collects Tile ID
id = map_data[x, y, z]
# Skip if 0 tile
next if id == 0
# Get Tile Priority
p = priorities[id]
# Cap Priority to Layer 3
p = 2 if p = 2
# Next If P isn't layer id
next if p != layer
# Draw Tile
if id < 384
# Gets Autotile Filename
filename = autotiles[id / 48 - 1]
# Reconfigure Tile ID
id %= 48
# Gets Generated Autotile Bitmap Section
b = RPG::Cache.autotile_tile(filename, id, 0)
# Draw Tile
bitmap.blt(x * 32, y * 32, b, Rect.new(0, 0, 32, 32))
# Draw Normal Tile
else
# Gets Tile Bitmap
b = RPG::Cache.tile(tileset, id, 0)
# Draws Tile
bitmap.blt(x * 32, y * 32, b, Rect.new(0, 0, 32, 32))
end
end
end
end
end
end
class Bitmap
#-------------------------------------------------------------------------
# * Name : Make PNG
# Info : Saves Bitmap to File
# Author : ??? - http://www.66rpg.com/htm/news624.htm
# Call Info : Zero to Three Arguments
# Name : Name of filenam
# Path : Directory in Game Folder
# Mode : Mode of Writing
#-------------------------------------------------------------------------
def make_png(name = 'like', path = '', mode = 0)
# Dir.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
end
#==============================================================================
# ** Modules.Zlib
#------------------------------------------------------------------------------
# Description:
# ------------
# Adds PNG_File class to save Bitmap's to PNG Files
#
# Class List:
# -----------
# Png_File
#==============================================================================
module Zlib
#============================================================================
# ** Png_File
#============================================================================
class Png_File < GzipWriter
#--------------------------------------------------------------------------
# * Make PNG
#--------------------------------------------------------------------------
def make_png(bitmap, mode = 0)
# Save Bitmap & Mode
@bitmap, @mode = bitmap, mode
# Create & Save PNG
self.write(make_header)
self.write(make_ihdr)
self.write(make_idat)
self.write(make_iend)
end
#--------------------------------------------------------------------------
# * Make Header
#--------------------------------------------------------------------------
def make_header
return [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a].pack('C*')
end
#--------------------------------------------------------------------------
# * Make IHDR
#--------------------------------------------------------------------------
def make_ihdr
ih_size = [13].pack("N")
ih_sign = 'IHDR'
ih_width = [@bitmap.width].pack('N')
ih_height = [@bitmap.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
#--------------------------------------------------------------------------
# * Make IDAT
#--------------------------------------------------------------------------
def make_idat
header = "\x49\x44\x41\x54"
data = @mode == 0 ? make_bitmap_data0 : make_bitmap_data1
data = Zlib::Deflate.deflate(data,
crc = [Zlib.crc32(header + data)].pack('N')
size = [data.length].pack('N')
return size + header + data + crc
end
#--------------------------------------------------------------------------
# * Make Bitmap Data 0
#--------------------------------------------------------------------------
def make_bitmap_data0
gz = Zlib::GzipWriter.open('hoge.gz')
t_Fx = 0
w = @bitmap.width
h = @bitmap.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
end
color = @bitmap.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
#--------------------------------------------------------------------------
# * Make Bitmap Data Mode 1
#--------------------------------------------------------------------------
def make_bitmap_data1
w = @bitmap.width
h = @bitmap.height
data = []
for y in 0...h
data.push(0)
for x in 0...w
color = @bitmap.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
#--------------------------------------------------------------------------
# * Make 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
#==============================================================================
# ** RPG::Cache
#==============================================================================
module RPG::Cache
#--------------------------------------------------------------------------
# * Auto-Tiles
#--------------------------------------------------------------------------
Autotiles = [
[[27, 28, 33, 34], [ 5, 28, 33, 34], [27, 6, 33, 34], [ 5, 6, 33, 34],
[27, 28, 33, 12], [ 5, 28, 33, 12], [27, 6, 33, 12], [ 5, 6, 33, 12]],
[[27, 28, 11, 34], [ 5, 28, 11, 34], [27, 6, 11, 34], [ 5, 6, 11, 34],
[27, 28, 11, 12], [ 5, 28, 11, 12], [27, 6, 11, 12], [ 5, 6, 11, 12]],
[[25, 26, 31, 32], [25, 6, 31, 32], [25, 26, 31, 12], [25, 6, 31, 12],
[15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12]],
[[29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],
[39, 40, 45, 46], [ 5, 40, 45, 46], [39, 6, 45, 46], [ 5, 6, 45, 46]],
[[25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],
[17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48]],
[[37, 38, 43, 44], [37, 6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],
[37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1, 2, 7, 8]]
]
#--------------------------------------------------------------------------
# * Autotile Cache
#
# @autotile_cache = {
# filename => { [autotile_id, frame_id, hue] => bitmap, ... },
# ...
# }
#--------------------------------------------------------------------------
@autotile_cache = {}
#--------------------------------------------------------------------------
# * Autotile Tile
#--------------------------------------------------------------------------
def self.autotile_tile(filename, tile_id, hue = 0, frame_id = nil)
# Gets Autotile Bitmap
autotile = self.autotile(filename)
# Configures Frame ID if not specified
if frame_id.nil?
# Animated Tiles
frames = autotile.width / 96
# Configures Animation Offset
fc = Graphics.frame_count / 16
frame_id = (fc) % frames * 96
end
# Creates list if already not created
@autotile_cache[filename] = {} unless @autotile_cache.has_key?(filename)
# Gets Key
key = [tile_id, frame_id, hue]
# If Key Not Found
unless @autotile_cache[filename].has_key?(key)
# Reconfigure Tile ID
tile_id %= 48
# Creates Bitmap
bitmap = Bitmap.new(32, 32)
# Collects Auto-Tile Tile Layout
tiles = Autotiles[tile_id / 8][tile_id % 8]
# Draws Auto-Tile Rects
for i in 0...4
tile_position = tiles[i] - 1
src_rect = Rect.new(tile_position % 6 * 16 + frame_id,
tile_position / 6 * 16, 16, 16)
bitmap.blt(i % 2 * 16, i / 2 * 16, autotile, src_rect)
end
# Saves Autotile to Cache
@autotile_cache[filename][key] = bitmap
# Change Hue
@autotile_cache[filename][key].hue_change(hue)
end
# Return Autotile
return @autotile_cache[filename][key]
end
#-------------------------------------------------------------------------
# * Name : Gradient
# Info : Loads A Gradient Bar
# Author : Trickster
# Call Info : One to Two Arguments
# String filename of Bar to load
# Integer hue - hue displacement
# Comment : Files are to be located in Graphics/Gradients
#-------------------------------------------------------------------------
def self.gradient(filename, hue = 0)
self.load_bitmap("Graphics/Gradients/", filename, hue)
end
end
#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
#end