Last active
August 29, 2015 14:19
-
-
Save endel/d8740aa2738680c84166 to your computer and use it in GitHub Desktop.
RPG Maker Sprite-Sheet extractor. It generates a separate .png file for each sprite.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# RPG Maker sprite-sheet extractor | |
require 'fileutils' | |
target_file = File.basename(ARGV[0], File.extname(ARGV[0])) | |
output_dir = "#{File.dirname(ARGV[0])}/#{target_file}" | |
FileUtils.mkdir_p(output_dir) | |
# extract each sprite | |
%x(convert #{ARGV[0]} -crop 24x32 #{output_dir}/sprite-%03d.png) | |
num_player = 0 | |
players = 8 | |
pos = 3 | |
positions = ['up', 'right', 'down', 'left'] | |
players_per_line = 4 | |
sprite_length = 12 | |
Dir.glob("#{output_dir}/*").each_with_index do |filename, i| | |
num_pos = (i % pos) | |
num_player = ((i.to_f / pos).to_i % sprite_length) % players_per_line | |
line = ((i.to_f / sprite_length).to_i) | |
num_player += 4 if line >= 4 | |
pos_name = positions[line % positions.length] | |
output = "#{output_dir}/player-#{num_player}-#{pos_name}-#{num_pos}.png" | |
puts "#{i} => #{num_pos} => #{num_player} => #{line} => #{pos_name} (#{filename} => #{output})" | |
FileUtils.mv(filename, output) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment