mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Fixed Code style and moved rendering code to serpeate method
This commit is contained in:
parent
1bf87a2fb3
commit
b27ed5f0bb
@ -248,13 +248,15 @@ export class HUDMassSelector extends BaseHUDPart {
|
|||||||
if (
|
if (
|
||||||
this.root.keyMapper.getBinding(KEYMAPPINGS.massSelect.massSelectSelectMultiLayer)
|
this.root.keyMapper.getBinding(KEYMAPPINGS.massSelect.massSelectSelectMultiLayer)
|
||||||
.pressed
|
.pressed
|
||||||
)
|
) {
|
||||||
entities = this.root.map.getLayersContentsMultipleXY(x, y);
|
entities = this.root.map.getLayersContentsMultipleXY(x, y);
|
||||||
else entities = [this.root.map.getLayerContentXY(x, y, this.root.currentLayer)];
|
} else {
|
||||||
|
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 && this.root.logic.canDeleteBuilding(entity))
|
||||||
this.selectedUids.add(entity.uid);
|
this.selectedUids.add(entity.uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -270,8 +272,6 @@ export class HUDMassSelector extends BaseHUDPart {
|
|||||||
* @param {DrawParameters} parameters
|
* @param {DrawParameters} parameters
|
||||||
*/
|
*/
|
||||||
draw(parameters) {
|
draw(parameters) {
|
||||||
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);
|
||||||
@ -300,63 +300,58 @@ export class HUDMassSelector extends BaseHUDPart {
|
|||||||
|
|
||||||
const renderedUids = new Set();
|
const renderedUids = new Set();
|
||||||
|
|
||||||
let isMultiLayerPressed = this.root.keyMapper.getBinding(
|
const isMultiLayerPressed = this.root.keyMapper.getBinding(
|
||||||
KEYMAPPINGS.massSelect.massSelectSelectMultiLayer
|
KEYMAPPINGS.massSelect.massSelectSelectMultiLayer
|
||||||
).pressed;
|
).pressed;
|
||||||
|
|
||||||
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 (isMultiLayerPressed) entities = this.root.map.getLayersContentsMultipleXY(x, y);
|
if (isMultiLayerPressed) {
|
||||||
else entities = [this.root.map.getLayerContentXY(x, y, this.root.currentLayer)];
|
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) {
|
for (let i = 0; i < Math.min(1, entities.length); ++i) {
|
||||||
let component = entities[i];
|
let entity = entities[i];
|
||||||
if (component && this.root.logic.canDeleteBuilding(component)) {
|
if (entity && this.root.logic.canDeleteBuilding(entity)) {
|
||||||
// Prevent rendering the overlay twice
|
// Prevent rendering the overlay twice
|
||||||
const uid = component.uid;
|
const uid = entity.uid;
|
||||||
if (renderedUids.has(uid)) {
|
if (renderedUids.has(uid)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
renderedUids.add(uid);
|
renderedUids.add(uid);
|
||||||
|
|
||||||
const staticComp = component.components.StaticMapEntity;
|
const staticComp = entity.components.StaticMapEntity;
|
||||||
|
|
||||||
const bounds = staticComp.getTileSpaceBounds();
|
const bounds = staticComp.getTileSpaceBounds();
|
||||||
|
|
||||||
parameters.context.beginPath();
|
this.RenderSelectonPreviewTile(parameters, bounds, entity);
|
||||||
if (this.root.currentLayer === "wires" || component.layer === "regular") {
|
|
||||||
parameters.context.fillStyle = THEME.map.selectionOverlay;
|
|
||||||
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
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
MapChunkView.drawSingleWiresOverviewTile({
|
|
||||||
context: parameters.context,
|
|
||||||
x: bounds.x * globalConfig.tileSize + boundsBorder,
|
|
||||||
y: bounds.y * globalConfig.tileSize + boundsBorder,
|
|
||||||
entity: component,
|
|
||||||
tileSizePixels: globalConfig.tileSize * 1.01,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
parameters.context.fill();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const renderedPositions = new Set();
|
||||||
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();
|
||||||
|
if (renderedPositions.has(bounds.toCompareableString())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
renderedPositions.add(bounds.toCompareableString());
|
||||||
|
this.RenderSelectonPreviewTile(parameters, bounds, entity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderSelectonPreviewTile(parameters, bounds, entity) {
|
||||||
|
const boundsBorder = 2;
|
||||||
|
|
||||||
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,
|
||||||
@ -365,7 +360,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,
|
||||||
@ -373,9 +368,7 @@ export class HUDMassSelector extends BaseHUDPart {
|
|||||||
entity: entity,
|
entity: entity,
|
||||||
tileSizePixels: globalConfig.tileSize * 1.01,
|
tileSizePixels: globalConfig.tileSize * 1.01,
|
||||||
});
|
});
|
||||||
}
|
}*/
|
||||||
|
|
||||||
parameters.context.fill();
|
parameters.context.fill();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user