swf2ass-go/ass/tag/DrawTag.go
2023-11-26 20:34:44 +01:00

52 lines
1.3 KiB
Go

package tag
import (
"fmt"
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/ass/time"
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/settings"
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/types/math"
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/types/shapes"
)
type DrawTag struct {
BaseDrawingTag
Scale int
}
func NewDrawTag(shape shapes.Shape, scale int) *DrawTag {
return &DrawTag{
Scale: scale,
BaseDrawingTag: BaseDrawingTag(shape),
}
}
func (t *DrawTag) ApplyMatrixTransform(transform math.MatrixTransform, applyTranslation bool) DrawingTag {
return &DrawTag{
BaseDrawingTag: BaseDrawingTag(t.AsShape().ApplyMatrixTransform(transform, applyTranslation)),
Scale: t.Scale,
}
}
func (t *DrawTag) TransitionShape(event Event, shape shapes.Shape) PathTag {
if t.AsShape().Equals(shape) {
return t
}
return nil
}
func (t *DrawTag) Equals(tag Tag) bool {
if o, ok := tag.(*DrawTag); ok {
return t.AsShape().Equals(o.AsShape())
}
return false
}
func (t *DrawTag) Encode(event time.EventTime) string {
scaleMultiplier := 1 << (t.Scale - 1)
precision := settings.GlobalSettings.ASSDrawingPrecision
if t.Scale >= 5 {
precision = 0
}
return fmt.Sprintf("\\p%d}%s{\\p0", t.Scale, t.GetCommands(scaleMultiplier, precision))
}