mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Add override shape and swap button for sandbox panel
This commit is contained in:
parent
f1d1cf29c5
commit
e195744480
@ -21,7 +21,7 @@
|
|||||||
.plusMinus {
|
.plusMinus {
|
||||||
@include S(margin-top, 4px);
|
@include S(margin-top, 4px);
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr auto auto;
|
grid-template-columns: 1fr auto auto auto;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@include S(grid-gap, 4px);
|
@include S(grid-gap, 4px);
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,10 @@ import { makeDiv } from "../../../core/utils";
|
|||||||
import { BaseHUDPart } from "../base_hud_part";
|
import { BaseHUDPart } from "../base_hud_part";
|
||||||
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
||||||
import { enumNotificationType } from "./notifications";
|
import { enumNotificationType } from "./notifications";
|
||||||
|
import { ShapeDefinition } from "../../shape_definition";
|
||||||
|
import { DialogWithForm } from "../../../core/modal_dialog_elements";
|
||||||
|
import { FormElementInput, FormElementItemChooser } from "../../../core/modal_dialog_forms";
|
||||||
|
import { HubGoals } from "../../hub_goals";
|
||||||
|
|
||||||
export class HUDSandboxController extends BaseHUDPart {
|
export class HUDSandboxController extends BaseHUDPart {
|
||||||
createElements(parent) {
|
createElements(parent) {
|
||||||
@ -16,30 +20,35 @@ export class HUDSandboxController extends BaseHUDPart {
|
|||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<div class="levelToggle plusMinus">
|
<div class="levelToggle plusMinus">
|
||||||
<label>Level</label>
|
<label>Level</label>
|
||||||
|
<button class="styledButton reset">⮂</button>
|
||||||
<button class="styledButton minus">-</button>
|
<button class="styledButton minus">-</button>
|
||||||
<button class="styledButton plus">+</button>
|
<button class="styledButton plus">+</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="upgradesBelt plusMinus">
|
<div class="upgradesBelt plusMinus">
|
||||||
<label>Upgrades → Belt</label>
|
<label>→ Belt</label>
|
||||||
|
<button class="styledButton reset">⮂</button>
|
||||||
<button class="styledButton minus">-</button>
|
<button class="styledButton minus">-</button>
|
||||||
<button class="styledButton plus">+</button>
|
<button class="styledButton plus">+</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="upgradesExtraction plusMinus">
|
<div class="upgradesExtraction plusMinus">
|
||||||
<label>Upgrades → Extraction</label>
|
<label>→ Extraction</label>
|
||||||
|
<button class="styledButton reset">⮂</button>
|
||||||
<button class="styledButton minus">-</button>
|
<button class="styledButton minus">-</button>
|
||||||
<button class="styledButton plus">+</button>
|
<button class="styledButton plus">+</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="upgradesProcessing plusMinus">
|
<div class="upgradesProcessing plusMinus">
|
||||||
<label>Upgrades → Processing</label>
|
<label>→ Processing</label>
|
||||||
|
<button class="styledButton reset">⮂</button>
|
||||||
<button class="styledButton minus">-</button>
|
<button class="styledButton minus">-</button>
|
||||||
<button class="styledButton plus">+</button>
|
<button class="styledButton plus">+</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="upgradesPainting plusMinus">
|
<div class="upgradesPainting plusMinus">
|
||||||
<label>Upgrades → Painting</label>
|
<label>→ Painting</label>
|
||||||
|
<button class="styledButton reset">⮂</button>
|
||||||
<button class="styledButton minus">-</button>
|
<button class="styledButton minus">-</button>
|
||||||
<button class="styledButton plus">+</button>
|
<button class="styledButton plus">+</button>
|
||||||
</div>
|
</div>
|
||||||
@ -50,6 +59,7 @@ export class HUDSandboxController extends BaseHUDPart {
|
|||||||
<button class="styledButton bigPlus">+100 All</button>
|
<button class="styledButton bigPlus">+100 All</button>
|
||||||
</div>
|
</div>
|
||||||
<button class="styledButton giveBlueprints">Fill blueprint shapes</button>
|
<button class="styledButton giveBlueprints">Fill blueprint shapes</button>
|
||||||
|
<button class="styledButton levelOverride">Override level</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
@ -60,18 +70,24 @@ export class HUDSandboxController extends BaseHUDPart {
|
|||||||
bind(".giveBlueprints", this.giveBlueprints);
|
bind(".giveBlueprints", this.giveBlueprints);
|
||||||
bind(".bigMinus", () => this.modifyAll(-100));
|
bind(".bigMinus", () => this.modifyAll(-100));
|
||||||
bind(".bigPlus", () => this.modifyAll(100));
|
bind(".bigPlus", () => this.modifyAll(100));
|
||||||
|
bind(".levelToggle .reset", this.resetLevel);
|
||||||
bind(".levelToggle .minus", () => this.modifyLevel(-1));
|
bind(".levelToggle .minus", () => this.modifyLevel(-1));
|
||||||
bind(".levelToggle .plus", () => this.modifyLevel(1));
|
bind(".levelToggle .plus", () => this.modifyLevel(1));
|
||||||
|
bind(".levelOverride", this.promptOverrideLevel);
|
||||||
|
|
||||||
|
bind(".upgradesBelt .reset", () => this.resetUpgrade("belt"));
|
||||||
bind(".upgradesBelt .minus", () => this.modifyUpgrade("belt", -1));
|
bind(".upgradesBelt .minus", () => this.modifyUpgrade("belt", -1));
|
||||||
bind(".upgradesBelt .plus", () => this.modifyUpgrade("belt", 1));
|
bind(".upgradesBelt .plus", () => this.modifyUpgrade("belt", 1));
|
||||||
|
|
||||||
|
bind(".upgradesExtraction .reset", () => this.resetUpgrade("miner"));
|
||||||
bind(".upgradesExtraction .minus", () => this.modifyUpgrade("miner", -1));
|
bind(".upgradesExtraction .minus", () => this.modifyUpgrade("miner", -1));
|
||||||
bind(".upgradesExtraction .plus", () => this.modifyUpgrade("miner", 1));
|
bind(".upgradesExtraction .plus", () => this.modifyUpgrade("miner", 1));
|
||||||
|
|
||||||
|
bind(".upgradesProcessing .reset", () => this.resetUpgrade("processors"));
|
||||||
bind(".upgradesProcessing .minus", () => this.modifyUpgrade("processors", -1));
|
bind(".upgradesProcessing .minus", () => this.modifyUpgrade("processors", -1));
|
||||||
bind(".upgradesProcessing .plus", () => this.modifyUpgrade("processors", 1));
|
bind(".upgradesProcessing .plus", () => this.modifyUpgrade("processors", 1));
|
||||||
|
|
||||||
|
bind(".upgradesPainting .reset", () => this.resetUpgrade("painting"));
|
||||||
bind(".upgradesPainting .minus", () => this.modifyUpgrade("painting", -1));
|
bind(".upgradesPainting .minus", () => this.modifyUpgrade("painting", -1));
|
||||||
bind(".upgradesPainting .plus", () => this.modifyUpgrade("painting", 1));
|
bind(".upgradesPainting .plus", () => this.modifyUpgrade("painting", 1));
|
||||||
}
|
}
|
||||||
@ -91,6 +107,16 @@ export class HUDSandboxController extends BaseHUDPart {
|
|||||||
this.modifyUpgrade("painting", amount);
|
this.modifyUpgrade("painting", amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resetUpgrade(id) {
|
||||||
|
const maxLevel = this.root.gameMode.getUpgrades()[id].length;
|
||||||
|
|
||||||
|
if (this.root.hubGoals.upgradeLevels[id] === maxLevel) {
|
||||||
|
this.modifyUpgrade(id, -this.root.hubGoals.upgradeLevels[id]);
|
||||||
|
} else {
|
||||||
|
this.modifyUpgrade(id, maxLevel - this.root.hubGoals.upgradeLevels[id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
modifyUpgrade(id, amount) {
|
modifyUpgrade(id, amount) {
|
||||||
const upgradeTiers = this.root.gameMode.getUpgrades()[id];
|
const upgradeTiers = this.root.gameMode.getUpgrades()[id];
|
||||||
const maxLevel = upgradeTiers.length;
|
const maxLevel = upgradeTiers.length;
|
||||||
@ -113,6 +139,16 @@ export class HUDSandboxController extends BaseHUDPart {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resetLevel(a) {
|
||||||
|
const level = this.root.hubGoals.level;
|
||||||
|
const levelCount = this.root.gameMode.getLevelDefinitions().length;
|
||||||
|
if (level === levelCount + 1) {
|
||||||
|
this.modifyLevel(1 - level);
|
||||||
|
} else {
|
||||||
|
this.modifyLevel(levelCount + 1 - level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
modifyLevel(amount) {
|
modifyLevel(amount) {
|
||||||
const hubGoals = this.root.hubGoals;
|
const hubGoals = this.root.hubGoals;
|
||||||
hubGoals.level = Math.max(1, hubGoals.level + amount);
|
hubGoals.level = Math.max(1, hubGoals.level + amount);
|
||||||
@ -121,8 +157,6 @@ export class HUDSandboxController extends BaseHUDPart {
|
|||||||
// Clear all shapes of this level
|
// Clear all shapes of this level
|
||||||
hubGoals.storedShapes[hubGoals.currentGoal.definition.getHash()] = 0;
|
hubGoals.storedShapes[hubGoals.currentGoal.definition.getHash()] = 0;
|
||||||
|
|
||||||
this.root.hud.parts.pinnedShapes.rerenderFull();
|
|
||||||
|
|
||||||
// Compute gained rewards
|
// Compute gained rewards
|
||||||
hubGoals.gainedRewards = {};
|
hubGoals.gainedRewards = {};
|
||||||
const levels = this.root.gameMode.getLevelDefinitions();
|
const levels = this.root.gameMode.getLevelDefinitions();
|
||||||
@ -133,12 +167,53 @@ export class HUDSandboxController extends BaseHUDPart {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.root.buffers.cache.get("hub").clear();
|
||||||
|
this.root.hud.parts.pinnedShapes.rerenderFull();
|
||||||
|
|
||||||
this.root.hud.signals.notification.dispatch(
|
this.root.hud.signals.notification.dispatch(
|
||||||
"Changed level to " + hubGoals.level,
|
"Changed level to " + hubGoals.level,
|
||||||
enumNotificationType.upgrade
|
enumNotificationType.upgrade
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
promptOverrideLevel() {
|
||||||
|
const signalValueInput = new FormElementInput({
|
||||||
|
id: "signalValue",
|
||||||
|
label: null,
|
||||||
|
placeholder: "",
|
||||||
|
defaultValue: "",
|
||||||
|
validator: val => ShapeDefinition.isValidShortKey(val),
|
||||||
|
});
|
||||||
|
|
||||||
|
const dialog = new DialogWithForm({
|
||||||
|
app: this.root.app,
|
||||||
|
title: "Override Level",
|
||||||
|
desc: "Enter shape to override with:",
|
||||||
|
formElements: [signalValueInput],
|
||||||
|
buttons: ["cancel:bad:escape", "ok:good:enter"],
|
||||||
|
closeButton: false,
|
||||||
|
});
|
||||||
|
this.root.hud.parts.dialogs.internalShowDialog(dialog);
|
||||||
|
|
||||||
|
dialog.buttonSignals.ok.add(() => this.overrideLevel(signalValueInput.getValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
overrideLevel(shape) {
|
||||||
|
console.log(shape);
|
||||||
|
const hubGoals = this.root.hubGoals;
|
||||||
|
hubGoals.currentGoal.definition = this.root.shapeDefinitionMgr.getShapeFromShortKey(shape);
|
||||||
|
|
||||||
|
hubGoals.storedShapes[hubGoals.currentGoal.definition.getHash()] = 0;
|
||||||
|
|
||||||
|
this.root.buffers.cache.get("hub").clear();
|
||||||
|
this.root.hud.parts.pinnedShapes.rerenderFull();
|
||||||
|
|
||||||
|
this.root.hud.signals.notification.dispatch(
|
||||||
|
"Overrode level to " + hubGoals.currentGoal.definition.getHash(),
|
||||||
|
enumNotificationType.upgrade
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
initialize() {
|
initialize() {
|
||||||
// Allow toggling the controller overlay
|
// Allow toggling the controller overlay
|
||||||
this.root.gameState.inputReciever.keydown.add(key => {
|
this.root.gameState.inputReciever.keydown.add(key => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user