Fixed robot save mechanic to include nodes and their states.
This commit is contained in:
@@ -14,6 +14,52 @@ public abstract class ProgramNode
|
||||
public abstract ProgramNode Duplicate();
|
||||
public abstract string Save();
|
||||
|
||||
public virtual NodeSaveData CreateSaveData()
|
||||
{
|
||||
return new NodeSaveData
|
||||
{
|
||||
NodeType = DisplayText,
|
||||
EditorNodeId = EditorNodeId,
|
||||
NextEditorNodeId = nextNode?.EditorNodeId,
|
||||
NegativeEditorNodeId = NegativeNode?.EditorNodeId,
|
||||
NodeContent = Save(),
|
||||
LastExecutionMessage = lastExecutionMessage
|
||||
};
|
||||
}
|
||||
|
||||
public virtual void Load(NodeSaveData saveData)
|
||||
{
|
||||
EditorNodeId = saveData.EditorNodeId;
|
||||
lastExecutionMessage = saveData.LastExecutionMessage;
|
||||
}
|
||||
|
||||
public void RestoreConnections(
|
||||
NodeSaveData saveData,
|
||||
Dictionary<string, ProgramNode> availableNodes
|
||||
)
|
||||
{
|
||||
nextNode = GetSavedConnection(saveData.NextEditorNodeId, availableNodes);
|
||||
NegativeNode = GetSavedConnection(saveData.NegativeEditorNodeId, availableNodes);
|
||||
}
|
||||
|
||||
public static ProgramNode CreateFromSaveData(NodeSaveData saveData)
|
||||
{
|
||||
return saveData.NodeType?.ToLower() switch
|
||||
{
|
||||
"start" => new StartNode(),
|
||||
"move" => new MoveNode(),
|
||||
"explore" => new ExploreNode(),
|
||||
"harvest" => new HarvestNode(),
|
||||
"craft" => new CraftNode(),
|
||||
"if" => new IfNode(),
|
||||
"while" => new WhileNode(),
|
||||
"for" => new ForNode(),
|
||||
"maintain" => new MaintainNode(),
|
||||
"sacrifice" => new SacrificeNode(),
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
public ProgramNode DuplicateForRuntime(string editorNodeId)
|
||||
{
|
||||
ProgramNode duplicate = Duplicate();
|
||||
@@ -65,4 +111,15 @@ public abstract class ProgramNode
|
||||
|
||||
return availableNodes[nodeName];
|
||||
}
|
||||
|
||||
private ProgramNode GetSavedConnection(
|
||||
string nodeId,
|
||||
Dictionary<string, ProgramNode> availableNodes
|
||||
)
|
||||
{
|
||||
if (string.IsNullOrEmpty(nodeId)) return null;
|
||||
if (!availableNodes.ContainsKey(nodeId)) return null;
|
||||
|
||||
return availableNodes[nodeId];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user