public bool Load(string path) { if (string.IsNullOrEmpty(path)) { return(false); } if (GraphInst != null) { GraphInst.OnGraphParameterUpdate -= GraphInst_OnGraphParameterUpdate; GraphInst.Dispose(); GraphInst = null; } nameMap = new Dictionary <string, GraphParameterValue>(); if (path.Contains("Materia::Layer::")) { isLayer = true; return(TryAndLoadLayer(path)); } isLayer = false; return(TryAndLoadFile(path)); }
void TryAndReleaseBuffers() { if (GraphInst != null) { GraphInst.ReleaseIntermediateBuffers(); } }
void TryAndReleaseBuffers() { if (ctk != null) { try { ctk.Cancel(); } catch (Exception e) { Console.WriteLine(e); } } ctk = new CancellationTokenSource(); Task.Delay(250, ctk.Token).ContinueWith(t => { if (t.IsCanceled) { return; } App.Current.Dispatcher.Invoke(() => { ctk = null; GraphInst.ReleaseIntermediateBuffers(); }); }); }
public override void AssignPixelType(GraphPixelType pix) { base.AssignPixelType(pix); if (GraphInst != null) { GraphInst.AssignPixelType(pix); } }
protected override void OnWidthHeightSet() { if (GraphInst != null) { GraphInst.ResizeWith(width, height); } Updated(); }
protected override void OnPixelFormatChange() { if (GraphInst != null) { GraphInst.AssignPixelType(internalPixelType); } base.OnPixelFormatChange(); }
public override void Dispose() { base.Dispose(); if (GraphInst != null) { GraphInst.Dispose(); GraphInst = null; } }
private void GraphParameterValue_OnGraphParameterUpdate(GraphParameterValue param) { if (GraphInst != null) { if (GraphInst.Parameters.Values.Contains(param) || GraphInst.CustomParameters.Contains(param)) { GraphInst.TryAndProcess(); } } }
public override void Dispose() { base.Dispose(); GraphParameterValue.OnGraphParameterUpdate -= GraphParameterValue_OnGraphParameterUpdate; if (GraphInst != null) { GraphInst.Dispose(); GraphInst = null; } }
public override string GetJson() { GraphInstanceNodeData d = new GraphInstanceNodeData(); FillBaseNodeData(d); d.rawData = GraphData; d.path = path; d.parameters = GraphInst.GetConstantParameters(); d.customParameters = GraphInst.GetCustomParameters(); d.randomSeed = RandomSeed; return(JsonConvert.SerializeObject(d)); }
public override Task GetTask() { return(Task.Factory.StartNew(() => { PrepareProcess(); }) .ContinueWith(t => { if (GraphInst != null) { GraphInst.TryAndProcess(); } }, Context)); }
//used for initial loading //not used for restoring from .materia public bool Load(string path) { if (GraphInst != null) { GraphData = null; GraphInst.Dispose(); GraphInst = null; } if (File.Exists(path) && Path.GetExtension(path).ToLower().Contains("mtg")) { this.path = path; string nm = Path.GetFileNameWithoutExtension(path); Name = nm; //the width and height here don't matter GraphInst = new Graph(nm); GraphData = File.ReadAllText(path); GraphInst.FromJson(GraphData); GraphInst.SetJsonReadyParameters(jsonParameters); GraphInst.SetJsonReadyCustomParameters(jsonCustomParameters); GraphInst.RandomSeed = randomSeed; //now do real initial resize GraphInst.ResizeWith(width, height); //mark as readonly GraphInst.ReadOnly = true; //setup inputs and outputs Setup(); return(true); } else { this.path = null; } return(false); }
public override void Dispose() { if (child != null) { child.Dispose(); child = null; } base.Dispose(); if (GraphInst != null) { GraphInst.OnGraphParameterUpdate -= GraphParameterValue_OnGraphParameterUpdate; GraphInst.Dispose(); GraphInst = null; } }
public override void TryAndProcess() { if (!Async) { PrepareProcess(); if (GraphInst != null) { GraphInst.TryAndProcess(); } return; } if (ParentGraph != null) { ParentGraph.Schedule(this); } }
public override void Dispose() { if (parentGraph != null) { parentGraph.OnGraphParameterUpdate -= ParentGraph_OnGraphParameterUpdate; } if (child != null) { child.Dispose(); child = null; } base.Dispose(); if (GraphInst != null) { GraphInst.OnGraphParameterUpdate -= GraphInst_OnGraphParameterUpdate; GraphInst.Dispose(); GraphInst = null; } }
public override void SetSize(int w, int h) { base.SetSize(w, h); GraphInst?.ResizeWith(w, h); }
public override void AssignPixelType(GraphPixelType pix) { base.AssignPixelType(pix); GraphInst?.AssignPixelType(pix); }
protected override void OnPixelFormatChange() { base.OnPixelFormatChange(); GraphInst?.AssignPixelType(internalPixelType); }
public void AssignSeed(int seed) { randomSeed = seed; GraphInst?.AssignSeed(seed); }
public bool Load(string path) { if (string.IsNullOrEmpty(path)) { return(false); } isArchive = path.ToLower().EndsWith(".mtga"); //convert path to a relative resource path string relative = Path.Combine("resources", Path.GetFileName(path)); if (GraphInst != null) { GraphData = null; GraphInst.OnGraphParameterUpdate -= GraphParameterValue_OnGraphParameterUpdate; GraphInst.Dispose(); GraphInst = null; } nameMap = new Dictionary <string, GraphParameterValue>(); //handle archives within archives if (isArchive && archive != null) { archive.Open(); var files = archive.GetAvailableFiles(); var m = files.Find(f => f.path.Equals(relative)); if (m != null) { loading = true; child = new MTGArchive(relative, m.ExtractBinary()); child.Open(); var childFiles = child.GetAvailableFiles(); if (childFiles != null) { var mtg = childFiles.Find(f => f.path.ToLower().EndsWith(".mtg")); if (mtg != null) { loading = true; this.path = path; string nm = Path.GetFileNameWithoutExtension(path); Name = nm; GraphData = mtg.ExtractText(); child.Close(); PrepareGraph(); archive.Close(); loading = false; return(true); } else { this.path = null; } } else { this.path = null; } } else { this.path = null; } archive.Close(); } //handle absolute path to archive when not in another archive else if (File.Exists(path) && isArchive && archive == null) { loading = true; child = new MTGArchive(path); child.Open(); var childFiles = child.GetAvailableFiles(); if (childFiles != null) { var mtg = childFiles.Find(f => f.path.ToLower().EndsWith(".mtg")); if (mtg != null) { loading = true; this.path = path; string nm = Path.GetFileNameWithoutExtension(path); Name = nm; GraphData = mtg.ExtractText(); child.Close(); PrepareGraph(); loading = false; return(true); } else { this.path = null; } } else { this.path = null; } } //otherwise try relative storage for the archive when not in another archive else if (isArchive && archive == null && ParentGraph != null && !string.IsNullOrEmpty(ParentGraph.CWD) && File.Exists(Path.Combine(ParentGraph.CWD, relative))) { string realPath = Path.Combine(ParentGraph.CWD, relative); child = new MTGArchive(realPath); child.Open(); var childFiles = child.GetAvailableFiles(); if (childFiles != null) { var mtg = childFiles.Find(f => f.path.ToLower().EndsWith(".mtg")); if (mtg != null) { loading = true; this.path = path; string nm = Path.GetFileNameWithoutExtension(path); Name = nm; GraphData = mtg.ExtractText(); child.Close(); PrepareGraph(); loading = false; return(true); } else { this.path = null; } } else { this.path = null; } } else if (!isArchive && File.Exists(path) && Path.GetExtension(path).ToLower().EndsWith("mtg")) { loading = true; this.path = path; string nm = Path.GetFileNameWithoutExtension(path); Name = nm; GraphData = File.ReadAllText(path); PrepareGraph(); loading = false; return(true); } else { this.path = null; } return(false); }