1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-11 01:01:53 +00:00

Used Prettier to Format Document

This commit is contained in:
Christopher-Robin 2020-10-08 00:37:32 +11:00
parent 5644c41057
commit 1bf87a2fb3
No known key found for this signature in database
GPG Key ID: 39A83BF9D91CC108

View File

@ -19,7 +19,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;
@ -49,7 +49,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);
@ -60,7 +60,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;
} }
@ -74,7 +74,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
) { ) {
@ -102,15 +102,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");
} }
} }
@ -121,8 +121,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
@ -138,12 +138,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
) { ) {
@ -162,17 +162,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);
} }
@ -180,7 +180,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(
@ -203,15 +203,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();
} }
@ -226,13 +226,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);
@ -242,18 +242,19 @@ 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) {
let entities = [];
let entities = [] if (
if(this.root.keyMapper.getBinding(KEYMAPPINGS.massSelect.massSelectSelectMultiLayer).pressed) this.root.keyMapper.getBinding(KEYMAPPINGS.massSelect.massSelectSelectMultiLayer)
.pressed
)
entities = this.root.map.getLayersContentsMultipleXY(x, y); entities = this.root.map.getLayersContentsMultipleXY(x, y);
else else entities = [this.root.map.getLayerContentXY(x, y, this.root.currentLayer)];
entities = [this.root.map.getLayerContentXY(x, y, this.root.currentLayer)];
for (let i = 0; i < entities.length; ++i) {
for(let i = 0; i < entities.length; ++i){
let entity = entities[i]; let entity = entities[i];
if(entity !== null && this.root.logic.canDeleteBuilding(entity)) if (entity !== null && this.root.logic.canDeleteBuilding(entity))
this.selectedUids.add(entity.uid); this.selectedUids.add(entity.uid);
} }
} }
@ -271,7 +272,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);
@ -299,36 +300,32 @@ export class HUDMassSelector extends BaseHUDPart {
const renderedUids = new Set(); const renderedUids = new Set();
let isMultiLayerPressed = this.root.keyMapper.getBinding(
let isMultiLayerPressed = this.root.keyMapper.getBinding(KEYMAPPINGS.massSelect.massSelectSelectMultiLayer).pressed; KEYMAPPINGS.massSelect.massSelectSelectMultiLayer
).pressed;
for (let x = realTileStart.x; x <= realTileEnd.x; ++x) {
for (let y = realTileStart.y; y <= realTileEnd.y; ++y) {
let entities = [];
if (isMultiLayerPressed) entities = this.root.map.getLayersContentsMultipleXY(x, y);
else entities = [this.root.map.getLayerContentXY(x, y, this.root.currentLayer)];
for(let x = realTileStart.x; x <= realTileEnd.x; ++x) { for (let i = 0; i < entities.length; ++i) {
for(let y = realTileStart.y; y <= realTileEnd.y; ++y) { let component = entities[i];
if (component && this.root.logic.canDeleteBuilding(component)) {
let entities = []
if(isMultiLayerPressed)
entities = this.root.map.getLayersContentsMultipleXY(x, y);
else
entities = [this.root.map.getLayerContentXY(x, y, this.root.currentLayer)];
for(let i = 0; i < entities.length; ++i) {
let component = entities[i];
if(component && this.root.logic.canDeleteBuilding(component)) {
// Prevent rendering the overlay twice // Prevent rendering the overlay twice
const uid = component.uid; const uid = component.uid;
if(renderedUids.has(uid)) { if (renderedUids.has(uid)) {
continue; continue;
} }
renderedUids.add(uid); renderedUids.add(uid);
const staticComp = component.components.StaticMapEntity; const staticComp = component.components.StaticMapEntity;
const bounds = staticComp.getTileSpaceBounds(); const bounds = staticComp.getTileSpaceBounds();
parameters.context.beginPath(); parameters.context.beginPath();
if(this.root.currentLayer === "wires" || component.layer === "regular"){ if (this.root.currentLayer === "wires" || component.layer === "regular") {
parameters.context.fillStyle = THEME.map.selectionOverlay; parameters.context.fillStyle = THEME.map.selectionOverlay;
parameters.context.beginRoundedRect( parameters.context.beginRoundedRect(
bounds.x * globalConfig.tileSize + boundsBorder, bounds.x * globalConfig.tileSize + boundsBorder,
@ -337,7 +334,7 @@ export class HUDMassSelector extends BaseHUDPart {
bounds.h * globalConfig.tileSize - 2 * boundsBorder, bounds.h * globalConfig.tileSize - 2 * boundsBorder,
2 2
); );
}else{ } else {
MapChunkView.drawSingleWiresOverviewTile({ MapChunkView.drawSingleWiresOverviewTile({
context: parameters.context, context: parameters.context,
x: bounds.x * globalConfig.tileSize + boundsBorder, x: bounds.x * globalConfig.tileSize + boundsBorder,
@ -354,13 +351,12 @@ export class HUDMassSelector extends BaseHUDPart {
} }
} }
parameters.context.fillStyle = THEME.map.selectionOverlay;
this.selectedUids.forEach(uid => { this.selectedUids.forEach(uid => {
const entity = this.root.entityMgr.findByUid(uid); const entity = this.root.entityMgr.findByUid(uid);
const staticComp = entity.components.StaticMapEntity; const staticComp = entity.components.StaticMapEntity;
const bounds = staticComp.getTileSpaceBounds(); const bounds = staticComp.getTileSpaceBounds();
parameters.context.beginPath(); parameters.context.beginPath();
if(this.root.currentLayer === "wires" || entity.layer === "regular"){ if (this.root.currentLayer === "wires" || entity.layer === "regular") {
parameters.context.fillStyle = THEME.map.selectionOverlay; parameters.context.fillStyle = THEME.map.selectionOverlay;
parameters.context.beginRoundedRect( parameters.context.beginRoundedRect(
bounds.x * globalConfig.tileSize + boundsBorder, bounds.x * globalConfig.tileSize + boundsBorder,
@ -369,7 +365,7 @@ export class HUDMassSelector extends BaseHUDPart {
bounds.h * globalConfig.tileSize - 2 * boundsBorder, bounds.h * globalConfig.tileSize - 2 * boundsBorder,
2 2
); );
}else{ } else {
MapChunkView.drawSingleWiresOverviewTile({ MapChunkView.drawSingleWiresOverviewTile({
context: parameters.context, context: parameters.context,
x: bounds.x * globalConfig.tileSize + boundsBorder, x: bounds.x * globalConfig.tileSize + boundsBorder,