mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 06:53:31 +08:00
UXAssist: new feature for 1.2.20
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UXAssist.Functions;
|
||||
|
||||
public static class FactoryFunctions
|
||||
@@ -19,4 +21,76 @@ public static class FactoryFunctions
|
||||
cargoTraffic._arrInputs(ref i0, ref i1, ref i2);
|
||||
cargoTraffic.AlterBeltConnections(beltId, 0, i0, i1, i2);
|
||||
}
|
||||
|
||||
public static void DismantleBlueprintSelectedBuildings()
|
||||
{
|
||||
var player = GameMain.mainPlayer;
|
||||
var build = player?.controller?.actionBuild;
|
||||
if (build == null) return;
|
||||
var blueprintCopyTool = build.blueprintCopyTool;
|
||||
if (blueprintCopyTool == null || !blueprintCopyTool.active) return;
|
||||
var factory = build.factory;
|
||||
List<int> buildPreviewsToRemove = [];
|
||||
foreach (var buildPreview in blueprintCopyTool.bpPool)
|
||||
{
|
||||
if (buildPreview?.item == null || buildPreview.objId <= 0) continue;
|
||||
int index;
|
||||
if ((index = buildPreviewsToRemove.BinarySearch(buildPreview.objId)) < 0)
|
||||
buildPreviewsToRemove.Insert(~index, buildPreview.objId);
|
||||
var isBelt = buildPreview.desc.isBelt;
|
||||
var isInserter = buildPreview.desc.isInserter;
|
||||
if (isInserter) continue;
|
||||
var objId = buildPreview.objId;
|
||||
if (isBelt)
|
||||
{
|
||||
var needCheck = false;
|
||||
for (var j = 0; j < 2; j++)
|
||||
{
|
||||
factory.ReadObjectConn(objId, j, out _, out var connObjId, out _);
|
||||
if (connObjId == 0 || factory.ObjectIsBelt(connObjId) || blueprintCopyTool.ObjectIsInserter(connObjId)) continue;
|
||||
needCheck = true;
|
||||
break;
|
||||
}
|
||||
if (needCheck)
|
||||
{
|
||||
for (var k = 0; k < 16; k++)
|
||||
{
|
||||
factory.ReadObjectConn(objId, k, out _, out var connObjId, out _);
|
||||
if (connObjId != 0 && (index = buildPreviewsToRemove.BinarySearch(connObjId)) < 0 && (factory.ObjectIsBelt(connObjId) || blueprintCopyTool.ObjectIsInserter(connObjId)))
|
||||
buildPreviewsToRemove.Insert(~index, connObjId);
|
||||
}
|
||||
}
|
||||
for (var m = 0; m < 4; m++)
|
||||
{
|
||||
factory.ReadObjectConn(objId, m, out _, out var connObjId, out _);
|
||||
if (connObjId == 0 || !factory.ObjectIsBelt(connObjId) || buildPreviewsToRemove.BinarySearch(connObjId) >= 0) continue;
|
||||
for (var j = 0; j < 2; j++)
|
||||
{
|
||||
factory.ReadObjectConn(connObjId, j, out _, out var connObjId2, out _);
|
||||
if (connObjId2 == 0 || (index = buildPreviewsToRemove.BinarySearch(connObjId2)) >= 0 || factory.ObjectIsBelt(connObjId2) || blueprintCopyTool.ObjectIsInserter(connObjId2)) continue;
|
||||
buildPreviewsToRemove.Insert(~index, connObjId2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (buildPreview.desc.addonType == EAddonType.Belt) continue;
|
||||
for (var j = 0; j < 16; j++)
|
||||
{
|
||||
factory.ReadObjectConn(objId, j, out _, out var connObjId, out _);
|
||||
if (connObjId != 0 && (index = buildPreviewsToRemove.BinarySearch(connObjId)) < 0 && (factory.ObjectIsBelt(connObjId) || blueprintCopyTool.ObjectIsInserter(connObjId)))
|
||||
buildPreviewsToRemove.Insert(~index, connObjId);
|
||||
}
|
||||
}
|
||||
foreach (var objId in buildPreviewsToRemove)
|
||||
{
|
||||
build.DoDismantleObject(objId);
|
||||
}
|
||||
buildPreviewsToRemove = null;
|
||||
blueprintCopyTool.ClearSelection();
|
||||
blueprintCopyTool.ClearPreSelection();
|
||||
blueprintCopyTool.ResetBlueprint();
|
||||
blueprintCopyTool.ResetBuildPreviews();
|
||||
blueprintCopyTool.RefreshBlueprintData();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user