From d8d9636ab78464a9bd3c3408ce2516251b571105 Mon Sep 17 00:00:00 2001 From: Touhexel Date: Mon, 3 May 2021 14:50:08 -0400 Subject: [PATCH] Fix gitignore because oops --- .gitignore | 3 +- .../Localization/Editor/GoogleSheetsHelper.cs | 250 ------------------ .../Editor/GoogleSheetsHelper.cs.meta | 11 - .../Editor/LocalizationEditorWindow.cs | 94 ------- .../Editor/LocalizationEditorWindow.cs.meta | 11 - .../Localization/Editor/clients_secrets.json | 12 - .../Editor/clients_secrets.json.meta | 7 - 7 files changed, 2 insertions(+), 386 deletions(-) delete mode 100644 Assets/Code/Localization/Editor/GoogleSheetsHelper.cs delete mode 100644 Assets/Code/Localization/Editor/GoogleSheetsHelper.cs.meta delete mode 100644 Assets/Code/Localization/Editor/LocalizationEditorWindow.cs delete mode 100644 Assets/Code/Localization/Editor/LocalizationEditorWindow.cs.meta delete mode 100644 Assets/Code/Localization/Editor/clients_secrets.json delete mode 100644 Assets/Code/Localization/Editor/clients_secrets.json.meta diff --git a/.gitignore b/.gitignore index e1b5325..8ad29d6 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,5 @@ sysinfo.txt *.unitypackage # Hide our localization files with our precious, precious API Keys -Localization/Editor/ \ No newline at end of file +Localization/Editor/ +Assets/Code/Localization/Editor/ diff --git a/Assets/Code/Localization/Editor/GoogleSheetsHelper.cs b/Assets/Code/Localization/Editor/GoogleSheetsHelper.cs deleted file mode 100644 index 9b2d75a..0000000 --- a/Assets/Code/Localization/Editor/GoogleSheetsHelper.cs +++ /dev/null @@ -1,250 +0,0 @@ -using Google.Apis.Auth.OAuth2; -using Google.Apis.Sheets.v4; -using Google.Apis.Sheets.v4.Data; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using UnityEngine; -using System.Linq; - -using UnityEditor; - -public static class GoogleSheetsHelper { - - static readonly string JsonLocation = "Assets/Code/Localization/Editor/"; - static readonly string JsonFile = "clients_secrets.json"; // No use in actual build. This shit has owner permissions. - - static readonly string[] Scopes = { SheetsService.Scope.Spreadsheets }; - static readonly string ApplicationName = "Localization"; - static readonly string SpreadsheetId = "1O_Uyml6J_dx7Vt7DLHTTnJqLBXr0ol_xS5pPCjbR1ks"; - static readonly string cutscenesheet = "mainsheet"; - static SheetsService service; - - static char LanguageRange = (char)('A' + Localization.LanguageCount); - - static GoogleSheetsHelper() { - GoogleCredential credential; - using (var stream = new FileStream(System.IO.Path.Combine(JsonLocation, JsonFile), FileMode.Open, FileAccess.Read)) { - credential = GoogleCredential.FromStream(stream) - .CreateScoped(Scopes); - } - - service = new SheetsService(new Google.Apis.Services.BaseClientService.Initializer() { - HttpClientInitializer = credential, - ApplicationName = ApplicationName - } - - ); - } - - #region Push - - public static void Push() { - var locals = ReadLocalizaiton(); - var sheets = ReadGoogleSheets(); - - // Create - foreach(var item in locals){ - string[] list; - if (!sheets.TryGetValue(item.Key, out list)){ - list = new string[Localization.LanguageCount]; - sheets.Add(item.Key, list); - } - list[0] = item.Value; - } - - string message = string.Format("Sending {0} keys.", sheets.Keys.Count); - - if (EditorUtility.DisplayDialog("Confirm Push?", message, "Push", "Do Not Push")) { - // Sort - var parse = sheets.ToList().Select(s => (s.Key, s.Value)).ToList(); - parse.Sort((pair1, pair2) => pair1.Key.CompareTo(pair2.Key)); - - string prev = string.Empty; - for(var i = 0; i < parse.Count; i++){ - var n = parse[i].Key; - - if (string.IsNullOrWhiteSpace(n)) continue; - - var t = n.Substring(0, n.IndexOf('_')); - - if (!string.IsNullOrWhiteSpace(prev) && t != prev){ - parse.Insert(i, (" ", new string[Localization.LanguageCount])); - i++; - } - prev = t; - } - - SendToGoogleSheets(parse); - } - } - - public static void Pull(){ - var sheets = ReadGoogleSheets(); - - if (EditorUtility.DisplayDialog("Confirm Pull?", "", "Pull", "Do not Pull")){ - var serializedObject = new SerializedObject(Localization.Instance); - serializedObject.Update(); - - var langauges = Localization.Langauges; - for (var i = 0; i < langauges.Length; i++){ - var langauge = (LocalizationLanguage)langauges.GetValue(i); - var field = string.Format("{0}Locals", langauge.ToString().ToLowerInvariant()); - var prop = serializedObject.FindProperty(field); - - var s = 0; - foreach(var set in sheets){ - if (s >= prop.arraySize){ - prop.InsertArrayElementAtIndex(s); - } - SerializedProperty element = prop.GetArrayElementAtIndex(s); - SerializedProperty keyProp = element.FindPropertyRelative("key"); - SerializedProperty textProp = element.FindPropertyRelative("text"); - keyProp.stringValue = set.Key; - textProp.stringValue = set.Value[i]; - s++; - } - } - - serializedObject.ApplyModifiedProperties(); - } - } - - #endregion - - #region Assets - - public static Dictionary ReadLocalizaiton(){ - var dict = new Dictionary(); - - var l = Localization.Instance; - - var locals = l.englishLocals; - - for(var j = 0; j < locals.Length; j++){ - var item = locals[j]; - dict.Add(item.key, item.text); - } - - return dict; - } - - #endregion - - #region Google Sheets Read - - /// - /// Returns a dictionary of all keys found with their respective localized text. - /// - /// - public static Dictionary ReadGoogleSheets() { - var dict = new Dictionary(); - - // Ask google sheets - var range = string.Format("{0}!A2:{1}", cutscenesheet, LanguageRange); - var request = service.Spreadsheets.Values.Get(SpreadsheetId, range); - - var response = request.Execute(); - var values = response.Values; - - // If received valid response - if (values != null && values.Count > 0) { - foreach (var row in values) { - if (row.Count > 0) { - var key = row[0] as string; - if (string.IsNullOrWhiteSpace(key)) continue; - - var list = new string[Localization.LanguageCount]; - for (var i = 0; i < list.Length; i++){ - string text; - if (i + 1 < row.Count) text = row[i + 1] as string; - else text = string.Empty; - - list[i] = text; - } - - dict.Add(key, list); - } - } - } - - return dict; - } - - #endregion - - #region Google Sheets Write - - /// - /// Writes to google sheets. - /// - /// - public static void SendToGoogleSheets(List<(string key, string[] texts)> locals) { - var columns = CreateGoogleSheetsColumns(locals); - ClearGoogleSheets(); - WriteToGoogleSheets(columns); - } - - /// - /// Creates a tabled list to be send with . - /// - /// - /// - public static List> CreateGoogleSheetsColumns(List<(string key, string[] texts)> locals) { - // Create list to send to google sheets - var columns = new List>(); - - // Top part with the langauges - var header = new List(); - header.Add("Keys"); - var langauges = Localization.Langauges; - foreach(LocalizationLanguage e in langauges) { - header.Add(e.ToString()); - } - columns.Add(header); - - foreach (var pair in locals) { - var key = pair.key; - var texts = pair.texts; - - var row = new List(); - row.Add(key); - foreach(var t in texts){ - if (t != null) row.Add(t); - } - - columns.Add(row); - } - - return columns; - } - - /// - /// Wipes it clean. - /// - public static void ClearGoogleSheets() { - var clearRange = new ClearValuesRequest(); - var clearRequest = service.Spreadsheets.Values.Clear(clearRange, SpreadsheetId, cutscenesheet); - var clearReponse = clearRequest.Execute(); - Debug.Log("Clearing google sheets"); - } - - /// - /// Overwrites the sheet with . - /// - /// - public static void WriteToGoogleSheets(List> columns) { - // Create range - var range = string.Format("{0}!A1:{1}", cutscenesheet, LanguageRange); - var valueRange = new ValueRange(); - valueRange.Values = columns; - - // Send to Google Sheets - var updateRequest = service.Spreadsheets.Values.Update(valueRange, SpreadsheetId, range); - updateRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED; - var updateReponse = updateRequest.Execute(); - Debug.Log("Finished syncing to google sheets"); - } - - #endregion -} diff --git a/Assets/Code/Localization/Editor/GoogleSheetsHelper.cs.meta b/Assets/Code/Localization/Editor/GoogleSheetsHelper.cs.meta deleted file mode 100644 index 0b3209d..0000000 --- a/Assets/Code/Localization/Editor/GoogleSheetsHelper.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 268efed12188dba47a731c1d552e15cf -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Code/Localization/Editor/LocalizationEditorWindow.cs b/Assets/Code/Localization/Editor/LocalizationEditorWindow.cs deleted file mode 100644 index 1c18e9e..0000000 --- a/Assets/Code/Localization/Editor/LocalizationEditorWindow.cs +++ /dev/null @@ -1,94 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEditor; - -public class LocalizationEditorWindow : EditorWindow { - - [MenuItem("Window/Localization")] - static void Init() { - var window = EditorWindow.GetWindow(); - window.Show(); - } - - const int heightLimit = 15; - - Localization item; - SerializedObject serializedObject; - int page = 0; - - private void OnGUI() { - GetLocalization(); - - var halfwidth = position.width / 2f - 6f; - - serializedObject.Update(); - - var englishProp = serializedObject.FindProperty("englishLocals"); - - EditorGUILayout.BeginHorizontal(); - EditorGUILayout.LabelField("Keys", GUILayout.Width(halfwidth)); - EditorGUILayout.LabelField("Text", GUILayout.Width(halfwidth)); - EditorGUILayout.EndHorizontal(); - - page = Mathf.Clamp(page, 0, englishProp.arraySize / 15); - - var h = 0; - var i = page * heightLimit; - while(i < englishProp.arraySize && h < heightLimit){ - var element = englishProp.GetArrayElementAtIndex(i); - var key = element.FindPropertyRelative("key"); - var text = element.FindPropertyRelative("text"); - - EditorGUILayout.BeginHorizontal(); - key.stringValue = EditorGUILayout.TextField(key.stringValue, GUILayout.Width(halfwidth)); - text.stringValue = EditorGUILayout.TextField(text.stringValue, GUILayout.Width(halfwidth)); - EditorGUILayout.EndHorizontal(); - - i++; - h++; - } - - EditorGUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - if (GUILayout.Button("Prev Page")){ - page--; - GUIUtility.keyboardControl = 0; - } - GUILayout.Label(string.Format("{0}-{1}", page * heightLimit, Mathf.Min((page + 1) * heightLimit, englishProp.arraySize))); - if (GUILayout.Button("Next Page")) { - page++; - GUIUtility.keyboardControl = 0; - } - GUILayout.FlexibleSpace(); - EditorGUILayout.EndHorizontal(); - - EditorGUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - if (GUILayout.Button("Add key")){ - englishProp.InsertArrayElementAtIndex(englishProp.arraySize); - } - GUILayout.FlexibleSpace(); - EditorGUILayout.EndHorizontal(); - - GUILayout.Space(20f); - if (GUILayout.Button("Push")){ - GoogleSheetsHelper.Push(); - } - if (GUILayout.Button("Pull")){ - GoogleSheetsHelper.Pull(); - } - - serializedObject.ApplyModifiedProperties(); - } - - void GetLocalization(){ - if (item == null) { - item = Localization.Instance; - } - - if (serializedObject == null){ - serializedObject = new SerializedObject(item); - } - } -} diff --git a/Assets/Code/Localization/Editor/LocalizationEditorWindow.cs.meta b/Assets/Code/Localization/Editor/LocalizationEditorWindow.cs.meta deleted file mode 100644 index 2cfa3fe..0000000 --- a/Assets/Code/Localization/Editor/LocalizationEditorWindow.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 1e800b8713d85cc43ba90cb5189fed09 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Code/Localization/Editor/clients_secrets.json b/Assets/Code/Localization/Editor/clients_secrets.json deleted file mode 100644 index 86e8956..0000000 --- a/Assets/Code/Localization/Editor/clients_secrets.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "type": "service_account", - "project_id": "ladyebony-158823", - "private_key_id": "0858ab1766408852d7b6b6c48b76870623d52f21", - "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDBbrE1L7Ja8xnA\n4Vha3Z6K9zdwW+TSNW/Axn31MnL/sti5naqfcqliJf/7phDsiCw+6DSR53Jv0Imu\nIspoEco404pGItATjN3qzt8jU90/Sa7tVob2EPHlXO24w0ney9/+79qjot6mrxhv\nqwfVKfoJDwsgChCnYbdri2TWvOhnZ+Hrf5Qil/+y6TU6kFChFBez2ST4WncokQx7\nP9nRiOMPNIFVn+gLueBvfmqpajWV2IpPk5jUMEwq/nqz+87nUJi67fX9ODb76wzv\n4QHY2pz9ef4Tr78B9Hh5b0R4WeoQ9RPZ+iRpFKdqccPSlcuHqTOm+II3zCqi5pF0\nHVn/FniLAgMBAAECggEAAvWMW0TxVJGqT8uvjCXrZzLXzUc90LcMKgXSjXq9GaS4\nMUOOBaxwybvNFu6rQAMa5W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Twa2z9CVSqQZtjDc61c2ufiIvtOxWscJb60A6PP\nXDvDD2Kg/ky7Tf5I/+khF+5lznDhlc5XaKJvkWko9o0KlT9HjQNgF9oiQB9Zaa4q\nFbmtUK4R/9Qztx5QXyMtmUuA\n-----END PRIVATE KEY-----\n", - "client_email": "stationjam@ladyebony-158823.iam.gserviceaccount.com", - "client_id": "112738889077453044854", - "auth_uri": "https://accounts.google.com/o/oauth2/auth", - "token_uri": "https://oauth2.googleapis.com/token", - "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", - "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/stationjam%40ladyebony-158823.iam.gserviceaccount.com" -} diff --git a/Assets/Code/Localization/Editor/clients_secrets.json.meta b/Assets/Code/Localization/Editor/clients_secrets.json.meta deleted file mode 100644 index 4d50476..0000000 --- a/Assets/Code/Localization/Editor/clients_secrets.json.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: c6876940ea5acb34fad008bc1c07ab95 -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: