Fix the editor to also crop the selection
This commit is contained in:
parent
214eaad1f5
commit
246e56187c
@ -197,7 +197,7 @@ export class EditorLevelMetaOverlay extends DialogOverlay {
|
||||
let size_x = Math.max(1, Math.min(100, parseInt(els.size_x.value, 10)));
|
||||
let size_y = Math.max(1, Math.min(100, parseInt(els.size_y.value, 10)));
|
||||
if (size_x !== stored_level.size_x || size_y !== stored_level.size_y) {
|
||||
this.conductor.editor.resize_level(size_x, size_y);
|
||||
this.conductor.editor.crop_level(0, 0, size_x, size_y);
|
||||
}
|
||||
|
||||
stored_level.blob_behavior = parseInt(els.blob_behavior.value, 10);
|
||||
|
||||
@ -1632,7 +1632,26 @@ export class Editor extends PrimaryView {
|
||||
);
|
||||
}
|
||||
|
||||
resize_level(size_x, size_y, x0 = 0, y0 = 0) {
|
||||
crop_level(x0, y0, size_x, size_y) {
|
||||
let original_cells = this.stored_level.linear_cells;
|
||||
let original_size_x = this.stored_level.size_x;
|
||||
let original_size_y = this.stored_level.size_y;
|
||||
|
||||
let old_selection_cells, new_selection_cells;
|
||||
if (this.selection) {
|
||||
this.selection.commit_floating();
|
||||
|
||||
old_selection_cells = this.selection.cells;
|
||||
new_selection_cells = new Set;
|
||||
for (let n of old_selection_cells) {
|
||||
let x = n % original_size_x - x0;
|
||||
let y = Math.floor(n / original_size_x) - y0;
|
||||
if (0 <= x && x < size_x && 0 <= y && y < size_y) {
|
||||
new_selection_cells.add(x + y * size_x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let new_cells = [];
|
||||
for (let y = y0; y < y0 + size_y; y++) {
|
||||
for (let x = x0; x < x0 + size_x; x++) {
|
||||
@ -1640,21 +1659,24 @@ export class Editor extends PrimaryView {
|
||||
}
|
||||
}
|
||||
|
||||
let original_cells = this.stored_level.linear_cells;
|
||||
let original_size_x = this.stored_level.size_x;
|
||||
let original_size_y = this.stored_level.size_y;
|
||||
|
||||
this._do(() => {
|
||||
this.stored_level.linear_cells = new_cells;
|
||||
this.stored_level.size_x = size_x;
|
||||
this.stored_level.size_y = size_y;
|
||||
this.update_after_size_change();
|
||||
if (this.selection) {
|
||||
this.selection._set_from_set(new_selection_cells);
|
||||
}
|
||||
}, () => {
|
||||
this.stored_level.linear_cells = original_cells;
|
||||
this.stored_level.size_x = original_size_x;
|
||||
this.stored_level.size_y = original_size_y;
|
||||
this.update_after_size_change();
|
||||
if (this.selection) {
|
||||
this.selection._set_from_set(old_selection_cells);
|
||||
}
|
||||
});
|
||||
|
||||
this.commit_undo();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user