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
@@ -19,6 +19,17 @@ module Drakkon
19
19
  exit 1
20
20
  end
21
21
 
22
+ def self.check_version!
23
+ return if Hub.version?(version)
24
+
25
+ LogBot.warn('Setup', "DragonRuby #{version} not installed.")
26
+ LogBot.warn('Setup', 'Select a version to use:')
27
+
28
+ Version.set
29
+
30
+ exit(1) unless Hub.version?(version)
31
+ end
32
+
22
33
  def self.prompt
23
34
  TTY::Prompt.new(active_color: :cyan, interrupt: :exit)
24
35
  end
@@ -55,10 +66,18 @@ module Drakkon
55
66
  config[:font_index]
56
67
  end
57
68
 
69
+ def self.sound_index?
70
+ config[:sound_index]
71
+ end
72
+
58
73
  def self.bundle_compile?
59
74
  config[:bundle_compile]
60
75
  end
61
76
 
77
+ def self.manifest_compile?
78
+ config[:manifest_compile]
79
+ end
80
+
62
81
  def self.manifest?
63
82
  config[:manifest]
64
83
  end
@@ -67,14 +86,35 @@ module Drakkon
67
86
  "#{Dir.pwd}/.drakkon"
68
87
  end
69
88
 
89
+ def self.image_magick_installed?
90
+ # Use Minimagick's utilities to check if ImageMagick is installed
91
+ # https://github.com/minimagick/minimagick/pull/193
92
+ !MiniMagick::Utilities.which('convert').nil?
93
+
94
+ # MiniMagick::Image.open('metadata/icon.png')
95
+ rescue MiniMagick::Invalid, Errno::ENOENT
96
+ false
97
+ end
98
+
99
+ def self.enable_image_index?
100
+ return false unless image_magick_installed?
101
+
102
+ # TODO: Determine if this should default to True?
103
+ return true if config[:image_index].nil?
104
+
105
+ config[:image_index]
106
+ end
107
+
70
108
  def self.config_defaults
71
109
  # Defaults
72
110
  @config[:platforms] ||= []
73
111
  @config[:version] ||= Hub.version_latest
74
- @config[:image_index] = true if @config[:image_index].nil?
112
+ @config[:image_index] = enable_image_index?
75
113
  @config[:manifest] = true if @config[:manifest].nil?
76
114
  @config[:bundle_compile] = true if @config[:bundle_compile].nil?
115
+ @config[:manifest_compile] = false if @config[:manifest_compile].nil?
77
116
  @config[:font_index] = true if @config[:font_index].nil?
117
+ @config[:sound_index] = true if @config[:sound_index].nil?
78
118
  @config[:gems] ||= {}
79
119
  end
80
120
 
@@ -85,6 +125,7 @@ module Drakkon
85
125
  if @config.nil?
86
126
  @config ||= JSON.parse(File.read(config_file), { symbolize_names: true })
87
127
  config_defaults
128
+ write
88
129
  end
89
130
 
90
131
  @config
@@ -111,7 +152,9 @@ module Drakkon
111
152
  menu.choice name: 'version', value: :version
112
153
  menu.choice name: 'image_index', value: :image_index
113
154
  menu.choice name: 'font_index', value: :font_index
155
+ menu.choice name: 'sound_index', value: :sound_index
114
156
  menu.choice name: 'manifest', value: :manifest
157
+ menu.choice name: 'manifest_compile', value: :manifest_compile
115
158
  menu.choice name: 'bundle_compile', value: :bundle_compile
116
159
  menu.choice name: 'exit', value: :exit
117
160
  end
@@ -132,8 +175,13 @@ module Drakkon
132
175
  when :bundle_compile
133
176
  Settings.update(:bundle_compile,
134
177
  prompt.yes?("Create Bundle / Compile Gems? (Enabled: #{config[:bundle_compile]})"))
178
+ when :manifest_compile
179
+ Settings.update(:manifest_compile,
180
+ prompt.yes?("Bundle Manifest On Build? (Enabled: #{config[:manifest_compile]})"))
135
181
  when :font_index
136
182
  Settings.update(:font_index, prompt.yes?("Index Fonts? (Enabled: #{config[:font_index]})"))
183
+ when :sound_index
184
+ Settings.update(:font_index, prompt.yes?("Index Sounds? (Enabled: #{config[:sound_index]})"))
137
185
  when :exit
138
186
  exit 0
139
187
  end
@@ -0,0 +1,126 @@
1
+ module Drakkon
2
+ module Sounds
3
+ # General Sound Index Helper
4
+ module Index
5
+ def self.index
6
+ @index ||= {}
7
+
8
+ @index
9
+ end
10
+
11
+ def self.context
12
+ @context ||= Dir.pwd
13
+
14
+ @context
15
+ end
16
+
17
+ def self.catalog
18
+ # Better way to do this?
19
+ @catalog ||= Hash.new { |hash, key| hash[key] = Hash.new(&hash.default_proc) }
20
+
21
+ @catalog
22
+ end
23
+
24
+ def self.file_list
25
+ Dir["#{sounds_directory}/**/*"].select { |file| File.file?(file) }
26
+ end
27
+
28
+ def self.digest
29
+ Digest::MD5.hexdigest(file_list.map { |x| Digest::MD5.file(x).hexdigest }.join)
30
+ end
31
+
32
+ def self.sounds_directory
33
+ "#{context}/sounds"
34
+ end
35
+
36
+ def self.run!(force: false, dir: nil)
37
+ @context = dir || Dir.pwd
38
+
39
+ # Create Directory if sprites directory is missing
40
+ FileUtils.mkdir_p(sounds_directory)
41
+
42
+ if Settings.config[:sound_digest] == digest && File.exist?("#{context}/app/drakkon/sound_index.rb")
43
+ LogBot.info('Sounds Index', 'Nothing New')
44
+ return unless force
45
+ end
46
+
47
+ build_index
48
+
49
+ Settings.update(:sound_digest, digest)
50
+
51
+ File.write("#{context}/app/drakkon/sound_index.rb", result)
52
+ end
53
+
54
+ def self.build_index
55
+ check sounds_directory
56
+ end
57
+
58
+ def self.result
59
+ <<~RB
60
+ module Drakkon
61
+ module Sounds
62
+ def self.index
63
+ #{index.inspect}
64
+ end
65
+
66
+ def self.catalog
67
+ #{catalog.inspect}
68
+ end
69
+
70
+ end
71
+ end
72
+ RB
73
+ end
74
+
75
+ # Recursively Go through
76
+ def self.check(dir = nil)
77
+ LogBot.info('Sound Index', "Check: #{dir}")
78
+
79
+ # Collect Sounds
80
+ list = file_list
81
+
82
+ # Ignore Empties
83
+ return if list.empty?
84
+
85
+ # Do other things
86
+ Dir["#{dir}/*"].each do |file|
87
+ if File.directory?(file)
88
+ check(file)
89
+ next
90
+ end
91
+
92
+ process(file)
93
+ end
94
+
95
+ :done
96
+ end
97
+
98
+ def self.process(file = nil)
99
+ # Safety
100
+ return if file.nil?
101
+
102
+ full_name = file.gsub(sounds_directory, '')[1..].gsub(File.extname(file), '')
103
+
104
+ name = File.basename(file, File.extname(file))
105
+ path = file.gsub(sounds_directory, '')[1..]
106
+ index[full_name] = path
107
+
108
+ details = { path: full_name }
109
+ tag = WahWah.open(file)
110
+ details[:duration_s] = tag.duration
111
+ details[:duration_tick] = tag.duration * 60
112
+
113
+ # Catalog
114
+ catalog_list = path.split('/')[0..-2]
115
+ catalog_location = []
116
+ catalog_list.each do |idx|
117
+ catalog_location.push idx
118
+ catalog.dig(*catalog_location)
119
+ end
120
+ catalog.dig(*catalog_list)[name] = details
121
+ end
122
+ # =========================================================
123
+ end
124
+ # =========================================================
125
+ end
126
+ end
@@ -0,0 +1,38 @@
1
+ module Drakkon
2
+ module Utils
3
+ # General Entry Point For Images Subcommand
4
+ module CLI
5
+ def self.run!(args = [])
6
+ args ||= []
7
+ cmd = if args.empty?
8
+ nil
9
+ else
10
+ args.shift.to_sym
11
+ end
12
+ start(cmd, args)
13
+ end
14
+
15
+ def self.start(cmd, args)
16
+ case cmd
17
+ when :normalize then Utils::DowncaseNormalize.run!(args)
18
+ else
19
+ start(menu, args)
20
+ end
21
+ end
22
+
23
+ def self.menu
24
+ prompt.select('Utilties:', filter: true, per_page: 20) do |menu|
25
+ menu.choice name: 'Rename Files - Normalize [normalize]', value: :normalize
26
+ end
27
+ rescue TTY::Reader::InputInterrupt
28
+ exit 0
29
+ end
30
+
31
+ def self.prompt
32
+ TTY::Prompt.new(active_color: :cyan, interrupt: :exit)
33
+ end
34
+ # =========================================================
35
+ end
36
+ # =========================================================
37
+ end
38
+ end
@@ -0,0 +1,75 @@
1
+ module Drakkon
2
+ module Utils
3
+ # This downcases all the things
4
+ module DowncaseNormalize
5
+ def self.run!(_args = nil)
6
+ puts <<~HELP
7
+ Usage: Run in the directory you wish to rename files
8
+ - Downcase
9
+ - Normalize
10
+ - To Underscores:
11
+ - Space
12
+ - Perentheses
13
+ - Dash
14
+ - Remove Double Underscores
15
+ - Remove Commas
16
+ - Delete Final Chars
17
+ - If Underscore
18
+ Current Directory;
19
+ #{Dir.pwd.pastel(:yellow)}
20
+
21
+ Files:
22
+ HELP
23
+
24
+ files.each do |img|
25
+ img_s = img.gsub("#{Dir.pwd}/", '').pastel(:yellow)
26
+ puts " - #{img_s}"
27
+ end
28
+ puts
29
+
30
+ exit unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)} Rename!? #{'(Destructive)'.pastel(:red)}"
31
+
32
+ start
33
+ end
34
+
35
+ def self.start
36
+ files.each do |file|
37
+ process(file)
38
+ end
39
+ end
40
+
41
+ # Image file name normalization. Downcase and replace spaces with underscore, commas, and double underscores
42
+ def self.process(file)
43
+ new_name = File.basename(file).downcase.gsub(' ', '_').gsub('(', '_').gsub(')', '_').gsub('-', '_').gsub(',', '_').gsub('__', '_').gsub(
44
+ '__', '_'
45
+ )
46
+ path = File.dirname(file)
47
+
48
+ # Remove Final Underscore last char of basename is an underscore
49
+ ext = File.extname(new_name)
50
+ basename = File.basename(new_name, ext)
51
+ if basename[-1] == '_' && basename.length > 1
52
+ new_name = basename[0..-2]
53
+ new_name += ext
54
+ end
55
+
56
+ # Skip if the same
57
+ return if new_name == File.basename(file)
58
+
59
+ LogBot.info('Rename Files Normalize', "Old: #{File.basename(file)}, New: #{new_name}")
60
+ FileUtils.mv(file, "#{path}/#{new_name}")
61
+ end
62
+
63
+ # Select all local dir files
64
+ def self.files
65
+ Dir["#{Dir.pwd}/*"]
66
+ end
67
+
68
+ def self.prompt
69
+ TTY::Prompt.new(active_color: :cyan, interrupt: :exit)
70
+ end
71
+ # =========================================================
72
+ end
73
+ # =========================================================
74
+ end
75
+ end
@@ -37,11 +37,25 @@ module Drakkon
37
37
  exit(1)
38
38
  end
39
39
 
40
+ # rubocop:disable Metrics/BlockLength
40
41
  Dir.mktmpdir('drakkon-sauce-') do |tmp|
41
42
  # full_path = "#{Dir.pwd}/#{zip}"
42
43
 
43
- # Execut Unzip / Better Way to do this?
44
- system("unzip -q -d #{tmp} #{zip}")
44
+ # Unzip install file
45
+ Zip::File.open(zip) do |zip_file|
46
+ zip_file.each do |entry|
47
+ path = File.join(tmp, entry.name)
48
+ FileUtils.mkdir_p(File.dirname(path))
49
+
50
+ next if File.exist?(path)
51
+
52
+ # Extract
53
+ zip_file.extract(entry, path)
54
+
55
+ # Preserve Permissions
56
+ FileUtils.chmod(entry.unix_perms, path)
57
+ end
58
+ end
45
59
 
46
60
  # Find Dir
47
61
  dr_dir = Dir["#{tmp}/*"].first
@@ -78,6 +92,7 @@ module Drakkon
78
92
  # Finish
79
93
  LogBot.info('Version', "#{dr_version} Installed!")
80
94
  end
95
+ # rubocop:enable Metrics/BlockLength
81
96
  end
82
97
 
83
98
  def self.prompt
@@ -1,3 +1,3 @@
1
1
  module Drakkon
2
- VERSION = '0.0.8'.freeze
2
+ VERSION = '0.0.10'.freeze
3
3
  end
@@ -0,0 +1,14 @@
1
+ module Drakkon
2
+ # Run Command for CLI
3
+ module Run
4
+ # Runnable Terminal Commands
5
+ module Commands
6
+ def self.cmd_utils(_args)
7
+ Utils::Index.run!(force: true, dir: Run.context)
8
+ end
9
+
10
+ # ========================================================================
11
+ end
12
+ # ==========================================================================
13
+ end
14
+ end
@@ -1,6 +1,8 @@
1
1
  module Drakkon
2
2
  # Run Command for CLI
3
3
  module Run
4
+ extend PlatformCompat
5
+
4
6
  def self.index
5
7
  @index ||= build_index
6
8
  @index
@@ -18,13 +20,14 @@ module Drakkon
18
20
 
19
21
  # Exec skips the weird shell stuff
20
22
  def self.run_cmd
21
- "PATH=#{version_dir}:$PATH exec dragonruby #{@context}"
23
+ ['./dragonruby', @context, *args]
22
24
  # "PATH=#{version_dir}:$PATH exec dragonruby #{@context} > #{log_file}"
23
25
  end
24
26
 
25
- def self.log_file
26
- "#{Hub.dir}/log.txt"
27
- end
27
+ # No longer used
28
+ # def self.log_file
29
+ # "#{Hub.dir}/log.txt"
30
+ # end
28
31
 
29
32
  def self.dragonruby(value = nil)
30
33
  @dragonruby ||= value
@@ -54,6 +57,10 @@ module Drakkon
54
57
  args.include?('fonts')
55
58
  end
56
59
 
60
+ def self.force_sounds?
61
+ args.include?('sounds')
62
+ end
63
+
57
64
  def self.prompt
58
65
  TTY::Prompt.new(active_color: :cyan, interrupt: :exit)
59
66
  end
@@ -15,7 +15,7 @@ module TTY
15
15
  attr_accessor :line, :breaker
16
16
 
17
17
  def read_line(prompt = '', value: '', echo: true, raw: true, nonblock: false)
18
- # Greenhat Shim:: Store Line
18
+ # Shim:: Store Line
19
19
  self.breaker = false
20
20
  self.line = Line.new(value, prompt: prompt)
21
21
  screen_width = TTY::Screen.width
@@ -27,17 +27,17 @@ module TTY
27
27
  (code = codes[0])
28
28
  char = codes.pack('U*')
29
29
 
30
- # GreenHat Shim / Back Tab Down Submodule
30
+ # Shim / Back Tab Down Submodule
31
31
  if [:back_tab, :ctrl_c].include? console.keys[char]
32
32
  clear_display(line, screen_width)
33
33
  trigger_key_event(char, line: line.to_s)
34
34
  break
35
35
  end
36
36
 
37
- # Greenhat Shim
37
+ # Shim
38
38
  if EXIT_KEYS.include?(console.keys[char])
39
39
  trigger_key_event(char, line: line.to_s)
40
- raise Interrupt
40
+ raise TTY::Reader::InputInterrupt
41
41
  end
42
42
 
43
43
  clear_display(line, screen_width) if raw && echo
@@ -92,7 +92,7 @@ module TTY
92
92
  end
93
93
  end
94
94
 
95
- # Greenhat Shim do things
95
+ # Shim do things
96
96
  next unless [CARRIAGE_RETURN, NEWLINE].include?(code) || breaker
97
97
 
98
98
  buffer = ''
@@ -103,7 +103,11 @@ module TTY
103
103
  add_to_history(line.text.rstrip) if track_history? && echo
104
104
 
105
105
  line.text
106
+ # ===================================
107
+ rescue
108
+ puts 'rescue'
106
109
  end
110
+ # ===================================
107
111
  end
108
112
  end
109
113
 
data/lib/drakkon/run.rb CHANGED
@@ -4,6 +4,8 @@ module Drakkon
4
4
  # General Run
5
5
  def self.go!(raw)
6
6
  Settings.ready?
7
+ Settings.check_version!
8
+
7
9
  args(raw)
8
10
 
9
11
  # Save Current Directory before changing to Version Directory
@@ -63,11 +65,12 @@ module Drakkon
63
65
  Images::Index.run!(force: force_images?) if Settings.image_index?
64
66
  Manifest.run!(force: force_manifest?) if Settings.manifest?
65
67
  Fonts::Index.run!(force: force_fonts?) if Settings.font_index?
68
+ Sounds::Index.run!(force: force_sounds?) if Settings.sound_index?
66
69
  Gems::Bundle.build!(args, @context)
67
70
  end
68
71
 
69
72
  def self.runtime
70
- @dragonruby = IO.popen(run_cmd)
73
+ @dragonruby = IO.popen(run_env, run_cmd)
71
74
  end
72
75
 
73
76
  def self.restart
@@ -14,7 +14,10 @@ module Drakkon
14
14
 
15
15
  template[:files].each do |files|
16
16
  file_src = "#{template[:path]}/#{files[:source]}"
17
- raise 'Missing File!' unless File.exist?(file_src)
17
+ unless File.exist?(file_src)
18
+ LogBot.fatal('Skeleton', "Missing File! File: #{file_src}")
19
+ exit 0
20
+ end
18
21
 
19
22
  src = File.read(file_src)
20
23
  result = process_variables(src, variables)
data/lib/drakkon/web.rb CHANGED
@@ -3,26 +3,35 @@ module Drakkon
3
3
  module Web
4
4
  # Free running
5
5
  def self.run!(_args = [])
6
- # Web::Runny.run!
7
-
8
6
  # Save Current Directory before changing to Version Directory
9
7
  @context = Dir.pwd
10
8
 
11
9
  # Yes... Run.run!
12
10
  Dir.chdir(Run.version_dir) do
13
- system run_cmd
11
+ runtime
12
+ output
14
13
  end
14
+ rescue SystemExit, Interrupt
15
+ LogBot.info('Web', 'Exiting')
16
+ exit 0
15
17
  end
16
18
 
17
- def self.runtime
18
- @dragonruby = IO.popen(run_cmd)
19
+ # Send output to console
20
+ def self.output
21
+ loop do
22
+ next unless @dragonruby.ready?
23
+
24
+ puts @dragonruby.readline
25
+ end
26
+ end
19
27
 
20
- # @dragonruby = Process.spawn run_cmd
28
+ def self.runtime
29
+ @dragonruby = IO.popen(Run.run_env, run_cmd)
21
30
  end
22
31
 
23
32
  # Exec skips the weird shell stuff
24
33
  def self.run_cmd
25
- "PATH=#{Run.version_dir}:$PATH exec dragonruby-httpd #{@context} 8000"
34
+ ['./dragonruby-httpd', @context, '8000']
26
35
  end
27
36
 
28
37
  # ==========================================================================
data/lib/drakkon.rb CHANGED
@@ -28,8 +28,14 @@ require 'filewatcher'
28
28
  # Dev
29
29
  require 'pry'
30
30
 
31
- # Web
32
- require 'sinatra/base'
31
+ # Install handling
32
+ require 'zip'
33
+
34
+ # Audio
35
+ require 'wahwah'
36
+
37
+ # Require this first
38
+ require_relative 'drakkon/lib/platform_compat'
33
39
 
34
40
  # Load All Sub Directories / Order Matters
35
41
  require_all "#{File.dirname(__FILE__)}/drakkon"