feat: resolve character figures from config
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0f9f80db3d2de844d98f572f6561e81e
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3ed8765b09cf5f646a7a9ee47b8fa859
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using XGame;
|
||||||
|
|
||||||
|
public sealed class CharacterConfigDataTests
|
||||||
|
{
|
||||||
|
private static CharacterConfigData CreateConfig()
|
||||||
|
{
|
||||||
|
return new CharacterConfigData
|
||||||
|
{
|
||||||
|
defaultCharacterId = "Assasin",
|
||||||
|
characters = new List<CharacterConfigItem>
|
||||||
|
{
|
||||||
|
new CharacterConfigItem { id = "Assasin", prefabPath = "Assets/Game/Art/Actor/Prefab/Assasin.prefab" },
|
||||||
|
new CharacterConfigItem { id = "bls", prefabPath = "Assets/Game/Art/Actor/Prefab/bls.prefab" },
|
||||||
|
new CharacterConfigItem { id = "boy", prefabPath = "Assets/Game/Art/Actor/Prefab/boy.prefab" },
|
||||||
|
new CharacterConfigItem { id = "captain", prefabPath = "Assets/Game/Art/Actor/Prefab/captain.prefab" },
|
||||||
|
new CharacterConfigItem { id = "cityboy_sk", prefabPath = "Assets/Game/Art/Actor/Prefab/cityboy_sk.prefab" },
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GetFigureReturnsGeneratedListIndexForCityboy()
|
||||||
|
{
|
||||||
|
Assert.That(CreateConfig().GetFigure("cityboy_sk"), Is.EqualTo(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GetFigureUsesDefaultForAnUnknownId()
|
||||||
|
{
|
||||||
|
Assert.That(CreateConfig().GetFigure("missing"), Is.EqualTo(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GetByFigureReturnsTheConfiguredPrefabPath()
|
||||||
|
{
|
||||||
|
CharacterConfigItem item = CreateConfig().GetByFigure(5);
|
||||||
|
|
||||||
|
Assert.That(item.id, Is.EqualTo("cityboy_sk"));
|
||||||
|
Assert.That(item.prefabPath, Is.EqualTo("Assets/Game/Art/Actor/Prefab/cityboy_sk.prefab"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GetByFigureUsesDefaultForAnInvalidIndex()
|
||||||
|
{
|
||||||
|
Assert.That(CreateConfig().GetByFigure(99).id, Is.EqualTo("Assasin"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void EmptyConfigHasNoUsableFigure()
|
||||||
|
{
|
||||||
|
CharacterConfigData config = new CharacterConfigData();
|
||||||
|
|
||||||
|
Assert.That(config.GetFigure("cityboy_sk"), Is.EqualTo(0));
|
||||||
|
Assert.That(config.GetByFigure(1), Is.Null);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 47b7140934731c5468fc9a11064a59b6
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "XWorld.Link.EditModeTests",
|
||||||
|
"rootNamespace": "",
|
||||||
|
"references": ["XWorld.Link"],
|
||||||
|
"includePlatforms": ["Editor"],
|
||||||
|
"excludePlatforms": [],
|
||||||
|
"allowUnsafeCode": false,
|
||||||
|
"overrideReferences": false,
|
||||||
|
"precompiledReferences": [],
|
||||||
|
"autoReferenced": true,
|
||||||
|
"defineConstraints": [],
|
||||||
|
"versionDefines": [],
|
||||||
|
"noEngineReferences": false,
|
||||||
|
"optionalUnityReferences": ["TestAssemblies"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d8a5f61959a9cf247820e4e20a9ba310
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -15,12 +15,12 @@ namespace XGame
|
|||||||
public CharacterConfigItem GetDefault()
|
public CharacterConfigItem GetDefault()
|
||||||
{
|
{
|
||||||
CharacterConfigItem item = Find(defaultCharacterId);
|
CharacterConfigItem item = Find(defaultCharacterId);
|
||||||
return item ?? (characters.Count > 0 ? characters[0] : null);
|
return item ?? (characters != null && characters.Count > 0 ? characters[0] : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CharacterConfigItem Find(string id)
|
public CharacterConfigItem Find(string id)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(id))
|
if (string.IsNullOrEmpty(id) || characters == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -36,6 +36,40 @@ namespace XGame
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int GetFigure(string id)
|
||||||
|
{
|
||||||
|
return GetFigure(Find(id) ?? GetDefault());
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetFigure(CharacterConfigItem item)
|
||||||
|
{
|
||||||
|
if (item == null || characters == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < characters.Count; i++)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(characters[i], item))
|
||||||
|
{
|
||||||
|
return i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CharacterConfigItem GetByFigure(int figure)
|
||||||
|
{
|
||||||
|
int index = figure - 1;
|
||||||
|
if (characters != null && index >= 0 && index < characters.Count && characters[index] != null)
|
||||||
|
{
|
||||||
|
return characters[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
return GetDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
|
|||||||
Reference in New Issue
Block a user