mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Pipette
This commit is contained in:
parent
38114ff3f6
commit
0b31ad0c7b
@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
@include DarkThemeOverride {
|
@include DarkThemeOverride {
|
||||||
.gameLoadingOverlay {
|
.gameLoadingOverlay {
|
||||||
background: #56565c;
|
background: $darkModeGameBackground;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ import { HUDPartTutorialHints } from "./parts/tutorial_hints";
|
|||||||
import { HUDWaypoints } from "./parts/waypoints";
|
import { HUDWaypoints } from "./parts/waypoints";
|
||||||
import { HUDInteractiveTutorial } from "./parts/interactive_tutorial";
|
import { HUDInteractiveTutorial } from "./parts/interactive_tutorial";
|
||||||
import { HUDScreenshotExporter } from "./parts/screenshot_exporter";
|
import { HUDScreenshotExporter } from "./parts/screenshot_exporter";
|
||||||
|
import { Entity } from "../entity";
|
||||||
|
|
||||||
export class GameHUD {
|
export class GameHUD {
|
||||||
/**
|
/**
|
||||||
@ -75,6 +76,7 @@ export class GameHUD {
|
|||||||
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<number>]>} */ (new Signal()),
|
||||||
|
pipetteExecuted: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
|
||||||
pasteBlueprintRequested: new Signal(),
|
pasteBlueprintRequested: new Signal(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import { makeDiv } from "../../../core/utils";
|
|||||||
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
||||||
import { blueprintShape } from "../../upgrades";
|
import { blueprintShape } from "../../upgrades";
|
||||||
import { T } from "../../../translations";
|
import { T } from "../../../translations";
|
||||||
|
import { PipetteBlueprint } from "./pipette_blueprint";
|
||||||
|
|
||||||
export class HUDBlueprintPlacer extends BaseHUDPart {
|
export class HUDBlueprintPlacer extends BaseHUDPart {
|
||||||
createElements(parent) {
|
createElements(parent) {
|
||||||
@ -34,11 +35,9 @@ export class HUDBlueprintPlacer extends BaseHUDPart {
|
|||||||
|
|
||||||
const keyActionMapper = this.root.keyMapper;
|
const keyActionMapper = this.root.keyMapper;
|
||||||
keyActionMapper.getBinding(KEYMAPPINGS.general.back).add(this.abortPlacement, this);
|
keyActionMapper.getBinding(KEYMAPPINGS.general.back).add(this.abortPlacement, this);
|
||||||
keyActionMapper
|
|
||||||
.getBinding(KEYMAPPINGS.placement.abortBuildingPlacement)
|
|
||||||
.add(this.abortPlacement, this);
|
|
||||||
keyActionMapper.getBinding(KEYMAPPINGS.placement.rotateWhilePlacing).add(this.rotateBlueprint, this);
|
keyActionMapper.getBinding(KEYMAPPINGS.placement.rotateWhilePlacing).add(this.rotateBlueprint, this);
|
||||||
keyActionMapper.getBinding(KEYMAPPINGS.massSelect.pasteLastBlueprint).add(this.pasteBlueprint, this);
|
keyActionMapper.getBinding(KEYMAPPINGS.massSelect.pasteLastBlueprint).add(this.pasteBlueprint, this);
|
||||||
|
keyActionMapper.getBinding(KEYMAPPINGS.placement.pipette).add(this.startPipette, this);
|
||||||
|
|
||||||
this.root.camera.downPreHandler.add(this.onMouseDown, this);
|
this.root.camera.downPreHandler.add(this.onMouseDown, this);
|
||||||
this.root.camera.movePreHandler.add(this.onMouseMove, this);
|
this.root.camera.movePreHandler.add(this.onMouseMove, this);
|
||||||
@ -57,15 +56,36 @@ export class HUDBlueprintPlacer extends BaseHUDPart {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the pipette function
|
||||||
|
*/
|
||||||
|
startPipette() {
|
||||||
|
const mousePosition = this.root.app.mousePosition;
|
||||||
|
if (!mousePosition) {
|
||||||
|
// Not on screen
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const worldPos = this.root.camera.screenToWorld(mousePosition);
|
||||||
|
const tile = worldPos.toTileSpace();
|
||||||
|
const contents = this.root.map.getTileContent(tile);
|
||||||
|
if (contents) {
|
||||||
|
const blueprint = PipetteBlueprint.fromEntity(contents);
|
||||||
|
|
||||||
|
// Notice: Order here matters, since pipetteExecuted clears the blueprint
|
||||||
|
this.root.hud.signals.pipetteExecuted.dispatch(contents);
|
||||||
|
this.currentBlueprint.set(blueprint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onCanAffordChanged(canAfford) {
|
onCanAffordChanged(canAfford) {
|
||||||
this.costDisplayParent.classList.toggle("canAfford", canAfford);
|
this.costDisplayParent.classList.toggle("canAfford", canAfford);
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
this.domAttach.update(this.currentBlueprint.get());
|
const currentBlueprint = this.currentBlueprint.get();
|
||||||
this.trackedCanAfford.set(
|
this.domAttach.update(currentBlueprint && currentBlueprint.getCost() > 0);
|
||||||
this.currentBlueprint.get() && this.currentBlueprint.get().canAfford(this.root)
|
this.trackedCanAfford.set(currentBlueprint && currentBlueprint.canAfford(this.root));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,15 +97,13 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
keyActionMapper
|
keyActionMapper
|
||||||
.getBinding(KEYMAPPINGS.placement.switchDirectionLockSide)
|
.getBinding(KEYMAPPINGS.placement.switchDirectionLockSide)
|
||||||
.add(this.switchDirectionLockSide, this);
|
.add(this.switchDirectionLockSide, this);
|
||||||
keyActionMapper
|
|
||||||
.getBinding(KEYMAPPINGS.placement.abortBuildingPlacement)
|
|
||||||
.add(this.abortPlacement, this);
|
|
||||||
keyActionMapper.getBinding(KEYMAPPINGS.general.back).add(this.abortPlacement, this);
|
keyActionMapper.getBinding(KEYMAPPINGS.general.back).add(this.abortPlacement, this);
|
||||||
this.root.gameState.inputReciever.keyup.add(this.checkForDirectionLockSwitch, this);
|
this.root.gameState.inputReciever.keyup.add(this.checkForDirectionLockSwitch, this);
|
||||||
|
|
||||||
// BINDINGS TO GAME EVENTS
|
// BINDINGS TO GAME EVENTS
|
||||||
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);
|
||||||
|
this.root.hud.signals.pipetteExecuted.add(this.abortPlacement, this);
|
||||||
this.root.signals.storyGoalCompleted.add(() => this.signals.variantChanged.dispatch());
|
this.root.signals.storyGoalCompleted.add(() => this.signals.variantChanged.dispatch());
|
||||||
this.root.signals.upgradePurchased.add(() => this.signals.variantChanged.dispatch());
|
this.root.signals.upgradePurchased.add(() => this.signals.variantChanged.dispatch());
|
||||||
|
|
||||||
|
@ -164,10 +164,17 @@ export class HUDKeybindingOverlay extends BaseHUDPart {
|
|||||||
condition: () => this.mapOverviewActive && !this.blueprintPlacementActive,
|
condition: () => this.mapOverviewActive && !this.blueprintPlacementActive,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// Pipette
|
||||||
|
label: T.ingame.keybindingsOverlay.pipette,
|
||||||
|
keys: [k.placement.pipette],
|
||||||
|
condition: () => !this.mapOverviewActive,
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
// Cancel placement
|
// Cancel placement
|
||||||
label: T.ingame.keybindingsOverlay.stopPlacement,
|
label: T.ingame.keybindingsOverlay.stopPlacement,
|
||||||
keys: [KEYCODE_RMB, DIVIDER_TOKEN, k.placement.abortBuildingPlacement],
|
keys: [KEYCODE_RMB],
|
||||||
condition: () => this.anyPlacementActive,
|
condition: () => this.anyPlacementActive,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
23
src/js/game/hud/parts/pipette_blueprint.js
Normal file
23
src/js/game/hud/parts/pipette_blueprint.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { Vector } from "../../../core/vector";
|
||||||
|
import { Entity } from "../../entity";
|
||||||
|
import { Blueprint } from "./blueprint";
|
||||||
|
|
||||||
|
export class PipetteBlueprint extends Blueprint {
|
||||||
|
/**
|
||||||
|
* @see Blueprint.getCost
|
||||||
|
*/
|
||||||
|
getCost() {
|
||||||
|
// Its free
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new pipetted blueprint from a given entity
|
||||||
|
* @param {Entity} entity
|
||||||
|
*/
|
||||||
|
static fromEntity(entity) {
|
||||||
|
const clone = entity.duplicateWithoutContents();
|
||||||
|
clone.components.StaticMapEntity.origin = new Vector(0, 0);
|
||||||
|
return new PipetteBlueprint([clone]);
|
||||||
|
}
|
||||||
|
}
|
@ -24,7 +24,7 @@ export const KEYMAPPINGS = {
|
|||||||
menuOpenStats: { keyCode: key("G") },
|
menuOpenStats: { keyCode: key("G") },
|
||||||
|
|
||||||
toggleHud: { keyCode: 113 }, // F2
|
toggleHud: { keyCode: 113 }, // F2
|
||||||
exportScreenshot: { keyCode: 114 }, // F3
|
exportScreenshot: { keyCode: 114 }, // F3PS
|
||||||
toggleFPSInfo: { keyCode: 115 }, // F4
|
toggleFPSInfo: { keyCode: 115 }, // F4
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ export const KEYMAPPINGS = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
placement: {
|
placement: {
|
||||||
abortBuildingPlacement: { keyCode: key("Q") },
|
pipette: { keyCode: key("Q") },
|
||||||
rotateWhilePlacing: { keyCode: key("R") },
|
rotateWhilePlacing: { keyCode: key("R") },
|
||||||
rotateInverseModifier: { keyCode: 16 }, // SHIFT
|
rotateInverseModifier: { keyCode: 16 }, // SHIFT
|
||||||
cycleBuildingVariants: { keyCode: key("T") },
|
cycleBuildingVariants: { keyCode: key("T") },
|
||||||
|
@ -288,6 +288,7 @@ ingame:
|
|||||||
cutSelection: Cut
|
cutSelection: Cut
|
||||||
copySelection: Copy
|
copySelection: Copy
|
||||||
clearSelection: Clear Selection
|
clearSelection: Clear Selection
|
||||||
|
pipette: Pipette
|
||||||
|
|
||||||
# Everything related to placing buildings (I.e. as soon as you selected a building
|
# Everything related to placing buildings (I.e. as soon as you selected a building
|
||||||
# from the toolbar)
|
# from the toolbar)
|
||||||
@ -738,7 +739,7 @@ keybindings:
|
|||||||
painter: *painter
|
painter: *painter
|
||||||
trash: *trash
|
trash: *trash
|
||||||
|
|
||||||
abortBuildingPlacement: Abort Placement
|
pipette: Pipette
|
||||||
rotateWhilePlacing: Rotate
|
rotateWhilePlacing: Rotate
|
||||||
rotateInverseModifier: >-
|
rotateInverseModifier: >-
|
||||||
Modifier: Rotate CCW instead
|
Modifier: Rotate CCW instead
|
||||||
|
Loading…
Reference in New Issue
Block a user