drakkon 0.0.7 → 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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/drakkon/build.rb +61 -4
  3. data/lib/drakkon/cli.rb +3 -1
  4. data/lib/drakkon/gem/bundle.rb +86 -17
  5. data/lib/drakkon/gem/cli.rb +2 -0
  6. data/lib/drakkon/gem/helpers/modules.rb +5 -0
  7. data/lib/drakkon/init.rb +23 -15
  8. data/lib/drakkon/lib/fonts/fonts.rb +88 -0
  9. data/lib/drakkon/lib/hub.rb +4 -3
  10. data/lib/drakkon/lib/images/biggest.rb +8 -6
  11. data/lib/drakkon/lib/images/bulk_rename.rb +1 -13
  12. data/lib/drakkon/lib/images/cli.rb +35 -19
  13. data/lib/drakkon/lib/images/compress.rb +60 -0
  14. data/lib/drakkon/lib/images/double.rb +77 -0
  15. data/lib/drakkon/lib/images/downcase_normalize.rb +70 -0
  16. data/lib/drakkon/lib/images/hue_modulation.rb +71 -0
  17. data/lib/drakkon/lib/images/index.rb +43 -20
  18. data/lib/drakkon/lib/images/layers.rb +55 -0
  19. data/lib/drakkon/lib/images/resize.rb +3 -2
  20. data/lib/drakkon/lib/images/split.rb +4 -4
  21. data/lib/drakkon/lib/images/spritesheet.rb +52 -13
  22. data/lib/drakkon/lib/images/text.rb +4 -1
  23. data/lib/drakkon/lib/images/trim.rb +7 -6
  24. data/lib/drakkon/lib/manifest.rb +24 -16
  25. data/lib/drakkon/lib/pastel.rb +1 -1
  26. data/lib/drakkon/lib/platform_compat.rb +27 -0
  27. data/lib/drakkon/lib/settings.rb +68 -5
  28. data/lib/drakkon/lib/sounds/sounds.rb +126 -0
  29. data/lib/drakkon/lib/utils/cli.rb +38 -0
  30. data/lib/drakkon/lib/utils/rename_normalize.rb +75 -0
  31. data/lib/drakkon/lib/version.rb +17 -2
  32. data/lib/drakkon/release.rb +1 -1
  33. data/lib/drakkon/run/commands/utils.rb +14 -0
  34. data/lib/drakkon/run/helpers.rb +15 -4
  35. data/lib/drakkon/run/reader_shim.rb +9 -5
  36. data/lib/drakkon/run/tty.rb +1 -1
  37. data/lib/drakkon/run.rb +6 -2
  38. data/lib/drakkon/skeleton/deploy.rb +4 -1
  39. data/lib/drakkon/web.rb +16 -44
  40. data/lib/drakkon.rb +10 -7
  41. metadata +32 -35
