Skip to content

Commit

Permalink
Snapshot fixes: sizing, and saving of image now working.
Browse files Browse the repository at this point in the history
  • Loading branch information
EtherCD committed Aug 21, 2024
1 parent 585c652 commit c28ec7d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/managers/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const SnapshotManager = {
this.captureMode.value = false;
this.empty.value = false;
this.toClipboard();
return;
}
this.clear();
this.startPoint.value = startPoint;
Expand All @@ -66,15 +67,15 @@ export const SnapshotManager = {
if (width < 0) {
width = Math.abs(width);
changed = true;
offsetPoint.x = point.x;
offsetPoint.x = point.x + 1;
} else if (!Number.isNaN(offsetPoint.x)) {
offsetPoint.x = NaN;
changed = true;
}
if (height < 0) {
height = Math.abs(height);
changed = true;
offsetPoint.y = point.y;
offsetPoint.y = point.y + 1;
} else if (!Number.isNaN(offsetPoint.y)) {
offsetPoint.y = NaN;
changed = true;
Expand Down Expand Up @@ -136,8 +137,10 @@ export const SnapshotManager = {

async toFile(scaleLimit = 10) {
const image = PlaceManager.image.value;
const startPoint = this.startPoint.value;
const offsetPoint = this.offsetPoint.value;
if (!image) return;
const pos = new Point(this.startPoint.value.x - this.offsetPoint.value.x, this.startPoint.value.y - this.offsetPoint.value.y);
const pos = new Point(!Number.isNaN(offsetPoint.x) ? offsetPoint.x : startPoint.x, !Number.isNaN(offsetPoint.y) ? offsetPoint.y : startPoint.y);
const size = this.size.value;
let scale = this.scale.value;
if (scale > scaleLimit) scale = scaleLimit;
Expand All @@ -157,7 +160,9 @@ export const SnapshotManager = {
const dataURL = canvas.toDataURL("image/png");
const link = document.createElement("a");
link.href = dataURL;
link.download = `result.png`;
link.download = `pixelbattle_snapshot_${!Number.isNaN(offsetPoint.x) ? offsetPoint.x : startPoint.x}_${!Number.isNaN(offsetPoint.y) ? offsetPoint.y : startPoint.y}_${size.x}_${
size.y
}.png`;
link.click();
},
};
Expand Down

0 comments on commit c28ec7d

Please sign in to comment.