Created
February 12, 2017 03:21
-
-
Save kainjow/f06ed0f9edcb484b539f1662bcb1ec8f to your computer and use it in GitHub Desktop.
Script used to convert https://github.com/kainjow/Glypha/blob/dab40dd9c8a0313d874e03fd7e6ba55677c16d3d/game/GLResources.cpp to binary files
This file contains hidden or 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
#!/usr/bin/ruby | |
current_filename = nil | |
current_file = nil | |
# http://anthonylewis.com/2011/02/09/to-hex-and-back-with-ruby/ | |
def hex_to_bin(s) | |
s.scan(/../).map { |x| x.hex }.pack('c*') | |
end | |
File.readlines(File.dirname(__FILE__) + '/GLResources.cpp').each do |line| | |
next if line.strip!.empty? | |
next if line.match(/^#include/) || | |
line.match(/^const char/) || | |
line.match(/^};$/) || | |
line.match(/^unsigned int/) | |
match = line.match(/^unsigned char GL::(.*?)\[\] = {$/) | |
if match | |
current_filename = match[1].gsub('_', '.') | |
current_file.close if current_file | |
current_file = File.open(File.dirname(__FILE__) + '/resources/' + current_filename, 'w') | |
next | |
end | |
match = line.match(/^0x[a-f0-9]{2,}/) | |
if match | |
values = line.gsub(' ', '').gsub('0x', '').split(',').each do |hex| | |
current_file.write(hex_to_bin(hex)) | |
end | |
next | |
end | |
abort "Unknown line: #{line}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment