Advertisement
M3rein

Untitled

Apr 1st, 2018
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.83 KB | None | 0 0
  1. def pbGetActiveEventPage(event, mapid = nil)
  2. mapid ||= event.map.map_id if event.respond_to?(:map)
  3. pages = (event.is_a?(RPG::Event) ? event.pages : event.instance_eval { @event.pages })
  4. for i in 0...pages.size
  5. c = pages[pages.size - 1 - i].condition
  6. ss = !(c.self_switch_valid && !$game_self_switches[[mapid,
  7. event.id,c.self_switch_ch]])
  8. sw1 = !(c.switch1_valid && !$game_switches[c.switch1_id])
  9. sw2 = !(c.switch2_valid && !$game_switches[c.switch2_id])
  10. var = true
  11. if c.variable_valid
  12. if !c.variable_value || !$game_variables[c.variable_id].is_a?(Numeric) ||
  13. $game_variables[c.variable_id] < c.variable_value
  14. var = false
  15. end
  16. end
  17. if ss && sw1 && sw2 && var # All conditions are met
  18. return pages[pages.size - 1 - i]
  19. end
  20. end
  21. return nil
  22. end
  23.  
  24. #==============================================================================#
  25. # Map Exporter #
  26. # by Marin #
  27. #==============================================================================#
  28. # Manually export a map using `pbExportMap(id)`, or go into the Debug menu and #
  29. # choose the `Export a Map` option that is now in there. #
  30. # #
  31. # `pbExportMap(id, options)`, where `options` is an array that can contain: #
  32. # - :events -> This will also export all events present on the map #
  33. # - :player -> This will also export the player if they're on that map #
  34. # `id` can be nil, which case it will use the current map the player is on. #
  35. #==============================================================================#
  36. # Please give credit when using this. #
  37. #==============================================================================#
  38.  
  39. ExportedMapFilename = "Exported Map.png"
  40.  
  41. def pbExportMap(id = nil, options = [])
  42. MarinMapExporter.new(id, options)
  43. end
  44.  
  45. def pbExportAMap
  46. vp = Viewport.new(0, 0, Graphics.width, Graphics.height)
  47. vp.z = 99999
  48. s = Sprite.new(vp)
  49. s.bitmap = Bitmap.new(Graphics.width, Graphics.height)
  50. s.bitmap.fill_rect(0, 0, Graphics.width, Graphics.height, Color.new(0,0,0))
  51. mapid = pbListScreen(_INTL("Export Map"),MapLister.new(pbDefaultMap))
  52. if mapid > 0
  53. player = $game_map.map_id == mapid
  54. if player
  55. cmds = ["Export", "[ ] Events", "[ ] Player", "Cancel"]
  56. else
  57. cmds = ["Export", "[ ] Events", "Cancel"]
  58. end
  59. cmd = 0
  60. loop do
  61. cmd = Kernel.pbShowCommands(nil,cmds,-1,cmd)
  62. if cmd == 0
  63. options = []
  64. options << :events if cmds[1].split("")[1] == "X"
  65. options << :player if player && cmds[2].split("")[1] == "X"
  66. pbExportMap(mapid, options)
  67. Kernel.pbMessage(_INTL("Successfully exported this map."))
  68. break
  69. elsif cmd == 1
  70. if cmds[1].split("")[1] == " "
  71. cmds[1] = "[X] Events"
  72. else
  73. cmds[1] = "[ ] Events"
  74. end
  75. elsif cmd == 2 && player
  76. if cmds[2].split("")[1] == " "
  77. cmds[2] = "[X] Player"
  78. else
  79. cmds[2] = "[ ] Player"
  80. end
  81. elsif cmd == 3 || cmd == 2 && !player || cmd == -1
  82. break
  83. end
  84. end
  85. end
  86. s.bitmap.dispose
  87. s.dispose
  88. vp.dispose
  89. end
  90.  
  91. alias map_exporter_menu pbDebugMenuCommands
  92. def pbDebugMenuCommands(showall = true)
  93. cmds = map_exporter_menu(showall)
  94. if showall
  95. cmds.add("fieldmenu","exportmap",_INTL("Export a Map"),
  96. _INTL("Choose one map to export it to a PNG."))
  97. end
  98. return cmds
  99. end
  100.  
  101. alias map_exporter_actions pbDebugMenuActions
  102. def pbDebugMenuActions(cmd = "", sprites = nil, viewport = nil)
  103. if cmd == "exportmap"
  104. pbExportAMap
  105. return false
  106. end
  107. return map_exporter_actions
  108. end
  109.  
  110. class MarinMapExporter
  111. def initialize(id = nil, options = [])
  112. @id = id || $game_map.map_id
  113. @options = options
  114. @data = load_data("Data/Map#{@id.to_digits}.rxdata")
  115. @tiles = @data.data
  116. @result = Bitmap.new(32 * @tiles.xsize, 32 * @tiles.ysize)
  117. @tilesetdata = load_data("Data/Tilesets.rxdata")
  118. tilesetname = @tilesetdata[@data.tileset_id].name
  119. @tileset = BitmapCache.load_bitmap("Graphics/Tilesets/#{tilesetname}")
  120. @autotiles = @tilesetdata[@data.tileset_id].autotile_names.map do |e|
  121. BitmapCache.load_bitmap("Graphics/Autotiles/#{e}")
  122. end
  123. for z in 0..2
  124. for y in 0...@tiles.ysize
  125. for x in 0...@tiles.xsize
  126. id = @tiles[x, y, z]
  127. next if id == 0
  128. if id < 384 # Autotile
  129. build_autotile(@result, x * 32, y * 32, id)
  130. else # Normal tile
  131. @result.blt(x * 32, y * 32, @tileset,
  132. Rect.new(32 * ((id - 384) % 8),32 * ((id - 384) / 8).floor,32,32))
  133. end
  134. end
  135. end
  136. end
  137. if @options.include?(:events)
  138. @data.events.each do |id,event|
  139. page = pbGetActiveEventPage(event, @id)
  140. if page && page.graphic && page.graphic.character_name
  141. bmp = BitmapCache.load_bitmap("Graphics/Characters/#{page.graphic.character_name}")
  142. if bmp
  143. bmp = bmp.clone
  144. bmp.hue_change(page.graphic.character_hue) unless page.graphic.character_hue == 0
  145. ex = bmp.width / 4 * page.graphic.pattern
  146. ey = bmp.height / 4 * (page.graphic.direction / 2 - 1)
  147. @result.blt(event.x * 32, (event.y + 1) * 32 - bmp.height / 4, bmp,
  148. Rect.new(ex, ey, bmp.width / 4, bmp.height / 4))
  149. end
  150. bmp = nil
  151. end
  152. end
  153. end
  154. if @options.include?(:player) && $game_map.map_id == @id
  155. bmp = BitmapCache.load_bitmap("Graphics/Characters/#{$game_player.character_name}")
  156. dir = $game_player.direction
  157. @result.blt($game_player.x * 32, ($game_player.y + 1) * 32 - bmp.height / 4,
  158. bmp, Rect.new(0, bmp.height / 4 * (dir / 2 - 1), bmp.width / 4, bmp.height / 4))
  159. end
  160. @result.export(ExportedMapFilename)
  161. Input.update
  162. end
  163.  
  164. def build_autotile(bitmap, x, y, id)
  165. autotile = @autotiles[id / 48 - 1]
  166. return unless autotile
  167. if autotile.height == 32
  168. bitmap.blt(x,y,autotile,Rect.new(0,0,32,32))
  169. else
  170. id %= 48
  171. tiles = CustomTilemap::Autotiles[id >> 3][id & 7]
  172. src = Rect.new(0,0,0,0)
  173. halfTileWidth = halfTileHeight = halfTileSrcWidth = halfTileSrcHeight = 32 >> 1
  174. for i in 0...4
  175. tile_position = tiles[i] - 1
  176. src.set((tile_position % 6) * halfTileSrcWidth,
  177. (tile_position / 6) * halfTileSrcHeight, halfTileSrcWidth, halfTileSrcHeight)
  178. bitmap.blt(i % 2 * halfTileWidth + x, i / 2 * halfTileHeight + y,
  179. autotile, src)
  180. end
  181. end
  182. end
  183. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement