Skip to content

Instantly share code, notes, and snippets.

@Phrogz
Last active August 29, 2015 14:06
Show Gist options
  • Save Phrogz/f7603a5d36a28e8e99bc to your computer and use it in GitHub Desktop.
Save Phrogz/f7603a5d36a28e8e99bc to your computer and use it in GitHub Desktop.
# 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