updated ruby scripts

Originally committed to SVN as r946.
This commit is contained in:
pomyk 2007-03-10 20:33:49 +00:00
parent ef403060f8
commit fab3dd81a1
2 changed files with 25 additions and 17 deletions

View File

@ -3,7 +3,7 @@ load 'utils.rb'
include Aegisub include Aegisub
$script_name = "k-replacer test" $script_name = "simple k-replacer"
$script_description = "k-replacer test" $script_description = "k-replacer test"
$script_author = "Pomyk" $script_author = "Pomyk"
$script_version = "1" $script_version = "1"
@ -31,11 +31,10 @@ def k_replace_filter(subs, opt)
k_replace(l, opt[:templ], opt[:strip]) if l[:class] == :dialogue && # replace if its dialogue k_replace(l, opt[:templ], opt[:strip]) if l[:class] == :dialogue && # replace if its dialogue
opt[:style] =="" || l[:style] == opt[:style] # and has the right style opt[:style] =="" || l[:style] == opt[:style] # and has the right style
end end
write_options(subs, {$script_name => opt})
return subs return subs
end end
def k_replace_cfg(subs, store) def k_replace_cfg(subs, opt)
styles = [] styles = []
subs.each { |l| # read style names subs.each { |l| # read style names
styles << l[:name] if l[:class] == :style styles << l[:name] if l[:class] == :style
@ -52,13 +51,12 @@ Calculation example:
\\t($start,%$start+$dur*2%,\\fscx110) \\t($start,%$start+$dur*2%,\\fscx110)
\\t(%$start+$dur*2%,$end,\\fscx90) \\t(%$start+$dur*2%,$end,\\fscx90)
head head
opt = read_options(subs, $script_name) opt ||= {}
s_name = $script_name.to_sym
cfg = ScriptCfg.new # helper class for building dialogs cfg = ScriptCfg.new # helper class for building dialogs
cfg.header header_text, :x => 1, :width => 1 cfg.header header_text, :x => 1, :width => 1
cfg.edit :templ, "template", :text => opt[s_name][:templ] cfg.edit :templ, "template", :text => opt[:templ]
cfg.dropdown :style, "Style", :items => styles, :value => opt[s_name][:style] cfg.dropdown :style, "Style", :items => styles, :value => opt[:style]
cfg.checkbox :strip, "", :label => "Strip tags?", :value => (opt[s_name][:strip] == "true" ? true : false) cfg.checkbox :strip, "", :label => "Strip tags?", :value => (opt[:strip] == "true" ? true : false)
cfg.to_ary # convert to array cfg.to_ary # convert to array
end end

View File

@ -1,4 +1,4 @@
include Aegisub #include Aegisub
class Object class Object
def deep_clone def deep_clone
@ -69,19 +69,17 @@ module Aegisub
value = opt.delete(l[:key]) value = opt.delete(l[:key])
l[:value] = value.instance_of?(Hash) ? value.to_a.flatten!.join(sep) : value.to_s if value l[:value] = value.instance_of?(Hash) ? value.to_a.flatten!.join(sep) : value.to_s if value
l l
else elsif info
if info
r = [l] r = [l]
opt.each do |key, val| opt.each do |key, val|
r << {:class => :info, :key => key, r << {:class => :info, :key => key,
:value => value.instance_of?(Hash) ? value.to_a.flatten!.join(sep) : value.to_s, :value => value.instance_of?(Hash) ? value.to_a.flatten!.join(sep) : value.to_s,
:section => "[Script Info]"} :section => "[Script Info]"}
end end
info = false info = false
r r
else else
l l
end
end end
end end
end end
@ -99,6 +97,18 @@ module Aegisub
end end
return opt return opt
end end
def rgb_to_ssa(*c)
res = "&H"
c.reverse_each {|v| res << "%02X" % v}
res << "&"
return res
end
def ssa_to_rgb(col)
res = []
col.scan(/[0-9a-fA-F]{2}/) { res.unshift $1.to_i(16) }
res
end
end end