Advertisement
LiTTleDRAgo

[RGSS/2/3] Map Screenshot

Aug 12th, 2013
1,077
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.95 KB | None | 0 0
  1. #==============================================================================
  2. # Map Screenshot
  3. # Version : 1.06
  4. # Author : LiTTleDRAgo
  5. #==============================================================================
  6. #
  7. #  How to Use :
  8. #    
  9. #     Press F6 to take map screenshot
  10. #     Press F7 to take snapshot
  11. #
  12. #==============================================================================
  13.  
  14. ($imported ||= {})[:drg_map_screenshot_xp] = 1.06
  15.  
  16. text = "This Script needs Drago - Core Engine v1.35 or later"
  17. ($imported[:drg_core_engine] || 0) >= 1.35 || raise(text)
  18. #==============================================================================
  19. # ** Spriteset_Map
  20. #------------------------------------------------------------------------------
  21. #  This class brings together map screen sprites, tilemaps, etc.
  22. #  It's used within the Scene_Map class.
  23. #==============================================================================
  24. class Spriteset_Map
  25.   #--------------------------------------------------------------------------
  26.   # * Constant
  27.   #--------------------------------------------------------------------------
  28.   INPUT_MAP_SCREENSHOT = Input::F6   # Change to nil to disable
  29.   INPUT_SCREENSHOT     = Input::F7   # Change to nil to disable
  30.   SCREENSHOT_FOLDER    = "Screenshot"
  31.   #--------------------------------------------------------------------------
  32.   # * Alias Method
  33.   #--------------------------------------------------------------------------
  34.   alias_sec_method :map_screenshot, :update
  35.   #--------------------------------------------------------------------------
  36.   # * Frame Update
  37.   #--------------------------------------------------------------------------
  38.   def update(*args)
  39.     map_screenshot(*args)
  40.     return if @take_screenshot
  41.     snap_map_screenshot if INPUT_MAP_SCREENSHOT && Input.trigger?(INPUT_MAP_SCREENSHOT)
  42.     snap_screenshot     if INPUT_SCREENSHOT && Input.trigger?(INPUT_SCREENSHOT)
  43.   end
  44.   #--------------------------------------------------------------------------
  45.   # * snap_map_screenshot
  46.   #--------------------------------------------------------------------------
  47.   def snap_map_screenshot
  48.     old_time = Time.now
  49.     bitmap = collect_snap_map_bitmap
  50.     name = sprintf("Screenshot - Map%03d", $game_map.map_id)
  51.     export_screenshot(bitmap,"#{name}")
  52.     bitmap.dispose
  53.   end
  54.   #--------------------------------------------------------------------------
  55.   # * snap_screenshot
  56.   #--------------------------------------------------------------------------
  57.   def snap_screenshot
  58.     bitmap = Graphics.snap_to_bitmap
  59.     Dir.make_dir(SCREENSHOT_FOLDER) if FileTest.not.directory?(SCREENSHOT_FOLDER)
  60.     dir = Dir.new(SCREENSHOT_FOLDER)
  61.     count = dir.entries.select {|s| s.to_s =~ /Screenshot/ }
  62.     name = sprintf("Screenshot - %03d", count.size + 1)
  63.     count.reverse.each_with_index do |s,i|
  64.       temp = sprintf("Screenshot - %03d", i + 1)
  65.       name = temp if File.not.exist?("#{SCREENSHOT_FOLDER}/#{temp}.png")
  66.     end
  67.     export_screenshot(bitmap,"#{name}")
  68.     bitmap.dispose
  69.   end
  70.   #--------------------------------------------------------------------------
  71.   # * export_screenshot
  72.   #--------------------------------------------------------------------------
  73.   def export_screenshot(bitmap,name='snapshot')
  74.     exp_time = (bitmap.height * bitmap.width) * 0.00000664
  75.     string = "Taking screenshot please wait.... \n" +
  76.              "Number of pixels: #{bitmap.height * bitmap.width} \n"+
  77.              "Estimated time: #{exp_time} seconds."
  78.     report_screenshot("#{string.to_s}")
  79.     old_time = Time.now
  80.     Dir.make_dir(SCREENSHOT_FOLDER) if FileTest.not.directory?(SCREENSHOT_FOLDER)
  81.     bitmap.export("#{SCREENSHOT_FOLDER}/#{name}.png")
  82.     if File.exist?("#{SCREENSHOT_FOLDER}/#{name}.png")
  83.       string = "#{name}.png was created. \n" +
  84.                 "File size: width #{bitmap.width}, height #{bitmap.height}. \n" +
  85.                 "Time taken: #{Time.now - old_time} seconds."
  86.     else
  87.       string = "Failed to create #{name}.png.\n" +
  88.               "Time taken: #{Time.now - old_time} seconds."          
  89.     end          
  90.     report_screenshot("#{string.to_s}")
  91.   end
  92.   #--------------------------------------------------------------------------
  93.   # * report_screenshot
  94.   #--------------------------------------------------------------------------
  95.   def report_screenshot(*args)
  96.     defined?(Window_BattleActor) ? msgbox(*args) : print(*args)
  97.   end
  98.   #--------------------------------------------------------------------------
  99.   # * collect_snap_map_bitmap
  100.   #--------------------------------------------------------------------------
  101.   def collect_snap_map_bitmap
  102.     bitmap = Bitmap.new($game_map.width * 32, $game_map.height * 32)
  103.     _w = (($game_map.width / 4) % Graphics.width).floor + 1
  104.     _h = (($game_map.height / 4) % Graphics.height).floor + 1
  105.     _x = (0.._w).to_a.collect {|s| s * Graphics.width}
  106.     _y = (0.._h).to_a.collect {|s| s * Graphics.height}
  107.     _dx = $game_map.display_x
  108.     _dy = $game_map.display_y
  109.     _x.each do |x|
  110.       _y.each do |y|
  111.         $game_map.instance_variable_set(:@display_x, x/tilemap_move_multiplier)
  112.         $game_map.instance_variable_set(:@display_y, y/tilemap_move_multiplier)
  113.         @take_screenshot = true
  114.         update
  115.         Graphics.update unless defined?(Window_ActorCommand)
  116.         snap = Graphics.snap_to_bitmap
  117.         bitmap.blt(x,y,snap,snap.rect)
  118.         snap.dispose
  119.       end
  120.     end
  121.     $game_map.instance_variable_set(:@display_x, _dx)
  122.     $game_map.instance_variable_set(:@display_y, _dy)
  123.     update
  124.     @take_screenshot = false
  125.     bitmap
  126.   end
  127.   #--------------------------------------------------------------------------
  128.   # * tilemap_move_multiplier
  129.   #--------------------------------------------------------------------------
  130.   def tilemap_move_multiplier
  131.     n = 1.00 / 4
  132.     n = 1.00 / 8  if defined?(Window_ActorCommand)
  133.     n = 1.00 * 32 if defined?(Window_BattleActor)
  134.     return n
  135.   end  
  136. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement