Skip to content

Commit

Permalink
gh-2-SubGraphParts Overhaul of generic data types
Browse files Browse the repository at this point in the history
  • Loading branch information
TomNCatz committed May 3, 2021
1 parent c8720b5 commit 899da07
Show file tree
Hide file tree
Showing 47 changed files with 612 additions and 723 deletions.
61 changes: 31 additions & 30 deletions Code/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class App

public readonly Dictionary<string, KeySlot> generatedKeys = new Dictionary<string, KeySlot>();

private readonly Dictionary<string, GenericDataArray> _nodeData = new Dictionary<string, GenericDataArray>();
private readonly Dictionary<string, GenericDataDictionary> _nodeData = new Dictionary<string, GenericDataDictionary>();
private readonly List<Color> _parentChildColors = new List<Color> ();
private readonly List<Color> _keyColors = new List<Color>();
public bool copyingData;
Expand All @@ -53,8 +53,8 @@ public class App
private string _defaultListing;
private string _explicitNode;
private bool _hasUnbackedChanges;
private GenericDataArray _model;
private readonly List<GenericDataArray> _topModels = new List<GenericDataArray>();
private GenericDataDictionary _model;
private readonly List<GenericDataDictionary> _topModels = new List<GenericDataDictionary>();
private ExportRulesAbstract _exportRules;
private string _loadingPath;

Expand Down Expand Up @@ -117,7 +117,7 @@ public App(MainView mainView)
ServiceProvider.Add(this);

_mainView = mainView;
_model = new GenericDataArray();
_model = new GenericDataDictionary();
OS.LowProcessorUsageMode = true;
}

Expand All @@ -134,7 +134,7 @@ private void LoadSettings()
File file = new File();
if( !file.FileExists( SETTINGS_SOURCE ) )return;

GenericDataArray gda = new GenericDataArray();
GenericDataDictionary gda = new GenericDataDictionary();
gda.FromJson( LoadJsonFile( SETTINGS_SOURCE ) );

gda.GetValue( "backgroundColor", out Color background );
Expand Down Expand Up @@ -278,6 +278,7 @@ public void ClearData()
_mainView.nodes[i].CloseRequest();
}

_mainView.CurrentParentIndex = -1;
_nodeData.Clear();
ClearBackup();
HasUnsavedChanges = false;
Expand All @@ -287,7 +288,7 @@ public void ClearData()

