mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Placing blueprints no longer triggers the redirection of belts.
This commit is contained in:
parent
affac62a66
commit
03670eb403
@ -8,6 +8,7 @@ import { findNiceIntegerValue } from "../../../core/utils";
|
|||||||
import { Math_pow } from "../../../core/builtins";
|
import { Math_pow } from "../../../core/builtins";
|
||||||
import { blueprintShape } from "../../upgrades";
|
import { blueprintShape } from "../../upgrades";
|
||||||
import { globalConfig } from "../../../core/config";
|
import { globalConfig } from "../../../core/config";
|
||||||
|
import { Rectangle } from "../../../core/rectangle";
|
||||||
|
|
||||||
const logger = createLogger("blueprint");
|
const logger = createLogger("blueprint");
|
||||||
|
|
||||||
@ -176,6 +177,15 @@ export class Blueprint {
|
|||||||
tryPlace(root, tile) {
|
tryPlace(root, tile) {
|
||||||
return root.logic.performBulkOperation(() => {
|
return root.logic.performBulkOperation(() => {
|
||||||
let anyPlaced = false;
|
let anyPlaced = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To avoid recomputing belt direction when belts are placed, we manually
|
||||||
|
* recompute the belt cache without redirecting the belts by calculating the
|
||||||
|
* area that needs to update.
|
||||||
|
* @type {Rectangle?}
|
||||||
|
*/
|
||||||
|
let rectCoveredByBlueprint = null;
|
||||||
|
|
||||||
for (let i = 0; i < this.entities.length; ++i) {
|
for (let i = 0; i < this.entities.length; ++i) {
|
||||||
let placeable = true;
|
let placeable = true;
|
||||||
const entity = this.entities[i];
|
const entity = this.entities[i];
|
||||||
@ -216,9 +226,21 @@ export class Blueprint {
|
|||||||
|
|
||||||
root.map.placeStaticEntity(clone);
|
root.map.placeStaticEntity(clone);
|
||||||
root.entityMgr.registerEntity(clone);
|
root.entityMgr.registerEntity(clone);
|
||||||
|
if (rectCoveredByBlueprint === null) {
|
||||||
|
rectCoveredByBlueprint = rect.clone();
|
||||||
|
} else {
|
||||||
|
rectCoveredByBlueprint = rectCoveredByBlueprint.getUnion(rect);
|
||||||
|
}
|
||||||
anyPlaced = true;
|
anyPlaced = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (anyPlaced) {
|
||||||
|
logger.log(rectCoveredByBlueprint);
|
||||||
|
root.signals.blueprintPlacedUpdateBeltCache.dispatch(
|
||||||
|
rectCoveredByBlueprint.expandedInAllDirections(1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return anyPlaced;
|
return anyPlaced;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
/* eslint-disable no-unused-vars */
|
/* eslint-disable no-unused-vars */
|
||||||
|
|
||||||
import { Signal } from "../core/signal";
|
import { Signal } from "../core/signal";
|
||||||
|
import { Rectangle } from "../core/rectangle";
|
||||||
import { RandomNumberGenerator } from "../core/rng";
|
import { RandomNumberGenerator } from "../core/rng";
|
||||||
import { createLogger } from "../core/logging";
|
import { createLogger } from "../core/logging";
|
||||||
|
|
||||||
@ -133,6 +134,9 @@ export class GameRoot {
|
|||||||
entityQueuedForDestroy: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
|
entityQueuedForDestroy: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
|
||||||
entityDestroyed: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
|
entityDestroyed: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
|
||||||
|
|
||||||
|
// Special case for updating when a blueprint is placed.
|
||||||
|
blueprintPlacedUpdateBeltCache: /** @type {TypedSignal<[Rectangle]>} */ (new Signal()),
|
||||||
|
|
||||||
// Global
|
// Global
|
||||||
resized: /** @type {TypedSignal<[number, number]>} */ (new Signal()),
|
resized: /** @type {TypedSignal<[number, number]>} */ (new Signal()),
|
||||||
readyToRender: /** @type {TypedSignal<[]>} */ (new Signal()),
|
readyToRender: /** @type {TypedSignal<[]>} */ (new Signal()),
|
||||||
|
|||||||
@ -61,7 +61,8 @@ export class BeltSystem extends GameSystemWithFilter {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
this.root.signals.entityAdded.add(this.updateSurroundingBeltPlacement, this);
|
this.root.signals.entityManuallyPlaced.add(this.updateSurroundingBeltPlacement, this);
|
||||||
|
this.root.signals.blueprintPlacedUpdateBeltCache.add(this.updateAreaToRecompute, this);
|
||||||
this.root.signals.entityDestroyed.add(this.updateSurroundingBeltPlacement, this);
|
this.root.signals.entityDestroyed.add(this.updateSurroundingBeltPlacement, this);
|
||||||
this.root.signals.postLoadHook.add(this.computeBeltCache, this);
|
this.root.signals.postLoadHook.add(this.computeBeltCache, this);
|
||||||
|
|
||||||
@ -69,6 +70,19 @@ export class BeltSystem extends GameSystemWithFilter {
|
|||||||
this.areaToRecompute = null;
|
this.areaToRecompute = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queue the recomputation of the belt cache for the given affected area the change happened
|
||||||
|
* @param {Rectangle} affectedArea
|
||||||
|
*/
|
||||||
|
updateAreaToRecompute(affectedArea) {
|
||||||
|
if (this.areaToRecompute) {
|
||||||
|
this.areaToRecompute = this.areaToRecompute.getUnion(affectedArea);
|
||||||
|
} else {
|
||||||
|
this.areaToRecompute = affectedArea.clone();
|
||||||
|
}
|
||||||
|
logger.log("Queuing recompute:", this.areaToRecompute);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the belt placement after an entity has been added / deleted
|
* Updates the belt placement after an entity has been added / deleted
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
@ -123,12 +137,7 @@ export class BeltSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (anythingChanged) {
|
if (anythingChanged) {
|
||||||
if (this.areaToRecompute) {
|
this.updateAreaToRecompute(affectedArea);
|
||||||
this.areaToRecompute = this.areaToRecompute.getUnion(affectedArea);
|
|
||||||
} else {
|
|
||||||
this.areaToRecompute = affectedArea.clone();
|
|
||||||
}
|
|
||||||
logger.log("Queuing recompute:", this.areaToRecompute);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user