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')
|
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
|
$ mikunyan-json bundle.unity3d > bundle.json
|
||||||
|
|
||||||
Available options:
|
Available options:
|
||||||
|
|
||||||
- `--as-asset` (`-a`): interpret input file as not AssetBudnle but Asset
|
- `--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
|
## Dependencies
|
||||||
|
|
||||||
|
|||||||
+19
-8
@@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
require 'mikunyan'
|
require 'mikunyan'
|
||||||
require 'json'
|
|
||||||
require 'base64'
|
require 'base64'
|
||||||
|
|
||||||
def obj64(obj)
|
def obj64(obj)
|
||||||
@@ -19,7 +18,7 @@ def obj64(obj)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
opts = {:as_asset => false, :pretty => false}
|
opts = {:as_asset => false, :pretty => false, :yaml => false}
|
||||||
arg = nil
|
arg = nil
|
||||||
i = 0
|
i = 0
|
||||||
while i < ARGV.count
|
while i < ARGV.count
|
||||||
@@ -29,9 +28,10 @@ while i < ARGV.count
|
|||||||
opts[:as_asset] = true
|
opts[:as_asset] = true
|
||||||
when '--pretty', '-p'
|
when '--pretty', '-p'
|
||||||
opts[:pretty] = true
|
opts[:pretty] = true
|
||||||
|
when '--yaml', '-y'
|
||||||
|
opts[:yaml] = true
|
||||||
else
|
else
|
||||||
warn("Unknown option: #{ARGV[i]}")
|
warn("Unknown option: #{ARGV[i]}")
|
||||||
exit(1)
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
arg = ARGV[i] unless arg
|
arg = ARGV[i] unless arg
|
||||||
@@ -39,6 +39,10 @@ while i < ARGV.count
|
|||||||
i += 1
|
i += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if option[:pretty] && option[:yaml]
|
||||||
|
warn("Option --pretty is ignored if --yaml is specified.")
|
||||||
|
end
|
||||||
|
|
||||||
unless File.file?(arg)
|
unless File.file?(arg)
|
||||||
warn("File not found: #{arg}")
|
warn("File not found: #{arg}")
|
||||||
exit(1)
|
exit(1)
|
||||||
@@ -51,7 +55,7 @@ if opts[:as_asset]
|
|||||||
objs = []
|
objs = []
|
||||||
asset.path_ids.each do |e|
|
asset.path_ids.each do |e|
|
||||||
obj = asset.parse_object_simple(e)
|
obj = asset.parse_object_simple(e)
|
||||||
objs << obj64(obj) if obj
|
objs << obj
|
||||||
end
|
end
|
||||||
assets[asset.name] = objs
|
assets[asset.name] = objs
|
||||||
else
|
else
|
||||||
@@ -60,14 +64,21 @@ else
|
|||||||
objs = []
|
objs = []
|
||||||
asset.path_ids.each do |e|
|
asset.path_ids.each do |e|
|
||||||
obj = asset.parse_object_simple(e)
|
obj = asset.parse_object_simple(e)
|
||||||
objs << obj64(obj) if obj
|
objs << obj
|
||||||
end
|
end
|
||||||
assets[asset.name] = objs
|
assets[asset.name] = objs
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if opts[:pretty]
|
if opts[:yaml]
|
||||||
puts JSON.pretty_generate(assets)
|
require 'yaml'
|
||||||
|
puts YAML.dump(assets)
|
||||||
else
|
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user