tracksperanto 1.8.0 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +1 -1
- data/lib/export/flame_stabilizer.rb +0 -1
- data/lib/tracksperanto.rb +1 -1
- data/lib/tracksperanto/flame_builder.rb +20 -11
- data/test/test_flame_builder.rb +16 -6
- metadata +1 -1
data/History.txt
CHANGED
@@ -9,7 +9,6 @@ class Tracksperanto::Export::FlameStabilizer < Tracksperanto::Export::Base
|
|
9
9
|
"Flame/Smoke 2D Stabilizer setup"
|
10
10
|
end
|
11
11
|
|
12
|
-
# Builder-like writer for Flame chanels
|
13
12
|
def start_export( img_width, img_height)
|
14
13
|
@counter = 0
|
15
14
|
@width, @height = img_width, img_height
|
data/lib/tracksperanto.rb
CHANGED
@@ -6,18 +6,18 @@ class Tracksperanto::FlameBuilder
|
|
6
6
|
@io, @indent = io, indent
|
7
7
|
end
|
8
8
|
|
9
|
-
def write_block(name, value = nil, &blk)
|
10
|
-
value.nil? ? write_loose(name) : write_tuple(name, value)
|
9
|
+
def write_block!(name, value = nil, &blk)
|
10
|
+
value.nil? ? write_loose!(name) : write_tuple!(name, value)
|
11
11
|
yield(self.class.new(@io, @indent + 1))
|
12
12
|
@io.puts(INDENT * (@indent + 1) + "End")
|
13
13
|
end
|
14
14
|
|
15
|
-
def write_tuple(key, value)
|
16
|
-
@io.puts("%s%s %s" % [INDENT * @indent,
|
15
|
+
def write_tuple!(key, value)
|
16
|
+
@io.puts("%s%s %s" % [INDENT * @indent, __camelize(key), __flameize(value)])
|
17
17
|
end
|
18
18
|
|
19
|
-
def write_loose(value)
|
20
|
-
@io.puts("%s%s" % [INDENT * @indent,
|
19
|
+
def write_loose!(value)
|
20
|
+
@io.puts("%s%s" % [INDENT * @indent, __camelize(value)])
|
21
21
|
end
|
22
22
|
|
23
23
|
def linebreak!(how_many = 1)
|
@@ -25,7 +25,7 @@ class Tracksperanto::FlameBuilder
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def color_hash!(name, red, green, blue)
|
28
|
-
write_loose(name)
|
28
|
+
write_loose!(name)
|
29
29
|
n = self.class.new(@io, @indent + 1)
|
30
30
|
n.red(red)
|
31
31
|
n.green(green)
|
@@ -35,18 +35,27 @@ class Tracksperanto::FlameBuilder
|
|
35
35
|
private
|
36
36
|
|
37
37
|
def method_missing(meth, arg = nil)
|
38
|
+
self.class.send(:alias_method, meth, :__generic)
|
38
39
|
if block_given?
|
39
|
-
|
40
|
+
__generic(meth, arg) {|*a| yield(*a) if block_given? }
|
40
41
|
else
|
41
|
-
|
42
|
+
__generic(meth, arg)
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
45
|
-
def
|
46
|
+
def __generic(meth, arg = nil)
|
47
|
+
if block_given?
|
48
|
+
write_block!(meth, arg) { |c| yield(c) }
|
49
|
+
else
|
50
|
+
arg.nil? ? write_loose!(meth) : write_tuple!(meth, arg)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def __camelize(s)
|
46
55
|
s.to_s.gsub(/(^|_)(.)/) { $2.upcase }
|
47
56
|
end
|
48
57
|
|
49
|
-
def
|
58
|
+
def __flameize(v)
|
50
59
|
case v
|
51
60
|
when Float
|
52
61
|
"%.3f" % v
|
data/test/test_flame_builder.rb
CHANGED
@@ -7,32 +7,42 @@ class FlameBuilderTest < Test::Unit::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_write_loose
|
10
|
-
@b.write_loose("Foo")
|
10
|
+
@b.write_loose!("Foo")
|
11
11
|
assert_equal "Foo\n", @s
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_write_tuple
|
15
|
-
@b.write_tuple("Foo", 3)
|
15
|
+
@b.write_tuple!("Foo", 3)
|
16
16
|
assert_equal "Foo 3\n", @s
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_write_tuple_with_true
|
20
|
-
@b.write_tuple("Foo", true)
|
20
|
+
@b.write_tuple!("Foo", true)
|
21
21
|
assert_equal "Foo yes\n", @s
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_write_tuple_with_false
|
25
|
-
@b.write_tuple("Foo", false)
|
25
|
+
@b.write_tuple!("Foo", false)
|
26
26
|
assert_equal "Foo no\n", @s
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_write_block
|
30
|
-
@b.write_block("Foo", 1) do | b |
|
31
|
-
b.write_tuple("Baz", 2)
|
30
|
+
@b.write_block!("Foo", 1) do | b |
|
31
|
+
b.write_tuple!("Baz", 2)
|
32
32
|
end
|
33
33
|
assert_equal "Foo 1\n\tBaz 2\n\tEnd\n", @s
|
34
34
|
end
|
35
35
|
|
36
|
+
def test_write_block_with_no_arg
|
37
|
+
@b.foo {|c| c.bar }
|
38
|
+
assert_equal "Foo\n\tBar\n\tEnd\n", @s
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_write_block_with_args
|
42
|
+
@b.foo(:bar) {|c| c.bar }
|
43
|
+
assert_equal "Foo bar\n\tBar\n\tEnd\n", @s
|
44
|
+
end
|
45
|
+
|
36
46
|
def test_automissing_with_values
|
37
47
|
@b.some_key(2)
|
38
48
|
assert_equal "SomeKey 2\n", @s
|