1
0
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:
Christopher-Robin 2020-10-07 04:15:31 +11:00
parent d33a72202a
commit 129c2baec7
No known key found for this signature in database
GPG Key ID: 39A83BF9D91CC108

View File

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