@@ -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
@@ -0,0 +1,70 @@
1
+ module Drakkon
2
+ module Images
3
+ # This downcases all the things
4
+ module DowncaseNormalize
5
+ def self.run!(_args = nil)
6
+ puts <<~HELP
7
+ - Run in the directory you wish to rename images
8
+ - Downcase
9
+ - Normalize
10
+ - To Underscores:
11
+ - Space
12
+ - Perentheses
13
+ - Dash
14
+ - Delete Final Chars
15
+ - If Underscore
16
+ Current Directory;
17
+ #{Dir.pwd.pastel(:yellow)}
18
+
19
+ Images:
20
+ HELP
21
+
22
+ images.each do |img|
23
+ img_s = img.gsub("#{Dir.pwd}/", '').pastel(:yellow)
24
+ puts " - #{img_s}"
25
+ end
26
+ puts
27
+
28
+ exit unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)} Rename!? #{'(Destructive)'.pastel(:red)}"
29
+
30
+ start
31
+ end
32
+
33
+ def self.start
34
+ images.each do |img|
35
+ process(img)
36
+ end
37
+ end
38
+
39
+ # Image file name normalization. Downcase and replace spaces with underscore
40
+ def self.process(file)
41
+ new_name = File.basename(file).downcase.gsub(' ', '_').gsub('(', '_').gsub(')', '_').gsub('-', '_')
42
+ path = File.dirname(file)
43
+
44
+ # Remove Final Underscore last char of basename is an underscore
45
+ ext = File.extname(new_name)
46
+ basename = File.basename(new_name, ext)
47
+ if basename[-1] == '_' && basename.length > 1
48
+ new_name = basename[0..-2]
49
+ new_name += ext
50
+ end
51
+
52
+ # Skip if the same
53
+ return if new_name == File.basename(file)
54
+
55
+ LogBot.info('Image Downcase Normalize', "Old: #{File.basename(file)}, New: #{new_name}")
56
+ FileUtils.mv(file, "#{path}/#{new_name}")
57
+ end
58
+
59
+ def self.images
60
+ Dir["#{Dir.pwd}/*.png"] + Dir["#{Dir.pwd}/*.PNG"]
61
+ end
62
+
63
+ def self.prompt
64
+ TTY::Prompt.new(active_color: :cyan, interrupt: :exit)
65
+ end
66
+ # =========================================================
67
+ end
68
+ # =========================================================
69
+ end
70
+ end
@@ -0,0 +1,71 @@
1
+ module Drakkon
2
+ module Images
3
+ # General Image Index Helper
4
+ # https://www.imagemagick.org/Usage/color_mods/#modulate_hue
5
+ module HueModulate
6
+ def self.run!(args = [])
7
+ # Amount
8
+ amount = if args.empty?
9
+ puts 'Amount Syntax: brightness,saturation,hue'
10
+ prompt.ask('Amount? (0..200) 100 is no change: ')
11
+ else
12
+ args.shift
13
+ end
14
+
15
+ puts <<~HELP
16
+ Usage
17
+ - Run in the directory you wish to modify the images
18
+ - Hue Modulates images via MiniMagick
19
+
20
+ Hue Modulate Amount: #{amount}
21
+ Current Directory;
22
+ #{Dir.pwd.pastel(:yellow)}
23
+
24
+ Current Directory;
25
+ #{Dir.pwd.pastel(:yellow)}
26
+
27
+ Images:
28
+ HELP
29
+
30
+ images.sort.each do |img|
31
+ img_s = img.gsub("#{Dir.pwd}/", '').pastel(:yellow)
32
+ puts " - #{img_s}"
33
+ end
34
+ puts
35
+
36
+ unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)} Hue Modulate!? #{'(Destructive)'.pastel(:red)}"
37
+ exit
38
+ end
39
+
40
+ start(amount)
41
+ end
42
+
43
+ def self.start(amount)
44
+ images.each do |img|
45
+ LogBot.info('Image Mod', img)
46
+ process(img, amount)
47
+ end
48
+ end
49
+
50
+ def self.process(file, amount)
51
+ image = MiniMagick::Image.open(file)
52
+
53
+ image.combine_options do |c|
54
+ c.modulate "100,100,#{amount}"
55
+ end
56
+
57
+ image.write(file)
58
+ end
59
+
60
+ def self.images
61
+ Dir["#{Dir.pwd}/**/*.png"]
62
+ end
63
+
64
+ def self.prompt
65
+ TTY::Prompt.new(active_color: :cyan, interrupt: :exit)
66
+ end
67
+ # =========================================================
68
+ end
69
+ # =========================================================
70
+ end
71
+ end
@@ -46,10 +46,13 @@ module Drakkon
46
46
  def self.run!(force: false, dir: nil)
47
47
  @context = dir || Dir.pwd
48
48
 
49
+ # Make Directory `app/drakkon` if it doesn't exist
50
+ FileUtils.mkdir_p('app/drakkon') unless File.directory?('app/drakkon')
51
+
49
52
  # Create Directory if sprites directory is missing
