-
Notifications
You must be signed in to change notification settings - Fork 6
/
DrawHelpers.js
87 lines (75 loc) · 3.32 KB
/
DrawHelpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
class DrawHelpers {
static deleteSprite() {
const { animationFrame, sprite } = DrawSectionHandler.currentSprite;
sprite.animation[animationFrame].sprite = SpritePixelArrays.EMPTY_ANIMATION_FRAME.sprite;
this.redrawAllSprites();
}
static flipHorzontally() {
const { animationFrame, sprite } = DrawSectionHandler.currentSprite;
const flippedSprite = spriteSheetCreator.hflip(sprite.animation[animationFrame].sprite);
sprite.animation[animationFrame].sprite = flippedSprite;
this.redrawAllSprites();
}
static flipVertically() {
const { animationFrame, sprite } = DrawSectionHandler.currentSprite;
const flippedSprite = spriteSheetCreator.vflip(sprite.animation[animationFrame].sprite);
sprite.animation[animationFrame].sprite = flippedSprite;
this.redrawAllSprites();
}
static moveUp() {
const { animationFrame, sprite } = DrawSectionHandler.currentSprite;
const movedSprite = this.swapLastWithFirst(sprite.animation[animationFrame].sprite);
sprite.animation[animationFrame].sprite = movedSprite;
this.redrawAllSprites();
}
static moveDown() {
const { animationFrame, sprite } = DrawSectionHandler.currentSprite;
const movedSprite = this.swapFirstWithlast(sprite.animation[animationFrame].sprite);
sprite.animation[animationFrame].sprite = movedSprite;
this.redrawAllSprites();
}
static moveLeft() {
const { animationFrame, sprite } = DrawSectionHandler.currentSprite;
const movedSprite = sprite.animation[animationFrame].sprite.map(arrayLine =>
this.swapLastWithFirst(arrayLine));
sprite.animation[animationFrame].sprite = movedSprite;
this.redrawAllSprites();
}
static moveRight() {
const { animationFrame, sprite } = DrawSectionHandler.currentSprite;
const movedSprite = sprite.animation[animationFrame].sprite.map(arrayLine =>
this.swapFirstWithlast(arrayLine));
sprite.animation[animationFrame].sprite = movedSprite;
this.redrawAllSprites();
}
static rotateLeft() {
const { animationFrame, sprite } = DrawSectionHandler.currentSprite;
const flippedSprite = spriteSheetCreator.rotate90(sprite.animation[animationFrame].sprite);
sprite.animation[animationFrame].sprite = flippedSprite;
this.redrawAllSprites();
}
static rotateRight() {
const { animationFrame, sprite } = DrawSectionHandler.currentSprite;
const flippedSprite = spriteSheetCreator.rotateCounterClockwise(sprite.animation[animationFrame].sprite);
sprite.animation[animationFrame].sprite = flippedSprite;
this.redrawAllSprites();
}
static swapLastWithFirst(arr) {
var tempArray = arr;
var firstElement = tempArray.shift();
tempArray.push(firstElement);
return tempArray;
}
static swapFirstWithlast(arr) {
var tempArray = arr;
var firstElement = tempArray.pop();
tempArray.unshift(firstElement);
return tempArray;
}
static redrawAllSprites() {
DrawSectionHandler.drawCurrentSprite();
DrawSectionHandler.redrawOutsideCanvases(true);
DrawSectionHandler.drawCurrentSprite();
DrawSectionHandler.redrawOutsideCanvases();
}
}