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
|
# File 'lib/ace/demo/atoms/vhs_tape_compiler.rb', line 9
def compile(spec:, output_path:, default_timeout: "2s")
settings = spec["settings"] || {}
lines = []
lines << "Output #{output_path}"
lines << ""
lines << "Set FontSize #{settings["font_size"] || 16}"
lines << "Set Width #{settings["width"] || 960}"
lines << "Set Height #{settings["height"] || 480}"
(settings["env"] || {}).each do |key, value|
lines << "Env #{key} \"#{value}\""
end
spec.fetch("scenes", []).each do |scene|
scene_name = scene["name"]
lines << ""
lines << "# Scene: #{scene_name}" unless scene_name.to_s.strip.empty?
scene.fetch("commands", []).each do |command|
type_text = command.fetch("type")
if type_text.include?('"') || type_text.include?("$") || type_text.include?("\\")
lines << "Type `#{type_text}`"
else
lines << "Type \"#{type_text}\""
end
lines << "Enter"
lines << "Sleep #{command["sleep"] || default_timeout}"
lines << ""
end
end
lines.join("\n").rstrip + "\n"
end
|