50
53
  FileUtils.mkdir_p(sprites_directory)
51
54
 
52
- if Settings.config[:image_digest] == digest
55
+ if Settings.config[:image_digest] == digest && File.exist?("#{context}/app/drakkon/image_index.rb")
53
56
  LogBot.info('Images Index', 'Nothing New')
54
57
  return unless force
55
58
  end
@@ -65,31 +68,49 @@ module Drakkon
65
68
  check sprites_directory
66
69
  end
67
70
 
71
+ # rubocop:disable Layout/HeredocIndentation
68
72
  def self.result
69
73
  <<~RB
70
74
  module Drakkon
71
- module Images
72
- def self.index
73
- #{index.inspect}
74
- end
75
-
76
- def self.catalog
77
- #{catalog.inspect}
78
- end
79
-
80
- def self.sprites
81
- #{sprites.inspect}
82
- end
83
-
84
- def self.reset_all
85
- #{all.inspect}.each do |sprite|
86
- $gtk.reset_sprite "sprites/\#{sprite}.png"
87
- end
88
- end
89
- end
75
+ module Images
76
+ def self.index
77
+ #{index.inspect}
78
+ end
79
+
80
+ def self.catalog
81
+ #{catalog.inspect}
82
+ end
83
+
84
+ def self.catalog_dig(long)
85
+ catalog.dig(*long.split('/'))
86
+ end
87
+
88
+ # Return Path from Catalog
89
+ def self.find_sprite(path)
90
+ catalog.dig(*path.split('/')).values.map(&:path)
91
+ end
92
+
93
+ # Return Path from Catalog
94
+ def self.find_anim(path)
95
+ catalog.dig(*path.split('/')).keys.map do |key|
96
+ "\#{path}/\#{key}"
97
+ end
98
+ end
99
+
100
+ def self.sprites
101
+ #{sprites.inspect}
102
+ end
103
+
104
+ def self.reset_all
105
+ #{all.inspect}.each do |sprite|
106
+ $gtk.reset_sprite "sprites/\#{sprite}.png"
107
+ end
108
+ end
109
+ end
90
110
  end
91
111
  RB
92
112
  end
113
+ # rubocop:enable Layout/HeredocIndentation
93
114
 
94
115
  # Recursively Go through
95
116
  def self.check(dir = nil)
@@ -164,6 +185,8 @@ module Drakkon
164
185
  def self.process_animation(list = nil)
165
186
  # Append all images to `all`
166
187
  list.each do |file|
188
+ # Also store individual image
189
+ process file
167
190
  all.push file.gsub(sprites_directory, '')[1..].gsub('.png', '')
168
191
  end
169
192
 
@@ -0,0 +1,55 @@
1
+ module Drakkon
2
+ module Images
3
+ # General Image Index Helper
4
+ # convert -dispose Background "Background.psd" -layers coalesce "output.png"
5
+ module Layers
6
+ def self.run!(args = [])
7
+ # File Select
8
+ file = if args.empty?
9
+ prompt.select('File to split?', files, filter: true)
10
+ else
11
+ args.first
12
+ end
13
+
14
+ output = if args.empty?
15
+ prompt.ask('Output File Pattern? (e.g. output): ')
16
+ else
17
+ args.shift
18
+ end
19
+
20
+ puts <<~HELP
21
+ Usage
22
+ - Use image magick to split layers of input file. Specifically intially used for PSD files.
23
+
24
+ Input: #{file}
25
+ Output: #{output}
26
+ HELP
27
+
28
+ puts
29
+
30
+ exit unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)}"
31
+
32
+ start(file, output)
33
+ end
34
+
35
+ def self.start(file, output)
36
+ MiniMagick::Tool::Convert.new do |convert|
37
+ convert.dispose 'Background'
38
+ convert << file
39
+ convert.layers 'coalesce'
40
+ convert << "#{output}.png"
41
+ end
42
+ end
43
+
44
+ def self.files
45
+ Dir["#{Dir.pwd}/*"]
46
+ end
47
+
48
+ def self.prompt
49
+ TTY::Prompt.new(active_color: :cyan, interrupt: :exit)
50
+ end
51
+ # =========================================================
52
+ end
53
+ # =========================================================
54
+ end
55
+ end
@@ -5,7 +5,8 @@ module Drakkon
5
5
  def self.run!(args = [])
