Skip to content

Commit

Permalink
Merge pull request #48 from StarCoreSE/yard-logging
Browse files Browse the repository at this point in the history
Yard logging
  • Loading branch information
InvalidArgument3 authored Nov 16, 2024
2 parents 4e4a91c + 469d080 commit e28ca3a
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 17 deletions.
22 changes: 19 additions & 3 deletions ShipyardsRevival/Data/Scripts/ShipyardMod/ProcessShipyardAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,17 @@ private bool StepWeld(ShipyardItem shipyardItem)
}

if (shipyardItem.BlocksToProcess.All(e => e.Value.All(t => t == null)))
{
shipyardItem.Disable(true, "No more blocks to weld");
return false;
}

if (shipyardItem.TargetBlocks.Count == 0)
{
Logging.Instance.WriteDebug($"[StepWeld] Populated {shipyardItem.TargetBlocks.Count} target blocks.");
shipyardItem.Disable(true, "No blocks require welding");
return false;
}

shipyardItem.UpdatePowerUse();
targetsToRedraw.Clear();
Expand Down Expand Up @@ -859,7 +869,7 @@ private bool StepWeld(ShipyardItem shipyardItem)
entry.Value[i] = null;
continue;
}

if (_stalledTargets.Contains(target))
{
var blockComponents = new Dictionary<string, int>();
Expand All @@ -872,9 +882,15 @@ private bool StepWeld(ShipyardItem shipyardItem)
else
shipyardItem.MissingComponentsDict.Add(component.Key, component.Value);
}


if (shipyardItem.MissingComponentsDict.Any())
{
shipyardItem.Disable(true, "Insufficient components to continue welding");
return false;
}

