TECH TREES WHOO

Implemented procedural tech tree generation by porting GraphSharp to Unity.
Also, some database editor convenience changes.
This commit is contained in:
hyperion51 2020-04-11 19:18:02 +01:00
commit d5f2e3734a
573 changed files with 31001 additions and 222 deletions

View file

@ -0,0 +1,66 @@
using System.ComponentModel;
using System.Diagnostics.Contracts;
using QuickGraph;
using System.Diagnostics;
namespace GraphSharp.Algorithms.Highlight
{
public abstract class HighlightAlgorithmBase<TVertex, TEdge, TGraph, TParameters> : IHighlightAlgorithm<TVertex, TEdge, TGraph>
where TVertex : class
where TEdge : IEdge<TVertex>
where TGraph : class, IBidirectionalGraph<TVertex, TEdge>
where TParameters : class, IHighlightParameters
{
public IHighlightController<TVertex, TEdge, TGraph> Controller { get; private set; }
IHighlightParameters IHighlightAlgorithm<TVertex, TEdge, TGraph>.Parameters
{
get { return Parameters; }
}
public TParameters Parameters { get; private set; }
protected HighlightAlgorithmBase(
IHighlightController<TVertex, TEdge, TGraph> controller,
IHighlightParameters parameters )
{
Controller = controller;
TrySetParameters( parameters );
}
public abstract void ResetHighlight();
public abstract bool OnVertexHighlighting( TVertex vertex );
public abstract bool OnVertexHighlightRemoving( TVertex vertex );
public abstract bool OnEdgeHighlighting( TEdge edge );
public abstract bool OnEdgeHighlightRemoving( TEdge edge );
public bool IsParametersSettable( IHighlightParameters parameters )
{
return parameters != null && parameters is TParameters;
}
public bool TrySetParameters( IHighlightParameters parameters )
{
if ( IsParametersSettable( parameters ) )
{
if ( Parameters != null )
Parameters.PropertyChanged -= OnParameterPropertyChanged;
Parameters = (TParameters)parameters;
if ( Parameters != null )
Parameters.PropertyChanged += OnParameterPropertyChanged;
return true;
}
return false;
}
protected virtual void OnParametersChanged()
{
this.ResetHighlight();
}
private void OnParameterPropertyChanged( object sender, PropertyChangedEventArgs e )
{
OnParametersChanged();
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: de0a87e59efe95a44a7c95625f1584af
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,20 @@
using QuickGraph;
namespace GraphSharp.Algorithms.Highlight
{
public class HighlightContext<TVertex, TEdge, TGraph> : IHighlightContext<TVertex, TEdge, TGraph>
where TVertex : class
where TEdge : IEdge<TVertex>
where TGraph : class, IBidirectionalGraph<TVertex, TEdge>
{
public TGraph Graph
{
get; private set;
}
public HighlightContext(TGraph graph)
{
this.Graph = graph;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2480fc7369694ef4e9506685b8902650
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,28 @@
using System.ComponentModel;
namespace GraphSharp.Algorithms.Highlight
{
public class HighlightParameterBase : IHighlightParameters
{
#region ICloneable Members
public object Clone()
{
return MemberwiseClone();
}
#endregion
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged( string propertyName )
{
if ( PropertyChanged != null )
PropertyChanged( this, new PropertyChangedEventArgs( propertyName ) );
}
#endregion
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 975eca90cc758be4886238e860c8edbc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,25 @@
using QuickGraph;
namespace GraphSharp.Algorithms.Highlight
{
public interface IHighlightAlgorithm<TVertex, TEdge, TGraph>
where TVertex : class
where TEdge : IEdge<TVertex>
where TGraph : class, IBidirectionalGraph<TVertex, TEdge>
{
IHighlightParameters Parameters { get; }
/// <summary>
/// Reset the whole highlight.
/// </summary>
void ResetHighlight();
bool OnVertexHighlighting( TVertex vertex );
bool OnVertexHighlightRemoving( TVertex vertex );
bool OnEdgeHighlighting( TEdge edge );
bool OnEdgeHighlightRemoving( TEdge edge );
bool IsParametersSettable(IHighlightParameters parameters);
bool TrySetParameters(IHighlightParameters parameters);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2c8c1786bae9007498205dc11952ffb9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,24 @@
using System.Collections.Generic;
using QuickGraph;
namespace GraphSharp.Algorithms.Highlight
{
public interface IHighlightAlgorithmFactory<TVertex, TEdge, TGraph>
where TVertex : class
where TEdge : IEdge<TVertex>
where TGraph : class, IBidirectionalGraph<TVertex, TEdge>
{
IEnumerable<string> HighlightModes { get; }
bool IsValidMode( string mode );
IHighlightAlgorithm<TVertex, TEdge, TGraph> CreateAlgorithm(
string highlightMode,
IHighlightContext<TVertex, TEdge, TGraph> context,
IHighlightController<TVertex, TEdge, TGraph> controller,
IHighlightParameters parameters );
IHighlightParameters CreateParameters( string highlightMode, IHighlightParameters oldParameters );
string GetHighlightMode( IHighlightAlgorithm<TVertex, TEdge, TGraph> algorithm );
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7544860789ab4cd42aef36c403689688
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,11 @@
using QuickGraph;
namespace GraphSharp.Algorithms.Highlight
{
public interface IHighlightContext<TVertex, TEdge, TGraph>
where TEdge : IEdge<TVertex>
where TGraph : IVertexAndEdgeListGraph<TVertex, TEdge>
{
TGraph Graph { get; }
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 79156d864172f444695ab27099ac9be9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,37 @@
using System.Collections.Generic;
using QuickGraph;
namespace GraphSharp.Algorithms.Highlight
{
public interface IHighlightController<TVertex, TEdge, TGraph>
where TVertex : class
where TEdge : IEdge<TVertex>
where TGraph : class, IBidirectionalGraph<TVertex, TEdge>
{
TGraph Graph { get; }
IEnumerable<TVertex> HighlightedVertices { get; }
IEnumerable<TVertex> SemiHighlightedVertices { get; }
IEnumerable<TEdge> HighlightedEdges { get; }
IEnumerable<TEdge> SemiHighlightedEdges { get; }
bool IsHighlightedVertex( TVertex vertex );
bool IsHighlightedVertex( TVertex vertex, out object highlightInfo );
bool IsSemiHighlightedVertex( TVertex vertex );
bool IsSemiHighlightedVertex( TVertex vertex, out object semiHighlightInfo );
bool IsHighlightedEdge( TEdge edge );
bool IsHighlightedEdge( TEdge edge, out object highlightInfo );
bool IsSemiHighlightedEdge( TEdge edge );
bool IsSemiHighlightedEdge( TEdge edge, out object semiHighlightInfo );
void HighlightVertex( TVertex vertex, object highlightInfo );
void SemiHighlightVertex( TVertex vertex, object semiHighlightInfo );
void HighlightEdge( TEdge edge, object highlightInfo );
void SemiHighlightEdge( TEdge edge, object semiHighlightInfo );
void RemoveHighlightFromVertex( TVertex vertex );
void RemoveSemiHighlightFromVertex( TVertex vertex );
void RemoveHighlightFromEdge( TEdge edge );
void RemoveSemiHighlightFromEdge( TEdge edge );
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e0e4a052750ba434d9e7b47f41254ebc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,9 @@
using System;
using System.ComponentModel;
namespace GraphSharp.Algorithms.Highlight
{
public interface IHighlightParameters : ICloneable, INotifyPropertyChanged
{
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 74d481da9efa96c4f835885ef71fb92f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,105 @@
using QuickGraph;
namespace GraphSharp.Algorithms.Highlight
{
public class SimpleHighlightAlgorithm<TVertex, TEdge, TGraph> : HighlightAlgorithmBase<TVertex, TEdge, TGraph, IHighlightParameters>
where TVertex : class
where TEdge : IEdge<TVertex>
where TGraph : class, IBidirectionalGraph<TVertex, TEdge>
{
public SimpleHighlightAlgorithm(
IHighlightController<TVertex, TEdge, TGraph> controller,
IHighlightParameters parameters )
: base( controller, parameters )
{
}
private void ClearSemiHighlights()
{
foreach ( var vertex in Controller.SemiHighlightedVertices )
Controller.RemoveSemiHighlightFromVertex( vertex );
foreach ( var edge in Controller.SemiHighlightedEdges )
Controller.RemoveSemiHighlightFromEdge( edge );
}
private void ClearAllHighlights()
{
ClearSemiHighlights();
foreach ( var vertex in Controller.HighlightedVertices )
Controller.RemoveHighlightFromVertex( vertex );
foreach ( var edge in Controller.HighlightedEdges )
Controller.RemoveHighlightFromEdge( edge );
}
/// <summary>
/// Resets the semi-highlights according to the actually
/// highlighted vertices/edges.
///
/// This method should be called if the graph changed,
/// or the highlights should be resetted.
/// </summary>
public override void ResetHighlight()
{
ClearAllHighlights();
}
public override bool OnVertexHighlighting( TVertex vertex )
{
ClearAllHighlights();
if ( vertex == null || !Controller.Graph.ContainsVertex( vertex ) )
return false;
//semi-highlight the in-edges, and the neighbours on their other side
foreach ( var edge in Controller.Graph.InEdges( vertex ) )
{
Controller.SemiHighlightEdge( edge, "InEdge" );
if ( edge.Source == vertex || Controller.IsHighlightedVertex( edge.Source ) )
continue;
Controller.SemiHighlightVertex( edge.Source, "Source" );
}
//semi-highlight the out-edges
foreach ( var edge in Controller.Graph.OutEdges( vertex ) )
{
Controller.SemiHighlightEdge( edge, "OutEdge" );
if ( edge.Target == vertex || Controller.IsHighlightedVertex( edge.Target ) )
continue;
Controller.SemiHighlightVertex( edge.Target, "Target" );
}
Controller.HighlightVertex( vertex, "None" );
return true;
}
public override bool OnVertexHighlightRemoving( TVertex vertex )
{
ClearAllHighlights();
return true;
}
public override bool OnEdgeHighlighting( TEdge edge )
{
ClearAllHighlights();
//highlight the source and the target
if ( Equals( edge, default( TEdge ) ) || !Controller.Graph.ContainsEdge( edge ) )
return false;
Controller.HighlightEdge( edge, null );
Controller.SemiHighlightVertex( edge.Source, "Source" );
Controller.SemiHighlightVertex( edge.Target, "Target" );
return true;
}
public override bool OnEdgeHighlightRemoving( TEdge edge )
{
ClearAllHighlights();
return true;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 707756178922bf343bb53c545a66f6d0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,58 @@
using System.Collections.Generic;
using System.Linq;
using QuickGraph;
namespace GraphSharp.Algorithms.Highlight
{
public class StandardHighlightAlgorithmFactory<TVertex, TEdge, TGraph> : IHighlightAlgorithmFactory<TVertex, TEdge, TGraph>
where TVertex : class
where TEdge : IEdge<TVertex>
where TGraph : class, IBidirectionalGraph<TVertex, TEdge>
{
private static readonly string[] highlightModes = { "Simple" };
public IEnumerable<string> HighlightModes
{
get { return highlightModes; }
}
public bool IsValidMode( string mode )
{
return string.IsNullOrEmpty( mode ) || highlightModes.Contains( mode );
}
public IHighlightAlgorithm<TVertex, TEdge, TGraph> CreateAlgorithm(
string highlightMode,
IHighlightContext<TVertex, TEdge, TGraph> context,
IHighlightController<TVertex, TEdge, TGraph> controller,
IHighlightParameters parameters )
{
switch (highlightMode)
{
case "Simple":
return new SimpleHighlightAlgorithm<TVertex, TEdge, TGraph>(controller, parameters);
default:
return null;
}
}
public IHighlightParameters CreateParameters( string highlightMode, IHighlightParameters oldParameters )
{
switch (highlightMode)
{
case "Simple":
return new HighlightParameterBase();
default:
return new HighlightParameterBase();
}
}
public string GetHighlightMode( IHighlightAlgorithm<TVertex, TEdge, TGraph> algorithm )
{
if ( algorithm is SimpleHighlightAlgorithm<TVertex, TEdge, TGraph> )
return "Simple";
return null;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ad9f5a34732fe36489821652974bddb8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: