mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Refactor smart underground belt logic
This commit is contained in:
parent
d452234c72
commit
f204189fdb
@ -4,6 +4,7 @@ export const CHANGELOG = [
|
||||
date: "unreleased",
|
||||
entries: [
|
||||
"Allow configuring autosave interval and disabling it in the settings",
|
||||
"The smart-tunnel placement has been reworked to properly replace belts. Thus the setting has been turned on again by default",
|
||||
"The soundtrack now has a higher quality on the standalone version than the web version",
|
||||
"Add setting to disable cut/delete warnings (by hexy)",
|
||||
"Fix bug where belts in blueprints don't orient correctly (by hexy)",
|
||||
|
@ -77,6 +77,7 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
||||
const tier = undergroundComp.tier;
|
||||
const range = globalConfig.undergroundBeltMaxTilesByTier[tier];
|
||||
|
||||
// FIND ENTRANCE
|
||||
// Search for the entrance which is furthes apart (this is why we can't reuse logic here)
|
||||
let matchingEntrance = null;
|
||||
for (let i = 0; i < range; ++i) {
|
||||
@ -104,31 +105,49 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove any belts between entrance and exit which have the same direction
|
||||
// DETECT OBSOLETE BELTS BETWEEN
|
||||
// Remove any belts between entrance and exit which have the same direction,
|
||||
// but only if they *all* have the right direction
|
||||
currentPos = tile.copy();
|
||||
let allBeltsMatch = true;
|
||||
for (let i = 0; i < matchingEntrance.range; ++i) {
|
||||
currentPos.addInplace(offset);
|
||||
|
||||
const contents = this.root.map.getTileContent(currentPos);
|
||||
if (!contents) {
|
||||
continue;
|
||||
allBeltsMatch = false;
|
||||
break;
|
||||
}
|
||||
|
||||
const contentsStaticComp = contents.components.StaticMapEntity;
|
||||
const contentsBeltComp = contents.components.Belt;
|
||||
if (!contentsBeltComp) {
|
||||
allBeltsMatch = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (contentsBeltComp) {
|
||||
// It's a belt
|
||||
if (
|
||||
contentsBeltComp.direction === enumDirection.top &&
|
||||
enumAngleToDirection[contentsStaticComp.rotation] === direction
|
||||
) {
|
||||
// It's same rotation, drop it
|
||||
this.root.logic.tryDeleteBuilding(contents);
|
||||
}
|
||||
// It's a belt
|
||||
if (
|
||||
contentsBeltComp.direction !== enumDirection.top ||
|
||||
enumAngleToDirection[contentsStaticComp.rotation] !== direction
|
||||
) {
|
||||
allBeltsMatch = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
currentPos = tile.copy();
|
||||
if (allBeltsMatch) {
|
||||
// All belts between this are obsolete, so drop them
|
||||
for (let i = 0; i < matchingEntrance.range; ++i) {
|
||||
currentPos.addInplace(offset);
|
||||
const contents = this.root.map.getTileContent(currentPos);
|
||||
assert(contents, "Invalid smart underground belt logic");
|
||||
this.root.logic.tryDeleteBuilding(contents);
|
||||
}
|
||||
}
|
||||
|
||||
// REMOVE OBSOLETE TUNNELS
|
||||
// Remove any double tunnels, by checking the tile plus the tile above
|
||||
currentPos = tile.copy().add(offset);
|
||||
for (let i = 0; i < matchingEntrance.range - 1; ++i) {
|
||||
|
@ -468,7 +468,7 @@ export class ApplicationSettings extends ReadWriteProxy {
|
||||
}
|
||||
|
||||
getCurrentVersion() {
|
||||
return 15;
|
||||
return 16;
|
||||
}
|
||||
|
||||
/** @param {{settings: SettingsStorage, version: number}} data */
|
||||
@ -530,6 +530,12 @@ export class ApplicationSettings extends ReadWriteProxy {
|
||||
data.version = 15;
|
||||
}
|
||||
|
||||
if (data.version < 16) {
|
||||
// RE-ENABLE this setting, it already existed
|
||||
data.settings.enableTunnelSmartplace = true;
|
||||
data.version = 16;
|
||||
}
|
||||
|
||||
return ExplainedResult.good();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user