6
6
  # Sizing
7
7
  size = if args.empty?
8
- prompt.ask('Target Size? (e.g. 200x200): ')
8
+ puts "Use '#{'!'.pastel(:bright_blue)}' to force the size"
9
+ prompt.ask('Target Size? (e.g. "200x200" or "64x64!"): ')
9
10
  else
10
11
  args.shift
11
12
  end
@@ -24,7 +25,7 @@ module Drakkon
24
25
  puts <<~HELP
25
26
  Usage [size] [filter = Lanczos2]
26
27
  - Run in the directory you wish to modify the images
27
- - Resizes the images via MiniMagick
28
+ - Resizes images via MiniMagick and will force the size (breaking aspect ratio)
28
29
  - Sizes are #{'width'.pastel(:blue)} x #{'height'.pastel(:blue)}
29
30
  - 200x200, 150,175, and etc
30
31
 
@@ -34,8 +34,9 @@ module Drakkon
34
34
  args.shift
35
35
  end
36
36
 
37
- width = sizing[:w] / columns
38
- height = sizing[:h] / rows
37
+ # Without Float it won't respect the exact sizing
38
+ width = sizing[:w] / columns.to_f
39
+ height = sizing[:h] / rows.to_f
39
40
 
40
41
  puts <<~HELP
41
42
  Usage [file]
@@ -55,8 +56,6 @@ module Drakkon
55
56
  exit unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)} Split!? #{'(Destructive)'.pastel(:red)}"
56
57
 
57
58
  process(image, width, height)
58
- rescue TTY::Reader::InputInterrupt
59
- exit 0
60
59
  end
61
60
 
62
61
  def self.process(file, width, height)
@@ -65,6 +64,7 @@ module Drakkon
65
64
  convert << file
66
65
  convert.crop("#{width}x#{height}")
67
66
  convert << file
67
+
68
68
  convert.call
69
69
  end
70
70
 
@@ -3,22 +3,31 @@ module Drakkon
3
3
  # General Image Index Helper
4
4
  module SpriteSheetCombine
5
5
  def self.run!(args = [])
6
+ # All images exist?
7
+ unless images.all? { |x| File.exist?(x) } ||
8
+ LogBot.fatal('SpriteSheetCombine', 'Invalid Images - Files must be numbered. e.g. 1.png, 2.png, 3.png')
9
+ exit 1
10
+ end
11
+
6
12
  img_name = if args.empty?
7
13
  prompt.ask('New File Name? (e.g. rawr): ')
8
14
  else
9
15
  args.shift
10
16
  end
11
17
 
12
- puts <<~HELP
13
- Usage [size] [filter = Lanczos2]
14
- - Run in the directory you wish to modify the images
15
- - Resizes the images via MiniMagick
16
- - Each image sizing values scaled by (value / 100)
18
+ grid = if args.empty?
19
+ prompt.ask('Grid? (WxH: e.g. 1x1, blank will leave up to ImageMagick): ')
20
+ else
21
+ args.shift
22
+ end
17
23
 
24
+ # Safety
25
+ img_name ||= 'rawr'
18
26
 
19
- Image Target: #{img_name}
20
- Current Directory;
21
- #{Dir.pwd.pastel(:yellow)}
27
+ puts <<~HELP
28
+ Usage
29
+ - Run in the directory you wish to modify the images
30
+ - Images must be numbered so that the spritesheet can be created correctly
22
31
 
23
32
  Images:
24
33
  HELP
