Skip to content

Commit

Permalink
Fixes #239 by Adding Update from Web to Language Preference
Browse files Browse the repository at this point in the history
WIP Add JSON Object Downloader

Add test file for JSONRetrieverTests

Rencode SimpleJson.json test file as UTF-8 (no BOM)

WIP improve WebRequest API and simplify test

Restructure folders to better group networking classes

Remove networking from JsonRetriver tests

I added a mock UnityWebRequestWrapper to act as a successful web
request.

Add WaitForResult method to AsyncOp

This makes for a cleaner API, though it does push some dependencies
into AsyncOp.

Add test for Timeout, rework API for WaitForResult

I needed to differentiate expected Timeout via the Request from timeout
from waiting for the operation to return. AsynOp should have never
set its own status, as the user / owner should be responsible for that.

Add test for InvalidJson

Improve MockWebRequest to act more like a standard WebRequest

Add test for invalid URI

Add test (and mock) for NetworkError

WIP Add LanguageRetriever to fetch and update languages

Add LanguageBookmarks file to locate langauges

WIP Implement LanguageRetriever

Rename Locale folder to Localization

This makes more sense in English.

Rename Localization files for better clarity in English

Locale is more of a place, so Locale as translated text was confusing.
Localized is synonymous with "translated" (for a region), which seems
like a better fit.

Add version number to Language JSON

This will help us version their languages as we update Mulligan or
its languages.

Use feature branch link for Langauge Bookmarks for now

This will just let me test stuff quickly in my feature branch until
it's ready to move to develop.

Add implementation to update and add new languages

Disallow changing to invalid LanguageKey in LocalizationManager

Add boilerplate and general comments

Delete unneeded interface

I've decided I don't really want to test LanguageRetrievers, because
JSONRetriever's already test for common networking errors. Testing
LanguageRetrievers would require lots of framework (it depends on
LocalizationManager which is a singleton and concrete class), and in
the end won't really help me that much except to vet the way the UI
presents networking errors. I will just manually test these cases for now
by supplying the test IWebRequest objects to the JSONRetrievers used
by LanguageRetriever.

Move Networking framework outside of ExtensionsAndUtilities folder

This wasn't the right place for it, as ExtensionsAndUtilities is meant
for Extension classes and UTILITY classes which is my name for "extensions"
to static classes (this mirror's Unity's naming. I personally don't
love it due to ambiguity.)

Add Dialog to report language update info

Add Display text for timeout and network error in LanguageUpdate

Add translatable strings for Language Update dialog

Add debug feature to allow updating languages from staging

Fix JSONRetrieverWeb to properly report 404, fix tests
  • Loading branch information
edwardrowe committed Mar 31, 2020
1 parent 3b6cb71 commit 0dfe884
Show file tree
Hide file tree
Showing 69 changed files with 3,406 additions and 1,687 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections;
using UnityEditor;
using UnityEngine;

public static class EditorCoroutineUtility
{
/// <summary>
/// Starts a Coroutine using Unity Editor's update loop. This is useful for EditorWindows
/// which aren't MonoBehaviours and therefore can't use Coroutines.
/// Utility function adapted from https://forum.unity.com/threads/using-unitywebrequest-in-editor-tools.397466/#post-4485181
/// </summary>
/// <param name="update"></param>
/// <param name="onEnd"></param>
public static void StartBackgroundTask(IEnumerator update, Action onEnd = null)
{
EditorApplication.CallbackFunction closureCallback = null;

closureCallback = () =>
{
try
{
if (update.MoveNext() == false)
{
if (onEnd != null)
{
onEnd();
}
EditorApplication.update -= closureCallback;
}
}
catch (Exception ex)
{
if (onEnd != null)
{
onEnd();
}
Debug.LogException(ex);
EditorApplication.update -= closureCallback;
}
};

EditorApplication.update += closureCallback;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void PopulateWithPresets(List<RenameSequencePreset> presets)
var copySerialized = JsonUtility.ToJson(preset);
var copy = JsonUtility.FromJson<RenameSequencePreset>(copySerialized);
this.presetsToDraw.Add(copy);
this.uniqueNames.Add(copy, LocaleManager.Instance.GetTranslation("preset") + " " + i);
this.uniqueNames.Add(copy, LocalizationManager.Instance.GetTranslation("preset") + " " + i);
}

this.reorderableList.list = this.presetsToDraw;
Expand All @@ -76,7 +76,7 @@ private void OnEnable()

private void DrawHeader(Rect rect)
{
GUI.Label(rect, LocaleManager.Instance.GetTranslation("savedPresets"), EditorStyles.label);
GUI.Label(rect, LocalizationManager.Instance.GetTranslation("savedPresets"), EditorStyles.label);
}

private void DrawElement(Rect rect, int index, bool isActive, bool isFocused)
Expand Down Expand Up @@ -147,7 +147,7 @@ private void OnGUI()
EditorGUILayout.BeginHorizontal();
GUILayout.Space(50.0f);
EditorGUILayout.LabelField(
LocaleManager.Instance.GetTranslation("errorNoSavedPresets"),
LocalizationManager.Instance.GetTranslation("errorNoSavedPresets"),
EditorStyles.wordWrappedLabel);
GUILayout.Space(50.0f);
EditorGUILayout.EndHorizontal();
Expand All @@ -160,13 +160,13 @@ private void HandleElementRemoved(UnityEditorInternal.ReorderableList list)
var indexToRemove = list.index;
var elementToDelete = this.presetsToDraw[indexToRemove];
var popupMessage = string.Format(
LocaleManager.Instance.GetTranslation("areYouSureDelete"), elementToDelete.Name
LocalizationManager.Instance.GetTranslation("areYouSureDelete"), elementToDelete.Name
);

if (EditorUtility.DisplayDialog(LocaleManager.Instance.GetTranslation("warning"),
if (EditorUtility.DisplayDialog(LocalizationManager.Instance.GetTranslation("warning"),
popupMessage,
LocaleManager.Instance.GetTranslation("deletePreset"),
LocaleManager.Instance.GetTranslation("no")))
LocalizationManager.Instance.GetTranslation("deletePreset"),
LocalizationManager.Instance.GetTranslation("no")))
{
this.presetsToDraw.RemoveAt(indexToRemove);
this.reorderableList.index = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,10 @@ private void InitializeGUIContents()
{
this.guiContents = new GUIContents();

this.guiContents.DropPrompt = new GUIContent(LocaleManager.Instance.GetTranslation("noObjectsSpecified"));
this.guiContents.DropPromptHintInsideScroll = new GUIContent(LocaleManager.Instance.GetTranslation("addMoreObjectsDragHere"));
this.guiContents.DropPromptHint = new GUIContent(LocaleManager.Instance.GetTranslation("addMoreObjectsDragPanel"));
this.guiContents.DropPromptRepeat = new GUIContent(LocaleManager.Instance.GetTranslation("toRenameMoreObjects"));
this.guiContents.DropPrompt = new GUIContent(LocalizationManager.Instance.GetTranslation("noObjectsSpecified"));
this.guiContents.DropPromptHintInsideScroll = new GUIContent(LocalizationManager.Instance.GetTranslation("addMoreObjectsDragHere"));
this.guiContents.DropPromptHint = new GUIContent(LocalizationManager.Instance.GetTranslation("addMoreObjectsDragPanel"));
this.guiContents.DropPromptRepeat = new GUIContent(LocalizationManager.Instance.GetTranslation("toRenameMoreObjects"));
}

private void InitializeGUIStyles()
Expand Down Expand Up @@ -464,7 +464,7 @@ public Vector2 Draw(Rect previewPanelRect, Vector2 previewPanelScrollPosition, B
var removeAllButtonRect = new Rect(addSelectedObjectsButtonRect);
removeAllButtonRect.width = 100.0f;
removeAllButtonRect.x -= (removeAllButtonRect.width + buttonSpacing);
if (GUI.Button(removeAllButtonRect, LocaleManager.Instance.GetTranslation("removeAll")))
if (GUI.Button(removeAllButtonRect, LocalizationManager.Instance.GetTranslation("removeAll")))
{
if (this.RemoveAllClicked != null)
{
Expand Down Expand Up @@ -525,14 +525,14 @@ private void DrawPreviewPanelContentsEmpty(Rect previewPanelRect)
string noun;
if (this.NumPreviouslyRenamedObjects == 1)
{
noun = LocaleManager.Instance.GetTranslation("object");
noun = LocalizationManager.Instance.GetTranslation("object");
}
else
{
noun = LocaleManager.Instance.GetTranslation("objects");
noun = LocalizationManager.Instance.GetTranslation("objects");
}

var renameSuccessContent = new GUIContent(string.Format("{0} {1} {2}", this.NumPreviouslyRenamedObjects, noun, LocaleManager.Instance.GetTranslation("renamed")));
var renameSuccessContent = new GUIContent(string.Format("{0} {1} {2}", this.NumPreviouslyRenamedObjects, noun, LocalizationManager.Instance.GetTranslation("renamed")));
EditorGUI.LabelField(labelRect, renameSuccessContent, this.guiStyles.RenameSuccessPrompt);
GUI.contentColor = oldColor;

Expand Down Expand Up @@ -561,8 +561,8 @@ private Vector2 DrawPreviewPanelContentsWithItems(
previewPanelScrollPosition.x = 0;
}

string originalNameColumnHeader = LocaleManager.Instance.GetTranslation(previewContents.RenameStepIndex < 1 ? "original" : "before");
string newNameColumnHeader = LocaleManager.Instance.GetTranslation("after");
string originalNameColumnHeader = LocalizationManager.Instance.GetTranslation(previewContents.RenameStepIndex < 1 ? "original" : "before");
string newNameColumnHeader = LocalizationManager.Instance.GetTranslation("after");
this.DrawPreviewHeader(
scrollLayout.HeaderRect,
-previewPanelScrollPosition.x,
Expand Down Expand Up @@ -645,7 +645,7 @@ private void DrawPreviewHeader(

if (thirdColumnWidth > 0.0f)
{
EditorGUI.LabelField(thirdColumnRect, LocaleManager.Instance.GetTranslation("finalName"), EditorStyles.boldLabel);
EditorGUI.LabelField(thirdColumnRect, LocalizationManager.Instance.GetTranslation("finalName"), EditorStyles.boldLabel);
}

GUI.EndGroup();
Expand Down Expand Up @@ -846,7 +846,7 @@ private bool DrawDividerAndCheckResize(Rect rect, bool alreadyDragging, out bool
private void DrawAddSelectedObjectsButton(Rect buttonRect)
{
EditorGUI.BeginDisabledGroup(DisableAddSelectedObjectsButton);
if (GUI.Button(buttonRect, LocaleManager.Instance.GetTranslation("addSelectedObjects")))
if (GUI.Button(buttonRect, LocalizationManager.Instance.GetTranslation("addSelectedObjects")))
{
if (this.AddSelectedObjectsClicked != null)
{
Expand Down Expand Up @@ -1135,7 +1135,7 @@ public PreviewRowModel this[int index]
else
{
throw new System.IndexOutOfRangeException(
LocaleManager.Instance.GetTranslation("errorTryingToAccessModel") + index);
LocalizationManager.Instance.GetTranslation("errorTryingToAccessModel") + index);
}
}
}
Expand Down Expand Up @@ -1172,7 +1172,7 @@ public static PreviewPanelContents CreatePreviewContentsForObjects(
}
else
{
info.WarningMessage = LocaleManager.Instance.GetTranslation("warningNewNameMatchesExisting");
info.WarningMessage = LocalizationManager.Instance.GetTranslation("warningNewNameMatchesExisting");
}
}
else
Expand Down Expand Up @@ -1232,11 +1232,11 @@ private static string GetWarningMessageForRenamePreview(RenamePreview preview)
{
if (preview.HasInvalidEmptyFinalName)
{
return LocaleManager.Instance.GetTranslation("assetBlankName");
return LocalizationManager.Instance.GetTranslation("assetBlankName");
}
else if (preview.FinalNameContainsInvalidCharacters)
{
return LocaleManager.Instance.GetTranslation("nameIncludeInvalidCharacter");
return LocalizationManager.Instance.GetTranslation("nameIncludeInvalidCharacter");
}
else
{
Expand Down
Loading

0 comments on commit 0dfe884

Please sign in to comment.