var toolLine = new Communication.ToolLineStruct
{
{
ToolId = entry.Key,
GridId = target.CubeGrid.EntityId,
BlockPos = target.GridPosition,
Expand Down
62 changes: 50 additions & 12 deletions ShipyardsRevival/Data/Scripts/ShipyardMod/ShipyardCorner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,42 +322,70 @@ public override void UpdateOnceBeforeFrame()
MyAPIGateway.TerminalControls.AddAction<IMyCollector>(stopAction);
}

private string _lastStatus = ""; // Add this as a class field

private void AppendingCustomInfo(IMyTerminalBlock b, StringBuilder arg2)
{
try
{
var sb = new StringBuilder();
ShipyardItem yard = GetYard(b);

if (yard == null)
{
sb.AppendLine("Not part of a valid shipyard");
_lastStatus = "Not part of a valid shipyard";
sb.AppendLine(_lastStatus);
arg2.Append(sb);
return;
}

// Power info
sb.Append("Required Input: ");
MyValueFormatter.AppendWorkInBestUnit(_power, sb);
sb.AppendLine();
sb.Append("Max required input: ");
MyValueFormatter.AppendWorkInBestUnit(_maxpower, sb);
sb.AppendLine();

// Shipyard status
sb.AppendLine($"Shipyard Status: {yard.YardType}");

if (yard.YardType == ShipyardType.Weld && yard.MissingComponentsDict.Any())
// Use the DisableReason from ShipyardItem
switch (yard.YardType)
{
sb.AppendLine("Welding paused - Missing components:");
foreach (var component in yard.MissingComponentsDict)
{
sb.AppendLine($" {component.Key}: {component.Value}");
}
case ShipyardType.Disabled:
_lastStatus = $"Status Reason: {yard.DisableReason}";
sb.AppendLine(_lastStatus);
break;

case ShipyardType.Invalid:
_lastStatus = "Status Reason: Shipyard configuration is invalid";
sb.AppendLine(_lastStatus);
break;

case ShipyardType.Weld:
if (yard.MissingComponentsDict.Any())
{
sb.AppendLine("Status Reason: Missing components - Welding paused");
sb.AppendLine("Missing Components:");
foreach (var component in yard.MissingComponentsDict)
{
sb.AppendLine($" {component.Key}: {component.Value}");
}
}
else if (!yard.Tools.Any(x => ((IMyFunctionalBlock)x).Enabled))
{
sb.AppendLine("Status Reason: One or more corner blocks are disabled");
}
break;

case ShipyardType.Grind:
if (!yard.Tools.Any(x => ((IMyFunctionalBlock)x).Enabled))
{
sb.AppendLine("Status Reason: One or more corner blocks are disabled");
}
break;
}

sb.AppendLine($"Blocks remaining: {yard.TargetBlocks.Count}");

// Additional debug info
if (ShipyardCore.Debug)
{
sb.AppendLine($"Connected cargo containers: {yard.ConnectedCargo.Count}");
Expand Down Expand Up @@ -532,7 +560,17 @@ public override void UpdateBeforeSimulation()

public override void UpdateBeforeSimulation10()
{
((IMyTerminalBlock)Container.Entity).RefreshCustomInfo();
try
{
if (_block != null && !string.IsNullOrEmpty(_lastStatus))
{
((IMyTerminalBlock)Container.Entity).RefreshCustomInfo();
}
}
catch (Exception ex)
{
Logging.Instance.WriteLine($"Error in UpdateBeforeSimulation10: {ex.Message}");
}
}

public override MyObjectBuilder_EntityBase GetObjectBuilder(bool copy = false)
Expand Down
10 changes: 8 additions & 2 deletions ShipyardsRevival/Data/Scripts/ShipyardMod/ShipyardItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class ShipyardItem

public ShipyardType YardType;
public bool StaticYard;
public string DisableReason { get; private set; } = "Shipyard is idle";

public ShipyardItem(MyOrientedBoundingBoxD box, IMyCubeBlock[] tools, ShipyardType yardType, IMyEntity yardEntity)
{
Expand Down Expand Up @@ -162,7 +163,7 @@ public void Init(ShipyardType yardType)
private volatile bool _isDisabling;
private volatile bool _isOperating;

public void Disable(bool broadcast = true)
public void Disable(bool broadcast = true, string reason = null)
{
lock (_stateLock)
{
Expand All @@ -172,9 +173,14 @@ public void Disable(bool broadcast = true)
return;
}

// Set the disable reason
DisableReason = reason ?? (MissingComponentsDict.Any()
? "Insufficient components to continue welding"
: "Shipyard is idle");

_isDisabling = true;
_isOperating = false;
Logging.Instance.WriteDebug($"[ShipyardItem.Disable] Starting disable for yard {EntityId}, broadcast={broadcast}");
Logging.Instance.WriteDebug($"[ShipyardItem.Disable] Starting disable for yard {EntityId}, broadcast={broadcast}, reason: {DisableReason}");
_shouldDisable.Item1 = true;
_shouldDisable.Item2 = broadcast;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@echo off
rem Testing mods in DS by yourself can be done without the need to re-publish every time.
rem You can simply update the files that are on your machine!
rem This will only work for you, anyone else joining the server will of course download the mod from the workshop.

rem To use:
rem 1. Copy this .bat file in the ROOT folder of your local mod (e.g. %appdata%/SpaceEngineers/Mods/YourLocalMod/<HERE>)

rem 2. Edit this variable if applicable (do not add quotes or end with backslash).
set STEAM_PATH=C:\Program Files\Steam

rem 3. Edit this with your mod's workshop id.
set WORKSHOP_ID=3013053286

rem Now you can run it every time you want to update the mod on DS and client.



rem Don't edit the below unless you really need different paths.
rem NOTE: don't add quotes and don't end with a backslash!

set CLIENT_PATH=O:\SteamLibrary\steamapps\workshop\content\244850\%WORKSHOP_ID%
set DS_PATH=C:\Torch\Instance\content\244850\%WORKSHOP_ID%

rmdir "%CLIENT_PATH%" /S /Q
rmdir "%DS_PATH%" /S /Q

robocopy.exe .\ "%DS_PATH%" *.* /S /xd .git bin obj .vs ignored /xf *.lnk *.git* *.bat *.zip *.7z *.blend* *.md *.log *.sln *.csproj *.csproj.user *.ruleset modinfo.sbmi
robocopy.exe "%DS_PATH%" "%CLIENT_PATH%" *.* /S

pause

0 comments on commit e28ca3a

Please sign in to comment.