Skip to content

Commit

Permalink
Merge pull request #293 from redbluegames/staging
Browse files Browse the repository at this point in the history
Merge Staging to Main (now v1.7.8)
  • Loading branch information
edwardrowe authored Feb 17, 2022
2 parents 5e016a2 + faba21b commit 715b04d
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,16 @@ public static string GetAssetPathWithSubAsset(UnityEngine.Object asset)
var assetsAtPath = new List<UnityEngine.Object>();
foreach (var filePath in filePaths)
{
// Textures have sprites in them. Add all assets in this file, including the file itself.
var assetRelativePath = filePath.Substring(filePath.IndexOf("Assets/"));

// Workaround: Scene assets for some reason error if you load them via LoadAllAssets.
// (does it maybe try to load the contents inside the scene?)
if (System.IO.Path.GetExtension(assetRelativePath) == ".unity")
if (System.IO.Path.GetExtension(filePath) == ".unity")
{
var sceneAsset = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(assetRelativePath);
var sceneAsset = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(filePath);
assetsAtPath.Add(sceneAsset);
}
else
{
var subAssets = AssetDatabase.LoadAllAssetsAtPath(assetRelativePath);
var subAssets = AssetDatabase.LoadAllAssetsAtPath(filePath);
foreach (var subAsset in subAssets)
{
// It's possible for user created assets to include nulls...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace RedBlueGames.MulliganRenamer
/// </summary>
public class MulliganRenamerWindow : EditorWindow, IHasCustomMenu
{
private const string VersionString = "1.7.6";
private const string VersionString = "1.7.8";
private const string WindowMenuPath = "Window/Red Blue/Mulligan Renamer";

private const string RenameOpsEditorPrefsKey = "RedBlueGames.MulliganRenamer.RenameOperationsToApply";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace RedBlueGames.MulliganRenamer
{
using UnityEditor;
using UnityEngine;
using System.Text.RegularExpressions;
using System.Collections.Generic;

/// <summary>
/// Handles drawing the PreferencesWindow in a generic way that works both in the
Expand Down Expand Up @@ -232,12 +234,7 @@ private static void DrawSampleInsertionLabel(Rect rect, MulliganUserPreferences
DiffTextColor = preferences.InsertionTextColor,
};

var renameResult = new RenameResult();
renameResult.Add(new Diff(LocalizationManager.Instance.GetTranslation("exampleThisIs") + " ", DiffOperation.Equal));
renameResult.Add(new Diff(LocalizationManager.Instance.GetTranslation("exampleSampleText"), DiffOperation.Insertion));
renameResult.Add(new Diff(" " + LocalizationManager.Instance.GetTranslation("exampleWithWords") + " ", DiffOperation.Equal));
renameResult.Add(new Diff(LocalizationManager.Instance.GetTranslation("exampleInserted"), DiffOperation.Insertion));

var renameResult = CreateSampleTextForDiffOp(new string[] {"exampleSampleText", "exampleInserted"}, DiffOperation.Insertion);
MulliganEditorGUIUtilities.DrawDiffLabel(rect, renameResult, false, diffLabelStyle, SampleDiffLabelStyle);
}

Expand All @@ -251,13 +248,34 @@ private static void DrawSampleDeletionLabel(Rect rect, MulliganUserPreferences p
DiffTextColor = preferences.DeletionTextColor,
};

var renameResult = CreateSampleTextForDiffOp(new string[] {"exampleSampleText", "exampleDeleted"}, DiffOperation.Deletion);
MulliganEditorGUIUtilities.DrawDiffLabel(rect, renameResult, true, diffLabelStyle, SampleDiffLabelStyle);
}

private static RenameResult CreateSampleTextForDiffOp(string[] keys, DiffOperation diffOp)
{
var renameResult = new RenameResult();
renameResult.Add(new Diff(LocalizationManager.Instance.GetTranslation("exampleThisIs") + " ", DiffOperation.Equal));
renameResult.Add(new Diff(LocalizationManager.Instance.GetTranslation("exampleSampleText"), DiffOperation.Deletion));
renameResult.Add(new Diff(" " + LocalizationManager.Instance.GetTranslation("exampleWithWords") + " ", DiffOperation.Equal));
renameResult.Add(new Diff(LocalizationManager.Instance.GetTranslation("exampleDeleted"), DiffOperation.Deletion));
string translatedText = LocalizationManager.Instance.GetTranslation("exampleTextWithInsertedWords");
Regex regex = new Regex(@"{+\d+}+");
MatchCollection matches = regex.Matches(translatedText);
List<Diff> subStrings = new List<Diff>();

MulliganEditorGUIUtilities.DrawDiffLabel(rect, renameResult, true, diffLabelStyle, SampleDiffLabelStyle);
for(int i = 0; i < matches.Count; i++)
{
var match = matches[i];
subStrings.Add(new Diff(translatedText.Substring(0, translatedText.IndexOf(match.Value)), DiffOperation.Equal));

var stringToInsert = i >= 0 && i < keys.Length ? LocalizationManager.Instance.GetTranslation(keys[i]) : "modified";
subStrings.Add(new Diff(stringToInsert, diffOp));
translatedText = translatedText.Remove(0, translatedText.IndexOf(match.Value) + match.Value.Length);
}

foreach (Diff currentString in subStrings)
{
renameResult.Add(currentString);
}

return renameResult;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ public bool FinalNameContainsInvalidCharacters
return false;
}

// Sprites are actually allowed to have all the characters that are considered invalid in Assets
if(this.ObjectToRename is Sprite)
{
return false;
}

var invalidCharacters = new char[] { '?', '/', '<', '>', '\\', '|', '*', ':', '"' };
return this.RenameResultSequence.NewName.IndexOfAny(invalidCharacters) >= 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,23 +150,23 @@ private static string ReplaceSpriteNameInMetaFile(string metafileText, string sp

private static string ReplaceFileIDRecycleNames(string metafileText, string oldName, string newName)
{
string fileIDPattern = "([\\d]{8}: )" + oldName + "(\r?\n)";
string fileIDPattern = "([\\d]{8}: )" + System.Text.RegularExpressions.Regex.Escape(oldName) + "(\r?\n)";
var fileIDRegex = new System.Text.RegularExpressions.Regex(fileIDPattern);
string replacementText = "${1}" + newName + "${2}";
return fileIDRegex.Replace(metafileText, replacementText);
}

private static string ReplaceSpriteData(string metafileText, string oldName, string newName)
{
string spritenamePattern = "(name: )" + oldName + "(\r?\n)";
string spritenamePattern = "(name: )" + System.Text.RegularExpressions.Regex.Escape(oldName) + "(\r?\n)";
var spritenameRegex = new System.Text.RegularExpressions.Regex(spritenamePattern);
string replacementText = "${1}" + newName + "${2}";
return spritenameRegex.Replace(metafileText, replacementText);
}

private static string ReplaceInternalIDToNameTable(string metafileText, string oldName, string newName)
{
string spritenamePattern = "(second: )" + oldName + "(\r?\n)";
string spritenamePattern = "(second: )" + System.Text.RegularExpressions.Regex.Escape(oldName) + "(\r?\n)";
var spritenameRegex = new System.Text.RegularExpressions.Regex(spritenamePattern);
string replacementText = "${1}" + newName + "${2}";
return spritenameRegex.Replace(metafileText, replacementText);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,17 +588,13 @@
"value": "Preferences"
},
{
"key": "exampleThisIs",
"value": "This is"
"key": "exampleTextWithInsertedWords",
"value": "This is {0} with words {1}"
},
{
"key": "exampleSampleText",
"value": "sample text"
},
{
"key": "exampleWithWords",
"value": "with words"
},
{
"key": "exampleInserted",
"value": "inserted"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,17 +588,13 @@
"value": "Preferencias"
},
{
"key": "exampleThisIs",
"value": "Esto es"
"key": "exampleTextWithInsertedWords",
"value": "Esto es {0} con palabras {1}"
},
{
"key": "exampleSampleText",
"value": "un ejemplo de texto"
},
{
"key": "exampleWithWords",
"value": "con palabras"
},
{
"key": "exampleInserted",
"value": "insertadas"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,17 +588,13 @@
"value": "Preferências"
},
{
"key": "exampleThisIs",
"value": "Esse é"
"key": "exampleTextWithInsertedWords",
"value": "Esse é {0} com palavras {1}"
},
{
"key": "exampleSampleText",
"value": "um texto exemplo"
},
{
"key": "exampleWithWords",
"value": "com palavras"
},
{
"key": "exampleInserted",
"value": "inseridas"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,17 +588,13 @@
"value": "首选项"
},
{
"key": "exampleThisIs",
"value": "这就是"
"key": "exampleTextWithInsertedWords",
"value": "这就是 {0} 带字 {1}"
},
{
"key": "exampleSampleText",
"value": "例文"
},
{
"key": "exampleWithWords",
"value": "带字"
},
{
"key": "exampleInserted",
"value": "插入式"
Expand Down

0 comments on commit 715b04d

Please sign in to comment.