Skip to content

Commit

Permalink
Merge pull request #21 from JohannesDeml/quick-cleanup
Browse files Browse the repository at this point in the history
Quick cleanups
  • Loading branch information
skjalgsm authored Dec 23, 2019
2 parents a8f7189 + 1bac3dc commit 0c18eb9
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 78 deletions.
22 changes: 12 additions & 10 deletions Assets/Polyglot/Editor/LocalizationPostProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@

using Polyglot;
#if UNITY_5
using JetBrains.Annotations;
#endif
using UnityEditor;

public class LocalizationPostProcessor : AssetPostprocessor
namespace Polyglot
{
#if UNITY_5
[UsedImplicitly]
#endif
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
public class LocalizationPostProcessor : AssetPostprocessor
{
for (int index = 0; index < importedAssets.Length; index++)
#if UNITY_5
[UsedImplicitly]
#endif
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
var str = importedAssets[index];
if (str.EndsWith(".csv") && str.Contains("Localization"))
for (int index = 0; index < importedAssets.Length; index++)
{
LocalizationImporter.Refresh();
var str = importedAssets[index];
if (str.EndsWith(".csv") && str.Contains("Localization"))
{
LocalizationImporter.Refresh();
}
}
}
}
Expand Down
13 changes: 5 additions & 8 deletions Assets/Polyglot/Scripts/CsvTsvParser/CsvReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Polyglot
/// <summary>
/// CSV Reader. this class accepts a CSV file generated by Microsoft Excel.
/// </summary>
public class CsvReader
public static class CsvReader
{

// flag for processing a CSV
Expand Down Expand Up @@ -45,7 +45,7 @@ public static List<List<string>> Parse(string src)

char c = src[i];

// remove whilespace at beginning of line
// remove whitespace at beginning of line
if (requireTrimLineHead)
{
if (isBlank.IsMatch(c.ToString()))
Expand Down Expand Up @@ -88,13 +88,10 @@ public static List<List<string>> Parse(string src)
return rows;
}

if (cols.Count == 0)
// if the final line is empty, ignore it.
if (cols.Count == 0 && string.Empty.Equals(c.ToString().Trim()))
{
// if the final line is empty, ignore it.
if (string.Empty.Equals(c.ToString().Trim()))
{
return rows;
}
return rows;
}

buffer.Append(c);
Expand Down
2 changes: 1 addition & 1 deletion Assets/Polyglot/Scripts/CsvTsvParser/TsvReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Polyglot
{
public class TsvReader
public static class TsvReader
{
/// <summary>
/// Parses the TSV string.
Expand Down
64 changes: 33 additions & 31 deletions Assets/Polyglot/Scripts/DownloadPolyglotSheetButton.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
using Polyglot;
using UnityEngine;
using UnityEngine;
using UnityEngine.UI;

public class DownloadPolyglotSheetButton : MonoBehaviour
namespace Polyglot
{
[SerializeField]
private Button button;
public class DownloadPolyglotSheetButton : MonoBehaviour
{
[SerializeField]
private Button button;

[SerializeField]
private RectTransform progressbar;
[SerializeField]
private RectTransform progressbar = null;

private float startWidth;
private float startWidth;

private void Reset()
{
button = GetComponent<Button>();
}

private void OnEnable()
{
startWidth = progressbar.sizeDelta.x;
button.onClick.AddListener(OnClick);
}
private void Reset()
{
button = GetComponent<Button>();
}

private void OnDisable()
{
button.onClick.RemoveListener(OnClick);
}
private void OnEnable()
{
startWidth = progressbar.sizeDelta.x;
button.onClick.AddListener(OnClick);
}

private void OnClick()
{
StartCoroutine(LocalizationImporter.DownloadPolyglotSheet(UpdateProgressbar));
}
private void OnDisable()
{
button.onClick.RemoveListener(OnClick);
}

private bool UpdateProgressbar(float progress)
{
if (progressbar != null)
private void OnClick()
{
progressbar.sizeDelta = new Vector2(progress * startWidth, progressbar.sizeDelta.y);
StartCoroutine(LocalizationImporter.DownloadPolyglotSheet(UpdateProgressbar));
}

return false;
private bool UpdateProgressbar(float progress)
{
if (progressbar != null)
{
progressbar.sizeDelta = new Vector2(progress * startWidth, progressbar.sizeDelta.y);
}

return false;
}
}
}
27 changes: 9 additions & 18 deletions Assets/Polyglot/Scripts/GoogleDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ public static class GoogleDownload
{
public static IEnumerator DownloadSheet(string docsId, string sheetId, Action<string> done, GoogleDriveDownloadFormat format = GoogleDriveDownloadFormat.CSV, Func<float, bool> progressbar = null)
{
if (progressbar != null)
if (progressbar != null && progressbar(0))
{
if (progressbar(0))
{
done(null);
yield break;
}
done(null);
yield break;
}

var url = string.Format("https://docs.google.com/spreadsheets/d/{0}/export?format={2}&gid={1}", docsId, sheetId, Enum.GetName(typeof(GoogleDriveDownloadFormat), format).ToLower());
Expand All @@ -37,24 +34,18 @@ public static IEnumerator DownloadSheet(string docsId, string sheetId, Action<st
#else
var progress = www.progress;
#endif
if (progressbar != null)
if (progressbar != null && progressbar(progress))
{
if (progressbar(progress))
{
done(null);
yield break;
}
done(null);
yield break;
}
yield return null;
}

if (progressbar != null)
if (progressbar != null && progressbar(1))
{
if (progressbar(1))
{
done(null);
yield break;
}
done(null);
yield break;
}

#if UNITY_5_5_OR_NEWER
Expand Down
13 changes: 6 additions & 7 deletions Assets/Polyglot/Scripts/Localization.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections;
#if UNITY_5_3_OR_NEWER
#if UNITY_5_3_OR_NEWER
using JetBrains.Annotations;
#endif
using UnityEngine;
Expand All @@ -14,19 +13,19 @@ public class Localization : ScriptableObject
private const string KeyNotFound = "[{0}]";

[SerializeField]
private LocalizationDocument polyglotDocument;
private LocalizationDocument polyglotDocument = null;

public LocalizationDocument PolyglotDocument { get { return polyglotDocument; } }


[SerializeField]
private LocalizationDocument customDocument;
private LocalizationDocument customDocument = null;

public LocalizationDocument CustomDocument { get { return customDocument; } }

[Tooltip("The comma separated text files to get localization strings from\nThese are prioritized, so the ones added later are always prioritized.")]
[SerializeField]
private List<LocalizationAsset> inputFiles;
private List<LocalizationAsset> inputFiles = null;

public List<LocalizationAsset> InputFiles { get { return inputFiles; } }

Expand Down Expand Up @@ -65,7 +64,7 @@ private static bool HasInstance
[Header("Language Support")]
[Tooltip("The supported languages by the game.\n Leave empty if you support them all.")]
[SerializeField]
private List<Language> supportedLanguages;
private List<Language> supportedLanguages = null;

public List<Language> SupportedLanguages{ get { return supportedLanguages; }}

Expand Down Expand Up @@ -342,7 +341,7 @@ public void RemoveOnLocalizeEvent(ILocalize localize)
}

/// <summary>
/// Retreives the correct language string by key.
/// Retrieves the correct language string by key.
/// </summary>
/// <param name="key">The key string</param>
/// <returns>A localized string</returns>
Expand Down
2 changes: 1 addition & 1 deletion Assets/Polyglot/Scripts/LocalizedTextComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public string Key

public List<object> Parameters { get { return parameters; } }

private List<object> parameters = new List<object>();
private readonly List<object> parameters = new List<object>();

#if UNITY_5 || UNITY_2017_1_OR_NEWER
[UsedImplicitly]
Expand Down
2 changes: 1 addition & 1 deletion Assets/Polyglot/Scripts/LocalizedTextMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class LocalizedTextMesh : MonoBehaviour, ILocalize

[Tooltip("The key to localize with")]
[SerializeField]
private string key;
private string key = null;

public string Key { get { return key; } }

Expand Down
1 change: 0 additions & 1 deletion Assets/Polyglot/Scripts/SaveLanguagePreference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using JetBrains.Annotations;
#endif
using UnityEngine;
using System.Collections;

namespace Polyglot
{
Expand Down

0 comments on commit 0c18eb9

Please sign in to comment.