Last active
August 29, 2015 14:06
-
-
Save Phrogz/f7603a5d36a28e8e99bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Returns a hash mapping image paths to arrays of the assets referencing them | |
def image_usage | |
{}.tap do |usage| | |
asset_types = app.metadata.by_name.values + @class_by_ref.values | |
image_properties_by_type = asset_types.flat_map do |type| | |
type.properties.values | |
.select{ |property| property.type=='Image' || property.type == 'Texture' } | |
.map{ |property| [type,property] } | |
end.group_by(&:first).tap{ |x| x.each{ |t,a| a.map!(&:last) } } | |
assets.each do |asset| | |
if properties = image_properties_by_type[asset.class] | |
properties.each do |property| | |
asset[property.name].values.compact.each do |value| | |
value = value['sourcepath'] if property.type=='Image' | |
usage[value] ||= [] | |
usage[value] << asset | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment