~eda-qa/dhlib/main

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/ruby
# Produces a Graft class from an XML specification

require 'rexml/document'
include REXML
require 'fileutils'

if ARGV.length != 4
	puts "Syntax: make_graft.rb graft.xml package class output_dir"
	exit -1
end

# Load XML Graft
file = File.new( ARGV[0] )
doc = Document.new( file )

# set output vars
package = ARGV[1]
_class = ARGV[2]
output_dir = ARGV[3]


fileName = "#{output_dir}/#{_class}.hx"
out = File.new( fileName, "w" )

out.puts "/* Generated by make_graft.rb */"
out.puts "package #{package};"
out.puts "import ui.Graft;"
out.puts "import mathx.Point2;"
out.puts "class #{_class} extends Graft {"

doc.elements.each( "//graft/part" ) { |el|
	out.puts "	public var #{el.attributes['name']}(default,null) : GraftItem;"
}

out.puts "	public function new() { "
out.puts "		super();"

doc.elements.each( "//graft/part" ) { |el|
	out.puts "		#{el.attributes['name']} = addSprite("
	out.puts "			new #{el.attributes['resource']}(),"
	out.puts "			Point2.at#{el.attributes['size']},"
	out.puts "			Point2.at#{el.attributes['origin']},"
	out.puts "			Point2.at#{el.attributes['pos']},"
	out.puts "			#{el.attributes['orient']}"
	out.puts "		);"
}

out.puts "	}"
out.puts "}"