|
| 1 | +---------------------------------------------------------------------- |
| 2 | +-- Creates a new layer that looks like a glass floor flattening the |
| 3 | +-- selected layers in the timeline. |
| 4 | +---------------------------------------------------------------------- |
| 5 | + |
| 6 | +do |
| 7 | + local spr = app.activeSprite |
| 8 | + if not spr then return app.alert "There is no active sprite" end |
| 9 | + |
| 10 | + app.transaction( |
| 11 | + function() |
| 12 | + local bounds = Rectangle() |
| 13 | + local layers = app.range.layers |
| 14 | + local newLayer = spr:newLayer() |
| 15 | + newLayer.name = "Glass Floor" |
| 16 | + newLayer.opacity = 128 |
| 17 | + |
| 18 | + for _,frame in ipairs(spr.frames) do |
| 19 | + for _,layer in ipairs(layers) do |
| 20 | + local img = Image(spr.spec) |
| 21 | + for _,l in ipairs(layers) do |
| 22 | + local layerCel = l:cel(frame) |
| 23 | + if layerCel then |
| 24 | + img:drawImage(layerCel.image, layerCel.position) |
| 25 | + bounds = bounds:union(layerCel.bounds) |
| 26 | + end |
| 27 | + end |
| 28 | + |
| 29 | + spr:newCel(newLayer, frame, img, Point(0, 0)) |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + local oldFrame = app.activeFrame |
| 34 | + app.activeLayer = newLayer |
| 35 | + for _,cel in ipairs(newLayer.cels) do |
| 36 | + app.activeFrame = cel.frame |
| 37 | + app.command.Flip{ target="mask", orientation="vertical" } |
| 38 | + cel.position = Point(cel.position.x, |
| 39 | + cel.position.y + 2*(bounds.y + bounds.height - spr.height/2)) |
| 40 | + end |
| 41 | + app.activeFrame = oldFrame |
| 42 | + end) |
| 43 | +end |
0 commit comments