58 lines
2.2 KiB
C#
58 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using BlockOutReplica.Domain;
|
|
using UnityEngine;
|
|
|
|
namespace BlockOutReplica.Infrastructure
|
|
{
|
|
public static class OriginalFlowRepository
|
|
{
|
|
private const string CatalogPath = "OriginalFlow/levelcatalog";
|
|
private const string ContinuousPath = "OriginalFlow/ContinuousLevelsConfigModel";
|
|
|
|
public static BlockOutFlowDefinition Load()
|
|
{
|
|
SeedList catalog = Read<SeedList>(CatalogPath);
|
|
ContinuousConfig continuous = Read<ContinuousConfig>(ContinuousPath);
|
|
|
|
List<string> result = new List<string>();
|
|
HashSet<string> used = new HashSet<string>(StringComparer.Ordinal);
|
|
// TutorialABTestLevelList contains alternative tutorial families, not
|
|
// twelve consecutive levels. Default packaged sequence is LevelsConfig.
|
|
foreach (var entry in OriginalLevelSettings.All)
|
|
AddUnique(new[] { entry.seedId }, result, used);
|
|
AddUnique(catalog.seeds, result, used);
|
|
|
|
if (result.Count == 0)
|
|
result.AddRange(OriginalLevelRepository.GetLevelIds());
|
|
|
|
int tutorialCount = 4;
|
|
int returnHome = continuous.IsEnabled ? Mathf.Max(1, continuous.Level) : 1;
|
|
return new BlockOutFlowDefinition(result, tutorialCount, returnHome);
|
|
}
|
|
|
|
private static T Read<T>(string resourcePath) where T : new()
|
|
{
|
|
TextAsset asset = Resources.Load<TextAsset>(resourcePath);
|
|
if (asset == null) return new T();
|
|
T value = JsonUtility.FromJson<T>(asset.text);
|
|
return value == null ? new T() : value;
|
|
}
|
|
|
|
private static void AddUnique(IEnumerable<string> source,
|
|
List<string> target, HashSet<string> used)
|
|
{
|
|
if (source == null) return;
|
|
foreach (string id in source)
|
|
if (!string.IsNullOrWhiteSpace(id) && used.Add(id)) target.Add(id);
|
|
}
|
|
|
|
[Serializable] private sealed class SeedList { public string[] seeds; }
|
|
[Serializable] private sealed class ContinuousConfig
|
|
{
|
|
public bool IsEnabled;
|
|
public int Level;
|
|
}
|
|
}
|
|
}
|