This repository was archived by the owner on Feb 23, 2021. It is now read-only.
forked from slackhq/magic-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommando-lightbox
executable file
·68 lines (52 loc) · 1.91 KB
/
commando-lightbox
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env ruby
require_relative 'commando-helpers.rb'
require 'yaml'
program :description, 'Renders LightBox projects to a frame sequence.'
program :version, '1.0.0'
def filename(id, prefix='', suffix='')
"#{prefix}#{sprintf "%05d", id}#{suffix}"
end
command :loop do |c|
c.description = 'Sorts bitmaps in <project> and moves & renames them to <output>'
c.option '--project DIR', String, 'LightBox project folder (the .lightbox directory)'
c.option '--output DIR', String, 'Output directory'
c.action do |args, options|
options.default \
project: "./",
output: "./output"
options.project = File.expand_path(options.project)
options.output = File.expand_path(options.output)
command_header(c, options)
if ! File.directory?(options.project)
crash "Project directory '#{options.project}' does not exist"
end
art_file = File.expand_path "#{options.project}/*.art"
art_file = Dir.glob(art_file)[0]
if ! File.exists?(art_file)
crash "Project directory '#{options.project}' does not seem to have an .art file..."
end
art_file = YAML.load_file art_file
if File.directory?("#{options.project}/bitmaps")
notice "Using ./bitmaps sub-directory within '#{options.project}'..."
options.project = "#{options.project}/bitmaps"
end
if ! File.directory?(options.output)
warning "Output directory '#{options.output}' does not exist, creating it..."
Dir.mkdir(options.output)
end
i = 0
art_file["frames"].each do |frame|
from = "#{options.project}/#{frame['drawingId']}.png"
to = "#{options.output}/#{filename frame['frameIndex']}.png"
next unless File.exists?(from)
FileUtils.cp from, to
i += 1
end
if i > 0
success "Moved and renamed #{i} frames to #{options.output}"
else
warning "Didn't move any files in #{options.project}..."
end
end
end
default_command :loop