-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Symmetrical Drawing Mode in the Map Editor (#19)
Co-authored-by: cpojer <[email protected]>
- Loading branch information
Showing
10 changed files
with
492 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Vector from '@deities/athena/map/Vector.tsx'; | ||
import { SizeVector } from '@deities/athena/MapData.tsx'; | ||
import { ComponentProps } from 'react'; | ||
import Cursor from '../Cursor.tsx'; | ||
import getSymmetricPositions from './lib/getSymmetricPositions.ts'; | ||
import { DrawingMode } from './Types.tsx'; | ||
|
||
export default function MapEditorMirrorCursors({ | ||
drawingMode, | ||
mapSize, | ||
origin: orign, | ||
...props | ||
}: { | ||
drawingMode: DrawingMode | undefined; | ||
mapSize: SizeVector; | ||
origin: Vector | null; | ||
} & Omit<ComponentProps<typeof Cursor>, 'position'>) { | ||
if (!orign || !drawingMode || drawingMode === 'regular') { | ||
return null; | ||
} | ||
|
||
const vectors = getSymmetricPositions(orign, drawingMode, mapSize); | ||
return vectors.size | ||
? [...vectors].map((vector) => ( | ||
<Cursor {...props} key={vector.toString()} position={vector} /> | ||
)) | ||
: null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
hera/editor/lib/__tests__/getSymmetricPositions.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import vec from '@deities/athena/map/vec.tsx'; | ||
import { SizeVector } from '@deities/athena/MapData.tsx'; | ||
import { expect, test } from 'vitest'; | ||
import getSymmetricPositions from '../getSymmetricPositions.ts'; | ||
|
||
test('`getSymmetricPositions` regular', () => { | ||
expect( | ||
getSymmetricPositions(vec(4, 4), 'regular', new SizeVector(10, 10)), | ||
).toMatchInlineSnapshot(`Set {}`); | ||
}); | ||
|
||
test('`getSymmetricPositions` horizontal', () => { | ||
expect(getSymmetricPositions(vec(4, 4), 'horizontal', new SizeVector(10, 10))) | ||
.toMatchInlineSnapshot(` | ||
Set { | ||
[ | ||
7, | ||
4, | ||
], | ||
} | ||
`); | ||
expect(getSymmetricPositions(vec(8, 8), 'horizontal', new SizeVector(10, 10))) | ||
.toMatchInlineSnapshot(` | ||
Set { | ||
[ | ||
3, | ||
8, | ||
], | ||
} | ||
`); | ||
}); | ||
|
||
test('`getSymmetricPositions` vertical', () => { | ||
expect(getSymmetricPositions(vec(4, 4), 'vertical', new SizeVector(10, 10))) | ||
.toMatchInlineSnapshot(` | ||
Set { | ||
[ | ||
4, | ||
7, | ||
], | ||
} | ||
`); | ||
expect(getSymmetricPositions(vec(8, 8), 'vertical', new SizeVector(10, 10))) | ||
.toMatchInlineSnapshot(` | ||
Set { | ||
[ | ||
8, | ||
3, | ||
], | ||
} | ||
`); | ||
}); | ||
|
||
test('`getSymmetricPositions` diagonal', () => { | ||
expect(getSymmetricPositions(vec(4, 4), 'diagonal', new SizeVector(10, 10))) | ||
.toMatchInlineSnapshot(` | ||
Set { | ||
[ | ||
7, | ||
7, | ||
], | ||
} | ||
`); | ||
expect(getSymmetricPositions(vec(8, 8), 'diagonal', new SizeVector(10, 10))) | ||
.toMatchInlineSnapshot(` | ||
Set { | ||
[ | ||
3, | ||
3, | ||
], | ||
} | ||
`); | ||
}); | ||
|
||
test('`getSymmetricPositions` horizontal-vertical', () => { | ||
expect( | ||
getSymmetricPositions( | ||
vec(4, 4), | ||
'horizontal-vertical', | ||
new SizeVector(10, 10), | ||
), | ||
).toMatchInlineSnapshot(` | ||
Set { | ||
[ | ||
7, | ||
4, | ||
], | ||
[ | ||
4, | ||
7, | ||
], | ||
[ | ||
7, | ||
7, | ||
], | ||
} | ||
`); | ||
expect( | ||
getSymmetricPositions( | ||
vec(8, 8), | ||
'horizontal-vertical', | ||
new SizeVector(10, 10), | ||
), | ||
).toMatchInlineSnapshot(` | ||
Set { | ||
[ | ||
3, | ||
8, | ||
], | ||
[ | ||
8, | ||
3, | ||
], | ||
[ | ||
3, | ||
3, | ||
], | ||
} | ||
`); | ||
}); | ||
|
||
test('`getSymmetricPositions` does not include vector itself', () => { | ||
expect( | ||
getSymmetricPositions(vec(3, 2), 'horizontal', new SizeVector(5, 5)), | ||
).toMatchInlineSnapshot(`Set {}`); | ||
expect( | ||
getSymmetricPositions(vec(2, 3), 'vertical', new SizeVector(5, 5)), | ||
).toMatchInlineSnapshot(`Set {}`); | ||
expect( | ||
getSymmetricPositions(vec(3, 3), 'diagonal', new SizeVector(5, 5)), | ||
).toMatchInlineSnapshot(`Set {}`); | ||
expect( | ||
getSymmetricPositions( | ||
vec(3, 3), | ||
'horizontal-vertical', | ||
new SizeVector(5, 5), | ||
), | ||
).toMatchInlineSnapshot(`Set {}`); | ||
}); |
Oops, something went wrong.