mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Moved from Set to Array for Selected Entities
This commit is contained in:
parent
27ebf23472
commit
eacf165e91
@ -57,6 +57,40 @@ export class Blueprint {
|
|||||||
return new Blueprint(newEntities);
|
return new Blueprint(newEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new blueprint from the given entities
|
||||||
|
* @param {GameRoot} root
|
||||||
|
* @param {Array<Entity>} entities
|
||||||
|
*/
|
||||||
|
static fromEntities(root, entities) {
|
||||||
|
const newEntities = [];
|
||||||
|
|
||||||
|
let averagePosition = new Vector();
|
||||||
|
|
||||||
|
// First, create a copy
|
||||||
|
for (let i = 0; i < entities.length; ++i) {
|
||||||
|
|
||||||
|
const entity = entities[i];//root.entityMgr.findByUid(uids[i]);
|
||||||
|
// assert(entity, "Entity for blueprint not found:" + uids[i]);
|
||||||
|
|
||||||
|
const clone = entity.clone();
|
||||||
|
newEntities.push(clone);
|
||||||
|
|
||||||
|
const pos = entity.components.StaticMapEntity.getTileSpaceBounds().getCenter();
|
||||||
|
averagePosition.addInplace(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
averagePosition.divideScalarInplace(entities.length);
|
||||||
|
const blueprintOrigin = averagePosition.subScalars(0.5, 0.5).floor();
|
||||||
|
|
||||||
|
for (let i = 0; i < entities.length; ++i) {
|
||||||
|
newEntities[i].components.StaticMapEntity.origin.subInplace(blueprintOrigin);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now, make sure the origin is 0,0
|
||||||
|
return new Blueprint(newEntities);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the cost of this blueprint in shapes
|
* Returns the cost of this blueprint in shapes
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -48,6 +48,7 @@ import { HUDBetaOverlay } from "./parts/beta_overlay";
|
|||||||
import { HUDStandaloneAdvantages } from "./parts/standalone_advantages";
|
import { HUDStandaloneAdvantages } from "./parts/standalone_advantages";
|
||||||
import { HUDCatMemes } from "./parts/cat_memes";
|
import { HUDCatMemes } from "./parts/cat_memes";
|
||||||
import { HUDTutorialVideoOffer } from "./parts/tutorial_video_offer";
|
import { HUDTutorialVideoOffer } from "./parts/tutorial_video_offer";
|
||||||
|
import { Entity } from "../entity";
|
||||||
|
|
||||||
export class GameHUD {
|
export class GameHUD {
|
||||||
/**
|
/**
|
||||||
@ -67,7 +68,7 @@ export class GameHUD {
|
|||||||
shapePinRequested: /** @type {TypedSignal<[ShapeDefinition]>} */ (new Signal()),
|
shapePinRequested: /** @type {TypedSignal<[ShapeDefinition]>} */ (new Signal()),
|
||||||
shapeUnpinRequested: /** @type {TypedSignal<[string]>} */ (new Signal()),
|
shapeUnpinRequested: /** @type {TypedSignal<[string]>} */ (new Signal()),
|
||||||
notification: /** @type {TypedSignal<[string, enumNotificationType]>} */ (new Signal()),
|
notification: /** @type {TypedSignal<[string, enumNotificationType]>} */ (new Signal()),
|
||||||
buildingsSelectedForCopy: /** @type {TypedSignal<[Array<number>]>} */ (new Signal()),
|
buildingsSelectedForCopy: /** @type {TypedSignal<[Array<Entity>]>} */ (new Signal()),
|
||||||
pasteBlueprintRequested: /** @type {TypedSignal<[]>} */ (new Signal()),
|
pasteBlueprintRequested: /** @type {TypedSignal<[]>} */ (new Signal()),
|
||||||
viewShapeDetailsRequested: /** @type {TypedSignal<[ShapeDefinition]>} */ (new Signal()),
|
viewShapeDetailsRequested: /** @type {TypedSignal<[ShapeDefinition]>} */ (new Signal()),
|
||||||
unlockNotificationFinished: /** @type {TypedSignal<[]>} */ (new Signal()),
|
unlockNotificationFinished: /** @type {TypedSignal<[]>} */ (new Signal()),
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import { SOUNDS } from "../../../platform/sound";
|
|||||||
import { T } from "../../../translations";
|
import { T } from "../../../translations";
|
||||||
import { Blueprint } from "../../blueprint";
|
import { Blueprint } from "../../blueprint";
|
||||||
import { enumMouseButton } from "../../camera";
|
import { enumMouseButton } from "../../camera";
|
||||||
|
import { Entity } from "../../entity";
|
||||||
import { KEYMAPPINGS } from "../../key_action_mapper";
|
import { KEYMAPPINGS } from "../../key_action_mapper";
|
||||||
import { BaseHUDPart } from "../base_hud_part";
|
import { BaseHUDPart } from "../base_hud_part";
|
||||||
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
||||||
@ -141,13 +142,13 @@ export class HUDBlueprintPlacer extends BaseHUDPart {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when an array of bulidings was selected
|
* Called when an array of bulidings was selected
|
||||||
* @param {Array<number>} uids
|
* @param {Array<Entity>} entities
|
||||||
*/
|
*/
|
||||||
createBlueprintFromBuildings(uids) {
|
createBlueprintFromBuildings(entities) {
|
||||||
if (uids.length === 0) {
|
if (entities.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.currentBlueprint.set(Blueprint.fromUids(this.root, uids));
|
this.currentBlueprint.set(Blueprint.fromEntities(this.root, entities));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -175,6 +176,7 @@ export class HUDBlueprintPlacer extends BaseHUDPart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.root.hud.signals.pasteBlueprintRequested.dispatch();
|
this.root.hud.signals.pasteBlueprintRequested.dispatch();
|
||||||
|
|
||||||
this.currentBlueprint.set(this.lastBlueprintUsed);
|
this.currentBlueprint.set(this.lastBlueprintUsed);
|
||||||
} else {
|
} else {
|
||||||
this.root.soundProxy.playUiError();
|
this.root.soundProxy.playUiError();
|
||||||
|
|||||||
@ -101,7 +101,7 @@ export class HUDKeybindingOverlay extends BaseHUDPart {
|
|||||||
*/
|
*/
|
||||||
get anythingSelectedOnMap() {
|
get anythingSelectedOnMap() {
|
||||||
const selector = this.root.hud.parts.massSelector;
|
const selector = this.root.hud.parts.massSelector;
|
||||||
return selector && selector.selectedUids.size > 0;
|
return selector && selector.selectedEntities.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -26,7 +26,9 @@ export class HUDMassSelector extends BaseHUDPart {
|
|||||||
this.multiLayerSelect = false;
|
this.multiLayerSelect = false;
|
||||||
this.currentSelectionStartWorld = null;
|
this.currentSelectionStartWorld = null;
|
||||||
this.currentSelectionEnd = null;
|
this.currentSelectionEnd = null;
|
||||||
this.selectedUids = new Set();
|
|
||||||
|
/**@type {Array<Entity>} */
|
||||||
|
this.selectedEntities = [];
|
||||||
|
|
||||||
this.root.signals.entityQueuedForDestroy.add(this.onEntityDestroyed, this);
|
this.root.signals.entityQueuedForDestroy.add(this.onEntityDestroyed, this);
|
||||||
this.root.hud.signals.pasteBlueprintRequested.add(this.clearSelection, this);
|
this.root.hud.signals.pasteBlueprintRequested.add(this.clearSelection, this);
|
||||||
@ -54,7 +56,9 @@ export class HUDMassSelector extends BaseHUDPart {
|
|||||||
if (this.root.bulkOperationRunning) {
|
if (this.root.bulkOperationRunning) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.selectedUids.delete(entity.uid);
|
const index = this.selectedEntities.indexOf(entity);
|
||||||
|
if(index != -1)
|
||||||
|
this.selectedEntities.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,8 +66,8 @@ export class HUDMassSelector extends BaseHUDPart {
|
|||||||
*/
|
*/
|
||||||
onBack() {
|
onBack() {
|
||||||
// Clear entities on escape
|
// Clear entities on escape
|
||||||
if (this.selectedUids.size > 0) {
|
if (this.selectedEntities.length > 0) {
|
||||||
this.selectedUids = new Set();
|
this.selectedEntities = [];
|
||||||
return STOP_PROPAGATION;
|
return STOP_PROPAGATION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -72,19 +76,19 @@ export class HUDMassSelector extends BaseHUDPart {
|
|||||||
* Clears the entire selection
|
* Clears the entire selection
|
||||||
*/
|
*/
|
||||||
clearSelection() {
|
clearSelection() {
|
||||||
this.selectedUids = new Set();
|
this.selectedEntities = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
confirmDelete() {
|
confirmDelete() {
|
||||||
if (
|
if (
|
||||||
!this.root.app.settings.getAllSettings().disableCutDeleteWarnings &&
|
!this.root.app.settings.getAllSettings().disableCutDeleteWarnings &&
|
||||||
this.selectedUids.size > 100
|
this.selectedEntities.length > 100
|
||||||
) {
|
) {
|
||||||
const { ok } = this.root.hud.parts.dialogs.showWarning(
|
const { ok } = this.root.hud.parts.dialogs.showWarning(
|
||||||
T.dialogs.massDeleteConfirm.title,
|
T.dialogs.massDeleteConfirm.title,
|
||||||
T.dialogs.massDeleteConfirm.desc.replace(
|
T.dialogs.massDeleteConfirm.desc.replace(
|
||||||
"<count>",
|
"<count>",
|
||||||
"" + formatBigNumberFull(this.selectedUids.size)
|
"" + formatBigNumberFull(this.selectedEntities.length)
|
||||||
),
|
),
|
||||||
["cancel:good:escape", "ok:bad:enter"]
|
["cancel:good:escape", "ok:bad:enter"]
|
||||||
);
|
);
|
||||||
@ -95,7 +99,7 @@ export class HUDMassSelector extends BaseHUDPart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
doDelete() {
|
doDelete() {
|
||||||
const entityUids = Array.from(this.selectedUids);
|
const entities = Array.from(this.selectedEntities);
|
||||||
|
|
||||||
// Build mapping from uid to entity
|
// Build mapping from uid to entity
|
||||||
/**
|
/**
|
||||||
@ -104,11 +108,11 @@ 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 < entities.length; ++i) {
|
||||||
const uid = entityUids[i];
|
const entity = mapUidToEntity.get(entities[i].uid);
|
||||||
const entity = mapUidToEntity.get(uid);
|
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
logger.error("Entity not found by uid:", uid);
|
logger.warn("Invalid Entity in Selected Entities");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,11 +123,11 @@ export class HUDMassSelector extends BaseHUDPart {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Clear uids later
|
// Clear uids later
|
||||||
this.selectedUids = new Set();
|
this.selectedEntities = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
startCopy() {
|
startCopy() {
|
||||||
if (this.selectedUids.size > 0) {
|
if (this.selectedEntities.length > 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,
|
||||||
@ -131,8 +135,10 @@ export class HUDMassSelector extends BaseHUDPart {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.root.hud.signals.buildingsSelectedForCopy.dispatch(Array.from(this.selectedUids));
|
|
||||||
this.selectedUids = new Set();
|
this.root.hud.signals.buildingsSelectedForCopy.dispatch(this.selectedEntities);
|
||||||
|
|
||||||
|
this.selectedEntities = [];
|
||||||
this.root.soundProxy.playUiClick();
|
this.root.soundProxy.playUiClick();
|
||||||
} else {
|
} else {
|
||||||
this.root.soundProxy.playUiError();
|
this.root.soundProxy.playUiError();
|
||||||
@ -147,13 +153,13 @@ export class HUDMassSelector extends BaseHUDPart {
|
|||||||
);
|
);
|
||||||
} else if (
|
} else if (
|
||||||
!this.root.app.settings.getAllSettings().disableCutDeleteWarnings &&
|
!this.root.app.settings.getAllSettings().disableCutDeleteWarnings &&
|
||||||
this.selectedUids.size > 100
|
this.selectedEntities.length > 100
|
||||||
) {
|
) {
|
||||||
const { ok } = this.root.hud.parts.dialogs.showWarning(
|
const { ok } = this.root.hud.parts.dialogs.showWarning(
|
||||||
T.dialogs.massCutConfirm.title,
|
T.dialogs.massCutConfirm.title,
|
||||||
T.dialogs.massCutConfirm.desc.replace(
|
T.dialogs.massCutConfirm.desc.replace(
|
||||||
"<count>",
|
"<count>",
|
||||||
"" + formatBigNumberFull(this.selectedUids.size)
|
"" + formatBigNumberFull(this.selectedEntities.length)
|
||||||
),
|
),
|
||||||
["cancel:good:escape", "ok:bad:enter"]
|
["cancel:good:escape", "ok:bad:enter"]
|
||||||
);
|
);
|
||||||
@ -164,24 +170,22 @@ export class HUDMassSelector extends BaseHUDPart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
doCut() {
|
doCut() {
|
||||||
if (this.selectedUids.size > 0) {
|
if (this.selectedEntities.length > 0) {
|
||||||
const entityUids = Array.from(this.selectedUids);
|
const entities = Array.from(this.selectedEntities);
|
||||||
|
|
||||||
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(entities);
|
||||||
|
|
||||||
for (let i = 0; i < entityUids.length; ++i) {
|
for (let i = 0; i < entities.length; ++i) {
|
||||||
const uid = entityUids[i];
|
const entity = entities[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");
|
logger.error("Error in mass cut, could not remove building");
|
||||||
this.selectedUids.delete(uid);
|
this.selectedEntities.splice(i, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const blueprint = Blueprint.fromUids(this.root, entityUids);
|
const blueprint = Blueprint.fromEntities(this.root, entities);
|
||||||
if (blueprint.canAfford(this.root)) {
|
if (blueprint.canAfford(this.root)) {
|
||||||
cutAction();
|
cutAction();
|
||||||
} else {
|
} else {
|
||||||
@ -219,7 +223,7 @@ export class HUDMassSelector extends BaseHUDPart {
|
|||||||
|
|
||||||
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.selectedEntities = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentSelectionStartWorld = this.root.camera.screenToWorld(pos.copy());
|
this.currentSelectionStartWorld = this.root.camera.screenToWorld(pos.copy());
|
||||||
@ -260,7 +264,7 @@ export class HUDMassSelector extends BaseHUDPart {
|
|||||||
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 && this.root.logic.canDeleteBuilding(entity))
|
if (entity && this.root.logic.canDeleteBuilding(entity))
|
||||||
this.selectedUids.add(entity.uid);
|
this.selectedEntities.push(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -334,11 +338,15 @@ export class HUDMassSelector extends BaseHUDPart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//EXTREMELY SLOW. There must be a better way. (Possibly use a Array)
|
//EXTREMELY SLOW. There must be a better way. (Possibly use a Array)
|
||||||
this.selectedUids.forEach(uid => {
|
for(let i = 0; i < this.selectedEntities.length; ++ i){
|
||||||
const entity = this.root.entityMgr.findByUid(uid);
|
const entity = this.selectedEntities[i];
|
||||||
|
|
||||||
this.RenderSelectonPreviewTile(parameters, entity);
|
this.RenderSelectonPreviewTile(parameters, entity);
|
||||||
});
|
}
|
||||||
|
// this.selectedUids.forEach(uid => {
|
||||||
|
// const entity = this.root.entityMgr.findByUid(uid);
|
||||||
|
|
||||||
|
// this.RenderSelectonPreviewTile(parameters, entity);
|
||||||
|
// });
|
||||||
|
|
||||||
parameters.context.globalAlpha = 1;
|
parameters.context.globalAlpha = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user