Added load mechanic to temporary scripts to allow the player modifications to it.
This commit is contained in:
@@ -12,8 +12,8 @@ public partial class Robot : Node3D
|
|||||||
private const float MaintenanceLossPerSecond = 0.025f;
|
private const float MaintenanceLossPerSecond = 0.025f;
|
||||||
|
|
||||||
private bool isExecuting = false;
|
private bool isExecuting = false;
|
||||||
private ProgramNode currentNode;
|
|
||||||
|
|
||||||
|
public ProgramNode currentNode;
|
||||||
public string currentProgram;
|
public string currentProgram;
|
||||||
public string currentMessage = "";
|
public string currentMessage = "";
|
||||||
public float heat = 0f;
|
public float heat = 0f;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ public partial class CodingWindow : PanelContainer
|
|||||||
nameInput.Text = robot.Name;
|
nameInput.Text = robot.Name;
|
||||||
SetupScriptOptions();
|
SetupScriptOptions();
|
||||||
ClearWindow();
|
ClearWindow();
|
||||||
|
LoadTemporaryProgram();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupScriptOptions()
|
private void SetupScriptOptions()
|
||||||
@@ -162,6 +163,50 @@ public partial class CodingWindow : PanelContainer
|
|||||||
availableScripts.Select(0);
|
availableScripts.Select(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void LoadTemporaryProgram()
|
||||||
|
{
|
||||||
|
if (robot == null) return;
|
||||||
|
if (robot.currentNode == null) return;
|
||||||
|
|
||||||
|
ProgramNode firstNode = robot.currentNode;
|
||||||
|
while (firstNode.previousNode != null)
|
||||||
|
{
|
||||||
|
firstNode = firstNode.previousNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
HashSet<ProgramNode> loadedNodes = new HashSet<ProgramNode>();
|
||||||
|
ProgramNode nodeToLoad = firstNode;
|
||||||
|
while (nodeToLoad != null && !loadedNodes.Contains(nodeToLoad))
|
||||||
|
{
|
||||||
|
loadedNodes.Add(nodeToLoad);
|
||||||
|
|
||||||
|
NodeDisplay nodeDisplay = NodeDisplay.Load(nodeToLoad.Save(), DSLNodes);
|
||||||
|
if (nodeDisplay != null)
|
||||||
|
{
|
||||||
|
editorWindow.AddChild(nodeDisplay);
|
||||||
|
nodeDisplay.ShowEditorDisplay();
|
||||||
|
nodeDisplay.OnDeleteNode += () =>
|
||||||
|
{
|
||||||
|
editorWindow.RemoveChild(nodeDisplay);
|
||||||
|
nodeDisplay.QueueFree();
|
||||||
|
};
|
||||||
|
nodeDisplay.OnMoveNode += (int direction) =>
|
||||||
|
{
|
||||||
|
int targetIndex = Mathf.Clamp(
|
||||||
|
nodeDisplay.GetIndex() + direction,
|
||||||
|
0,
|
||||||
|
editorWindow.GetChildCount() - 1
|
||||||
|
);
|
||||||
|
editorWindow.MoveChild(nodeDisplay, targetIndex);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
nodeToLoad = nodeToLoad.nextNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
scriptName.Text = robot.currentProgram ?? "";
|
||||||
|
}
|
||||||
|
|
||||||
public void DeleteProgram()
|
public void DeleteProgram()
|
||||||
{
|
{
|
||||||
string filename = scriptName.Text;
|
string filename = scriptName.Text;
|
||||||
|
|||||||
Reference in New Issue
Block a user