public void SaveSettings()
{
GenericDataArray gda = new GenericDataArray();
GenericDataDictionary gda = new GenericDataDictionary();
gda.AddValue( "RecentFiles", _recentFiles );
gda.AddValue( "RecentTemplates", _recentTemplates );
gda.AddValue( "backgroundColor", _mainView.Color );
Expand Down Expand Up @@ -327,15 +328,15 @@ public void CatchException( Exception ex )

private void UpdateData()
{
GenericDataArray gda;
GenericDataDictionary gda;

if( _topModels.Count == 1 )
{
gda = _topModels[0];
}
else
{
gda = new GenericDataArray();
gda = new GenericDataDictionary();

gda.AddValue( _defaultListing, _topModels );
}
Expand Down Expand Up @@ -400,9 +401,9 @@ private IPromise CheckIfShouldRestoreFirst(string path)

LoadTemplate( json );

var graph = new GenericDataArray();
var graph = new GenericDataDictionary();
graph.FromJson( json );
graph.GetValue( GRAPH_DATA_KEY, out GenericDataArray data );
graph.GetValue( GRAPH_DATA_KEY, out GenericDataDictionary data );
LoadData( data );

HasUnsavedChanges = true;
Expand Down Expand Up @@ -431,12 +432,12 @@ private IPromise CheckIfShouldRestoreFirst(string path)
#endregion

#region Get Data
public GenericDataArray GetNodeData(string index)
public GenericDataDictionary GetNodeData(string index)
{
return _nodeData[index];
}

public SlottedGraphNode LoadNode( GenericDataArray nodeContent )
public SlottedGraphNode LoadNode( GenericDataDictionary nodeContent )
{
if( _nodeData.Count == 0 ) throw new KeyNotFoundException("No Nodes currently loaded");

Expand All @@ -448,7 +449,7 @@ public SlottedGraphNode LoadNode( GenericDataArray nodeContent )
throw new ArgumentOutOfRangeException($"'{nodeName}' not found in loaded data");
}

GenericDataArray nodeData = _nodeData[nodeName];
GenericDataDictionary nodeData = _nodeData[nodeName];

if( nodeData == null ) throw new ArgumentNullException($"Data for '{nodeName}' was null");

Expand Down Expand Up @@ -524,7 +525,7 @@ public void ExportSet(string exportName)

ExportSet exportSet = _exportRules.ExportTargets[exportName];

if (!(_model.GetRelativeGdo(exportSet.gdoExportTarget) is GenericDataArray data))
if (!(_model.GetRelativeGdo(exportSet.gdoExportTarget) is GenericDataDictionary data))
{
throw new Exception($"Object at path {exportSet.gdoExportTarget} is not an array");
}
Expand All @@ -547,15 +548,15 @@ public void ExportSet(string exportName)
itemCount = data.values.Count;
}

List<GenericDataArray> items = new List<GenericDataArray>();
var graph = new GenericDataArray(){type = data.type};
List<GenericDataDictionary> items = new List<GenericDataDictionary>();
var graph = new GenericDataDictionary(){type = data.type};

foreach (KeyValuePair<string, GenericDataObject> pair in data.values)
{
if(current == itemCount)
{
items.Add(graph);
graph = new GenericDataArray(){type = data.type};
graph = new GenericDataDictionary(){type = data.type};
current = 0;
}
graph.AddValue(pair.Key, pair.Value);
Expand All @@ -575,7 +576,7 @@ public void ExportSet(string exportName)
NODE_SIZE_KEY
};

_exportRules.PreprocessExportGDA(items[i], keys, exportName, myPath, i+1);
_exportRules.PreprocessExportGdo(items[i], keys, exportName, myPath, i+1);

if(keys != null)
{
Expand Down Expand Up @@ -644,9 +645,9 @@ public void LoadGraph( string path )

LoadTemplateInternal(json);

var graph = new GenericDataArray();
var graph = new GenericDataDictionary();
graph.FromJson( json );
graph.GetValue( GRAPH_DATA_KEY, out GenericDataArray data );
graph.GetValue( GRAPH_DATA_KEY, out GenericDataDictionary data );
LoadData( data );

SaveFilePath = path;
Expand All @@ -661,7 +662,7 @@ public void LoadGraph( string path )
});
}

