2019-08-03 15:03:33 +02:00
|
|
|
import { name, version } from '../package.json'
|
2018-12-22 14:16:53 +01:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: name,
|
|
|
|
version: version,
|
|
|
|
hooks: {
|
2021-11-21 17:38:05 +01:00
|
|
|
preRender: svg => svg.attributes.set('freesewing:plugin-flip', version)
|
2018-12-22 14:16:53 +01:00
|
|
|
},
|
|
|
|
macros: {
|
2021-01-31 09:22:15 +01:00
|
|
|
flip: function () {
|
2019-08-03 15:03:33 +02:00
|
|
|
let flipped = null
|
|
|
|
let ops = ['from', 'to', 'cp1', 'cp2']
|
2019-07-06 13:57:38 +02:00
|
|
|
for (let id in this.points) {
|
|
|
|
// Keep track of the amount of flips (needed to allow flipping twice, but also avoid double flips in paths below)
|
|
|
|
if (flipped === null) {
|
2019-08-03 15:03:33 +02:00
|
|
|
flipped = this.points[id].attributes.get('flipped')
|
|
|
|
if (flipped === false) flipped = 1
|
|
|
|
else flipped += 1
|
2019-07-06 13:57:38 +02:00
|
|
|
}
|
2019-08-03 15:03:33 +02:00
|
|
|
this.points[id].x = this.points[id].x * -1
|
|
|
|
this.points[id].attributes.set('flipped', flipped)
|
2019-07-06 13:57:38 +02:00
|
|
|
}
|
|
|
|
for (let id of Object.keys(this.paths)) {
|
|
|
|
for (let op in this.paths[id].ops) {
|
2018-12-22 14:16:53 +01:00
|
|
|
for (let type of ops) {
|
2019-08-03 15:03:33 +02:00
|
|
|
if (typeof this.paths[id].ops[op][type] !== 'undefined') {
|
2019-07-06 13:57:38 +02:00
|
|
|
// Path ops can use points not listed in part.points. We should only flip those here
|
|
|
|
// and not double flip the points flipped above
|
2019-08-03 15:03:33 +02:00
|
|
|
let wasFlipped = this.paths[id].ops[op][type].attributes.get('flipped')
|
|
|
|
if (wasFlipped !== false) wasFlipped = parseInt(wasFlipped)
|
2019-07-06 13:57:38 +02:00
|
|
|
if (wasFlipped !== flipped) {
|
2019-08-03 15:03:33 +02:00
|
|
|
this.paths[id].ops[op][type].x = this.paths[id].ops[op][type].x * -1
|
|
|
|
this.paths[id].ops[op][type].attributes.set('flipped', flipped)
|
2019-07-06 13:57:38 +02:00
|
|
|
}
|
|
|
|
}
|
2018-12-22 14:16:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-06 13:57:38 +02:00
|
|
|
for (let id of Object.keys(this.snippets)) {
|
|
|
|
// Snippets use points not listed in part.points. We should only flip those here
|
|
|
|
// and not double flip the points flipped above
|
2019-08-03 15:03:33 +02:00
|
|
|
let wasFlipped = this.snippets[id].anchor.attributes.get('flipped')
|
|
|
|
if (wasFlipped !== false) wasFlipped = parseInt(wasFlipped)
|
|
|
|
if (wasFlipped !== flipped) this.snippets[id].anchor.x = this.snippets[id].anchor.x * -1
|
2019-07-06 13:57:38 +02:00
|
|
|
}
|
2021-04-24 10:16:31 +02:00
|
|
|
},
|
|
|
|
},
|
2019-08-03 15:03:33 +02:00
|
|
|
}
|