2021-06-21 21:35:28 +00:00
|
|
|
import Command from './command'
|
|
|
|
import history from '../history'
|
|
|
|
import { DirectionSnapshot } from 'state/sessions/direction-session'
|
|
|
|
import { Data, LineShape, RayShape } from 'types'
|
|
|
|
import { getPage } from 'utils/utils'
|
2021-05-15 15:20:21 +00:00
|
|
|
|
2021-05-19 09:35:00 +00:00
|
|
|
export default function directCommand(
|
2021-05-15 15:20:21 +00:00
|
|
|
data: Data,
|
|
|
|
before: DirectionSnapshot,
|
|
|
|
after: DirectionSnapshot
|
2021-06-21 21:35:28 +00:00
|
|
|
): void {
|
2021-05-15 15:20:21 +00:00
|
|
|
history.execute(
|
|
|
|
data,
|
|
|
|
new Command({
|
2021-06-21 21:35:28 +00:00
|
|
|
name: 'set_direction',
|
|
|
|
category: 'canvas',
|
2021-05-15 15:20:21 +00:00
|
|
|
do(data) {
|
2021-05-22 15:45:24 +00:00
|
|
|
const { shapes } = getPage(data)
|
2021-05-15 15:20:21 +00:00
|
|
|
|
2021-06-21 21:35:28 +00:00
|
|
|
for (const { id, direction } of after.shapes) {
|
2021-05-15 15:20:21 +00:00
|
|
|
const shape = shapes[id] as RayShape | LineShape
|
|
|
|
|
|
|
|
shape.direction = direction
|
|
|
|
}
|
|
|
|
},
|
|
|
|
undo(data) {
|
2021-05-22 15:45:24 +00:00
|
|
|
const { shapes } = getPage(data, before.currentPageId)
|
2021-05-15 15:20:21 +00:00
|
|
|
|
2021-06-21 21:35:28 +00:00
|
|
|
for (const { id, direction } of after.shapes) {
|
2021-05-15 15:20:21 +00:00
|
|
|
const shape = shapes[id] as RayShape | LineShape
|
|
|
|
|
|
|
|
shape.direction = direction
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|