This repository has been archived by the owner on Nov 20, 2021. It is now read-only.
forked from BinaryElement/Chroma
-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
317 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
namespace Chroma | ||
{ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using Newtonsoft.Json; | ||
|
||
internal static class LightIDTableManager | ||
{ | ||
private static readonly Dictionary<string, Dictionary<int, int>[]> _lightIDTable = new Dictionary<string, Dictionary<int, int>[]>(); | ||
|
||
private static Dictionary<int, int>[] _activeTable; | ||
|
||
internal static int? GetActiveTableValue(int type, int id) | ||
{ | ||
if (_activeTable != null) | ||
{ | ||
if (_activeTable[type].TryGetValue(id, out int newId)) | ||
{ | ||
return newId; | ||
} | ||
else | ||
{ | ||
ChromaLogger.Log($"Unable to find value for type [{type}] and id [{id}].", IPA.Logging.Logger.Level.Warning); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
internal static void SetEnvironment(string environmentName) | ||
{ | ||
if (_lightIDTable.TryGetValue(environmentName, out Dictionary<int, int>[] activeTable)) | ||
{ | ||
_activeTable = activeTable; | ||
} | ||
else | ||
{ | ||
_activeTable = null; | ||
ChromaLogger.Log($"Table not found for: {environmentName}", IPA.Logging.Logger.Level.Warning); | ||
} | ||
} | ||
|
||
internal static void InitTable() | ||
{ | ||
string tableNamespace = "Chroma.LightIDTables."; | ||
Assembly assembly = Assembly.GetExecutingAssembly(); | ||
IEnumerable<string> tableNames = assembly.GetManifestResourceNames().Where(n => n.StartsWith(tableNamespace)); | ||
foreach (string tableName in tableNames) | ||
{ | ||
using (JsonReader reader = new JsonTextReader(new StreamReader(assembly.GetManifestResourceStream(tableName)))) | ||
{ | ||
Dictionary<int, int>[] typeTable = new Dictionary<int, int>[5]; | ||
|
||
JsonSerializer serializer = new JsonSerializer(); | ||
Dictionary<string, Dictionary<string, int>> rawDict = serializer.Deserialize<Dictionary<string, Dictionary<string, int>>>(reader); | ||
|
||
foreach (KeyValuePair<string, Dictionary<string, int>> typePair in rawDict) | ||
{ | ||
typeTable[int.Parse(typePair.Key)] = typePair.Value.ToDictionary(n => int.Parse(n.Key), n => n.Value); | ||
} | ||
|
||
string tableNameWithoutExtension = Path.GetFileNameWithoutExtension(tableName.Remove(tableName.IndexOf(tableNamespace), tableNamespace.Length)); | ||
_lightIDTable.Add(tableNameWithoutExtension, typeTable); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"0":{"1":4,"2":1,"3":3},"1":{"1":14,"2":8,"3":0,"4":12,"5":16,"6":6,"7":3,"8":9,"9":17,"10":5,"11":2,"12":10,"13":15,"14":4,"15":1,"16":11,"17":24,"18":22,"19":23,"20":21},"2":{"1":8,"2":12,"3":10,"4":17,"5":4,"6":25,"7":18,"8":1,"9":21,"10":14,"11":6,"12":27,"13":16,"14":3,"15":24,"16":15,"17":7,"18":28,"19":20,"20":2,"21":23,"22":13,"23":5,"24":26,"25":19,"26":0,"27":22},"3":{"1":0,"2":20,"3":10,"4":19,"5":5,"6":21,"7":16,"8":8,"9":24,"10":12,"11":2,"12":27,"13":18,"14":6,"15":22,"16":13,"17":1,"18":26,"19":17,"20":7,"21":23,"22":11,"23":3,"24":28,"25":15,"26":9,"27":25},"4":{"1":7,"2":8,"3":10,"4":9,"5":12}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"0":{"1":7,"2":9,"3":6,"4":3,"5":2,"6":0,"7":5,"8":1,"9":8,"10":4},"1":{"1":3,"2":4,"3":5,"4":6,"5":7,"6":8,"7":9,"8":10,"9":11,"10":12,"11":13,"12":14,"13":15,"14":16,"15":17,"16":18,"17":19,"18":20,"19":21,"20":22,"21":23,"22":24,"23":25,"24":26,"25":27,"26":28,"27":29,"28":30,"29":31,"30":32,"31":33,"32":34,"33":35,"34":36,"35":37,"36":38,"37":39,"38":40,"39":41,"40":42,"41":43,"42":44,"43":45,"44":46,"45":47,"46":48,"47":49,"48":50,"49":51,"50":52,"51":53,"52":54,"53":55,"54":56,"55":57,"56":58,"57":59,"58":60,"59":61,"60":62},"2":{"1":4,"2":2,"3":1,"4":3,"5":6},"3":{"1":3,"2":2,"3":1,"4":4,"5":6},"4":{"1":19,"2":17,"3":10,"4":14,"5":13,"6":15,"7":11,"8":16,"9":18,"10":12,"11":4,"12":2,"13":5,"14":7,"15":8,"16":9}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"0":{"1":3,"2":5,"3":11,"4":9,"5":12,"6":8,"7":10,"8":4},"1":{"1":3,"2":11,"3":8,"4":10,"5":6,"6":4,"7":9},"2":{"1":3,"2":1,"3":2,"4":4,"5":5},"3":{"1":5,"2":4,"3":2,"4":1,"5":3},"4":{"1":16,"2":18,"3":10,"4":9,"5":1,"6":11,"7":7,"8":0,"9":13,"10":19,"11":20,"12":17,"13":6,"14":4}} |
Oops, something went wrong.