Skip to content

Commit 7d0f46e

Browse files
committed
rotsprite MVP
1 parent 7d7942b commit 7d0f46e

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

app/components/import/state.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,29 @@ class ImportState {
6363
this.canvas = node;
6464
this.ctx = node.getContext('2d');
6565

66-
const img = new Image();
66+
if (this.path) {
67+
const img = new Image();
68+
69+
img.onload = () => {
70+
node.width = img.width;
71+
node.height = img.height;
72+
this.ctx.drawImage(img, 0, 0);
73+
requestAnimationFrame(this.loaded);
74+
};
6775

68-
img.onload = () => {
69-
node.width = img.width;
70-
node.height = img.height;
71-
this.ctx.drawImage(img, 0, 0);
72-
requestAnimationFrame(this.loaded);
73-
};
76+
img.onerror = (e) => {
77+
errorMsg('Import Error', `Error loading ${this.path}`);
78+
this.cancel();
79+
};
7480

75-
img.onerror = (e) => {
76-
errorMsg('Import Error', `Error loading ${this.path}`);
77-
this.cancel();
78-
};
81+
img.src = this.path;
7982

80-
img.src = this.path;
83+
} else if (this.rotCanvas) {
84+
console.log(this.rotCanvas);
85+
this.ctx.drawImage(this.rotCanvas, 0, 0);
86+
delete this.rotCanvas;
87+
requestAnimationFrame(this.loaded);
88+
}
8189
};
8290

8391
loaded = () => {

app/components/mappings/rotate.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { rotateImageData } from '#util/rotsprite';
66
import { Input, Slider, Item, Button, Modal } from '#ui';
77
import { mappingState } from './state';
88

9+
import { importState } from '../import/state';
10+
911
function rotateCurrentSprite(canvas, angle) {
1012
const spriteCanv = exportSprite(environment.currentSprite);
1113
const spriteCtx = spriteCanv.getContext('2d');
@@ -41,6 +43,11 @@ export const Rotate = observer(() => {
4143
return value;
4244
};
4345

46+
function reImport() {
47+
importState.rotCanvas = canvasRef.current;
48+
importState.config.active = true;
49+
}
50+
4451
return (
4552
<Modal
4653
className="rotsprite"
@@ -86,7 +93,7 @@ export const Rotate = observer(() => {
8693
<Button color="magenta" onClick={mappingState.toggleRotate}>
8794
close
8895
</Button>
89-
<Button color="red">Reimport</Button>
96+
<Button color="red" onClick={reImport}>Reimport</Button>
9097
</div>
9198
</Modal>
9299
);

0 commit comments

Comments
 (0)