Skip to content

Commit 0ff37d1

Browse files
committed
Aegisub-Motion: try to interpolate position from \move.
If there is no \pos override in the line, check for \move. This was a horrible idea and someone should have convinced me not to do it.
1 parent ac95aaf commit 0ff37d1

3 files changed

Lines changed: 35 additions & 8 deletions

File tree

Aegisub-Motion.moon

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,15 @@ prepareLines = ( lineCollection ) ->
267267
styles = @styles
268268
lineStyle = line.styleRef
269269
unless line\extraMetrics lineStyle
270-
line\ensureLeadingOverrideBlockExists
271-
272-
-- Note that we are repeatedly shadowing @, so in this function it
273-
-- refers to the line. This is interestingly the opposite of how
274-
-- fat arrow functions work in coffeescript.
275-
line\runCallbackOnFirstOverride ( tagBlock ) =>
276-
return tagBlock\gsub "{", ("{\\pos(%g,%g)")\format @xPosition, @yPosition
270+
-- fuck
271+
unless line\moveToPosition math.floor(0.5*(aegisub.ms_from_frame(lineCollection.startFrame + options.main.startFrame - 1) + aegisub.ms_from_frame(lineCollection.startFrame + options.main.startFrame))) - line.start_time
272+
line\ensureLeadingOverrideBlockExists
273+
274+
-- Note that we are repeatedly shadowing @, so in this function it
275+
-- refers to the line. This is interestingly the opposite of how
276+
-- fat arrow functions work in coffeescript.
277+
line\runCallbackOnFirstOverride ( tagBlock ) =>
278+
return tagBlock\gsub "{", ("{\\pos(%g,%g)")\format @xPosition, @yPosition
277279

278280
-- Add any tags we need that are missing from the line.
279281
line\runCallbackOnFirstOverride ( tagBlock ) =>

src/Line.moon

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,25 @@ class Line
7171

7272
return true
7373

74+
-- this should not have been added and the name is probably misleading.
75+
moveToPosition: ( time ) =>
76+
moveTag = tags.allTags.move
77+
posTag = tags.allTags.pos
78+
found = false
79+
@runCallbackOnOverrides ( tagBlock ) =>
80+
tagBlock = tagBlock\gsub moveTag.pattern, ( value ) ->
81+
found = true
82+
move = moveTag\convert value
83+
progress = (time - move.start)/(move.end - move.start)
84+
newPos = moveTag\interpolate {move.x1, move.y1}, {move.x2, move.y2}, progress
85+
@xPosition = newPos[1]
86+
@yPosition = newPos[2]
87+
return posTag\format newPos
88+
89+
return tagBlock
90+
-- shitty hacks
91+
return found
92+
7493
generateTagIndex: ( major, minor ) ->
7594
return tonumber tostring( major ) .. "." .. tostring minor
7695

src/Tags.moon

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ interpolateMulti = ( before, after, progress ) =>
4848

4949
return result
5050

51+
interpolatePosition = ( before, after, progress ) =>
52+
return {
53+
interpolateNumber @, before[1], after[1], progress
54+
interpolateNumber @, before[2], after[2], progress
55+
}
56+
5157
interpolateColor = ( before, after, progress ) =>
5258
return interpolateMulti { fieldnames: { 'b', 'g', 'r' } }, before, after, progress
5359

@@ -126,7 +132,7 @@ return {
126132
vectiClip:{ fieldnames: { "scale", "shape" }, output: "multi", pattern: "\\iclip%((%d+,)?([^,]-)%)" , tag: "\\iclip", format: formatMulti, convert: convertMultiValue }
127133
rectClip: { fieldnames: { "xLeft", "yTop", "xRight", "yBottom" }, output: "multi", pattern: "\\clip%(([%-%d%.]+,[%-%d%.]+,[%-%d%.]+,[%-%d%.]+)%)" , transformable: true, tag: "\\clip" , format: formatMulti, convert: convertMultiValue, interpolate: interpolateMulti }
128134
rectiClip:{ fieldnames: { "xLeft", "yTop", "xRight", "yBottom" }, output: "multi", pattern: "\\iclip%(([%-%d%.]+,[%-%d%.]+,[%-%d%.]+,[%-%d%.]+)%)", transformable: true, tag: "\\iclip", format: formatMulti, convert: convertMultiValue, interpolate: interpolateMulti }
129-
move: { fieldnames: { "x1", "y1", "x2", "y2", "start", "end" }, output: "multi", pattern: "\\move%(([%.%d%-]+,[%.%d%-]+,[%.%d%-]+,[%.%d%-]+,[%d%-]+,[%d%-]+)%)", tag: "\\move" , format: formatMulti, convert: convertMultiValue }
135+
move: { fieldnames: { "x1", "y1", "x2", "y2", "start", "end" }, output: "multi", pattern: "\\move%(([%.%d%-]+,[%.%d%-]+,[%.%d%-]+,[%.%d%-]+,[%d%-]+,[%d%-]+)%)", tag: "\\move" , format: formatMulti, convert: convertMultiValue, interpolate: interpolatePosition }
130136
fade: { fieldnames: { "a1", "a2", "a3", "a4", "in", "mid", "out" }, output: "multi", pattern: "\\fade%((%d+,%d+,%d+,%d+,[%d%-]+,[%d%-]+,[%d%-]+)%)" , tag: "\\fade" , format: formatMulti, convert: convertMultiValue }
131137
}
132138
}

0 commit comments

Comments
 (0)