ezmash

Lazy Tilesets - Importer (VX Ace)

Jan 28th, 2015
516
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. =begin
  2.  
  3. Lazy Tilesets - Importer
  4. Version 1.0
  5. by Shaz, for RPG Maker Web
  6.  
  7. -------------------------------- IMPORTANT ------------------------------------
  8. The names you use must EXACTLY match the files provided with your tileset.
  9. This relies on you NOT renaming any of the tileset resources or the settings file.
  10. -------------------------------------------------------------------------------
  11.  
  12.  
  13. This script allows you to create a new blank tileset, add some commands to
  14. the note box, run your game, and the tileset slots will be populated for you,
  15. with all the correct settings.  Close your project without saving, then reopen,
  16. to see the updated tilesets.  No more spending hours wading through, guessing
  17. what the settings should be!  
  18.  
  19. When you're all done, you can remove the script and all of the .VXATileset
  20. files, as well as the tileset notes you added for this purpose.
  21.  
  22. For the examples below, we'll assume the files RTPExterior.VXATileset,
  23. RTPInterior.VXATileset and RTPDungeon.VXATileset contain the data for
  24. the RTP tilesets.
  25.  
  26.  
  27. BEGINNER MODE:
  28. Put the following into the note of a new tileset, to have the full details
  29. populated:
  30.   <import RTPExterior>
  31.  
  32. INTERMEDIATE MODE:
  33. Put the following into the note of a new tileset, to have only the specified
  34. slots in a new tileset populated:
  35.   <import RTPExterior A1 A2 A3 A4 A5>
  36.  
  37. Put the following into the note of a new tileset, to have a combination of
  38. slots from multiple tilesets:
  39.   <import RTPExterior A1 A2 A3 A4 A5>
  40.   <import RTPInterior B C D E>
  41.  
  42.   (the following would also achive the same thing):
  43.   <import RTPExterior>
  44.   <import RTPInterior B C D E>
  45.  
  46. ADVANCED MODE:
  47. Put the following into the note of a new tileset, to have a combination of
  48. slots from multiple tilesets and move them around as specified:
  49.   <import RTPInterior B C>
  50.   <import RTPDungeon B:D C:E>
  51.  
  52.   - the above copies slots B and C from the RTPInterior file, then copies
  53.     slots B and C from the RTPDungeon file, but puts them into slots D and E
  54.   - this can only be done with the B-E tiles, as they share the same format
  55.     and functionality
  56.  
  57. =end
  58.  
  59.  
  60. module RMWeb
  61.   module LazyTilesets
  62.     def self.import_tileset_data
  63.       backed_up = false
  64.       source_tilesets = {}
  65.       slots = {"A1" => [0, 2048, 2815],
  66.                "A2" => [1, 2816, 4351],
  67.                "A3" => [2, 4352, 5887],
  68.                "A4" => [3, 5888, 8191],
  69.                "A5" => [4, 1536, 1663],
  70.                "B"  => [5, 0, 255],
  71.                "C"  => [6, 256, 511],
  72.                "D"  => [7, 512, 767],
  73.                "E"  => [8, 768, 1023] }
  74.                
  75.       target_tilesets = load_data("Data/Tilesets.rvdata2")
  76.      
  77.       target_tilesets.each { |target|
  78.         next if !target || target.note !~ /<import (.*)>/i
  79.        
  80.         msgprfx = "Tileset #{target.id} - #{target.name}:"
  81.        
  82.         # Backup the original before making any changes
  83.         if !backed_up
  84.           timestamp = Time.now.strftime('%Y%m%d%H%M%S')
  85.           File.open("Data/Tilesets#{timestamp}.rvdata2", "wb") { |file|
  86.             Marshal.dump(target_tilesets, file)
  87.             backed_up = true
  88.           }
  89.         end
  90.        
  91.         # process each import statement
  92.         target.note.split(/[\r\n]+/).each { |line|
  93.           next if !line || line !~ /<import (.*)>/i
  94.           res = /<import (.*)>/i.match(line)[1].scan(/[^ ]+/).collect { |det| det }
  95.           tileset_name = res.shift
  96.  
  97.           # grab the tileset we're copying from
  98.           if !source_tilesets.has_key?(tileset_name)
  99.             begin
  100.               source_tilesets[tileset_name] = load_data(
  101.                 "Graphics/Tilesets/#{tileset_name}.VXATileset")
  102.             rescue
  103.               raise("#{msgprfx} Unable to find Graphics/Tilesets/#{tileset_name}.VXATileset")
  104.             end
  105.           end
  106.           source = source_tilesets[tileset_name]
  107.          
  108.           # copy the whole lot if individual slots haven't been specified
  109.           res = slots.keys if res.size == 0
  110.          
  111.           res.each { |copy_group|
  112.             from_slot, to_slot = copy_group.split(/:/)
  113.             to_slot = from_slot if !to_slot || to_slot == ''
  114.            
  115.             # ensure slots are valid, and cross-copying is only done between B-E slots
  116.             raise("#{msgprfx} Invalid slot #{from_slot}") if !slots.has_key?(from_slot)
  117.             raise("#{msgprfx} Invalid slot #{to_slot}") if !slots.has_key?(to_slot)
  118.             raise("#{msgprfx} A1-A5 slots cannot be moved") if from_slot != to_slot &&
  119.               (!'BCDE'.include?(from_slot) || !'BCDE'.include?(to_slot))
  120.            
  121.             from_slot_id, from_slot_start, from_slot_end = slots[from_slot]
  122.             to_slot_id, to_slot_counter, tmp = slots[to_slot]
  123.            
  124.             # and copy the slot
  125.             target.tileset_names[to_slot_id] = source.tileset_names[from_slot_id]
  126.             (from_slot_start .. from_slot_end).each { |tile|
  127.               target.flags[to_slot_counter] = source.flags[tile]
  128.               to_slot_counter += 1
  129.             }
  130.            
  131.             # A2 tile determines the tileset mode
  132.             target.mode = source.mode if from_slot == "A2"
  133.           }
  134.         }
  135.       }
  136.      
  137.       # If any changes were made, save the new tileset
  138.       if backed_up
  139.         File.open("Data/Tilesets.rvdata2", "wb") { |file|
  140.           Marshal.dump(target_tilesets, file)
  141.         }
  142.       end
  143.     end
  144.   end
  145. end
  146.  
  147. RMWeb::LazyTilesets.import_tileset_data
RAW Paste Data