Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # Map Screenshot
- # Version : 1.06
- # Author : LiTTleDRAgo
- #==============================================================================
- #
- # How to Use :
- #
- # Press F6 to take map screenshot
- # Press F7 to take snapshot
- #
- #==============================================================================
- ($imported ||= {})[:drg_map_screenshot_xp] = 1.06
- text = "This Script needs Drago - Core Engine v1.35 or later"
- ($imported[:drg_core_engine] || 0) >= 1.35 || raise(text)
- #==============================================================================
- # ** Spriteset_Map
- #------------------------------------------------------------------------------
- # This class brings together map screen sprites, tilemaps, etc.
- # It's used within the Scene_Map class.
- #==============================================================================
- class Spriteset_Map
- #--------------------------------------------------------------------------
- # * Constant
- #--------------------------------------------------------------------------
- INPUT_MAP_SCREENSHOT = Input::F6 # Change to nil to disable
- INPUT_SCREENSHOT = Input::F7 # Change to nil to disable
- SCREENSHOT_FOLDER = "Screenshot"
- #--------------------------------------------------------------------------
- # * Alias Method
- #--------------------------------------------------------------------------
- alias_sec_method :map_screenshot, :update
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update(*args)
- map_screenshot(*args)
- return if @take_screenshot
- snap_map_screenshot if INPUT_MAP_SCREENSHOT && Input.trigger?(INPUT_MAP_SCREENSHOT)
- snap_screenshot if INPUT_SCREENSHOT && Input.trigger?(INPUT_SCREENSHOT)
- end
- #--------------------------------------------------------------------------
- # * snap_map_screenshot
- #--------------------------------------------------------------------------
- def snap_map_screenshot
- old_time = Time.now
- bitmap = collect_snap_map_bitmap
- name = sprintf("Screenshot - Map%03d", $game_map.map_id)
- export_screenshot(bitmap,"#{name}")
- bitmap.dispose
- end
- #--------------------------------------------------------------------------
- # * snap_screenshot
- #--------------------------------------------------------------------------
- def snap_screenshot
- bitmap = Graphics.snap_to_bitmap
- Dir.make_dir(SCREENSHOT_FOLDER) if FileTest.not.directory?(SCREENSHOT_FOLDER)
- dir = Dir.new(SCREENSHOT_FOLDER)
- count = dir.entries.select {|s| s.to_s =~ /Screenshot/ }
- name = sprintf("Screenshot - %03d", count.size + 1)
- count.reverse.each_with_index do |s,i|
- temp = sprintf("Screenshot - %03d", i + 1)
- name = temp if File.not.exist?("#{SCREENSHOT_FOLDER}/#{temp}.png")
- end
- export_screenshot(bitmap,"#{name}")
- bitmap.dispose
- end
- #--------------------------------------------------------------------------
- # * export_screenshot
- #--------------------------------------------------------------------------
- def export_screenshot(bitmap,name='snapshot')
- exp_time = (bitmap.height * bitmap.width) * 0.00000664
- string = "Taking screenshot please wait.... \n" +
- "Number of pixels: #{bitmap.height * bitmap.width} \n"+
- "Estimated time: #{exp_time} seconds."
- report_screenshot("#{string.to_s}")
- old_time = Time.now
- Dir.make_dir(SCREENSHOT_FOLDER) if FileTest.not.directory?(SCREENSHOT_FOLDER)
- bitmap.export("#{SCREENSHOT_FOLDER}/#{name}.png")
- if File.exist?("#{SCREENSHOT_FOLDER}/#{name}.png")
- string = "#{name}.png was created. \n" +
- "File size: width #{bitmap.width}, height #{bitmap.height}. \n" +
- "Time taken: #{Time.now - old_time} seconds."
- else
- string = "Failed to create #{name}.png.\n" +
- "Time taken: #{Time.now - old_time} seconds."
- end
- report_screenshot("#{string.to_s}")
- end
- #--------------------------------------------------------------------------
- # * report_screenshot
- #--------------------------------------------------------------------------
- def report_screenshot(*args)
- defined?(Window_BattleActor) ? msgbox(*args) : print(*args)
- end
- #--------------------------------------------------------------------------
- # * collect_snap_map_bitmap
- #--------------------------------------------------------------------------
- def collect_snap_map_bitmap
- bitmap = Bitmap.new($game_map.width * 32, $game_map.height * 32)
- _w = (($game_map.width / 4) % Graphics.width).floor + 1
- _h = (($game_map.height / 4) % Graphics.height).floor + 1
- _x = (0.._w).to_a.collect {|s| s * Graphics.width}
- _y = (0.._h).to_a.collect {|s| s * Graphics.height}
- _dx = $game_map.display_x
- _dy = $game_map.display_y
- _x.each do |x|
- _y.each do |y|
- $game_map.instance_variable_set(:@display_x, x/tilemap_move_multiplier)
- $game_map.instance_variable_set(:@display_y, y/tilemap_move_multiplier)
- @take_screenshot = true
- update
- Graphics.update unless defined?(Window_ActorCommand)
- snap = Graphics.snap_to_bitmap
- bitmap.blt(x,y,snap,snap.rect)
- snap.dispose
- end
- end
- $game_map.instance_variable_set(:@display_x, _dx)
- $game_map.instance_variable_set(:@display_y, _dy)
- update
- @take_screenshot = false
- bitmap
- end
- #--------------------------------------------------------------------------
- # * tilemap_move_multiplier
- #--------------------------------------------------------------------------
- def tilemap_move_multiplier
- n = 1.00 / 4
- n = 1.00 / 8 if defined?(Window_ActorCommand)
- n = 1.00 * 32 if defined?(Window_BattleActor)
- return n
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement