mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
added Multi Layer Copying
This commit is contained in:
parent
d33a72202a
commit
129c2baec7
@ -18,7 +18,7 @@ import { Blueprint } from "../../blueprint";
|
||||
const logger = createLogger("hud/mass_selector");
|
||||
|
||||
export class HUDMassSelector extends BaseHUDPart {
|
||||
createElements(parent) {}
|
||||
createElements(parent) { }
|
||||
|
||||
initialize() {
|
||||
this.currentSelectionStartWorld = null;
|
||||
@ -48,7 +48,7 @@ export class HUDMassSelector extends BaseHUDPart {
|
||||
* @param {Entity} entity
|
||||
*/
|
||||
onEntityDestroyed(entity) {
|
||||
if (this.root.bulkOperationRunning) {
|
||||
if(this.root.bulkOperationRunning) {
|
||||
return;
|
||||
}
|
||||
this.selectedUids.delete(entity.uid);
|
||||
@ -59,7 +59,7 @@ export class HUDMassSelector extends BaseHUDPart {
|
||||
*/
|
||||
onBack() {
|
||||
// Clear entities on escape
|
||||
if (this.selectedUids.size > 0) {
|
||||
if(this.selectedUids.size > 0) {
|
||||
this.selectedUids = new Set();
|
||||
return STOP_PROPAGATION;
|
||||
}
|
||||
@ -73,7 +73,7 @@ export class HUDMassSelector extends BaseHUDPart {
|
||||
}
|
||||
|
||||
confirmDelete() {
|
||||
if (
|
||||
if(
|
||||
!this.root.app.settings.getAllSettings().disableCutDeleteWarnings &&
|
||||
this.selectedUids.size > 100
|
||||
) {
|
||||
@ -101,15 +101,15 @@ export class HUDMassSelector extends BaseHUDPart {
|
||||
const mapUidToEntity = this.root.entityMgr.getFrozenUidSearchMap();
|
||||
|
||||
this.root.logic.performBulkOperation(() => {
|
||||
for (let i = 0; i < entityUids.length; ++i) {
|
||||
for(let i = 0; i < entityUids.length; ++i) {
|
||||
const uid = entityUids[i];
|
||||
const entity = mapUidToEntity.get(uid);
|
||||
if (!entity) {
|
||||
if(!entity) {
|
||||
logger.error("Entity not found by uid:", uid);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!this.root.logic.tryDeleteBuilding(entity)) {
|
||||
if(!this.root.logic.tryDeleteBuilding(entity)) {
|
||||
logger.error("Error in mass delete, could not remove building");
|
||||
}
|
||||
}
|
||||
@ -120,8 +120,8 @@ export class HUDMassSelector extends BaseHUDPart {
|
||||
}
|
||||
|
||||
startCopy() {
|
||||
if (this.selectedUids.size > 0) {
|
||||
if (!this.root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_blueprints)) {
|
||||
if(this.selectedUids.size > 0) {
|
||||
if(!this.root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_blueprints)) {
|
||||
this.root.hud.parts.dialogs.showInfo(
|
||||
T.dialogs.blueprintsNotUnlocked.title,
|
||||
T.dialogs.blueprintsNotUnlocked.desc
|
||||
@ -137,12 +137,12 @@ export class HUDMassSelector extends BaseHUDPart {
|
||||
}
|
||||
|
||||
confirmCut() {
|
||||
if (!this.root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_blueprints)) {
|
||||
if(!this.root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_blueprints)) {
|
||||
this.root.hud.parts.dialogs.showInfo(
|
||||
T.dialogs.blueprintsNotUnlocked.title,
|
||||
T.dialogs.blueprintsNotUnlocked.desc
|
||||
);
|
||||
} else if (
|
||||
} else if(
|
||||
!this.root.app.settings.getAllSettings().disableCutDeleteWarnings &&
|
||||
this.selectedUids.size > 100
|
||||
) {
|
||||
@ -161,17 +161,17 @@ export class HUDMassSelector extends BaseHUDPart {
|
||||
}
|
||||
|
||||
doCut() {
|
||||
if (this.selectedUids.size > 0) {
|
||||
if(this.selectedUids.size > 0) {
|
||||
const entityUids = Array.from(this.selectedUids);
|
||||
|
||||
const cutAction = () => {
|
||||
// copy code relies on entities still existing, so must copy before deleting.
|
||||
this.root.hud.signals.buildingsSelectedForCopy.dispatch(entityUids);
|
||||
|
||||
for (let i = 0; i < entityUids.length; ++i) {
|
||||
for(let i = 0; i < entityUids.length; ++i) {
|
||||
const uid = entityUids[i];
|
||||
const entity = this.root.entityMgr.findByUid(uid);
|
||||
if (!this.root.logic.tryDeleteBuilding(entity)) {
|
||||
if(!this.root.logic.tryDeleteBuilding(entity)) {
|
||||
logger.error("Error in mass cut, could not remove building");
|
||||
this.selectedUids.delete(uid);
|
||||
}
|
||||
@ -179,7 +179,7 @@ export class HUDMassSelector extends BaseHUDPart {
|
||||
};
|
||||
|
||||
const blueprint = Blueprint.fromUids(this.root, entityUids);
|
||||
if (blueprint.canAfford(this.root)) {
|
||||
if(blueprint.canAfford(this.root)) {
|
||||
cutAction();
|
||||
} else {
|
||||
const { cancel, ok } = this.root.hud.parts.dialogs.showWarning(
|
||||
@ -202,15 +202,15 @@ export class HUDMassSelector extends BaseHUDPart {
|
||||
* @param {enumMouseButton} mouseButton
|
||||
*/
|
||||
onMouseDown(pos, mouseButton) {
|
||||
if (!this.root.keyMapper.getBinding(KEYMAPPINGS.massSelect.massSelectStart).pressed) {
|
||||
if(!this.root.keyMapper.getBinding(KEYMAPPINGS.massSelect.massSelectStart).pressed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mouseButton !== enumMouseButton.left) {
|
||||
if(mouseButton !== enumMouseButton.left) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.root.keyMapper.getBinding(KEYMAPPINGS.massSelect.massSelectSelectMultiple).pressed) {
|
||||
if(!this.root.keyMapper.getBinding(KEYMAPPINGS.massSelect.massSelectSelectMultiple).pressed) {
|
||||
// Start new selection
|
||||
this.selectedUids = new Set();
|
||||
}
|
||||
@ -225,13 +225,13 @@ export class HUDMassSelector extends BaseHUDPart {
|
||||
* @param {Vector} pos
|
||||
*/
|
||||
onMouseMove(pos) {
|
||||
if (this.currentSelectionStartWorld) {
|
||||
if(this.currentSelectionStartWorld) {
|
||||
this.currentSelectionEnd = pos.copy();
|
||||
}
|
||||
}
|
||||
|
||||
onMouseUp() {
|
||||
if (this.currentSelectionStartWorld) {
|
||||
if(this.currentSelectionStartWorld) {
|
||||
const worldStart = this.currentSelectionStartWorld;
|
||||
const worldEnd = this.root.camera.screenToWorld(this.currentSelectionEnd);
|
||||
|
||||
@ -241,11 +241,12 @@ export class HUDMassSelector extends BaseHUDPart {
|
||||
const realTileStart = tileStart.min(tileEnd);
|
||||
const realTileEnd = tileStart.max(tileEnd);
|
||||
|
||||
for (let x = realTileStart.x; x <= realTileEnd.x; ++x) {
|
||||
for (let y = realTileStart.y; y <= realTileEnd.y; ++y) {
|
||||
const contents = this.root.map.getLayerContentXY(x, y, this.root.currentLayer);
|
||||
if (contents && this.root.logic.canDeleteBuilding(contents)) {
|
||||
this.selectedUids.add(contents.uid);
|
||||
for(let x = realTileStart.x; x <= realTileEnd.x; ++x) {
|
||||
for(let y = realTileStart.y; y <= realTileEnd.y; ++y) {
|
||||
|
||||
for(let contents of this.root.map.getLayersContentsMultipleXY(x, y)){
|
||||
if(this.root.logic.canDeleteBuilding(contents))
|
||||
this.selectedUids.add(contents.uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -262,7 +263,7 @@ export class HUDMassSelector extends BaseHUDPart {
|
||||
draw(parameters) {
|
||||
const boundsBorder = 2;
|
||||
|
||||
if (this.currentSelectionStartWorld) {
|
||||
if(this.currentSelectionStartWorld) {
|
||||
const worldStart = this.currentSelectionStartWorld;
|
||||
const worldEnd = this.root.camera.screenToWorld(this.currentSelectionEnd);
|
||||
|
||||
@ -292,27 +293,30 @@ export class HUDMassSelector extends BaseHUDPart {
|
||||
|
||||
const renderedUids = new Set();
|
||||
|
||||
for (let x = realTileStart.x; x <= realTileEnd.x; ++x) {
|
||||
for (let y = realTileStart.y; y <= realTileEnd.y; ++y) {
|
||||
const contents = this.root.map.getLayerContentXY(x, y, this.root.currentLayer);
|
||||
if (contents && this.root.logic.canDeleteBuilding(contents)) {
|
||||
// Prevent rendering the overlay twice
|
||||
const uid = contents.uid;
|
||||
if (renderedUids.has(uid)) {
|
||||
continue;
|
||||
}
|
||||
renderedUids.add(uid);
|
||||
for(let x = realTileStart.x; x <= realTileEnd.x; ++x) {
|
||||
for(let y = realTileStart.y; y <= realTileEnd.y; ++y) {
|
||||
|
||||
const staticComp = contents.components.StaticMapEntity;
|
||||
const bounds = staticComp.getTileSpaceBounds();
|
||||
parameters.context.beginRoundedRect(
|
||||
bounds.x * globalConfig.tileSize + boundsBorder,
|
||||
bounds.y * globalConfig.tileSize + boundsBorder,
|
||||
bounds.w * globalConfig.tileSize - 2 * boundsBorder,
|
||||
bounds.h * globalConfig.tileSize - 2 * boundsBorder,
|
||||
2
|
||||
);
|
||||
parameters.context.fill();
|
||||
for(let component of this.root.map.getLayersContentsMultipleXY(x, y)) {
|
||||
|
||||
if(component && this.root.logic.canDeleteBuilding(component)) {
|
||||
// Prevent rendering the overlay twice
|
||||
const uid = component.uid;
|
||||
if(renderedUids.has(uid)) {
|
||||
continue;
|
||||
}
|
||||
renderedUids.add(uid);
|
||||
|
||||
const staticComp = component.components.StaticMapEntity;
|
||||
const bounds = staticComp.getTileSpaceBounds();
|
||||
parameters.context.beginRoundedRect(
|
||||
bounds.x * globalConfig.tileSize + boundsBorder,
|
||||
bounds.y * globalConfig.tileSize + boundsBorder,
|
||||
bounds.w * globalConfig.tileSize - 2 * boundsBorder,
|
||||
bounds.h * globalConfig.tileSize - 2 * boundsBorder,
|
||||
2
|
||||
);
|
||||
parameters.context.fill();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user