mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Add belt lock feature
This commit is contained in:
parent
b753187cde
commit
35a13a09e5
@ -1,4 +1,4 @@
|
|||||||
import { Math_abs, Math_degrees, Math_radians } from "../../../core/builtins";
|
import { Math_abs, Math_degrees, Math_radians, Math_sign } from "../../../core/builtins";
|
||||||
import { globalConfig } from "../../../core/config";
|
import { globalConfig } from "../../../core/config";
|
||||||
import { DrawParameters } from "../../../core/draw_parameters";
|
import { DrawParameters } from "../../../core/draw_parameters";
|
||||||
import { drawRotatedSprite } from "../../../core/draw_utils";
|
import { drawRotatedSprite } from "../../../core/draw_utils";
|
||||||
@ -20,6 +20,7 @@ import { BaseHUDPart } from "../base_hud_part";
|
|||||||
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
||||||
import { T } from "../../../translations";
|
import { T } from "../../../translations";
|
||||||
import { KEYMAPPINGS } from "../../key_action_mapper";
|
import { KEYMAPPINGS } from "../../key_action_mapper";
|
||||||
|
import { THEME } from "../../theme";
|
||||||
|
|
||||||
export class HUDBuildingPlacer extends BaseHUDPart {
|
export class HUDBuildingPlacer extends BaseHUDPart {
|
||||||
initialize() {
|
initialize() {
|
||||||
@ -38,6 +39,7 @@ export class HUDBuildingPlacer extends BaseHUDPart {
|
|||||||
|
|
||||||
keyActionMapper.getBinding(KEYMAPPINGS.placement.rotateWhilePlacing).add(this.tryRotate, this);
|
keyActionMapper.getBinding(KEYMAPPINGS.placement.rotateWhilePlacing).add(this.tryRotate, this);
|
||||||
keyActionMapper.getBinding(KEYMAPPINGS.placement.cycleBuildingVariants).add(this.cycleVariants, this);
|
keyActionMapper.getBinding(KEYMAPPINGS.placement.cycleBuildingVariants).add(this.cycleVariants, this);
|
||||||
|
keyActionMapper.getBinding(KEYMAPPINGS.placement.lockBeltDirection).add(this.resetBeltLock, this);
|
||||||
|
|
||||||
this.root.hud.signals.buildingsSelectedForCopy.add(this.abortPlacement, this);
|
this.root.hud.signals.buildingsSelectedForCopy.add(this.abortPlacement, this);
|
||||||
this.root.hud.signals.pasteBlueprintRequested.add(this.abortPlacement, this);
|
this.root.hud.signals.pasteBlueprintRequested.add(this.abortPlacement, this);
|
||||||
@ -76,6 +78,12 @@ export class HUDBuildingPlacer extends BaseHUDPart {
|
|||||||
*/
|
*/
|
||||||
this.initialDragTile = null;
|
this.initialDragTile = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The first initial placement direction we performed
|
||||||
|
* @type {Vector}
|
||||||
|
*/
|
||||||
|
this.initialPlacementVector = null;
|
||||||
|
|
||||||
this.root.signals.storyGoalCompleted.add(this.rerenderVariants, this);
|
this.root.signals.storyGoalCompleted.add(this.rerenderVariants, this);
|
||||||
this.root.signals.upgradePurchased.add(this.rerenderVariants, this);
|
this.root.signals.upgradePurchased.add(this.rerenderVariants, this);
|
||||||
}
|
}
|
||||||
@ -106,6 +114,13 @@ export class HUDBuildingPlacer extends BaseHUDPart {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets the belt lock, called after pressing shift
|
||||||
|
*/
|
||||||
|
resetBeltLock() {
|
||||||
|
this.initialPlacementVector = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mouse down pre handler
|
* mouse down pre handler
|
||||||
* @param {Vector} pos
|
* @param {Vector} pos
|
||||||
@ -150,7 +165,7 @@ export class HUDBuildingPlacer extends BaseHUDPart {
|
|||||||
const metaBuilding = this.currentMetaBuilding.get();
|
const metaBuilding = this.currentMetaBuilding.get();
|
||||||
if ((metaBuilding || this.currentlyDeleting) && this.lastDragTile) {
|
if ((metaBuilding || this.currentlyDeleting) && this.lastDragTile) {
|
||||||
const oldPos = this.lastDragTile;
|
const oldPos = this.lastDragTile;
|
||||||
const newPos = this.root.camera.screenToWorld(pos).toTileSpace();
|
let newPos = this.root.camera.screenToWorld(pos).toTileSpace();
|
||||||
|
|
||||||
if (this.root.camera.desiredCenter) {
|
if (this.root.camera.desiredCenter) {
|
||||||
// Camera is moving
|
// Camera is moving
|
||||||
@ -158,6 +173,20 @@ export class HUDBuildingPlacer extends BaseHUDPart {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Direction lock
|
||||||
|
if (
|
||||||
|
this.root.keyMapper.getBinding(KEYMAPPINGS.placement.lockBeltDirection).isCurrentlyPressed()
|
||||||
|
) {
|
||||||
|
if (this.initialPlacementVector) {
|
||||||
|
const lockX = Math_abs(Math_sign(this.initialPlacementVector.x));
|
||||||
|
const lockY = Math_abs(Math_sign(this.initialPlacementVector.y));
|
||||||
|
const delta = newPos.sub(oldPos);
|
||||||
|
delta.x *= lockX;
|
||||||
|
delta.y *= lockY;
|
||||||
|
newPos = oldPos.add(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!oldPos.equals(newPos)) {
|
if (!oldPos.equals(newPos)) {
|
||||||
if (
|
if (
|
||||||
metaBuilding &&
|
metaBuilding &&
|
||||||
@ -200,6 +229,12 @@ export class HUDBuildingPlacer extends BaseHUDPart {
|
|||||||
this.root.logic.tryDeleteBuilding(contents);
|
this.root.logic.tryDeleteBuilding(contents);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (!this.initialPlacementVector) {
|
||||||
|
const origin = newPos.sub(oldPos);
|
||||||
|
console.log("ORIGIN:", origin);
|
||||||
|
this.initialPlacementVector = origin;
|
||||||
|
}
|
||||||
|
|
||||||
this.tryPlaceCurrentBuildingAt(new Vector(x0, y0));
|
this.tryPlaceCurrentBuildingAt(new Vector(x0, y0));
|
||||||
}
|
}
|
||||||
if (x0 === x1 && y0 === y1) break;
|
if (x0 === x1 && y0 === y1) break;
|
||||||
@ -235,6 +270,7 @@ export class HUDBuildingPlacer extends BaseHUDPart {
|
|||||||
abortDragging() {
|
abortDragging() {
|
||||||
this.currentlyDragging = true;
|
this.currentlyDragging = true;
|
||||||
this.currentlyDeleting = false;
|
this.currentlyDeleting = false;
|
||||||
|
this.initialPlacementVector = null;
|
||||||
this.lastDragTile = null;
|
this.lastDragTile = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -637,6 +673,32 @@ export class HUDBuildingPlacer extends BaseHUDPart {
|
|||||||
if (canBuild) {
|
if (canBuild) {
|
||||||
this.drawMatchingAcceptorsAndEjectors(parameters);
|
this.drawMatchingAcceptorsAndEjectors(parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw direction lock
|
||||||
|
|
||||||
|
if (this.root.keyMapper.getBinding(KEYMAPPINGS.placement.lockBeltDirection).isCurrentlyPressed()) {
|
||||||
|
if (this.lastDragTile && this.initialPlacementVector) {
|
||||||
|
parameters.context.fillStyle = THEME.map.selectionBackground;
|
||||||
|
parameters.context.strokeStyle = THEME.map.selectionOverlay;
|
||||||
|
parameters.context.lineWidth = 3;
|
||||||
|
|
||||||
|
const startLine = this.lastDragTile.toWorldSpaceCenterOfTile();
|
||||||
|
const endLine = tile.toWorldSpaceCenterOfTile();
|
||||||
|
|
||||||
|
parameters.context.beginCircle(startLine.x, startLine.y, 7);
|
||||||
|
parameters.context.fill();
|
||||||
|
parameters.context.stroke();
|
||||||
|
|
||||||
|
parameters.context.beginPath();
|
||||||
|
parameters.context.moveTo(startLine.x, startLine.y);
|
||||||
|
parameters.context.lineTo(endLine.x, endLine.y);
|
||||||
|
parameters.context.stroke();
|
||||||
|
|
||||||
|
parameters.context.beginCircle(endLine.x, endLine.y, 4);
|
||||||
|
parameters.context.fill();
|
||||||
|
parameters.context.stroke();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,6 +61,7 @@ export const KEYMAPPINGS = {
|
|||||||
rotateInverseModifier: { keyCode: 16 }, // SHIFT
|
rotateInverseModifier: { keyCode: 16 }, // SHIFT
|
||||||
cycleBuildingVariants: { keyCode: key("T") },
|
cycleBuildingVariants: { keyCode: key("T") },
|
||||||
cycleBuildings: { keyCode: 9 }, // TAB
|
cycleBuildings: { keyCode: 9 }, // TAB
|
||||||
|
lockBeltDirection: { keyCode: 16 }, // SHIFT
|
||||||
},
|
},
|
||||||
|
|
||||||
massSelect: {
|
massSelect: {
|
||||||
|
@ -735,6 +735,7 @@ keybindings:
|
|||||||
confirmMassDelete: Confirm Mass Delete
|
confirmMassDelete: Confirm Mass Delete
|
||||||
pasteLastBlueprint: Paste last blueprint
|
pasteLastBlueprint: Paste last blueprint
|
||||||
cycleBuildings: Cycle Buildings
|
cycleBuildings: Cycle Buildings
|
||||||
|
lockBeltDirection: Lock Belt Direction
|
||||||
|
|
||||||
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