feat: 增加本地化图片播放
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using AibisDream.EditorTools.Localization;
|
||||
using AibisDream.UI;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace AibisDream.SystemEditor.Tests
|
||||
{
|
||||
public sealed class LocalizedObjSpriteTests
|
||||
{
|
||||
private string temporaryRoot;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
temporaryRoot = Path.Combine(
|
||||
Path.GetTempPath(),
|
||||
"AibisDreamLocalizedObjSpriteTests",
|
||||
Guid.NewGuid().ToString("N"));
|
||||
Directory.CreateDirectory(temporaryRoot);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(temporaryRoot) && Directory.Exists(temporaryRoot))
|
||||
Directory.Delete(temporaryRoot, true);
|
||||
}
|
||||
|
||||
[TestCase("zh-Hans", "病历")]
|
||||
[TestCase("zh-CN", "病历")]
|
||||
[TestCase("en", "病历-en")]
|
||||
[TestCase("en-US", "病历-en")]
|
||||
[TestCase("ja-JP", "病历-ja-JP")]
|
||||
[TestCase("ru-RU", "病历-ru")]
|
||||
[TestCase("es-ES", "病历-es")]
|
||||
[TestCase("pt-BR", "病历-pt-BR")]
|
||||
public void GetPicName_UsesCanonicalLocaleSuffix(
|
||||
string localeCode,
|
||||
string expected)
|
||||
{
|
||||
Assert.That(
|
||||
LocalizedObjSpriteNaming.GetPicName("病历.png", localeCode),
|
||||
Is.EqualTo(expected));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CandidateNames_FallBackToUnsuffixedChineseWithoutDuplicates()
|
||||
{
|
||||
Assert.That(
|
||||
LocalizedObjSpriteNaming.GetCandidatePicNames("病历.png", "en"),
|
||||
Is.EqualTo(new[] { "病历-en", "病历" }));
|
||||
Assert.That(
|
||||
LocalizedObjSpriteNaming.GetCandidatePicNames("病历.png", "zh-Hans"),
|
||||
Is.EqualTo(new[] { "病历" }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validator_IgnoresUnsuffixedOnlySprites()
|
||||
{
|
||||
WriteSprite("普通图片.png");
|
||||
|
||||
Assert.That(
|
||||
LocalizedObjSpriteValidator.Validate(temporaryRoot),
|
||||
Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validator_RequiresEveryVariantAfterAGroupIsDetected()
|
||||
{
|
||||
WriteCompleteGroup("病历");
|
||||
Assert.That(
|
||||
LocalizedObjSpriteValidator.Validate(temporaryRoot),
|
||||
Is.Empty);
|
||||
|
||||
File.Delete(Path.Combine(temporaryRoot, "病历-ru.png"));
|
||||
var issues = LocalizedObjSpriteValidator.Validate(temporaryRoot);
|
||||
|
||||
Assert.That(issues, Has.Count.EqualTo(1));
|
||||
Assert.That(issues.Single().AssetPath, Does.EndWith("病历-ru.png"));
|
||||
Assert.That(issues.Single().Message, Does.Contain("'ru'"));
|
||||
}
|
||||
|
||||
private void WriteCompleteGroup(string logicalName)
|
||||
{
|
||||
WriteSprite($"{logicalName}.png");
|
||||
foreach (string localeCode in LocalizedObjSpriteNaming.NonDefaultLocaleCodes)
|
||||
WriteSprite($"{logicalName}-{localeCode}.png");
|
||||
}
|
||||
|
||||
private void WriteSprite(string fileName)
|
||||
{
|
||||
File.WriteAllBytes(Path.Combine(temporaryRoot, fileName), Array.Empty<byte>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 212d27ffec81bcb48a886db924f43e1a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -36,7 +36,11 @@ namespace AibisDream.SystemEditor.Tests
|
||||
source.sections[SnapshotProviderIds.PlayTool] = new PlayToolSnapshotDto
|
||||
{
|
||||
isObjVisible = true,
|
||||
objPicName = "证物"
|
||||
objPicName = "证物",
|
||||
objIsLocalized = true,
|
||||
isFullScreenVisible = true,
|
||||
fullScreenPicName = "病历",
|
||||
fullScreenIsLocalized = true
|
||||
};
|
||||
|
||||
var restored = JsonConvert.DeserializeObject<SaveSnapshot>(
|
||||
@@ -50,6 +54,14 @@ namespace AibisDream.SystemEditor.Tests
|
||||
Assert.That(showcase.displayMode, Is.EqualTo("Large"));
|
||||
Assert.That(showcase.picName, Is.EqualTo("D2S星图"));
|
||||
Assert.That(playTool.objPicName, Is.EqualTo("证物"));
|
||||
Assert.That(playTool.objIsLocalized, Is.True);
|
||||
Assert.That(playTool.fullScreenPicName, Is.EqualTo("病历"));
|
||||
Assert.That(playTool.fullScreenIsLocalized, Is.True);
|
||||
|
||||
var legacyPlayTool = JsonConvert.DeserializeObject<PlayToolSnapshotDto>(
|
||||
"{\"isObjVisible\":true,\"objPicName\":\"legacy\"}");
|
||||
Assert.That(legacyPlayTool.objIsLocalized, Is.False);
|
||||
Assert.That(legacyPlayTool.fullScreenIsLocalized, Is.False);
|
||||
|
||||
var legacy = JsonConvert.DeserializeObject<SaveSnapshot>(
|
||||
"{\"schemaVersion\":1,\"sections\":{}}");
|
||||
|
||||
Reference in New Issue
Block a user