drakkon 0.0.8 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/lib/drakkon/build.rb +57 -4
  3. data/lib/drakkon/cli.rb +3 -1
  4. data/lib/drakkon/gem/bundle.rb +19 -15
  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 -17
  8. data/lib/drakkon/lib/{images → fonts}/fonts.rb +3 -3
  9. data/lib/drakkon/lib/hub.rb +2 -1
  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 +3 -0
  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 +49 -1
  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 +11 -4
  35. data/lib/drakkon/run/reader_shim.rb +9 -5
  36. data/lib/drakkon/run.rb +4 -1
  37. data/lib/drakkon/skeleton/deploy.rb +4 -1
  38. data/lib/drakkon/web.rb +16 -7
  39. data/lib/drakkon.rb +8 -2
  40. metadata +44 -6
@@ -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
@@ -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
@@ -13,17 +13,9 @@ module Drakkon
13
13
  end
14
14
 
15
15
  def self.run!(force: false)
16
- list
17
- search("#{Dir.pwd}/app")
18
-
19
- # No Dupes please
20
- list.reject! { |x| x.include? 'app/drakkon/manifest.rb' }
21
-
22
- list.map! do |file|
23
- file.gsub(root_directory, '')
24
- end
16
+ index
25
17
 
26
- if Settings.config[:manifest_digest] == digest
18
+ if Settings.config[:manifest_digest] == digest && File.exist?('app/drakkon/manifest.rb')
27
19
  LogBot.info('Manifest', 'Nothing New')
28
20
  return unless force
29
21
  end
@@ -34,10 +26,22 @@ module Drakkon
34
26
 
35
27
  # Make Directory `app/drakkon` if it doesn't exist
36
28
  FileUtils.mkdir_p('app/drakkon') unless File.directory?('app/drakkon')
37
-
38
29
  File.write('app/drakkon/manifest.rb', required)
39
30
  end
40
31
 
32
+ # Split out | Just collect information
33
+ def self.index
34
+ list
35
+ search("#{Dir.pwd}/app")
36
+
37
+ # General Cleanup
38
+ list.reject! { |x| x.include? 'app/main.rb' }
39
+
40
+ list.map! do |file|
41
+ file.gsub(root_directory, '')
42
+ end
43
+ end
44
+
41
45
  def self.digest
42
46
  Digest::MD5.hexdigest(list.map { |x| Digest::MD5.file(x).hexdigest }.join)
43
47
  end
@@ -49,6 +53,9 @@ module Drakkon
49
53
  end
50
54
 
51
55
  def self.search(dir)
56
+ # Skip Drakkon
57
+ return if dir.include?('app/drakkon')
58
+
52
59
  @list.concat Dir["#{dir}/*.rb"]
53
60
 
54
61
  Dir["#{dir}/*"].each do |file|
@@ -61,11 +68,12 @@ module Drakkon
61
68
  # Generate Require Statements
62
69
  # Sure there gonna be plenty of opinions on this bad boi
63
70
  def self.required
64
- <<~TEMPLATE
65
- #{Manifest.list.reverse.inspect}.each do |file|
66
- require file
67
- end
68
- TEMPLATE
71
+ require_strings = ''
72
+ list.reverse.each do |file|
73
+ require_strings << "require '#{file}'\n"
74
+ end
75
+
76
+ require_strings
69
77
  end
70
78
 
71
79
  # ----------------------
@@ -3,7 +3,7 @@ module Drakkon
3
3
  # Replace Colorize with Pastel Monkey Patch String Shim
4
4
  # https://github.com/piotrmurach/pastel#features
5
5
 
6
- # Looping in GreenHat to allow disabling of Color
6
+ # Looping in to allow disabling of Color
7
7
  module Color
8
8
  def self.pastel
9
9
  @pastel ||= Pastel.new
@@ -0,0 +1,27 @@
1
+ module Drakkon
2
+ # Helper to provide platform compatibility
3
+ module PlatformCompat
4
+ def run_env
5
+ {
6
+ 'PATH' => "#{version_dir}#{path_divider}#{ENV.fetch('PATH', nil)}"
7
+ }
8
+ end
9
+
10
+ def build_env
11
+ run_env # not sure if these will ever be different
12
+ end
13
+
14
+ def windows?
15
+ (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
16
+ end
17
+
18
+ def path_divider
19
+ if windows?
20
+ ';'
21
+ # Linux uses ':' (same with mac/unix?)
22
+ else
23
+ ':'
24
+ end
25
+ end
26
+ end
27
+ end