Skip to content

Instantly share code, notes, and snippets.

@cmhobbs
Created November 25, 2012 06:43
Show Gist options
  • Save cmhobbs/4142659 to your computer and use it in GitHub Desktop.
Save cmhobbs/4142659 to your computer and use it in GitHub Desktop.
Path Macro Maker for TinyFugue
#!/usr/bin/env ruby
def path_maker(name, path)
input_array = path.split
defstring = "/def #{name} = "
path = []
input_array.each do |step|
if step[0].match(/\d/)
s = split_step(step)
s[0].times { path << s[1] }
else
path << step
end
end
return defstring + path.join("%;")
end
def split_step(step)
return [step.match(/\d+/)[0..-1][0].to_i, step.split(/\d/)[-1]]
end
puts path_maker(ARGV[0], ARGV[1])
@cmhobbs
Copy link
Author

cmhobbs commented Nov 25, 2012

This script has no error checking and expects the first argument to be the name you want the path to be followed by a path string enclosed in quotes. Just copy the resulting line to your ~/.tfrc and run /name to call your macro.

Here's an example:

[00:45][christopher@ryleh:~/tmp]$ ./pathmaker.rb goblin_caves "9e 3se 3e s se 2s sw s w 2s se s 2e d 3n e ne"
/def goblin_caves = e%;e%;e%;e%;e%;e%;e%;e%;e%;se%;se%;se%;e%;e%;e%;s%;se%;s%;s%;sw%;s%;w%;s%;s%;se%;s%;e%;e%;d%;n%;n%;n%;e%;ne

@cmhobbs
Copy link
Author

cmhobbs commented Nov 25, 2012

PS - Join me at faeroes.sdf.org port 4000. You don't have to be a member of the SDF Public Access UNIX System to play, but we'd love to see you there, too!

@cmhobbs
Copy link
Author

cmhobbs commented Nov 25, 2012

Just found a bug where the script doesn't account for path numbers larger than 9 (for example, 12w would mangle the path). Fix incoming.

@cmhobbs
Copy link
Author

cmhobbs commented Nov 25, 2012

Fixed to account for an arbitrary multiplier for a given step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment