drakkon 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/drakkon/build.rb +57 -4
- data/lib/drakkon/cli.rb +3 -1
- data/lib/drakkon/gem/bundle.rb +19 -15
- data/lib/drakkon/gem/cli.rb +2 -0
- data/lib/drakkon/gem/helpers/modules.rb +5 -0
- data/lib/drakkon/init.rb +23 -17
- data/lib/drakkon/lib/{images → fonts}/fonts.rb +3 -3
- data/lib/drakkon/lib/hub.rb +2 -1
- data/lib/drakkon/lib/images/biggest.rb +8 -6
- data/lib/drakkon/lib/images/bulk_rename.rb +1 -13
- data/lib/drakkon/lib/images/cli.rb +35 -19
- data/lib/drakkon/lib/images/compress.rb +60 -0
- data/lib/drakkon/lib/images/double.rb +77 -0
- data/lib/drakkon/lib/images/downcase_normalize.rb +70 -0
- data/lib/drakkon/lib/images/hue_modulation.rb +71 -0
- data/lib/drakkon/lib/images/index.rb +43 -20
- data/lib/drakkon/lib/images/layers.rb +55 -0
- data/lib/drakkon/lib/images/resize.rb +3 -2
- data/lib/drakkon/lib/images/split.rb +4 -4
- data/lib/drakkon/lib/images/spritesheet.rb +52 -13
- data/lib/drakkon/lib/images/text.rb +3 -0
- data/lib/drakkon/lib/images/trim.rb +7 -6
- data/lib/drakkon/lib/manifest.rb +24 -16
- data/lib/drakkon/lib/pastel.rb +1 -1
- data/lib/drakkon/lib/platform_compat.rb +27 -0
- data/lib/drakkon/lib/settings.rb +49 -1
- data/lib/drakkon/lib/sounds/sounds.rb +126 -0
- data/lib/drakkon/lib/utils/cli.rb +38 -0
- data/lib/drakkon/lib/utils/rename_normalize.rb +75 -0
- data/lib/drakkon/lib/version.rb +17 -2
- data/lib/drakkon/release.rb +1 -1
- data/lib/drakkon/run/commands/utils.rb +14 -0
- data/lib/drakkon/run/helpers.rb +11 -4
- data/lib/drakkon/run/reader_shim.rb +9 -5
- data/lib/drakkon/run.rb +4 -1
- data/lib/drakkon/skeleton/deploy.rb +4 -1
- data/lib/drakkon/web.rb +16 -7
- data/lib/drakkon.rb +8 -2
- metadata +44 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20674edb1e5357b6971a88c0dd4b222274ee75bb65bed6f8840530f8d9a804ec
|
4
|
+
data.tar.gz: 530c12ba7dedaa85213710fe7fd46f2b220feb02526002c21bac9450687d5cc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f52deb9d5a66285535f3cd03089575a8a7f1831923a6a7f37d688f008468711e759fe25aa7841012e499fa8f7e89f082f3fe318dcede83579f9a77ae0266635c
|
7
|
+
data.tar.gz: 065b90c52e8d60a35a0c3a4b1f141056a8fac63df483c074dec858bb41471ea975f67fe20a41a2fc75f27fcdec19806e3fa7a52b7a91c1ab4f52a0d166f1370b
|
data/lib/drakkon/build.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Drakkon
|
2
2
|
# Run Command for CLI
|
3
3
|
module Build
|
4
|
+
extend PlatformCompat
|
5
|
+
|
4
6
|
def self.args(raw = nil)
|
5
7
|
@args ||= raw
|
6
8
|
|
@@ -15,6 +17,9 @@ module Drakkon
|
|
15
17
|
|
16
18
|
Settings.update(:platforms, platform_setup) unless Settings.platforms?
|
17
19
|
|
20
|
+
# Run Index if configured
|
21
|
+
Manifest.index if Settings.config[:manifest]
|
22
|
+
|
18
23
|
builder = if args.empty?
|
19
24
|
Settings.platforms
|
20
25
|
else
|
@@ -40,8 +45,12 @@ module Drakkon
|
|
40
45
|
# Clean Up Accidental Leftovers
|
41
46
|
FileUtils.rm_r(context_name) if Dir.exist? context_name
|
42
47
|
|
43
|
-
|
44
|
-
|
48
|
+
if Settings.manifest_compile?
|
49
|
+
manifest_compile(context, context_name)
|
50
|
+
else
|
51
|
+
# DragonRuby Publish doesn't like symlinks or PATH...
|
52
|
+
FileUtils.cp_r(context, context_name)
|
53
|
+
end
|
45
54
|
|
46
55
|
# Clean Builds Dir
|
47
56
|
FileUtils.rm_r(Dir['builds/*'])
|
@@ -50,7 +59,8 @@ module Drakkon
|
|
50
59
|
FileUtils.rm_r("#{context_name}/builds") if Dir.exist? "#{context_name}/builds"
|
51
60
|
|
52
61
|
# Execute
|
53
|
-
|
62
|
+
io = IO.popen(build_env, build!(list, context_name, publish))
|
63
|
+
output(io)
|
54
64
|
|
55
65
|
# Preflight
|
56
66
|
FileUtils.mkdir_p("#{context}/builds")
|
@@ -73,13 +83,52 @@ module Drakkon
|
|
73
83
|
end
|
74
84
|
# rubocop:enable Metrics/AbcSize
|
75
85
|
|
86
|
+
# Send output to console
|
87
|
+
def self.output(io)
|
88
|
+
loop do
|
89
|
+
next unless io.ready?
|
90
|
+
end
|
91
|
+
rescue SystemExit, Interrupt, EOFError
|
92
|
+
LogBot.info('Build', 'Exiting')
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.manifest_compile(context, context_name)
|
96
|
+
# Base Folders
|
97
|
+
Dir.mkdir context_name
|
98
|
+
Dir.mkdir "#{context_name}/app"
|
99
|
+
|
100
|
+
# Copy Directories that are not being managed
|
101
|
+
FileUtils.cp_r("#{context}/fonts", "#{context_name}/fonts")
|
102
|
+
FileUtils.cp_r("#{context}/sprites", "#{context_name}/sprites")
|
103
|
+
FileUtils.cp_r("#{context}/sounds", "#{context_name}/sounds")
|
104
|
+
FileUtils.cp_r("#{context}/metadata", "#{context_name}/metadata")
|
105
|
+
|
106
|
+
# Copy over base files
|
107
|
+
FileUtils.cp("#{context}/app/main.rb", "#{context_name}/app/main.rb")
|
108
|
+
FileUtils.cp_r("#{context}/app/drakkon", "#{context_name}/app/drakkon")
|
109
|
+
|
110
|
+
# Compile into Manifest
|
111
|
+
File.open("#{context_name}/app/drakkon/manifest.rb", 'w') do |f|
|
112
|
+
Manifest.index.reverse.each do |file|
|
113
|
+
f << File.read("#{context}/#{file}")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
76
118
|
def self.metadata_version(context)
|
77
119
|
File.read("#{context}/metadata/game_metadata.txt").split("\n").find { |y| y.include? 'version' }.split('=').last
|
78
120
|
end
|
79
121
|
|
80
122
|
# DEW THE BUILD
|
81
123
|
def self.build!(list, context, package = '--package')
|
82
|
-
|
124
|
+
# 5.25 not liking the blank package flag
|
125
|
+
cmd = []
|
126
|
+
cmd.push './dragonruby-publish'
|
127
|
+
cmd.push package unless package.nil? || package.empty?
|
128
|
+
cmd.push "--platforms=#{list}"
|
129
|
+
cmd.push context
|
130
|
+
|
131
|
+
cmd
|
83
132
|
end
|
84
133
|
|
85
134
|
def self.version_dir
|
@@ -94,6 +143,10 @@ module Drakkon
|
|
94
143
|
args.include?('fonts')
|
95
144
|
end
|
96
145
|
|
146
|
+
def self.force_sounds?
|
147
|
+
args.include?('sounds')
|
148
|
+
end
|
149
|
+
|
97
150
|
def self.force_manifest?
|
98
151
|
args.include?('manifest')
|
99
152
|
end
|
data/lib/drakkon/cli.rb
CHANGED
@@ -21,6 +21,7 @@ module Drakkon
|
|
21
21
|
when :build then Build.go!(args)
|
22
22
|
when :publish then Build.go!([], '')
|
23
23
|
when :images then Images::CLI.run!(args)
|
24
|
+
when :utils then Utils::CLI.run!(args)
|
24
25
|
when :install then Version.install!(args)
|
25
26
|
when :gem then Gems::CLI.init!(args)
|
26
27
|
when :skeleton then Skeleton::CLI.init!(args)
|
@@ -48,7 +49,8 @@ module Drakkon
|
|
48
49
|
menu.choice name: 'build', value: :build
|
49
50
|
menu.choice name: 'publish', value: :publish
|
50
51
|
menu.choice name: 'install (DragonRuby Versions)', value: :install
|
51
|
-
menu.choice name: 'images', value: :images
|
52
|
+
menu.choice name: 'Image Helpers [images]', value: :images
|
53
|
+
menu.choice name: 'Utilities [utils]', value: :utils
|
52
54
|
menu.choice name: 'gem (Shared Code)', value: :gem
|
53
55
|
menu.choice name: 'skeleton (Templates)', value: :skeleton
|
54
56
|
menu.choice name: 'console (pry)', value: :console
|
data/lib/drakkon/gem/bundle.rb
CHANGED
@@ -8,7 +8,7 @@ module Drakkon
|
|
8
8
|
|
9
9
|
@context = context
|
10
10
|
|
11
|
-
if Settings.config[:bundle_digest] == digest && !args.include?('bundle')
|
11
|
+
if Settings.config[:bundle_digest] == digest && !args.include?('bundle') && File.exist?(bundle_file)
|
12
12
|
LogBot.info('Gems Bundle', 'Nothing New')
|
13
13
|
return unless args.include?('bundle')
|
14
14
|
else
|
@@ -61,8 +61,9 @@ module Drakkon
|
|
61
61
|
|
62
62
|
# Include other files
|
63
63
|
f << "require 'app/drakkon/image_index.rb' \n" if Settings.image_index?
|
64
|
-
f << "require 'app/drakkon/manifest.rb' \n" if Settings.manifest?
|
65
64
|
f << "require 'app/drakkon/font_index.rb' \n" if Settings.font_index?
|
65
|
+
f << "require 'app/drakkon/sound_index.rb' \n" if Settings.sound_index?
|
66
|
+
f << "require 'app/drakkon/manifest.rb' \n" if Settings.manifest?
|
66
67
|
|
67
68
|
# File Close
|
68
69
|
end
|
@@ -97,8 +98,9 @@ module Drakkon
|
|
97
98
|
|
98
99
|
# Include other files
|
99
100
|
f << "require 'app/drakkon/image_index.rb' \n" if Settings.image_index?
|
100
|
-
f << "require 'app/drakkon/manifest.rb' \n" if Settings.manifest?
|
101
101
|
f << "require 'app/drakkon/font_index.rb' \n" if Settings.font_index?
|
102
|
+
f << "require 'app/drakkon/sound_index.rb' \n" if Settings.sound_index?
|
103
|
+
f << "require 'app/drakkon/manifest.rb' \n" if Settings.manifest?
|
102
104
|
|
103
105
|
# File Close
|
104
106
|
end
|
@@ -122,20 +124,22 @@ module Drakkon
|
|
122
124
|
path = gem[:data][:path]
|
123
125
|
|
124
126
|
# Modules
|
125
|
-
gem[:data]
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
127
|
+
if gem[:data].key?(:modules)
|
128
|
+
gem[:data][:modules].each do |mod|
|
129
|
+
idx[mod.weight] ||= []
|
130
|
+
mod.files.each do |file|
|
131
|
+
file_name = "#{path}/#{file}.rb"
|
132
|
+
unless File.exist?(file_name)
|
133
|
+
LogBot.fatal('Bundle',
|
134
|
+
"Module File not found #{mod.name.pastel(:bright_blue)}, #{file_name.pastel(:red)}")
|
135
|
+
next
|
136
|
+
end
|
134
137
|
|
135
|
-
|
136
|
-
|
138
|
+
# Convert full file path into single string / relative naming (no directories)
|
139
|
+
safe_name = "#{gem.name}_#{file.gsub('/', '_')}"
|
137
140
|
|
138
|
-
|
141
|
+
idx[mod.weight].push(path: file_name, name: file, safe_name: safe_name)
|
142
|
+
end
|
139
143
|
end
|
140
144
|
end
|
141
145
|
|
data/lib/drakkon/gem/cli.rb
CHANGED
@@ -3,6 +3,8 @@ module Drakkon
|
|
3
3
|
# General Helpers for Gem Class
|
4
4
|
module GemHelpers
|
5
5
|
def select_modules
|
6
|
+
return if (data[:modules].nil? || data[:modules].empty?) && modules.empty?
|
7
|
+
|
6
8
|
data[:modules] = prompt_modules.map do |selected|
|
7
9
|
modules.find { |x| x[:name] == selected }
|
8
10
|
end
|
@@ -13,6 +15,9 @@ module Drakkon
|
|
13
15
|
valid_structure?
|
14
16
|
load_modules
|
15
17
|
|
18
|
+
# Ignore if no modules
|
19
|
+
return if data[:modules].nil? || data[:modules].empty?
|
20
|
+
|
16
21
|
data[:modules] = data[:modules].map(&:name).map do |selected|
|
17
22
|
modules.find { |x| x[:name] == selected }
|
18
23
|
end
|
data/lib/drakkon/init.rb
CHANGED
@@ -27,15 +27,30 @@ module Drakkon
|
|
27
27
|
metadata
|
28
28
|
|
29
29
|
# TODO: Validate / Confirm
|
30
|
-
|
30
|
+
try_write('app/main.rb') do |to|
|
31
|
+
File.write(to, main_tick)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.try_write(to, &blk)
|
36
|
+
if File.exist?(to)
|
37
|
+
LogBot.warn('Init', "- Tried to create #{to} but it already exists")
|
38
|
+
else
|
39
|
+
LogBot.info('Init', "- Created #{to}")
|
40
|
+
blk.call(to)
|
41
|
+
end
|
31
42
|
end
|
32
43
|
|
33
44
|
def self.metadata
|
34
45
|
# Icon is required for build
|
35
|
-
|
46
|
+
try_write('metadata/icon.png') do |to|
|
47
|
+
FileUtils.cp(metdata_dir('icon.png'), to)
|
48
|
+
end
|
36
49
|
|
37
50
|
# Copy metdata files
|
38
|
-
|
51
|
+
try_write('metadata/game_metadata.txt') do |to|
|
52
|
+
FileUtils.cp(metdata_dir('game_metadata.txt'), to)
|
53
|
+
end
|
39
54
|
end
|
40
55
|
|
41
56
|
def self.metdata_dir(file_name = nil)
|
@@ -45,20 +60,11 @@ module Drakkon
|
|
45
60
|
def self.settings
|
46
61
|
LogBot.info('Init', 'Settings Setup')
|
47
62
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
manifest: true,
|
54
|
-
bundle_compile: true,
|
55
|
-
gems: {}
|
56
|
-
}
|
57
|
-
|
58
|
-
# TODO: Be better, this is lazy...
|
59
|
-
opts.each do |key, value|
|
60
|
-
Settings.update(key, value)
|
61
|
-
end
|
63
|
+
# If we're here, it means Settings.init? returned false,
|
64
|
+
# which eans the config file doesn't exist.
|
65
|
+
# As a happy accident, accessing Settings.config for the first time also
|
66
|
+
# writes out a default config file
|
67
|
+
Settings.config
|
62
68
|
end
|
63
69
|
|
64
70
|
def self.directories
|
@@ -15,12 +15,12 @@ module Drakkon
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.digest
|
18
|
-
list = Dir["#{fonts_directory}
|
18
|
+
list = Dir["#{fonts_directory}/**/*"].select { |file| File.file?(file) }
|
19
19
|
Digest::MD5.hexdigest(list.map { |x| Digest::MD5.file(x).hexdigest }.join)
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.fonts_directory
|
23
|
-
"#{context}/fonts
|
23
|
+
"#{context}/fonts"
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.run!(force: false, dir: nil)
|
@@ -29,7 +29,7 @@ module Drakkon
|
|
29
29
|
# Create Directory if sprites directory is missing
|
30
30
|
FileUtils.mkdir_p(fonts_directory)
|
31
31
|
|
32
|
-
if Settings.config[:font_digest] == digest
|
32
|
+
if Settings.config[:font_digest] == digest && File.exist?("#{context}/app/drakkon/font_index.rb")
|
33
33
|
LogBot.info('Fonts Index', 'Nothing New')
|
34
34
|
return unless force
|
35
35
|
end
|
data/lib/drakkon/lib/hub.rb
CHANGED
@@ -7,16 +7,17 @@ module Drakkon
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.start
|
10
|
-
index = []
|
11
10
|
LogBot.info('Image Biggest Index')
|
12
|
-
images.
|
13
|
-
|
11
|
+
index = images.map do |img|
|
12
|
+
process(img)
|
14
13
|
end
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
img_w = index.max_by(&:w)
|
16
|
+
img_h = index.max_by(&:h)
|
18
17
|
|
19
|
-
puts "Largest
|
18
|
+
puts "Largest Sizes: { w: #{img_w.w}, h: #{img_h.h} }"
|
19
|
+
puts " Width: #{img_w}"
|
20
|
+
puts " Height: #{img_h}"
|
20
21
|
end
|
21
22
|
|
22
23
|
def self.process(file)
|
@@ -24,6 +25,7 @@ module Drakkon
|
|
24
25
|
img = MiniMagick::Image.open(file)
|
25
26
|
|
26
27
|
{
|
28
|
+
file: File.basename(file),
|
27
29
|
w: img.width,
|
28
30
|
h: img.height
|
29
31
|
}
|
@@ -58,22 +58,10 @@ module Drakkon
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
def self.process(file, filter, size)
|
62
|
-
image = MiniMagick::Image.open(file)
|
63
|
-
|
64
|
-
# Ignore if the same for w/h
|
65
|
-
return if image.width == size.split('x', 2).first.to_i && image.height == size.split('x', 2).last.to_i
|
66
|
-
|
67
|
-
LogBot.info('Image Resize', "Resizing: #{file}: #{size}")
|
68
|
-
image.filter filter
|
69
|
-
image.resize size
|
70
|
-
image.write file
|
71
|
-
end
|
72
|
-
|
73
61
|
def self.images
|
74
62
|
# Dir["#{Dir.pwd}/*.png"].sort_by(&:File.basename)
|
75
63
|
|
76
|
-
Dir["#{Dir.pwd}/*.png"]
|
64
|
+
Dir["#{Dir.pwd}/*.png"]
|
77
65
|
end
|
78
66
|
|
79
67
|
def self.prompt
|
@@ -25,50 +25,66 @@ module Drakkon
|
|
25
25
|
when :flip_flop then Images::FlipFlop.run!(args)
|
26
26
|
when :rotate then Images::Rotate.run!(args)
|
27
27
|
when :canvas then Images::Canvas.run!(args)
|
28
|
+
when :desaturate then Images::Desaturate.run!(args)
|
28
29
|
when :blur then Images::Blur.run!(args)
|
29
30
|
when :split then Images::SplitSpriteSheet.run!(args)
|
30
31
|
when :combine then Images::SpriteSheetCombine.run!(args)
|
32
|
+
when :double then Images::Double.run!(args)
|
31
33
|
when :trim then Images::Trim.run!(args)
|
32
34
|
when :gif_split then Images::GifSplit.run!(args)
|
33
35
|
when :sepia then Images::Sepia.run!(args)
|
34
36
|
when :modulate then Images::Modulate.run!(args)
|
37
|
+
when :layers then Images::Layers.run!(args)
|
38
|
+
when :hue_modulate then Images::HueModulate.run!(args)
|
35
39
|
when :bulk_rename then Images::BulkRename.run!(args)
|
40
|
+
when :downcase_norm then Images::DowncaseNormalize.run!(args)
|
36
41
|
when :text_to_image then Images::TextToImage.run!(args)
|
42
|
+
when :compress then Images::Compress.run!(args)
|
37
43
|
when :index then Images::Index.run!(force: true)
|
38
44
|
when :exit then exit(0)
|
39
45
|
else
|
40
46
|
start(menu, args)
|
41
47
|
end
|
48
|
+
rescue TTY::Reader::InputInterrupt
|
49
|
+
exit 0
|
42
50
|
end
|
43
51
|
# rubocop:enable Metrics/CyclomaticComplexity
|
44
52
|
|
53
|
+
# rubocop:disable Metrics/BlockLength
|
45
54
|
def self.menu
|
46
55
|
prompt.select('Image Helpers:', filter: true, per_page: 20) do |menu|
|
47
56
|
menu.choice name: 'Listing; Filter', value: :list
|
48
|
-
menu.choice name: 'Biggest: Find largest dimensions', value: :biggest
|
49
|
-
menu.choice name: 'Convert alpha to white', value: :white
|
50
|
-
menu.choice name: 'Resize WxH', value: :resize
|
51
|
-
menu.choice name: 'Scale', value: :scale
|
52
|
-
menu.choice name: 'Shift (Splice/Gravity)', value: :shift
|
53
|
-
menu.choice name: 'Roll', value: :roll
|
54
|
-
menu.choice name: 'Flip/Flop', value: :flip_flop
|
55
|
-
menu.choice name: 'Rotate', value: :rotate
|
56
|
-
menu.choice name: 'Canvas (Change/Retain)', value: :canvas
|
57
|
-
menu.choice name: 'Desaturate (Grey Colorspace)', value: :desaturate
|
58
|
-
menu.choice name: 'Blur', value: :blur
|
59
|
-
menu.choice name: 'Split SpriteSheet
|
60
|
-
menu.choice name: 'Create SpriteSheet
|
61
|
-
menu.choice name: '
|
62
|
-
menu.choice name: '
|
63
|
-
menu.choice name: '
|
64
|
-
menu.choice name: '
|
65
|
-
menu.choice name: '
|
66
|
-
menu.choice name: '
|
57
|
+
menu.choice name: 'Biggest: Find largest dimensions [biggest]', value: :biggest
|
58
|
+
menu.choice name: 'Convert alpha to white [white]', value: :white
|
59
|
+
menu.choice name: 'Resize WxH [resize]', value: :resize
|
60
|
+
menu.choice name: 'Scale [scale]', value: :scale
|
61
|
+
menu.choice name: 'Shift (Splice/Gravity) [shift]', value: :shift
|
62
|
+
menu.choice name: 'Roll [roll]', value: :roll
|
63
|
+
menu.choice name: 'Flip/Flop [flip_flop]', value: :flip_flop
|
64
|
+
menu.choice name: 'Rotate [rotate]', value: :rotate
|
65
|
+
menu.choice name: 'Canvas (Change/Retain) [canvas]', value: :canvas
|
66
|
+
menu.choice name: 'Desaturate (Grey Colorspace) [desaturate]', value: :desaturate
|
67
|
+
menu.choice name: 'Blur [blur]', value: :blur
|
68
|
+
menu.choice name: 'Split SpriteSheet [split]', value: :split
|
69
|
+
menu.choice name: 'Create SpriteSheet [combine]', value: :combine
|
70
|
+
menu.choice name: 'Double Image [double]', value: :double
|
71
|
+
menu.choice name: 'Trim Transparency (:trim]', value: :trim
|
72
|
+
menu.choice name: 'Gif Split [gif_split]', value: :gif_split
|
73
|
+
menu.choice name: 'Sepia [sepia]', value: :sepia
|
74
|
+
menu.choice name: 'Modulate [modulate]', value: :modulate
|
75
|
+
menu.choice name: 'Layers [layers]', value: :layers
|
76
|
+
menu.choice name: 'Bulk Rename [bulk_rename]', value: :bulk_rename
|
77
|
+
menu.choice name: 'Downcase Normalize [downcase_norm]', value: :downcase_norm
|
78
|
+
menu.choice name: 'Hue Modulate [hue_modulate]', value: :hue_modulate
|
79
|
+
menu.choice name: 'TextToImage [text_to_image]', value: :text_to_image
|
80
|
+
menu.choice name: 'Compress (file size) [compress]', value: :compress
|
81
|
+
menu.choice name: 'Index (Re-run Index) [index]', value: :index
|
67
82
|
menu.choice name: 'exit', value: :exit
|
68
83
|
end
|
69
84
|
rescue TTY::Reader::InputInterrupt
|
70
85
|
exit 0
|
71
86
|
end
|
87
|
+
# rubocop:enable Metrics/BlockLength
|
72
88
|
|
73
89
|
def self.prompt
|
74
90
|
TTY::Prompt.new(active_color: :cyan, interrupt: :exit)
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Drakkon
|
2
|
+
module Images
|
3
|
+
# Dirty Compression.. Bad Idea?
|
4
|
+
module Compress
|
5
|
+
def self.run!(_args = [])
|
6
|
+
puts <<~HELP
|
7
|
+
Usage
|
8
|
+
- Run in the directory you wish to modify the images
|
9
|
+
- Converts the Images to Webp and then back to PNG
|
10
|
+
Images:
|
11
|
+
HELP
|
12
|
+
|
13
|
+
images.sort.each do |img|
|
14
|
+
img_s = img.gsub("#{Dir.pwd}/", '').pastel(:yellow)
|
15
|
+
puts " - #{img_s}"
|
16
|
+
end
|
17
|
+
puts
|
18
|
+
|
19
|
+
exit unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)} Compress!? #{'(Destructive)'.pastel(:red)}"
|
20
|
+
|
21
|
+
start
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.start
|
25
|
+
images.each do |img|
|
26
|
+
LogBot.info('Image Compress', img)
|
27
|
+
process(img)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.process(file)
|
32
|
+
basename = File.basename(file, '.png')
|
33
|
+
path = File.dirname(file)
|
34
|
+
|
35
|
+
# Write Webp
|
36
|
+
image = MiniMagick::Image.open(file)
|
37
|
+
image.format 'webp'
|
38
|
+
image.write "#{path}/#{basename}.webp"
|
39
|
+
|
40
|
+
# Write back to PNG
|
41
|
+
image = MiniMagick::Image.open("#{path}/#{basename}.webp")
|
42
|
+
image.format 'png'
|
43
|
+
image.write "#{path}/#{basename}.png"
|
44
|
+
|
45
|
+
# Delete Temp
|
46
|
+
FileUtils.rm("#{path}/#{basename}.webp")
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.images
|
50
|
+
Dir["#{Dir.pwd}/*.png"]
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.prompt
|
54
|
+
TTY::Prompt.new(active_color: :cyan, interrupt: :exit)
|
55
|
+
end
|
56
|
+
# =========================================================
|
57
|
+
end
|
58
|
+
# =========================================================
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Drakkon
|
2
|
+
module Images
|
3
|
+
# General Image Index Helper
|
4
|
+
module Double
|
5
|
+
def self.run!(args = [])
|
6
|
+
# Alpha
|
7
|
+
alpha = if args.empty?
|
8
|
+
prompt.ask('Amount of Doubled Alpha? (e.g. 0..1): ')
|
9
|
+
else
|
10
|
+
args.shift
|
11
|
+
end
|
12
|
+
LogBot.info('Double Image Alhpa', "Alpha: #{alpha}")
|
13
|
+
|
14
|
+
puts <<~HELP
|
15
|
+
Usage [alpha]
|
16
|
+
- Run in the directory you wish to modify the images
|
17
|
+
- Adds the layer onto itself with a alpha value via MiniMagick
|
18
|
+
Current Directory;
|
19
|
+
#{Dir.pwd.pastel(:yellow)}
|
20
|
+
|
21
|
+
Images:
|
22
|
+
HELP
|
23
|
+
|
24
|
+
images.sort.each do |img|
|
25
|
+
img_s = img.gsub("#{Dir.pwd}/", '').pastel(:yellow)
|
26
|
+
puts " - #{img_s}"
|
27
|
+
end
|
28
|
+
puts
|
29
|
+
|
30
|
+
unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)} Double Images!? #{'(Destructive)'.pastel(:red)}"
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
|
34
|
+
start(alpha)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.start(alpha)
|
38
|
+
images.each do |img|
|
39
|
+
double(img, alpha)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.double(file, alpha)
|
44
|
+
image = MiniMagick::Image.open(file)
|
45
|
+
|
46
|
+
LogBot.info('Image Double', "#{File.basename file}")
|
47
|
+
|
48
|
+
# Create a copy of the image for overlay
|
49
|
+
overlay = image.clone
|
50
|
+
|
51
|
+
# Apply alpha to the overlay
|
52
|
+
overlay = overlay.compose('Over') do |c|
|
53
|
+
c.gravity 'center' # Center the overlay
|
54
|
+
c.define "compose:args=1,0,0,#{alpha}" # Control the alpha
|
55
|
+
end
|
56
|
+
|
57
|
+
# Combine the original image and the overlay
|
58
|
+
result = image.composite(overlay) do |c|
|
59
|
+
c.gravity 'center' # Center the overlay on the original image
|
60
|
+
end
|
61
|
+
|
62
|
+
# Save the result
|
63
|
+
result.write(file)
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.images
|
67
|
+
Dir["#{Dir.pwd}/**/*.png"]
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.prompt
|
71
|
+
TTY::Prompt.new(active_color: :cyan, interrupt: :exit)
|
72
|
+
end
|
73
|
+
# =========================================================
|
74
|
+
end
|
75
|
+
# =========================================================
|
76
|
+
end
|
77
|
+
end
|