8170b700b2
Features: Sacrifice-Node, Maintain-Node, Options for screen type, lightcolor and soundvolume, tied in sound effects, game pause when menu is open, visibly open up gate when opening it.
221 lines
6.1 KiB
C#
221 lines
6.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Godot;
|
|
|
|
public partial class NodeDisplay : PanelContainer
|
|
{
|
|
[Export] PanelContainer editorDisplay;
|
|
[Export] public Button listDisplay;
|
|
public ProgramNode node;
|
|
|
|
[Signal]
|
|
public delegate void OnDeleteNodeEventHandler();
|
|
|
|
public void SetNode(ProgramNode node)
|
|
{
|
|
this.node = node;
|
|
}
|
|
|
|
public override void _Ready()
|
|
{
|
|
if (node == null) return;
|
|
|
|
node.Setup(this);
|
|
}
|
|
|
|
public void ShowListDisplay()
|
|
{
|
|
editorDisplay.Visible = false;
|
|
listDisplay.Visible = true;
|
|
}
|
|
|
|
public void ShowEditorDisplay()
|
|
{
|
|
editorDisplay.Visible = true;
|
|
listDisplay.Visible = false;
|
|
}
|
|
|
|
public void DeleteNodePressed()
|
|
{
|
|
EmitSignal(SignalName.OnDeleteNode);
|
|
}
|
|
|
|
public static NodeDisplay Load(string content, Dictionary<ProgramNode, PackedScene> DSLNodes)
|
|
{
|
|
string nodeSanitized = content.Replace("\r\n", "").Trim();
|
|
if (nodeSanitized.Length <= 0) return null;
|
|
|
|
string nodeName = nodeSanitized.Split(",")[0].Replace("Name: ", "").ToLower();
|
|
PackedScene prefab = GetPrefab(nodeName, DSLNodes);
|
|
if (prefab == null) return null;
|
|
|
|
NodeDisplay result = prefab.Instantiate<NodeDisplay>();
|
|
|
|
switch (nodeName)
|
|
{
|
|
case "move":
|
|
result.node = new MoveNode();
|
|
result.LoadMove(nodeSanitized);
|
|
break;
|
|
case "harvest":
|
|
result.node = new HarvestNode();
|
|
result.LoadHarvest(nodeSanitized);
|
|
break;
|
|
case "explore":
|
|
result.node = new ExploreNode();
|
|
result.LoadExplore(nodeSanitized);
|
|
break;
|
|
case "craft":
|
|
result.node = new CraftNode();
|
|
result.LoadCraft(nodeSanitized);
|
|
break;
|
|
case "while":
|
|
result.node = new WhileNode();
|
|
result.LoadWhile(nodeSanitized);
|
|
break;
|
|
case "until":
|
|
result.node = new UntilNode();
|
|
result.LoadUntil(nodeSanitized);
|
|
break;
|
|
case "for":
|
|
result.node = new ForNode();
|
|
result.LoadFor(nodeSanitized);
|
|
break;
|
|
case "if":
|
|
result.node = new IfNode();
|
|
result.LoadIf(nodeSanitized);
|
|
break;
|
|
case "else":
|
|
result.node = new ElseNode();
|
|
result.LoadElse(nodeSanitized);
|
|
break;
|
|
case "maintain":
|
|
result.node = new MaintainNode();
|
|
result.LoadMaintain(nodeSanitized);
|
|
break;
|
|
case "sacrifice":
|
|
result.node = new SacrificeNode();
|
|
result.LoadSacrifice(nodeSanitized);
|
|
break;
|
|
default:
|
|
result.QueueFree();
|
|
return null;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
private void LoadElse(string content) { }
|
|
|
|
private void LoadMaintain(string content) { }
|
|
|
|
private void LoadSacrifice(string content) { }
|
|
|
|
private void LoadIf(string content)
|
|
{
|
|
HBoxContainer valueContainer = GetNode<HBoxContainer>("./EditorDisplay/VBoxContainer/Values");
|
|
string[] parts = content.Split(",");
|
|
string itemString = parts[1].Replace("Item:", "").Trim();
|
|
string comparatorString = parts[2].Replace("Comparator:", "").Trim();
|
|
if (itemString.ToLower() != "empty")
|
|
{
|
|
IfNode ifNode = node as IfNode;
|
|
if (ifNode != null)
|
|
{
|
|
ifNode.selectedItem = new Item { data = GameData.availableItems[itemString] };
|
|
ifNode.comparator = comparatorString;
|
|
}
|
|
}
|
|
string amountString = parts[3].Replace("Amount:", "").Trim();
|
|
valueContainer.GetNode<SpinBox>("./Amount").Value = int.Parse(amountString);
|
|
}
|
|
|
|
private void LoadFor(string content)
|
|
{
|
|
HBoxContainer valueContainer = GetNode<HBoxContainer>("./EditorDisplay/VBoxContainer/Values");
|
|
string[] parts = content.Split(",");
|
|
string amountExecuted = parts[1].Replace("AmountExecuted:", "").Trim();
|
|
ForNode forNode = node as ForNode;
|
|
if (forNode != null)
|
|
{
|
|
forNode.amountExecuted = int.Parse(amountExecuted);
|
|
}
|
|
string amountString = parts[2].Replace("Amount:", "").Trim();
|
|
valueContainer.GetNode<SpinBox>("./Amount").Value = int.Parse(amountString);
|
|
}
|
|
|
|
private void LoadUntil(string content) { }
|
|
|
|
private void LoadWhile(string content)
|
|
{
|
|
HBoxContainer valueContainer = GetNode<HBoxContainer>("./EditorDisplay/VBoxContainer/Values");
|
|
string[] parts = content.Split(",");
|
|
string itemString = parts[1].Replace("Item:", "").Trim();
|
|
string comparatorString = parts[2].Replace("Comparator:", "").Trim();
|
|
if (itemString.ToLower() != "empty")
|
|
{
|
|
WhileNode whileNode = node as WhileNode;
|
|
if (whileNode != null)
|
|
{
|
|
whileNode.selectedItem = new Item { data = GameData.availableItems[itemString] };
|
|
whileNode.comparator = comparatorString;
|
|
}
|
|
}
|
|
string amountString = parts[3].Replace("Amount:", "").Trim();
|
|
valueContainer.GetNode<SpinBox>("./Amount").Value = int.Parse(amountString);
|
|
}
|
|
|
|
private static PackedScene GetPrefab(string nodeName, Dictionary<ProgramNode, PackedScene> DSLNodes)
|
|
{
|
|
foreach (ProgramNode programNode in DSLNodes.Keys)
|
|
{
|
|
if (programNode.DisplayText.ToLower() == nodeName)
|
|
{
|
|
return DSLNodes[programNode];
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public void LoadHarvest(string content) { }
|
|
|
|
public void LoadMove(string content)
|
|
{
|
|
HBoxContainer valueContainer = GetNode<HBoxContainer>("./EditorDisplay/VBoxContainer/Values");
|
|
string[] parts = content.Split(",");
|
|
string positionValues = parts[1].Replace("Position:", "").Replace("(", "").Replace(")", "").Trim();
|
|
int posX = int.Parse(positionValues.Split("|")[0]);
|
|
int posY = int.Parse(positionValues.Split("|")[1]);
|
|
int posZ = int.Parse(positionValues.Split("|")[2]);
|
|
valueContainer.GetNode<SpinBox>("./CoordinateX").Value = posX;
|
|
valueContainer.GetNode<SpinBox>("./CoordinateY").Value = posY;
|
|
valueContainer.GetNode<SpinBox>("./CoordinateZ").Value = posZ;
|
|
|
|
MoveNode moveNode = node as MoveNode;
|
|
if (moveNode != null)
|
|
{
|
|
moveNode.targetPosition = new Vector3I(posX, posY, posZ);
|
|
}
|
|
}
|
|
|
|
public void LoadExplore(string content) { }
|
|
|
|
public void LoadCraft(string content)
|
|
{
|
|
HBoxContainer valueContainer = GetNode<HBoxContainer>("./EditorDisplay/VBoxContainer/Values");
|
|
string[] parts = content.Split(",");
|
|
string itemString = parts[1].Replace("Item:", "").Trim();
|
|
if (itemString.ToLower() != "empty")
|
|
{
|
|
CraftNode craftNode = node as CraftNode;
|
|
if (craftNode != null)
|
|
{
|
|
craftNode.selectedItem = new Item { data = GameData.availableItems[itemString] };
|
|
}
|
|
}
|
|
string amountString = parts[2].Replace("Amount:", "").Trim();
|
|
valueContainer.GetNode<SpinBox>("./Amount").Value = int.Parse(amountString);
|
|
}
|
|
}
|