From ae98448942bacedb249f00585d3560b2fdb74afd Mon Sep 17 00:00:00 2001 From: hyperion51 Date: Wed, 11 Mar 2020 15:18:36 +0000 Subject: [PATCH] Porting Galaxy Editor Ported the galaxy editor code from the old Aetheria --- .../.idea/contentModel.xml | 2 + Assembly-CSharp-Editor.csproj | 4 + Assembly-CSharp.csproj | 4 + Assets/Plugins/Microsoft.SqlServer.Types.dll | 3 + .../Microsoft.SqlServer.Types.dll.meta | 33 ++ Assets/Resources/Test Galaxy.asset | 3 + Assets/Resources/Test Galaxy.asset.meta | 8 + Assets/Scenes/Main.unity | 9 - Assets/Scripts/Editor/GalaxyEditor.cs | 400 ++++++++++++++++++ Assets/Scripts/Editor/GalaxyEditor.cs.meta | 11 + Assets/Scripts/MarkovNameGenerator.cs | 126 ++++++ Assets/Scripts/MarkovNameGenerator.cs.meta | 11 + Economy.Shared.Unity.csproj | 3 + MagicOnion.Abstractions.csproj | 3 + MagicOnion.Unity.csproj | 3 + MagicOnion.csproj | 3 + MessagePack.csproj | 3 + 17 files changed, 620 insertions(+), 9 deletions(-) create mode 100644 Assets/Plugins/Microsoft.SqlServer.Types.dll create mode 100644 Assets/Plugins/Microsoft.SqlServer.Types.dll.meta create mode 100644 Assets/Resources/Test Galaxy.asset create mode 100644 Assets/Resources/Test Galaxy.asset.meta create mode 100644 Assets/Scripts/Editor/GalaxyEditor.cs create mode 100644 Assets/Scripts/Editor/GalaxyEditor.cs.meta create mode 100644 Assets/Scripts/MarkovNameGenerator.cs create mode 100644 Assets/Scripts/MarkovNameGenerator.cs.meta diff --git a/.idea/.idea.Aetheria-Economy/.idea/contentModel.xml b/.idea/.idea.Aetheria-Economy/.idea/contentModel.xml index 1589cfacd..3c182b27c 100644 --- a/.idea/.idea.Aetheria-Economy/.idea/contentModel.xml +++ b/.idea/.idea.Aetheria-Economy/.idea/contentModel.xml @@ -16,6 +16,7 @@ + @@ -26,6 +27,7 @@ + diff --git a/Assembly-CSharp-Editor.csproj b/Assembly-CSharp-Editor.csproj index e381789a0..9f66292bd 100644 --- a/Assembly-CSharp-Editor.csproj +++ b/Assembly-CSharp-Editor.csproj @@ -61,6 +61,7 @@ + @@ -407,6 +408,9 @@ C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll + + C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Microsoft.SqlServer.Types.dll + C:/Program Files/Unity/Hub/Editor/2018.4.17f1/Editor/Data/MonoBleedingEdge/lib/mono/4.7.1-api/mscorlib.dll diff --git a/Assembly-CSharp.csproj b/Assembly-CSharp.csproj index a53de719a..d339cf467 100644 --- a/Assembly-CSharp.csproj +++ b/Assembly-CSharp.csproj @@ -72,6 +72,7 @@ + @@ -835,6 +836,9 @@ C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Google.Protobuf/lib/net45/Google.Protobuf.dll + + C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Microsoft.SqlServer.Types.dll + C:/Program Files/Unity/Hub/Editor/2018.4.17f1/Editor/Data/MonoBleedingEdge/lib/mono/4.7.1-api/mscorlib.dll diff --git a/Assets/Plugins/Microsoft.SqlServer.Types.dll b/Assets/Plugins/Microsoft.SqlServer.Types.dll new file mode 100644 index 000000000..baea04b3b --- /dev/null +++ b/Assets/Plugins/Microsoft.SqlServer.Types.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:953715190fcf3aed74ac1552a2d1c1ab0d487300cc673df28ff4efd0866cd1d4 +size 396992 diff --git a/Assets/Plugins/Microsoft.SqlServer.Types.dll.meta b/Assets/Plugins/Microsoft.SqlServer.Types.dll.meta new file mode 100644 index 000000000..fdb6b1155 --- /dev/null +++ b/Assets/Plugins/Microsoft.SqlServer.Types.dll.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: 0c9892977144f954eaeb53285dbbb60e +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + Windows Store Apps: WindowsStoreApps + second: + enabled: 0 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Test Galaxy.asset b/Assets/Resources/Test Galaxy.asset new file mode 100644 index 000000000..c8598fdde --- /dev/null +++ b/Assets/Resources/Test Galaxy.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:04fce9f206f067f70b4248f38c0ef6eebdbc784f7d33dc5baeb4fb60ba291237 +size 836 diff --git a/Assets/Resources/Test Galaxy.asset.meta b/Assets/Resources/Test Galaxy.asset.meta new file mode 100644 index 000000000..1ed5e52ab --- /dev/null +++ b/Assets/Resources/Test Galaxy.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 931e677be56754f4f9d3d0817e2d38df +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index 79b275d96..a7f483aaa 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -122,7 +122,6 @@ GameObject: m_Component: - component: {fileID: 408552541} - component: {fileID: 408552540} - - component: {fileID: 408552539} - component: {fileID: 408552538} m_Layer: 0 m_Name: Gravity Camera @@ -146,14 +145,6 @@ MonoBehaviour: BackgroundMaterial: {fileID: 2100000, guid: 90cead50364300d47bb35194fb52c117, type: 2} GravityTexture: {fileID: 0} GravityRenderer: {fileID: 1956833085} ---- !u!81 &408552539 -AudioListener: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 408552537} - m_Enabled: 1 --- !u!20 &408552540 Camera: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Editor/GalaxyEditor.cs b/Assets/Scripts/Editor/GalaxyEditor.cs new file mode 100644 index 000000000..1cf894fb3 --- /dev/null +++ b/Assets/Scripts/Editor/GalaxyEditor.cs @@ -0,0 +1,400 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Remoting.Messaging; +using MIConvexHull; +using UniRx; +using UnityEngine; +using UnityEditor; + +[CustomEditor(typeof(Galaxy))] +public class GalaxyEditor : Editor +{ + private Texture2D _preview; + private int _width = 0; + private TextAsset _nameData; + private bool _showNameData; + private bool _showCultureMaps; + private Dictionary _expandRegion = new Dictionary(); + private Dictionary _expandSubregion = new Dictionary(); + private NameData _names = new NameData(); + private GalaxyMapLayerData _currentLayer; + private string _currentLayerName = "Star Density"; + private bool _showStarEditor; + private int _hilbertOrder = 6; + private ulong _hilbertIndex; + private int _starCount = 1; + private int _nameMinLength = 5; + private int _nameMaxLength = 8; + private float _maxLinkLength = .1f; + private float _linkFilter = .5f; + private IEnumerable _stars = new Vector2[0]; + private bool _drawStars; + private bool _drawCulture; + private bool _drawLinks; + private VoronoiMesh< Vertex2, Cell2, VoronoiEdge> _voronoiMesh; + private List _starLinks = new List(); + + public override void OnInspectorGUI() + { + var galaxy = target as Galaxy; + + if (_currentLayer == null) + _currentLayer = galaxy.MapData.StarDensity; + + if (Screen.width != _width) + { + _width = Screen.width; + _preview = new Texture2D(_width,_width,TextureFormat.ARGB32,false); + Render(galaxy.MapData, _currentLayer); + } + + GUILayout.Label("Preview", EditorStyles.boldLabel); + EditorGUI.DrawPreviewTexture(EditorGUILayout.GetControlRect(false, _width), _preview); + EditorGUI.BeginChangeCheck(); + _drawStars = EditorGUILayout.ToggleLeft($"Display {_stars.Count()} Stars", _drawStars); + _drawCulture = EditorGUILayout.ToggleLeft("Display Cultures", _drawCulture); + _drawLinks = EditorGUILayout.ToggleLeft($"Display {_starLinks.Count} Links", _drawLinks); + GUILayout.Space(10); + + // Show default inspector property editor + DrawDefaultInspector (); + + if (galaxy.MapData.CultureDensities.Count != galaxy.NameDatabase.Count) + galaxy.MapData.CultureDensities = galaxy.NameDatabase.Select(continent=>new GalaxyMapLayerData()).ToList(); + EditorGUILayout.BeginVertical("Box"); + EditorGUI.indentLevel++; + GUILayout.Label(_currentLayerName); + Inspect(_currentLayer); + EditorGUI.indentLevel--; + EditorGUILayout.EndVertical(); + if(EditorGUI.EndChangeCheck()) + Render(galaxy.MapData, _currentLayer); + + EditorGUILayout.BeginVertical("Box"); + EditorGUI.indentLevel++; + _showCultureMaps = EditorGUILayout.Foldout(_showCultureMaps, "Culture Density Maps"); + if (_showCultureMaps) + { + EditorGUI.indentLevel++; + for (var i = 0; i < galaxy.MapData.CultureDensities.Count; i++) + { + var cultureMap = galaxy.MapData.CultureDensities[i]; + var data = galaxy.NameDatabase[i]; + if (GUILayout.Button("Inspect " + data.Name)) + { + _currentLayerName = data.Name; + _currentLayer = cultureMap; + Render(galaxy.MapData, _currentLayer); + } + } + EditorGUI.indentLevel--; + } + else if(_currentLayer != galaxy.MapData.StarDensity) + { + _currentLayerName = "Star Density"; + _currentLayer = galaxy.MapData.StarDensity; + Render(galaxy.MapData, _currentLayer); + } + EditorGUI.indentLevel--; + EditorGUILayout.EndVertical(); + + EditorGUILayout.BeginVertical("Box"); + EditorGUI.indentLevel++; + _showNameData = EditorGUILayout.Foldout(_showNameData, "Name Database Tools"); + if (_showNameData) + { + EditorGUI.indentLevel++; + foreach (var region in _names.Names.Keys) + { + if (!_expandRegion.ContainsKey(region)) + _expandRegion[region] = false; + _expandRegion[region] = EditorGUILayout.Foldout(_expandRegion[region], region + ": " + _names.Names[region].Count + " Subregions"); + if (_expandRegion[region]) + { + EditorGUI.indentLevel++; + foreach (var subregion in _names.Names[region].Keys) + { + if (!_expandSubregion.ContainsKey(subregion)) + _expandSubregion[subregion] = false; + _expandSubregion[subregion] = EditorGUILayout.Foldout(_expandSubregion[subregion], subregion + ": " + _names.Names[region][subregion].Count + " Towns"); + if (_expandSubregion[subregion]) + { + EditorGUI.indentLevel++; + foreach (var town in _names.Names[region][subregion]) + { + GUILayout.Label(town); + } + EditorGUI.indentLevel--; + } + } + EditorGUI.indentLevel--; + } + } + EditorGUI.indentLevel--; + GUILayout.Space(10); + _nameData = EditorGUILayout.ObjectField(_nameData, typeof(TextAsset), false) as TextAsset; + if (GUILayout.Button("Parse Data")) + { + _names.Names.Clear(); + foreach (var s in _nameData.text.Split('\n')) + _names.Add(s); + } + if (GUILayout.Button("Filter Data")) + { + if (!_names.Names.ContainsKey("World")) + { + _names.Names["World"] = new Dictionary>(); + _names.Names["World"]["Miscellaneous"] = new List(); + } + foreach (var region in _names.Names.Keys.Where(s=>s!="World").ToArray()) + { + if (!_names.Names[region].ContainsKey("Miscellaneous")) + _names.Names[region]["Miscellaneous"] = new List(); + foreach (var subregion in _names.Names[region].Keys.Where(s=>s!="Miscellaneous").ToArray()) + { + if (_names.Names[region][subregion].Count < 500) + { + _names.Names[region]["Miscellaneous"].AddRange(_names.Names[region][subregion]); + _names.Names[region].Remove(subregion); + } + } + if (_names.Names[region].Count == 1) + { + _names.Names["World"]["Miscellaneous"].AddRange(_names.Names[region]["Miscellaneous"]); + _names.Names.Remove(region); + } + } + } + if (GUILayout.Button("Set Data")) + { + var data = new List(); + data.AddRange(_names.Names.Select(kvp => new ContinentData{Name = kvp.Key,Regions = new List()})); + data.ForEach(c=>c.Regions.AddRange(_names.Names[c.Name].Select(kvp=> new RegionData{Name = kvp.Key,Towns = kvp.Value}))); + galaxy.NameDatabase = data; + } + } + EditorGUI.indentLevel--; + EditorGUILayout.EndVertical(); + + EditorGUILayout.BeginVertical("Box"); + EditorGUI.indentLevel++; + _showStarEditor = EditorGUILayout.Foldout(_showStarEditor, "Star Tools"); + if (_showStarEditor) + { + _hilbertOrder = EditorGUILayout.IntField("Hilbert Order", _hilbertOrder); + _starCount = EditorGUILayout.IntField("Star Count", _starCount); + //_hilbertIndex = (ulong) EditorGUILayout.IntField("Hilbert Index", (int) _hilbertIndex); + if (GUILayout.Button("Evaluate Hilbert Curve")) + { + var points = EvaluateHilbert(_hilbertOrder,false); + Debug.Log($"Hilbert curve has {points.Count()} points, resolution {Mathf.RoundToInt(points.Max(p=>p.x))+1}"); + } + if (GUILayout.Button("Generate Stars")) + { + var points = EvaluateHilbert(_hilbertOrder).ToArray(); + var stars = new List(); + int bail = 0; + while (stars.Count < _starCount && bail < 10) + { + var accum = 0f; + foreach (var hp in points.Select(p=>p+UnityEngine.Random.insideUnitCircle * ((points[0]-points[1]).magnitude/2))) + { + var den = galaxy.MapData.StarDensity.Evaluate(hp, galaxy.MapData); + if(!float.IsNaN(den)) + accum += den * UnityEngine.Random.value; +// else +// Debug.Log($"Density at ({hp.x},{hp.y}) is NaN"); + if (accum > 1) + { + stars.Add(hp); + accum = 0; + } + //Debug.Log($"Accumulator: {accum}"); + } + bail++; + } + Debug.Log($"Generated {stars.Count} stars."); + _stars = stars; + } + if (_stars.Any()) + { + _nameMinLength = EditorGUILayout.IntField("Minimum Length", _nameMinLength); + _nameMaxLength = EditorGUILayout.IntField("Maximum Length", _nameMaxLength); + if (GUILayout.Button("Generate Star Names")) + { + galaxy.MapData.Stars = _stars.Select(s => + { + var culture = galaxy.MapData.CultureDensities.IndexOf(galaxy.MapData.CultureDensities.OrderByDescending(c => c.Evaluate(s, galaxy.MapData)) + .First()); + var subculture = UnityEngine.Random.Range(0, galaxy.NameDatabase[culture].Regions.Count); + var markov = new MarkovNameGenerator(galaxy.NameDatabase[culture].Regions[subculture].Towns, 2, _nameMinLength, _nameMaxLength); + return new StarData + { + Position = s, + NameSource = (galaxy.NameDatabase[culture].Regions[subculture].Name == "Miscellaneous") + ? galaxy.NameDatabase[culture].Name + : galaxy.NameDatabase[culture].Regions[subculture].Name, + Names = Enumerable.Range(0,20).Select(_ => markov.NextName).ToList() + }; + }).ToList(); + } + _maxLinkLength = EditorGUILayout.FloatField("Max Link Length", _maxLinkLength); + if (GUILayout.Button("Generate Star Links")) + { + _voronoiMesh = VoronoiMesh>.Create(_stars.Select(s=>new Vertex2(s.x,s.y)).ToList()); + _starLinks.Clear(); + // Each cell in this collection represents one of the triangle faces of the Delaunay Triangulation + foreach (var cell in _voronoiMesh.Vertices) + { + var links = new[] {new VoronoiLink(cell.Vertices[0], cell.Vertices[1]), + new VoronoiLink(cell.Vertices[0], cell.Vertices[2]), + new VoronoiLink(cell.Vertices[2], cell.Vertices[1])}; + + _starLinks.AddRange(links.Where(l=>!_starLinks.ContainsLine(l) && l.Length < _maxLinkLength)); + } + } + if (_starLinks.Any()) + { + _linkFilter = EditorGUILayout.FloatField("Link Filter Percentage", _linkFilter); + if (GUILayout.Button("Filter Star Links")) + { + var bail = 0; + var count = _starLinks.Count * Mathf.Clamp01(_linkFilter); + var deadLinks = new List(); + for (int i = 0; i < count && bail < count*10; bail++) + { + var link = _starLinks.ElementAt(UnityEngine.Random.Range(0, _starLinks.Count)); + + if (deadLinks.Contains(link)) continue; + + var mapMinusLink = _starLinks.Where(l => !l.Equals(link)).ToArray(); + if (!mapMinusLink.ConnectedRegion(link.point1).Contains(link.point2)) + deadLinks.Add(link); + else + { + _starLinks.Remove(link); + i++; + } + //if (_starLinks.Count(sl => sl.ContainsPoint(link.point1)) > 1 && _starLinks.Count(sl => sl.ContainsPoint(link.point2)) > 1) + } + } + if (GUILayout.Button("Apply Star Links")) + { + foreach (var star in galaxy.MapData.Stars) + { + star.Links.Clear(); + star.Links.AddRange(_starLinks.Where(sl => (sl.point1.ToVector2() - star.Position).sqrMagnitude < float.Epsilon) + .Select(sl => galaxy.MapData.Stars.IndexOf(galaxy.MapData.Stars.First(s => (sl.point2.ToVector2() - s.Position).sqrMagnitude < float.Epsilon)))); + star.Links.AddRange(_starLinks.Where(sl => (sl.point2.ToVector2() - star.Position).sqrMagnitude < float.Epsilon) + .Select(sl => galaxy.MapData.Stars.IndexOf(galaxy.MapData.Stars.First(s => (sl.point1.ToVector2() - s.Position).sqrMagnitude < float.Epsilon)))); + } + } + } + } + } + EditorGUI.indentLevel--; + EditorGUILayout.EndVertical(); + + + EditorUtility.SetDirty(target); + +/* + EditorGUI.BeginChangeCheck(); + _arms = EditorGUILayout.IntField("Arms", _arms); + _twist = EditorGUILayout.FloatField("Twist", _twist); + _twistPower = EditorGUILayout.FloatField("Twist Power", _twistPower); + EditorGUILayout.field + + _edgeReduction = EditorGUILayout.FloatField("Edge Reduction", _edgeReduction); + _coreBoost = EditorGUILayout.FloatField("Core Boost", _coreBoost); + _coreBoostOffset = EditorGUILayout.FloatField("Core Boost Offset", _coreBoostOffset); + _coreBoostPower = EditorGUILayout.FloatField("Core Boost Power", _coreBoostPower); + _noiseAmplitude = EditorGUILayout.FloatField("Noise Amplitude", _noiseAmplitude); + _noise.SetFractalGain(_noiseGain = EditorGUILayout.FloatField("Noise Gain", _noiseGain)); + _noise.SetFractalLacunarity(_noiseLacunarity = EditorGUILayout.FloatField("Noise Lacunarity", _noiseLacunarity)); + _noise.SetFractalOctaves(_noiseOctaves = EditorGUILayout.IntField("Noise Octaves", _noiseOctaves)); + _noise.SetFrequency(_noiseFrequency = EditorGUILayout.FloatField("Noise Frequency", _noiseFrequency)); + if(EditorGUI.EndChangeCheck()) + Render(); + if (GUILayout.Button("Randomize Seed")) + { + _noise.SetSeed((int) (UnityEngine.Random.value*int.MaxValue)); + Render(); + } + if(GUILayout.Button("Regenerate")) + Render(); + */ + } + + private IEnumerable EvaluateHilbert(int order, bool normalized = true) + { + var points = new List(); + uint x = 0, y = 1; + ulong i = 1; + uint max = 0; + while (x != 0 || y != 0) + { + Microsoft.SqlServer.Types.SpaceFillingCurve.ReverseHilbert(order, i, out x, out y); + points.Add(new Vector2(x, y)); + if (x > max) + max = x; + i++; + } + return normalized ? points.Select(p => p / (max + 1)) : points; + } + + void Inspect(GalaxyMapLayerData layer) + { + layer.EdgeReduction = EditorGUILayout.FloatField("Edge Reduction", layer.EdgeReduction); + layer.CoreBoost = EditorGUILayout.FloatField("Core Boost", layer.CoreBoost); + layer.CoreBoostOffset = EditorGUILayout.FloatField("Core Boost Offset", layer.CoreBoostOffset); + layer.CoreBoostPower = EditorGUILayout.FloatField("Core Boost Power", layer.CoreBoostPower); + layer.NoiseOffset = EditorGUILayout.FloatField("Noise Offset", layer.NoiseOffset); + layer.NoiseAmplitude = EditorGUILayout.FloatField("Noise Amplitude", layer.NoiseAmplitude); + layer.NoiseGain = EditorGUILayout.FloatField("Noise Gain", layer.NoiseGain); + layer.NoiseLacunarity = EditorGUILayout.FloatField("Noise Lacunarity", layer.NoiseLacunarity); + layer.NoiseOctaves = EditorGUILayout.IntField("Noise Octaves", layer.NoiseOctaves); + layer.NoiseFrequency = EditorGUILayout.FloatField("Noise Frequency", layer.NoiseFrequency); + layer.NoiseOffset = EditorGUILayout.FloatField("Noise Seed", layer.NoiseOffset); + layer.SpokeOffset = EditorGUILayout.FloatField("Spoke Offset", layer.SpokeOffset); + layer.SpokeScale = EditorGUILayout.FloatField("Spoke Scale", layer.SpokeScale); + } + + void Render(GalaxyMapData galaxy, GalaxyMapLayerData layer) + { + Color[] pixels = new Color[_width*_width]; + Func indexToUV = i => new Vector2(i % _width / (float) _width, i / _width / (float) _width); + Func uvToIndex = v => (int) (v.y * _width) * _width + (int) (v.x * _width); + for (var i = 0; i < pixels.Length; i++) + { + Vector2 uv = indexToUV(i); + pixels[i] = layer.Evaluate(uv, galaxy) * Color.white; + if (_drawCulture) + pixels[i] += Color.HSVToRGB( + (float) galaxy.CultureDensities.IndexOf(galaxy.CultureDensities.OrderByDescending(m => m.Evaluate(uv, galaxy)).First()) / + galaxy.CultureDensities.Count, + 1, + .5f); + } + if(_drawStars) + foreach (var s in _stars) + { + pixels[uvToIndex(s)] = Color.white; + pixels[uvToIndex(s + Vector2.up / _width)] += Color.white / 2; + pixels[uvToIndex(s - Vector2.up / _width)] += Color.white / 2; + pixels[uvToIndex(s + Vector2.right / _width)] += Color.white / 2; + pixels[uvToIndex(s - Vector2.right / _width)] += Color.white / 2; + } + if(_drawLinks) + foreach (var l in _starLinks) + { + var pixelCount = Mathf.Max((int) (Mathf.Abs((float) (l.point1.x - l.point2.x)) * _width), (int) (Mathf.Abs((float) (l.point1.y - l.point2.y)) * _width)); + //Debug.Log($"Marching across {pixelCount} pixels!"); + for(int i=0;i sampleNames, int order, int minLength, int maxLength) + { + //fix parameter values + if (order < 1) + order = 1; + if (minLength < 1) + minLength = 1; + + _order = order; + _minLength = minLength; + _maxLength = maxLength; + + //split comma delimited lines + foreach (string line in sampleNames) + { + string[] tokens = line.Split(' ','-','\'','(',')'); + foreach (string word in tokens) + { + string upper = word.Trim().ToUpper(); + if (upper.Length < order + 1) + continue; + _samples.Add(upper + '|'); // Add end character + } + } + + //Build chains + foreach (string word in _samples) + { + for (int letter = 0; letter < word.Length - order; letter++) + { + string token = word.Substring(letter, order); + List entry = null; + if (_chains.ContainsKey(token)) + entry = _chains[token]; + else + { + entry = new List(); + _chains[token] = entry; + } + entry.Add(word[letter + order]); + } + } + } + + //Get the next random name + public string NextName + { + get + { + + string s = ""; + do + { + int n = UnityEngine.Random.Range(0,_samples.Count); + //int nameLength = _samples[n].Length; + //s = _samples[n].Substring(UnityEngine.Random.Range(0, _samples[n].Length - _order), _order);//get a random token somewhere in middle of sample word + s = _samples[n].Substring(0, _order);//get a random token at the start of a sample word + while (true)//(s.Length < nameLength) + { + string token = s.Substring(s.Length - _order, _order); + char c = GetLetter(token); + if (c != '?' && c != '|') + s += c;//GetLetter(token); + else + break; + } + +// if (s.Contains(" ")) +// { +// string[] tokens = s.Split(' '); +// s = ""; +// for (int t = 0; t < tokens.Length; t++) +// { +// if (tokens[t] == "") +// continue; +// if (tokens[t].Length == 1) +// tokens[t] = tokens[t].ToUpper(); +// else +// tokens[t] = tokens[t].Substring(0, 1) + tokens[t].Substring(1).ToLower(); +// if (s != "") +// s += " "; +// s += tokens[t]; +// } +// } +// else + s = s.Substring(0, 1) + s.Substring(1).ToLower(); + } + while (_used.Contains(s) || s.Length < _minLength || s.Length > _maxLength); + _used.Add(s); + return s; + } + } + + //Reset the used names + public void Reset() + { + _used.Clear(); + } + + //private members + private Dictionary> _chains = new Dictionary>(); + private List _samples = new List(); + private static List _used = new List(); + private int _order; + private int _minLength; + private int _maxLength; + + //Get a random letter from the chain + private char GetLetter(string token) + { + if (!_chains.ContainsKey(token)) + return '?'; + List letters = _chains[token]; + int n = UnityEngine.Random.Range(0,letters.Count); + return letters[n]; + } +} \ No newline at end of file diff --git a/Assets/Scripts/MarkovNameGenerator.cs.meta b/Assets/Scripts/MarkovNameGenerator.cs.meta new file mode 100644 index 000000000..a0219e5ec --- /dev/null +++ b/Assets/Scripts/MarkovNameGenerator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 33c3b119ccc9de447b8c8318b6f0d1af +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Economy.Shared.Unity.csproj b/Economy.Shared.Unity.csproj index c9d38d2e7..2b4177867 100644 --- a/Economy.Shared.Unity.csproj +++ b/Economy.Shared.Unity.csproj @@ -321,6 +321,9 @@ C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll + + C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Microsoft.SqlServer.Types.dll + C:/Program Files/Unity/Hub/Editor/2018.4.17f1/Editor/Data/MonoBleedingEdge/lib/mono/4.7.1-api/mscorlib.dll diff --git a/MagicOnion.Abstractions.csproj b/MagicOnion.Abstractions.csproj index 4ce1540ee..32fb479ed 100644 --- a/MagicOnion.Abstractions.csproj +++ b/MagicOnion.Abstractions.csproj @@ -327,6 +327,9 @@ C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll + + C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Microsoft.SqlServer.Types.dll + C:/Program Files/Unity/Hub/Editor/2018.4.17f1/Editor/Data/MonoBleedingEdge/lib/mono/4.7.1-api/mscorlib.dll diff --git a/MagicOnion.Unity.csproj b/MagicOnion.Unity.csproj index 174ab120f..987a3cd84 100644 --- a/MagicOnion.Unity.csproj +++ b/MagicOnion.Unity.csproj @@ -318,6 +318,9 @@ C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll + + C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Microsoft.SqlServer.Types.dll + C:/Program Files/Unity/Hub/Editor/2018.4.17f1/Editor/Data/MonoBleedingEdge/lib/mono/4.7.1-api/mscorlib.dll diff --git a/MagicOnion.csproj b/MagicOnion.csproj index 13a22d51b..579b80a9f 100644 --- a/MagicOnion.csproj +++ b/MagicOnion.csproj @@ -342,6 +342,9 @@ C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll + + C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Microsoft.SqlServer.Types.dll + C:/Program Files/Unity/Hub/Editor/2018.4.17f1/Editor/Data/MonoBleedingEdge/lib/mono/4.7.1-api/mscorlib.dll diff --git a/MessagePack.csproj b/MessagePack.csproj index 5e9ea9f52..059990fee 100644 --- a/MessagePack.csproj +++ b/MessagePack.csproj @@ -411,6 +411,9 @@ C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll + + C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Microsoft.SqlServer.Types.dll + C:/Program Files/Unity/Hub/Editor/2018.4.17f1/Editor/Data/MonoBleedingEdge/lib/mono/4.7.1-api/mscorlib.dll