1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Fix keys being stuck, show savegame levels in main menu

This commit is contained in:
tobspr
2020-05-28 14:53:11 +02:00
parent 2a4ee8e784
commit e0facaf788
28 changed files with 175 additions and 138 deletions

View File

@@ -873,19 +873,19 @@ export class Camera extends BasicSerializableObject {
let forceY = 0;
const actionMapper = this.root.keyMapper;
if (actionMapper.getBinding(KEYMAPPINGS.ingame.mapMoveUp).currentlyDown) {
if (actionMapper.getBinding(KEYMAPPINGS.ingame.mapMoveUp).isCurrentlyPressed()) {
forceY -= 1;
}
if (actionMapper.getBinding(KEYMAPPINGS.ingame.mapMoveDown).currentlyDown) {
if (actionMapper.getBinding(KEYMAPPINGS.ingame.mapMoveDown).isCurrentlyPressed()) {
forceY += 1;
}
if (actionMapper.getBinding(KEYMAPPINGS.ingame.mapMoveLeft).currentlyDown) {
if (actionMapper.getBinding(KEYMAPPINGS.ingame.mapMoveLeft).isCurrentlyPressed()) {
forceX -= 1;
}
if (actionMapper.getBinding(KEYMAPPINGS.ingame.mapMoveRight).currentlyDown) {
if (actionMapper.getBinding(KEYMAPPINGS.ingame.mapMoveRight).isCurrentlyPressed()) {
forceX += 1;
}

View File

@@ -59,6 +59,7 @@ export class GameHUD {
vignetteOverlay: new HUDVignetteOverlay(this.root),
// Must always exist
pinnedShapes: new HUDPinnedShapes(this.root),
notifications: new HUDNotifications(this.root),

View File

@@ -59,7 +59,7 @@ export class HUDBlueprintPlacer extends BaseHUDPart {
const tile = worldPos.toTileSpace();
if (blueprint.tryPlace(this.root, tile)) {
// This actually feels weird
// if (!this.root.keyMapper.getBinding(KEYMAPPINGS.placementModifiers.placeMultiple).currentlyDown) {
// if (!this.root.keyMapper.getBinding(KEYMAPPINGS.placementModifiers.placeMultiple).isCurrentlyPressed()) {
// this.currentBlueprint.set(null);
// }
}
@@ -84,7 +84,11 @@ export class HUDBlueprintPlacer extends BaseHUDPart {
rotateBlueprint() {
if (this.currentBlueprint.get()) {
if (this.root.keyMapper.getBinding(KEYMAPPINGS.placement.rotateInverseModifier).currentlyDown) {
if (
this.root.keyMapper
.getBinding(KEYMAPPINGS.placement.rotateInverseModifier)
.isCurrentlyPressed()
) {
this.currentBlueprint.get().rotateCcw();
} else {
this.currentBlueprint.get().rotateCw();

View File

@@ -161,9 +161,9 @@ export class HUDBuildingPlacer extends BaseHUDPart {
if (
metaBuilding &&
metaBuilding.getRotateAutomaticallyWhilePlacing(this.currentVariant.get()) &&
!this.root.keyMapper.getBinding(
KEYMAPPINGS.placementModifiers.placementDisableAutoOrientation
).currentlyDown
!this.root.keyMapper
.getBinding(KEYMAPPINGS.placementModifiers.placementDisableAutoOrientation)
.isCurrentlyPressed()
) {
const delta = newPos.sub(oldPos);
const angleDeg = Math_degrees(delta.angle());
@@ -171,8 +171,9 @@ export class HUDBuildingPlacer extends BaseHUDPart {
// Holding alt inverts the placement
if (
this.root.keyMapper.getBinding(KEYMAPPINGS.placementModifiers.placeInverse)
.currentlyDown
this.root.keyMapper
.getBinding(KEYMAPPINGS.placementModifiers.placeInverse)
.isCurrentlyPressed()
) {
this.currentBaseRotation = (180 + this.currentBaseRotation) % 360;
}
@@ -394,7 +395,11 @@ export class HUDBuildingPlacer extends BaseHUDPart {
tryRotate() {
const selectedBuilding = this.currentMetaBuilding.get();
if (selectedBuilding) {
if (this.root.keyMapper.getBinding(KEYMAPPINGS.placement.rotateInverseModifier).currentlyDown) {
if (
this.root.keyMapper
.getBinding(KEYMAPPINGS.placement.rotateInverseModifier)
.isCurrentlyPressed()
) {
this.currentBaseRotation = (this.currentBaseRotation + 270) % 360;
} else {
this.currentBaseRotation = (this.currentBaseRotation + 90) % 360;
@@ -479,16 +484,18 @@ export class HUDBuildingPlacer extends BaseHUDPart {
if (
metaBuilding.getFlipOrientationAfterPlacement() &&
!this.root.keyMapper.getBinding(
KEYMAPPINGS.placementModifiers.placementDisableAutoOrientation
).currentlyDown
!this.root.keyMapper
.getBinding(KEYMAPPINGS.placementModifiers.placementDisableAutoOrientation)
.isCurrentlyPressed()
) {
this.currentBaseRotation = (180 + this.currentBaseRotation) % 360;
}
if (
!metaBuilding.getStayInPlacementMode() &&
!this.root.keyMapper.getBinding(KEYMAPPINGS.placementModifiers.placeMultiple).currentlyDown &&
!this.root.keyMapper
.getBinding(KEYMAPPINGS.placementModifiers.placeMultiple)
.isCurrentlyPressed() &&
!this.root.app.settings.getAllSettings().alwaysMultiplace
) {
// Stop placement

View File

@@ -12,6 +12,7 @@ import { enumMouseButton } from "../../camera";
import { T } from "../../../translations";
import { KEYMAPPINGS } from "../../key_action_mapper";
import { THEME } from "../../theme";
import { enumHubGoalRewards } from "../../tutorial_goals";
const logger = createLogger("hud/mass_selector");
@@ -30,9 +31,9 @@ export class HUDMassSelector extends BaseHUDPart {
"ingame_HUD_MassSelector",
[],
T.ingame.massSelect.infoText
.replace("<keyDelete>", removalKeybinding)
.replace("<keyCopy>", copyKeybinding)
.replace("<keyCancel>", abortKeybinding)
.replace("<keyDelete>", `<code class='keybinding'>${removalKeybinding}</code>`)
.replace("<keyCopy>", `<code class='keybinding'>${copyKeybinding}</code>`)
.replace("<keyCancel>", `<code class='keybinding'>${abortKeybinding}</code>`)
);
}
@@ -107,6 +108,13 @@ export class HUDMassSelector extends BaseHUDPart {
startCopy() {
if (this.selectedUids.size > 0) {
if (!this.root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_blueprints)) {
this.root.hud.parts.dialogs.showInfo(
T.dialogs.blueprintsNotUnlocked.title,
T.dialogs.blueprintsNotUnlocked.desc
);
return;
}
this.root.hud.signals.buildingsSelectedForCopy.dispatch(Array.from(this.selectedUids));
this.selectedUids = new Set();
this.root.soundProxy.playUiClick();
@@ -121,7 +129,7 @@ export class HUDMassSelector extends BaseHUDPart {
* @param {enumMouseButton} mouseButton
*/
onMouseDown(pos, mouseButton) {
if (!this.root.keyMapper.getBinding(KEYMAPPINGS.massSelect.massSelectStart).currentlyDown) {
if (!this.root.keyMapper.getBinding(KEYMAPPINGS.massSelect.massSelectStart).isCurrentlyPressed()) {
return;
}
@@ -129,7 +137,11 @@ export class HUDMassSelector extends BaseHUDPart {
return;
}
if (!this.root.keyMapper.getBinding(KEYMAPPINGS.massSelect.massSelectSelectMultiple).currentlyDown) {
if (
!this.root.keyMapper
.getBinding(KEYMAPPINGS.massSelect.massSelectSelectMultiple)
.isCurrentlyPressed()
) {
// Start new selection
this.selectedUids = new Set();
}

View File

@@ -9,6 +9,19 @@ export class HUDPinnedShapes extends BaseHUDPart {
this.element = makeDiv(parent, "ingame_HUD_PinnedShapes", []);
}
serialize() {
return {
shapes: this.pinnedShapes,
};
}
deserialize(data) {
if (!data || !data.shapes || !Array.isArray(data.shapes)) {
return "Invalid pinned shapes data";
}
this.pinnedShapes = data.shapes;
}
initialize() {
/** @type {Array<{ key: string, goal: number }>} */
this.pinnedShapes = [];

View File

@@ -89,9 +89,10 @@ export class HUDUnlockNotification extends BaseHUDPart {
clearTimeout(this.buttonShowTimeout);
}
this.element.querySelector("button.close").classList.remove("unlocked");
this.buttonShowTimeout = setTimeout(
() => this.element.querySelector("button.close").classList.add("unlocked"),
G_IS_DEV ? 1000 : 10000
10000
);
}

View File

@@ -235,12 +235,17 @@ export class Keybinding {
this.builtin = builtin;
this.repeated = repeated;
this.currentlyDown = false;
this.signal = new Signal();
this.toggled = new Signal();
}
/**
* Returns whether this binding is currently pressed
*/
isCurrentlyPressed() {
return this.app.inputMgr.keysDown.has(this.keyCode);
}
/**
* Adds an event listener
* @param {function() : void} receiver
@@ -350,7 +355,6 @@ export class KeyActionMapper {
for (const key in this.keybindings) {
/** @type {Keybinding} */
const binding = this.keybindings[key];
binding.currentlyDown = false;
}
}
@@ -360,17 +364,16 @@ export class KeyActionMapper {
* @param {number} param0.keyCode
* @param {boolean} param0.shift
* @param {boolean} param0.alt
* @param {boolean=} param0.initial
*/
handleKeydown({ keyCode, shift, alt }) {
handleKeydown({ keyCode, shift, alt, initial }) {
let stop = false;
// Find mapping
for (const key in this.keybindings) {
/** @type {Keybinding} */
const binding = this.keybindings[key];
if (binding.keyCode === keyCode && (!binding.currentlyDown || binding.repeated)) {
binding.currentlyDown = true;
if (binding.keyCode === keyCode && (initial || binding.repeated)) {
/** @type {Signal} */
const signal = this.keybindings[key].signal;
if (signal.dispatch() === STOP_PROPAGATION) {
@@ -392,13 +395,7 @@ export class KeyActionMapper {
* @param {boolean} param0.alt
*/
handleKeyup({ keyCode, shift, alt }) {
for (const key in this.keybindings) {
/** @type {Keybinding} */
const binding = this.keybindings[key];
if (binding.keyCode === keyCode) {
binding.currentlyDown = false;
}
}
// Empty
}
/**

View File

@@ -23,6 +23,7 @@ export const enumHubGoalRewards = {
reward_painter_quad: "reward_painter_quad",
reward_storage: "reward_storage",
reward_blueprints: "reward_blueprints",
reward_freeplay: "reward_freeplay",
no_reward: "no_reward",
@@ -65,14 +66,14 @@ export const tutorialGoals = [
// Rotater
{
shape: "Cu----Cu", // belts t2
required: 300,
required: 200,
reward: enumHubGoalRewards.reward_tunnel,
},
// 6
{
shape: "Cu------", // miners t2
required: 500,
required: 400,
reward: enumHubGoalRewards.reward_painter,
},
@@ -80,14 +81,14 @@ export const tutorialGoals = [
// Painter
{
shape: "CrCrCrCr", // unused
required: 1000,
required: 800,
reward: enumHubGoalRewards.reward_rotater_ccw,
},
// 8
{
shape: "RbRb----", // painter t2
required: 1500,
required: 1250,
reward: enumHubGoalRewards.reward_mixer,
},
@@ -95,7 +96,7 @@ export const tutorialGoals = [
// Mixing (purple)
{
shape: "CpCpCpCp", // belts t3
required: 2500,
required: 1750,
reward: enumHubGoalRewards.reward_splitter_compact,
},
@@ -103,7 +104,7 @@ export const tutorialGoals = [
// Star shape + cyan
{
shape: "ScScScSc", // miners t3
required: 5000,
required: 2250,
reward: enumHubGoalRewards.reward_stacker,
},
@@ -111,46 +112,54 @@ export const tutorialGoals = [
// Stacker
{
shape: "CgScScCg", // processors t3
required: 6000,
required: 3000,
reward: enumHubGoalRewards.reward_miner_chainable,
},
// 12
// Blueprints
{
shape: "RpRpRpRp:CwCwCwCw", // painting t3
required: 7000,
reward: enumHubGoalRewards.reward_underground_belt_tier_2,
shape: "CbCbCbRb:CwCwCwCw",
required: 4000,
reward: enumHubGoalRewards.reward_blueprints,
},
// 13
{
shape: "SrSrSrSr:CyCyCyCy", // unused
required: 7850,
reward: enumHubGoalRewards.reward_storage,
shape: "RpRpRpRp:CwCwCwCw", // painting t3
required: 9000,
reward: enumHubGoalRewards.reward_underground_belt_tier_2,
},
// 14
{
shape: "SrSrSrSr:CyCyCyCy:SwSwSwSw", // belts t4 (two variants)
required: 8000,
reward: enumHubGoalRewards.reward_cutter_quad,
shape: "SrSrSrSr:CyCyCyCy", // unused
required: 12000,
reward: enumHubGoalRewards.reward_storage,
},
// 15
{
shape: "CbRbRbCb:CwCwCwCw:WbWbWbWb", // miner t4 (two variants)
required: 9000,
reward: enumHubGoalRewards.reward_painter_double,
shape: "SrSrSrSr:CyCyCyCy:SwSwSwSw", // belts t4 (two variants)
required: 14000,
reward: enumHubGoalRewards.reward_cutter_quad,
},
// 16
{
shape: "WrRgWrRg:CwCrCwCr:SgSgSgSg", // processors t4 (two varinats)
required: 10000,
reward: enumHubGoalRewards.reward_painter_quad,
shape: "CbRbRbCb:CwCwCwCw:WbWbWbWb", // miner t4 (two variants)
required: 17000,
reward: enumHubGoalRewards.reward_painter_double,
},
// 17
{
shape: "WrRgWrRg:CwCrCwCr:SgSgSgSg", // processors t4 (two varinats)
required: 30000,
reward: enumHubGoalRewards.reward_painter_quad,
},
// 18
{
shape: finalGameShape,
required: 50000,

View File

@@ -2,6 +2,7 @@ import { findNiceIntegerValue } from "../core/utils";
import { ShapeDefinition } from "./shape_definition";
export const finalGameShape = "RuCw--Cw:----Ru--";
export const blueprintShape = "CbCbCbRb:CwCwCwCw";
export const UPGRADES = {
belt: {