@@ -27,34 +36,64 @@ module Drakkon
27
36
  img_s = img.gsub("#{Dir.pwd}/", '').pastel(:yellow)
28
37
  puts " - #{img_s}"
29
38
  end
39
+
40
+ puts <<~OPTIONS
41
+ Image Target: #{img_name.inspect}, Grid: #{grid.inspect}
42
+ Current Directory;
43
+ #{Dir.pwd.pastel(:yellow)}
44
+ OPTIONS
45
+
30
46
  puts
31
47
 
32
- exit unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)} Combine?'"
48
+ exit unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)} Combine?"
33
49
 
34
- process(img_name)
50
+ process(img_name, grid)
35
51
  rescue TTY::Reader::InputInterrupt
36
52
  exit 0
37
53
  end
38
54
 
39
- def self.process(img_name)
55
+ def self.process(img_name, grid)
40
56
  LogBot.info('Image Spritesheet', img_name)
41
57
 
42
- img = dimensions(images.first)
58
+ # Find Largest
59
+ img = dimensions(images)
43
60
  img_name += '.png'
44
61
 
62
+ LogBot.info('Image Spritesheet', "Dimensions: #{img[:w]}x#{img[:h]}")
63
+
45
64
  montage = MiniMagick::Tool::Montage.new
46
65
  images.each do |imgn|
47
66
  montage << imgn
48
67
  end
49
68
 
50
69
  montage.geometry "#{img.w}x#{img.h}+0+0"
70
+ montage.tile grid unless grid.nil?
51
71
  montage.background 'none'
52
72
  montage << "#{Dir.pwd}/#{img_name}"
53
73
 
54
74
  montage.call
55
75
  end
56
76
 
57
- def self.dimensions(file)
77
+ def self.dimensions(_file)
78
+ # img = MiniMagick::Image.open(file)
79
+
80
+ # {
81
+ # w: img.width,
82
+ # h: img.height
83
+ # }
84
+
85
+ index = images.map do |img|
86
+ image_size(img)
87
+ end
88
+
89
+ w = index.max_by(&:w).w
90
+ h = index.max_by(&:h).h
91
+
92
+ { w: w, h: h }
93
+ end
94
+
95
+ def self.image_size(file)
96
+ # LogBot.info('Image Biggest', file)
58
97
  img = MiniMagick::Image.open(file)
59
98
 
60
99
  {
@@ -29,6 +29,9 @@ module Drakkon
29
29
 
30
30
  file.gsub!(/[^0-9A-Za-z.-]/, '_')
31
31
 
32
+ # Remove Dashes
33
+ file.gsub!(/-+/, '_')
34
+
32
35
  font = if args.empty?
33
36
  font_prompt
34
37
  else
@@ -50,7 +53,7 @@ module Drakkon
50
53
 
51
54
  puts
52
55
 
53
- exit unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)}"
56
+ exit unless prompt.yes? 'Are you sure?'.pastel(:bright_yellow).to_s
54
57
 
55
58
  generate(font: font, text: text, size: size, color: color, file: file)
56
59
  rescue TTY::Reader::InputInterrupt
@@ -7,7 +7,7 @@ module Drakkon
7
7
  Usage
8
8
  - Run in the directory you wish to modify the images
9
9
  - Trim/Repage the images via MiniMagick
10
- #{' '}
10
+
11
11
  Current Directory;
12
12
  #{Dir.pwd.pastel(:yellow)}
13
13
 
@@ -34,12 +34,13 @@ module Drakkon
34
34
  end
35
35
 
36
36
  def self.process(file)
37
- image = MiniMagick::Image.open(file)
38
-
39
37
  LogBot.info('Image Trim', File.basename(file).to_s)
40
- image.trim
41
- image.repage
42
- image.write output_file
38
+ MiniMagick::Tool::Convert.new do |convert|
39
+ convert << file
40
+ convert.trim
41
+ convert << '+repage'
42
+ convert << file
43
+ end
43
44
  end
44
45
 
45
46
  def self.images