public void LoadData(GenericDataArray data)
public void LoadData(GenericDataDictionary data)
{
if(data == null)
{
Expand All @@ -676,9 +677,9 @@ public void LoadData(GenericDataArray data)
{
string key = data.values.Keys.First();

data.GetValue( key, out List<GenericDataArray> items );
data.GetValue( key, out List<GenericDataDictionary> items );

foreach( GenericDataArray item in items )
foreach( GenericDataDictionary item in items )
{
if( !item.values.ContainsKey( NODE_NAME_KEY ) )
{
Expand Down Expand Up @@ -707,7 +708,7 @@ public void ShiftTemplateUnderData(string path)
.Then(() => {
try
{
_model.GetValue( GRAPH_DATA_KEY, out GenericDataArray data );
_model.GetValue( GRAPH_DATA_KEY, out GenericDataDictionary data );
data = data.DataCopy();
ClearData();
LoadTemplate( LoadJsonFile( path ) );
Expand Down Expand Up @@ -757,7 +758,7 @@ public void LoadTemplate( string json )

private void LoadTemplateInternal( string json )
{
GenericDataArray gda = new GenericDataArray();
GenericDataDictionary gda = new GenericDataDictionary();
gda.FromJson( json );

gda.GetValue( GRAPH_VERSION_KEY, out string targetVersion );
Expand All @@ -774,14 +775,14 @@ private void LoadTemplateInternal( string json )
{
_defaultListing = "listing";
}
GenericDataArray listing = gda.GetGdo( GRAPH_NODE_LIST_KEY ) as GenericDataArray;
gda.GetValue( GRAPH_NODE_LIST_KEY, out GenericDataList listing);

gda.GetValue( GRAPH_NESTED_COLORS_KEY, out List<Color> nestingColors );
gda.GetValue( GRAPH_KEY_COLORS_KEY, out List<Color> keyColors );
gda.GetValue( GRAPH_EXPORT_DLL_KEY, out bool reuseDll );
gda.GetValue( GRAPH_EXPORT_SCRIPT_KEY, out string exportScript );

List<GenericDataObject> dataList = listing.values.Values.ToList();
List<GenericDataObject> dataList = listing.values;
if( dataList == null )
{
throw new NullReferenceException("LoadTemplate does not accept a null dataList");
Expand Down Expand Up @@ -841,7 +842,7 @@ private void LoadTemplateInternal( string json )

foreach( GenericDataObject gdo in dataList )
{
GenericDataArray item = gdo as GenericDataArray;
GenericDataDictionary item = gdo as GenericDataDictionary;

item.GetValue( "title", out string title );

Expand All @@ -855,7 +856,7 @@ private void LoadTemplateInternal( string json )
}
}

List<GenericDataArray> nodeList = _nodeData.Values.ToList();
List<GenericDataDictionary> nodeList = _nodeData.Values.ToList();
_model.AddValue( GRAPH_NODE_LIST_KEY, nodeList );

_mainView.ResetCreateMenu(_nodeData.Keys.ToList());
Expand Down Expand Up @@ -892,7 +893,7 @@ private void LoadAssembly(string exportScript, bool reuseDll)
}
args.references.Add(SharpMods.GetPortableReferenceToType(typeof(Dictionary<,>)));
args.references.Add(SharpMods.GetPortableReferenceToType(typeof(ExportRulesAbstract)));
args.references.Add(SharpMods.GetPortableReferenceToType(typeof(GenericDataArray)));
args.references.Add(SharpMods.GetPortableReferenceToType(typeof(GenericDataDictionary)));
args.code = exportScript;
assembly = SharpMods.RoslynRuntimeCompile(args);
}
Expand Down
Binary file modified Code/DLLs/LibT.Debugging.dll
Binary file not shown.
Binary file modified Code/DLLs/LibT.Serialization.dll
Binary file not shown.
Binary file modified Code/DLLs/LibT.dll
Binary file not shown.
Binary file modified Code/DLLs/LibTGodot.dll
Binary file not shown.
Binary file modified Code/DLLs/MetaMakerLib.dll
Binary file not shown.
Binary file modified Code/DLLs/RSG.Promises.dll
Binary file not shown.
3 changes: 2 additions & 1 deletion Code/IField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ namespace MetaMaker
{
public interface IField
{
string Label{get;set;}
event Action OnValueUpdated;
void Init(GenericDataArray template, GenericDataArray parentModel);
void Init(GenericDataDictionary template, GenericDataObject parentModel);
}
}
9 changes: 0 additions & 9 deletions Code/IGdaLoadable.cs

This file was deleted.

19 changes: 4 additions & 15 deletions Code/NodeCode/HelpPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace MetaMaker
{
public class HelpPopup : WindowDialog, IGdaLoadable
public class HelpPopup : WindowDialog, IGddLoadable
{
[Export] public NodePath _treePath;
private Tree _tree;
Expand Down Expand Up @@ -33,15 +33,9 @@ public override void _Ready()

_tree.HideRoot = true;
_tree.Connect( "item_selected", this, nameof(HandleSelect) );

// var export_config = new ConfigFile();
// var config_error = export_config.Load( "res://export_presets.cfg" );
// object version = export_config.GetValue("preset.0.options","version/name", "failed");
//object version = ProjectSettings.GetSetting( "version" );

}

public void LoadFromGda( GenericDataArray data )
public void SetObjectData( GenericDataDictionary data )
{
data.GetValue( "helpInfo", out List<FaqData> infoData );

Expand Down Expand Up @@ -77,18 +71,13 @@ private void HandleSelect()
}
}

private class FaqData : IGdoConvertible
private class FaqData : IGddLoadable
{
public string Entry;
public string Info;
public List<FaqData> Branches;

public void GetObjectData( GenericDataArray objData )
{
throw new System.NotImplementedException();
}

public void SetObjectData( GenericDataArray objData )
public void SetObjectData( GenericDataDictionary objData )
{
objData.GetValue( "Entry", out Entry );
objData.GetValue( "Info", out Info );
Expand Down
Loading

0 comments on commit 899da07

Please sign in to comment.