#!/usr/bin/ruby require 'erb' pngs = Dir['resources/*.png'].map { |path| File.basename(path, '.png') } mp3s = Dir['resources/*.mp3'].map { |path| File.basename(path, '.mp3') } template = ERB.new <<-EOF package { public class Embeds { <% pngs.each do |png| %> [Embed(source="resources/<%= png %>.png")] public static var embed<%= png %>:Class;<% end %> <% mp3s.each do |mp3| %> [Embed(source="resources/<%= mp3 %>.mp3")] public static var embed<%= mp3 %>:Class;<% end %> private static var tileClasses:Vector.; private static var sounds:Vector.; public static function tileForType(type:int):Class { if (tileClasses == null) { tileClasses = new Vector.(<%= pngs.count %>); <% pngs.each do |png| %> tileClasses[TileModel.TILE_<%= png.ljust(20) %>] = embed<%= png %>;<% end %> } if (type < 0 || type >= tileClasses.length) { return null; } return tileClasses[type]; } public static function soundForType(type:int):Object { if (sounds == null) { sounds = new Vector.(<%= mp3s.count %>); <% mp3s.each do |mp3| %> sounds[SoundModel.SOUND_<%= mp3.ljust(20) %>] = new embed<%= mp3 %>();<% end %> } if (type < 0 || type >= sounds.length) { return null; } return sounds[type]; } public static function worker(facing:int, gender:int):Class { switch (gender) { case Gender.FEMALE: switch (facing) { case Direction.NORTH: return embedWomanN; case Direction.EAST: return embedWomanE; case Direction.SOUTH: return embedWomanS; case Direction.WEST: return embedWomanW; } break; case Gender.MALE: switch (facing) { case Direction.NORTH: return embedManN; case Direction.EAST: return embedManE; case Direction.SOUTH: return embedManS; case Direction.WEST: return embedManW; } break; } return null; } public static function coffeeEmoteForFullness(fullness:int):Class { switch (fullness) {<% pngs.each {|png| if png =~ /^EmoteCoffee(\\d+)/ then %> case <%= $1 %>: return embed<%= png %>;<% end } %> default: return null; } } } } EOF puts template.result(binding)