mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-02-21 23:39:20 +00:00
rewrite pipette to determine type using unplaced clones
This commit is contained in:
parent
d6c1cb15f6
commit
bc3f785d1b
@ -93,6 +93,7 @@ export class HUDBuildingsToolbar extends BaseHUDPart {
|
|||||||
|
|
||||||
this.lastSelectedIndex = 0;
|
this.lastSelectedIndex = 0;
|
||||||
actionMapper.getBinding(KEYMAPPINGS.placement.cycleBuildings).add(this.cycleBuildings, this);
|
actionMapper.getBinding(KEYMAPPINGS.placement.cycleBuildings).add(this.cycleBuildings, this);
|
||||||
|
actionMapper.getBinding(KEYMAPPINGS.placement.pipette).add(this.usePipette, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
@ -123,6 +124,101 @@ export class HUDBuildingsToolbar extends BaseHUDPart {
|
|||||||
this.selectBuildingForPlacement(metaBuilding);
|
this.selectBuildingForPlacement(metaBuilding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
detectPippeted(entity) {
|
||||||
|
const alike = [];
|
||||||
|
for (let i = 0; i < toolbarBuildings.length; ++i) {
|
||||||
|
const metaBuilding = gMetaBuildingRegistry.findByClass(toolbarBuildings[i]);
|
||||||
|
const handle = this.buildingHandles[metaBuilding.id];
|
||||||
|
if (!handle.unlocked) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const availableVariants = metaBuilding.getAvailableVariants(this.root);
|
||||||
|
checkVariant: for (let variant of availableVariants) {
|
||||||
|
let unplaced = metaBuilding.createUnplacedEntity({ root: this.root, variant });
|
||||||
|
// compare props
|
||||||
|
for (let c in entity.components) {
|
||||||
|
if (
|
||||||
|
(entity.components[c] && !unplaced.components[c]) ||
|
||||||
|
(!entity.components[c] && unplaced.components[c])
|
||||||
|
) {
|
||||||
|
continue checkVariant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
entity.components.ItemProcessor &&
|
||||||
|
entity.components.ItemProcessor.type != unplaced.components.ItemProcessor.type
|
||||||
|
) {
|
||||||
|
continue checkVariant;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
entity.components.UndergroundBelt &&
|
||||||
|
entity.components.UndergroundBelt.tier != unplaced.components.UndergroundBelt.tier
|
||||||
|
) {
|
||||||
|
continue checkVariant;
|
||||||
|
}
|
||||||
|
// tecnically this one is enough without all others BUT ubelts
|
||||||
|
if (
|
||||||
|
entity.components.StaticMapEntity.spriteKey !=
|
||||||
|
unplaced.components.StaticMapEntity.spriteKey &&
|
||||||
|
!entity.components.UndergroundBelt
|
||||||
|
) {
|
||||||
|
console.log("ignored %o cuz other sprite", unplaced);
|
||||||
|
continue checkVariant;
|
||||||
|
}
|
||||||
|
console.log("%O is probably %O (%s/%s)", entity, unplaced, metaBuilding.id, variant);
|
||||||
|
alike.push({ metaBuilding, variant, unplaced });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (alike.length == 1) {
|
||||||
|
let staticEntity = entity.components.StaticMapEntity;
|
||||||
|
let key = staticEntity.spriteKey || staticEntity.blueprintSpriteKey;
|
||||||
|
assertAlways(
|
||||||
|
key &&
|
||||||
|
key.includes(alike[0].metaBuilding.id) &&
|
||||||
|
(alike[0].variant == "default" || key.includes(alike[0].variant))
|
||||||
|
);
|
||||||
|
return alike[0];
|
||||||
|
}
|
||||||
|
if (alike.length > 1) {
|
||||||
|
console.warn("multiple alike buildings:", alike);
|
||||||
|
}
|
||||||
|
console.log("entity is unknown", entity);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
usePipette() {
|
||||||
|
if (this.root.hud.parts.buildingPlacer.currentMetaBuilding.get()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.root.camera.getIsMapOverlayActive()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const mousePos = this.root.app.mousePosition;
|
||||||
|
if (!mousePos) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const worldPos = this.root.camera.screenToWorld(mousePos);
|
||||||
|
const worldTile = worldPos.toTileSpace();
|
||||||
|
|
||||||
|
const entity = this.root.map.getTileContent(worldTile);
|
||||||
|
if (!entity) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let detected = this.detectPippeted(entity);
|
||||||
|
|
||||||
|
if (detected) {
|
||||||
|
this.selectBuildingForPlacement(detected.metaBuilding);
|
||||||
|
this.root.hud.parts.buildingPlacer.currentVariant.set(detected.variant);
|
||||||
|
this.root.hud.parts.buildingPlacer.currentBaseRotation =
|
||||||
|
(Math.round(entity.components.StaticMapEntity.originalRotation / 90) * 90 + 360) % 360;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {MetaBuilding} metaBuilding
|
* @param {MetaBuilding} metaBuilding
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -62,6 +62,7 @@ export const KEYMAPPINGS = {
|
|||||||
cycleBuildingVariants: { keyCode: key("T") },
|
cycleBuildingVariants: { keyCode: key("T") },
|
||||||
cycleBuildings: { keyCode: 9 }, // TAB
|
cycleBuildings: { keyCode: 9 }, // TAB
|
||||||
switchDirectionLockSide: { keyCode: key("R") },
|
switchDirectionLockSide: { keyCode: key("R") },
|
||||||
|
pipette: { keyCode: key("Q") },
|
||||||
},
|
},
|
||||||
|
|
||||||
massSelect: {
|
massSelect: {
|
||||||
|
|||||||
@ -136,6 +136,50 @@ export class MetaBuilding {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the entity but does not adds it to world
|
||||||
|
* @param {object} param0
|
||||||
|
* @param {GameRoot} param0.root
|
||||||
|
* @param {Vector} [param0.origin] Origin tile
|
||||||
|
* @param {number=} [param0.rotation] Rotation
|
||||||
|
* @param {number} [param0.originalRotation] Original Rotation
|
||||||
|
* @param {number} [param0.rotationVariant] Rotation variant
|
||||||
|
* @param {string} param0.variant
|
||||||
|
*/
|
||||||
|
createUnplacedEntity({
|
||||||
|
root,
|
||||||
|
origin = new Vector(9999, 9999),
|
||||||
|
rotation = 0,
|
||||||
|
originalRotation = 0,
|
||||||
|
rotationVariant = 0,
|
||||||
|
variant,
|
||||||
|
}) {
|
||||||
|
const entity = new Entity(root);
|
||||||
|
|
||||||
|
const blueprintSprite = this.getBlueprintSprite(rotationVariant, variant);
|
||||||
|
|
||||||
|
entity.addComponent(
|
||||||
|
new StaticMapEntityComponent({
|
||||||
|
spriteKey:
|
||||||
|
"sprites/buildings/" +
|
||||||
|
this.id +
|
||||||
|
(variant === defaultBuildingVariant ? "" : "-" + variant) +
|
||||||
|
".png",
|
||||||
|
origin: new Vector(origin.x, origin.y),
|
||||||
|
rotation,
|
||||||
|
originalRotation,
|
||||||
|
tileSize: this.getDimensions(variant).copy(),
|
||||||
|
silhouetteColor: this.getSilhouetteColor(),
|
||||||
|
blueprintSpriteKey: blueprintSprite ? blueprintSprite.spriteName : "",
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
this.setupEntityComponents(entity, root);
|
||||||
|
this.updateVariants(entity, rotationVariant, variant);
|
||||||
|
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the entity at the given location
|
* Creates the entity at the given location
|
||||||
* @param {object} param0
|
* @param {object} param0
|
||||||
|
|||||||
@ -746,6 +746,7 @@ keybindings:
|
|||||||
lockBeltDirection: Enable belt planner
|
lockBeltDirection: Enable belt planner
|
||||||
switchDirectionLockSide: >-
|
switchDirectionLockSide: >-
|
||||||
Planner: Switch side
|
Planner: Switch side
|
||||||
|
pipette: Pipette (select hovered)
|
||||||
|
|
||||||
massSelectStart: Hold and drag to start
|
massSelectStart: Hold and drag to start
|
||||||
massSelectSelectMultiple: Select multiple areas
|
massSelectSelectMultiple: Select multiple areas
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user