Fix Blueprint Class

Blueprint dependencies was a dict, should be a list
This commit is contained in:
hyperion51 2020-04-14 05:32:00 +01:00
commit dabfc62481
6 changed files with 56 additions and 21 deletions

View file

@ -1876,8 +1876,8 @@
<e p="ZoneGenerator.cs" t="Include" />
</e>
<e p="StrategyGameManager.cs" t="Include" />
<e p="TechTreeMsagl.cs" t="Include" />
<e p="TechTreeTest.cs" t="Include" />
<e p="TechTreeTestMsagl.cs" t="Include" />
<e p="UI" t="Include">
<e p="BackgroundRenderer.cs" t="Include" />
<e p="ClickableCollider.cs" t="Include" />

View file

@ -1020,8 +1020,8 @@
<Compile Include="Assets\Scripts\NIH\XKCDColors.cs" />
<Compile Include="Assets\Scripts\Prototype.cs" />
<Compile Include="Assets\Scripts\StrategyGameManager.cs" />
<Compile Include="Assets\Scripts\TechTreeMsagl.cs" />
<Compile Include="Assets\Scripts\TechTreeTest.cs" />
<Compile Include="Assets\Scripts\TechTreeTestMsagl.cs" />
<Compile Include="Assets\Scripts\UI\BackgroundRenderer.cs" />
<Compile Include="Assets\Scripts\UI\ClickableCollider.cs" />
<Compile Include="Assets\Scripts\UI\ClickCatcher.cs" />

View file

@ -34,7 +34,7 @@ public class BlueprintData : DatabaseEntry, INamedEntry
public float ResearchTime;
[InspectableDatabaseLink(typeof(BlueprintData)), JsonProperty("researchDependencies"), Key(9)]
public Dictionary<Guid, int> Dependencies = new Dictionary<Guid, int>();
public List<Guid> Dependencies = new List<Guid>();
[IgnoreMember] public string EntryName
{

View file

@ -13,6 +13,8 @@ public class StrategyGameManager : MonoBehaviour
public TabGroup PrimaryTabGroup;
public TabButton GalaxyTabButton;
public TabButton ZoneTabButton;
public TabButton TechTabButton;
public TechTreeMsagl TechTree;
public Prototype GalaxyZonePrototype;
public Prototype GalaxyZoneLinkPrototype;
public MeshRenderer GalaxyBackground;
@ -52,6 +54,7 @@ public class StrategyGameManager : MonoBehaviour
private float _galaxyOrthoSize = 50;
private Material _boundaryMaterial;
private Material _backgroundMaterial;
private bool _techLayoutGenerated;
void Start()
{
@ -99,6 +102,15 @@ public class StrategyGameManager : MonoBehaviour
PopulateZone();
Camera.transform.position = -Vector3.forward;
}
if (_currentTab == TechTabButton)
{
if (!_techLayoutGenerated)
{
TechTree.Blueprints = _cache.GetAll<BlueprintData>().ToArray();
TechTree.GenerateTechs();
}
}
};
_boundaryMaterial = ZoneBoundary.material;

View file

@ -12,7 +12,7 @@ using Random = UnityEngine.Random;
using Unity.Mathematics;
using static Unity.Mathematics.math;
public class TechTreeTestMsagl : MonoBehaviour
public class TechTreeMsagl : MonoBehaviour
{
[Section("Assets")]
public string IconsPath;
@ -69,6 +69,8 @@ public class TechTreeTestMsagl : MonoBehaviour
private List<Prototype> _arrowInstances = new List<Prototype>();
private Texture2D[] _icons;
public BlueprintData[] Blueprints { get; set; }
void Start()
{
_icons = Resources.LoadAll<Texture2D>(IconsPath);
@ -76,7 +78,7 @@ public class TechTreeTestMsagl : MonoBehaviour
void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
if(TestMode && Input.GetKeyDown(KeyCode.Space))
GenerateTechs();
}
@ -111,7 +113,7 @@ public class TechTreeTestMsagl : MonoBehaviour
return region;
}
void GenerateTechs()
public void GenerateTechs()
{
foreach (var instance in _ringInstances) instance.ReturnToPool();
_ringInstances.Clear();
@ -126,32 +128,53 @@ public class TechTreeTestMsagl : MonoBehaviour
_arrowInstances.Clear();
var graph = new GeometryGraph();
for (int i = 0; i < TechCount; i++)
if (TestMode)
{
var node = NewNode(i);
graph.Nodes.Add(node);
if(i>SeedTechs) graph.Edges.Add(new Edge(graph.Nodes[Random.Range(max(0,i-RollingWindowSize),i-1)], node));
for (int i = 0; i < TechCount; i++)
{
var node = NewNode(i);
graph.Nodes.Add(node);
if(i>SeedTechs) graph.Edges.Add(new Edge(graph.Nodes[Random.Range(max(0,i-RollingWindowSize),i-1)], node));
}
foreach (var vertex in graph.Nodes.Where(v=>!graph.Edges.Any(e=>e.Source==v||e.Target==v)))
{
graph.Edges.Add(new Edge(vertex, graph.Nodes[Random.Range(0,TechCount-1)]));
}
}
foreach (var vertex in graph.Nodes.Where(v=>!graph.Edges.Any(e=>e.Source==v||e.Target==v)))
else
{
graph.Edges.Add(new Edge(vertex, graph.Nodes[Random.Range(0,TechCount-1)]));
var nodeMap = new Dictionary<BlueprintData, Node>();
foreach (var blueprint in Blueprints)
{
var node = NewNode(blueprint);
nodeMap[blueprint] = node;
graph.Nodes.Add(node);
}
foreach (var targetBlueprint in Blueprints)
{
//foreach(var sourceBlueprint in Blueprints.Where(sb => targetBlueprint.Dependencies.Any(dep=>sb.ID==dep)))
}
}
var islands = graph.GetClusteredConnectedComponents();
var islandMap =
graph.Nodes.ToDictionary(n => n, n => islands.Find(c => c.Nodes.Any(cn => cn.UserData == n)));
foreach (var island in islands)
if (TestMode)
{
foreach (var node in island.Nodes)
foreach (var island in islands)
{
var region = GetRegion(island, node, DependencyAncestorDepth, DependencyDepth);
while (Random.value < MultipleDependencyProbability && region.Count > 0)
foreach (var node in island.Nodes)
{
var dependency = region.RandomElement();
graph.Edges.Add(new Edge(dependency.UserData as Node, node.UserData as Node));
region.Remove(dependency);
var region = GetRegion(island, node, DependencyAncestorDepth, DependencyDepth);
while (Random.value < MultipleDependencyProbability && region.Count > 0)
{
var dependency = region.RandomElement();
graph.Edges.Add(new Edge(dependency.UserData as Node, node.UserData as Node));
region.Remove(dependency);
}
}
}
}