1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

Puzzle Mode fixes: Correct zone restrictions and more (#1155)

* Hide Puzzle Editor Controls in regular game mode, fix typo

* Disallow shrinking zone if there are buildings

* Fix multi-tile buildings for shrinking
This commit is contained in:
dengr1065 2021-04-30 18:57:01 +03:00 committed by GitHub
parent 569921b51a
commit 36aaf7bfa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 33 additions and 20 deletions

View File

@ -72,7 +72,7 @@ export class Rectangle {
/** /**
* Returns if this rectangle is equal to the other while taking an epsilon into account * Returns if this rectangle is equal to the other while taking an epsilon into account
* @param {Rectangle} other * @param {Rectangle} other
* @param {number} epsilon * @param {number} [epsilon]
*/ */
equalsEpsilon(other, epsilon) { equalsEpsilon(other, epsilon) {
return ( return (

View File

@ -47,7 +47,7 @@ export class GameMode extends BasicSerializableObject {
constructor(root) { constructor(root) {
super(); super();
this.root = root; this.root = root;
this.hiddenHurtParts = {}; this.hiddenHudParts = {};
/** @type {typeof MetaBuilding[]} */ /** @type {typeof MetaBuilding[]} */
this.hiddenBuildings = [MetaItemProducerBuilding]; this.hiddenBuildings = [MetaItemProducerBuilding];
@ -83,7 +83,7 @@ export class GameMode extends BasicSerializableObject {
* @returns {boolean} * @returns {boolean}
*/ */
isHudPartExcluded(name) { isHudPartExcluded(name) {
return this.hiddenHurtParts[name] === false; return this.hiddenHudParts[name] === false;
} }
/** /**
@ -142,7 +142,7 @@ export class GameMode extends BasicSerializableObject {
* @param {number} w * @param {number} w
* @param {number} h * @param {number} h
*/ */
expandZone(w = 0, h = 0) { adjustZone(w = 0, h = 0) {
abstract; abstract;
return; return;
} }

View File

@ -234,7 +234,7 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
* @param {DrawParameters} parameters * @param {DrawParameters} parameters
*/ */
draw(parameters) { draw(parameters) {
if (this.root.camera.zoomLevel < globalConfig.mapChunkOverviewMinZoom) { if (this.root.camera.getIsMapOverlayActive()) {
// Dont allow placing in overview mode // Dont allow placing in overview mode
this.domAttach.update(false); this.domAttach.update(false);
this.variantsAttach.update(false); this.variantsAttach.update(false);

View File

@ -430,7 +430,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
* @param {Vector} tile * @param {Vector} tile
*/ */
tryPlaceCurrentBuildingAt(tile) { tryPlaceCurrentBuildingAt(tile) {
if (this.root.camera.zoomLevel < globalConfig.mapChunkOverviewMinZoom) { if (this.root.camera.getIsMapOverlayActive()) {
// Dont allow placing in overview mode // Dont allow placing in overview mode
return; return;
} }

View File

@ -48,7 +48,7 @@ export class HUDModeSettings extends BaseHUDPart {
} }
modifyZone(width, height) { modifyZone(width, height) {
this.root.gameMode.expandZone(width, height); this.root.gameMode.adjustZone(width, height);
this.updateZoneValues(); this.updateZoneValues();
} }

View File

@ -32,7 +32,7 @@ export class PuzzleGameMode extends GameMode {
const data = this.getSaveData(); const data = this.getSaveData();
this.hiddenHurtParts = { this.hiddenHudParts = {
[HUDGameMenu.name]: false, [HUDGameMenu.name]: false,
[HUDMassSelector.name]: false, [HUDMassSelector.name]: false,
[HUDInteractiveTutorial.name]: false, [HUDInteractiveTutorial.name]: false,

View File

@ -55,16 +55,30 @@ export class PuzzleEditGameMode extends PuzzleGameMode {
]; ];
} }
expandZone(w = 0, h = 0) { adjustZone(w = 0, h = 0) {
if (this.zoneWidth + w > 0) { // @todo notify user when zone cannot be shrunk
this.zoneWidth += w; if (this.zoneWidth + w <= 0) {
return;
} }
if (this.zoneHeight + h > 0) { if (this.zoneHeight + h <= 0) {
this.zoneHeight += h; return;
} }
this.zone = this.createCenteredRectangle(this.zoneWidth, this.zoneHeight); const newZone = this.createCenteredRectangle(this.zoneWidth + w, this.zoneHeight + h);
const entities = this.root.entityMgr.entities;
// @fixme find a better way to check this
for (const entity of entities) {
const staticComp = entity.components.StaticMapEntity;
const union = newZone.getUnion(staticComp.getTileSpaceBounds());
if (!union.equalsEpsilon(newZone)) {
return;
}
}
this.zoneWidth = newZone.w;
this.zoneHeight = newZone.h;
} }
getIsEditor() { getIsEditor() {

View File

@ -13,6 +13,7 @@ import { enumGameModeIds, enumGameModeTypes, GameMode } from "../game_mode";
import { ShapeDefinition } from "../shape_definition"; import { ShapeDefinition } from "../shape_definition";
import { enumHubGoalRewards } from "../tutorial_goals"; import { enumHubGoalRewards } from "../tutorial_goals";
import { HUDPuzzleDLCLogo } from "../hud/parts/puzzle_dlc_logo"; import { HUDPuzzleDLCLogo } from "../hud/parts/puzzle_dlc_logo";
import { HUDPuzzleEditorControls } from "../hud/parts/puzzle_editor_controls";
/** @typedef {{ /** @typedef {{
* shape: string, * shape: string,
@ -516,12 +517,13 @@ export class RegularGameMode extends GameMode {
constructor(root) { constructor(root) {
super(root); super(root);
this.hiddenHurtParts = { this.hiddenHudParts = {
[HUDModeMenuBack.name]: false, [HUDModeMenuBack.name]: false,
[HUDPuzzleReview.name]: false, [HUDPuzzleReview.name]: false,
[HUDModeMenu.name]: false, [HUDModeMenu.name]: false,
[HUDModeSettings.name]: false, [HUDModeSettings.name]: false,
[HUDPuzzleDLCLogo.name]: false, [HUDPuzzleDLCLogo.name]: false,
[HUDPuzzleEditorControls.name]: false,
}; };
this.hiddenBuildings = [MetaConstantProducerBuilding, MetaGoalAcceptorBuilding]; this.hiddenBuildings = [MetaConstantProducerBuilding, MetaGoalAcceptorBuilding];

View File

@ -49,17 +49,14 @@ export class ZoneSystem extends GameSystem {
transformed.y += tile.y; transformed.y += tile.y;
} }
let withinAnyZone = false;
for (const zone of zones) { for (const zone of zones) {
const intersection = zone.getIntersection(transformed); const intersection = zone.getIntersection(transformed);
if (intersection && intersection.w * intersection.h === transformed.w * transformed.h) { if (intersection && intersection.w * intersection.h === transformed.w * transformed.h) {
withinAnyZone = true; return;
} }
} }
if (!withinAnyZone) { return STOP_PROPAGATION;
return STOP_PROPAGATION;
}
} }
/** /**