Skip to content

Instantly share code, notes, and snippets.

@tonyc
Created January 15, 2014 03:08
Show Gist options
  • Save tonyc/8430083 to your computer and use it in GitHub Desktop.
Save tonyc/8430083 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'fileutils'
SRC = 'infected'
DEST_DIR = 'MachoMadness/sfx/npc'
MONSTER_TYPES = %w(quadruped smallbiped)
SOUND_TYPES = %w(attack1 attack2 death idle1 idle2 pain1 pain2 turnhostile)
monster_names = []
sounds_per_type = {}
SOUND_TYPES.each do |type|
sounds_per_type[type] ||= []
Dir.glob("sound_types/#{type}/*.wav") do |filename|
sounds_per_type[type] << filename
end
end
counts_per_type = SOUND_TYPES.inject({}) do |accum, type|
accum[type] = 0
accum
end
MONSTER_TYPES.each do |monster_type|
Dir.glob("#{DEST_DIR}/#{monster_type}/*.wav") do |filename|
file_name = File.basename filename
matches = /(\w+)_(\w+)\.wav\Z/.match(file_name)
monster_name = matches[1]
monster = {name: monster_name, type: monster_type}
monster_names << monster unless monster_names.include?(monster)
end
end
monster_names.each do |monster|
SOUND_TYPES.each do |sound_type|
sound_type_length = sounds_per_type[sound_type].length
src_file = sounds_per_type[sound_type][counts_per_type[sound_type] % sound_type_length]
monster_name = monster[:name]
monster_type = monster[:type]
dest_file = "#{DEST_DIR}/#{monster_type}/#{monster_name}_#{sound_type}.wav"
puts "copy #{src_file} -> #{dest_file}"
FileUtils.cp src_file, dest_file
counts_per_type[sound_type] += 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment