Add YAML mode to mikunyan-json
This commit is contained in:
@@ -118,16 +118,17 @@ img = Mikunyan::ImageDecoder.decode_object(obj)
|
||||
img.save('mikunyan.png')
|
||||
```
|
||||
|
||||
### Json Outputer
|
||||
### Json / YAML Outputer
|
||||
|
||||
`mikunyan-json` is the executable command for converting unity3d to json.
|
||||
`mikunyan-json` is an executable command for converting unity3d to json.
|
||||
|
||||
$ mikunyan-json bundle.unity3d > bundle.json
|
||||
|
||||
Available options:
|
||||
|
||||
- `--as-asset` (`-a`): interpret input file as not AssetBudnle but Asset
|
||||
- `--pretty` (`-p`): prettify output json
|
||||
- `--pretty` (`-p`): prettify output json (`mikunyan-json` only)
|
||||
- `--yaml` (`-y`): YAML mode
|
||||
|
||||
## Dependencies
|
||||
|
||||
|
||||
+19
-8
@@ -1,6 +1,5 @@
|
||||
#!/usr/bin/env ruby
|
||||
require 'mikunyan'
|
||||
require 'json'
|
||||
require 'base64'
|
||||
|
||||
def obj64(obj)
|
||||
@@ -19,7 +18,7 @@ def obj64(obj)
|
||||
end
|
||||
end
|
||||
|
||||
opts = {:as_asset => false, :pretty => false}
|
||||
opts = {:as_asset => false, :pretty => false, :yaml => false}
|
||||
arg = nil
|
||||
i = 0
|
||||
while i < ARGV.count
|
||||
@@ -29,9 +28,10 @@ while i < ARGV.count
|
||||
opts[:as_asset] = true
|
||||
when '--pretty', '-p'
|
||||
opts[:pretty] = true
|
||||
when '--yaml', '-y'
|
||||
opts[:yaml] = true
|
||||
else
|
||||
warn("Unknown option: #{ARGV[i]}")
|
||||
exit(1)
|
||||
end
|
||||
else
|
||||
arg = ARGV[i] unless arg
|
||||
@@ -39,6 +39,10 @@ while i < ARGV.count
|
||||
i += 1
|
||||
end
|
||||
|
||||
if option[:pretty] && option[:yaml]
|
||||
warn("Option --pretty is ignored if --yaml is specified.")
|
||||
end
|
||||
|
||||
unless File.file?(arg)
|
||||
warn("File not found: #{arg}")
|
||||
exit(1)
|
||||
@@ -51,7 +55,7 @@ if opts[:as_asset]
|
||||
objs = []
|
||||
asset.path_ids.each do |e|
|
||||
obj = asset.parse_object_simple(e)
|
||||
objs << obj64(obj) if obj
|
||||
objs << obj
|
||||
end
|
||||
assets[asset.name] = objs
|
||||
else
|
||||
@@ -60,14 +64,21 @@ else
|
||||
objs = []
|
||||
asset.path_ids.each do |e|
|
||||
obj = asset.parse_object_simple(e)
|
||||
objs << obj64(obj) if obj
|
||||
objs << obj
|
||||
end
|
||||
assets[asset.name] = objs
|
||||
end
|
||||
end
|
||||
|
||||
if opts[:pretty]
|
||||
puts JSON.pretty_generate(assets)
|
||||
if opts[:yaml]
|
||||
require 'yaml'
|
||||
puts YAML.dump(assets)
|
||||
else
|
||||
puts JSON.generate(assets)
|
||||
require 'json'
|
||||
assets = assets.map{|k, v| [k, obj64(v)]}.to_h
|
||||
if opts[:pretty]
|
||||
puts JSON.pretty_generate(assets)
|
||||
else
|
||||
puts JSON.generate(assets)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user