Skip to content

Instantly share code, notes, and snippets.

@torque
Created January 7, 2015 06:48
Show Gist options
  • Save torque/194882dea13dd9f60c2f to your computer and use it in GitHub Desktop.
Save torque/194882dea13dd9f60c2f to your computer and use it in GitHub Desktop.
convertClipToFP = ( clip ) ->
-- only muck around with vector clips (convert scaling factor into floating point coordinates).
unless clip\match "[%-%d%.]+, *[%-%d%.]+"
-- Convert clip with scale into floating point coordinates.
clip = clip\gsub "%((%d*),?(.-)%)", ( scaleFactor, points ) ->
if scaleFactor ~= ""
scaleFactor = tonumber scaleFactor
points = points\gsub "([%.%d%-]+) ([%.%d%-]+)", ( x, y ) ->
x = Math.round tonumber( x )/(2^(scaleFactor - 1)), 2
y = Math.round tonumber( y )/(2^(scaleFactor - 1)), 2
("%g %g")\format x, y
return '(' .. points .. ')'
return clip
dongs = (sub,sel,act) ->
for index in *sel
with line = sub[index]
line.text = line.text\gsub "({.-})", (override) ->
return override\gsub "(\\i?clip)(%(.-%))", (tag, clip) ->
return tag .. convertClipToFP(clip)
sub[index] = line
aegisub.register_macro "megadongs", "megadongs", dongs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment