Skip to content

Commit 86f0180

Browse files
committed
Transform: improve transform interpolation.
For #19.
1 parent ab225ab commit 86f0180

File tree

2 files changed

+47
-37
lines changed

2 files changed

+47
-37
lines changed

src/Transform.moon

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Math = require 'a-mo.Math'
33
bit = require 'bit'
44

55
class Transform
6-
@version: 0x010100
6+
@version: 0x010200
77
@version_major: bit.rshift( @version, 16 )
88
@version_minor: bit.band( bit.rshift( @version, 8 ), 0xFF )
99
@version_patch: bit.band( @version, 0xFF )
@@ -65,50 +65,60 @@ class Transform
6565
@priorValues = { k, v for k, v in pairs line.properties }
6666
-- Fill out all of the possible tag defaults for tags that aren't
6767
-- defined by styles. This works great for everything except \clip,
68-
-- which defaults to 0,0,width,height
69-
for tagName, tag in ipairs tags.allTags
70-
if tag.transformable and not tag.style
71-
@priorValues[tagName] = 0
72-
73-
@priorValues.rectClip = { 0, 0, line.parentCollection.meta.PlayResX, line.parentCollection.meta.PlayResY }
74-
@priorValues.rectiClip = { 0, 0, line.parentCollection.meta.PlayResX, line.parentCollection.meta.PlayResY }
75-
76-
unless @index
77-
log.windowError "An error has occurred with transform\ninterpolation in line #{line.humanizedNumber}."
68+
-- which defaults to 0, 0, width, height
69+
for tag in *tags.transformTags
70+
unless tag.style
71+
@priorValues[tag] = 0
7872

79-
major = math.floor @index
73+
@priorValues[tags.allTags.rectClip] = { 0, 0, line.parentCollection.meta.PlayResX, line.parentCollection.meta.PlayResY }
74+
@priorValues[tags.allTags.rectiClip] = { 0, 0, line.parentCollection.meta.PlayResX, line.parentCollection.meta.PlayResY }
8075

81-
line\runCallbackOnOverrides ( line, tagBlock, number ) ->
82-
for tagName, oldVal in pairs @effectTags
83-
tag = tags.allTags[tagName]
84-
tagBlock\gsub tag.pattern, ( value ) ->
85-
@priorValues[tagName] = tag\convert value
76+
count = math.floor @index
77+
i = 1
78+
text\gsub "({.-})", ( tagBlock ) ->
79+
if i == count
80+
tagBlock = tagBlock\gsub "(.+)#{placeholder}", "%1"
8681

82+
for tag, _ in pairs @effectTags
8783
if tag.affectedBy
88-
for otherTag in *tag.affectedBy
89-
newTag = tags.allTags[otherTag]
90-
tagBlock\gsub newTag.pattern, ( value ) ->
91-
@priorValues[tagName] = newTag\convert value,
92-
major
84+
newTagBlock = tagBlock\gsub ".-"..tag.pattern, ( value ) ->
85+
@priorValues[tag] = tag\convert value
86+
return ""
87+
for tagName in *tag.affectedBy
88+
newTag = tags.allTags[tagName]
89+
newTagBlock = newTagBlock\gsub ".-"..newTag.pattern, ( value ) ->
90+
@priorValues[tag] = newTag\convert value
91+
return ""
92+
else
93+
tagBlock\gsub tag.pattern, ( value ) ->
94+
@priorValues[tag] = tag\convert value
95+
96+
i += 1
97+
return nil,
98+
count
99+
100+
interpolate: ( line, text, index, time ) =>
101+
log.dump time
102+
placeholder = line.tPlaceholder index
103+
@collectPriorState line, text, placeholder
93104

94-
interpolate: ( time ) =>
95105
linearProgress = (time - @startTime)/(@endTime - @startTime)
96-
if linearProgress <= 0
97-
return ""
98-
elseif linearProgress >= 1
99-
return @effect
100-
101106
progress = math.pow linearProgress, @accel
102107

103-
for tagName, endValue in pairs @effectTags
104-
tag = tags.allTags[tagName]
105-
startValue = @priorValues[tagName]
106-
interpValue = tag\interpolate startValue, endValue, progress
107-
-- This is an atrocity against god and man
108-
@effect = @effect\gsub tag.pattern, ->
109-
return tag\format Math.round interpValue, 2
108+
text = text\gsub placeholder, ->
109+
resultString = {}
110+
for tag, endValues in pairs @effectTags
111+
if linearProgress <= 0
112+
return tag\format @priorValues[tag]
113+
elseif linearProgress >= 1
114+
return tag\format endValues.last
110115

111-
return @effect
116+
value = @priorValues[tag]
117+
for endValue in *endValues
118+
value = tag\interpolate value, endValue, progress
112119

120+
table.insert resultString, tag\format value
113121

122+
return table.concat resultString
114123

124+
return text

versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"src/ShakeShapeHandler.moon": "0x010000",
1111
"src/Statistics.moon": "0x000101",
1212
"src/Tags.moon": "0x010300",
13-
"src/Transform.moon": "0x010100",
13+
"src/Transform.moon": "0x010200",
1414
"src/TrimHandler.moon": "0x010001",
1515
"Aegisub-Motion.moon": "0x010000"
1616
}

0 commit comments

Comments
 (0)