Move designer surface projection into builders
This commit is contained in:
parent
72e2041071
commit
9211547d41
5 changed files with 275 additions and 128 deletions
|
|
@ -9618,7 +9618,9 @@ static void RequireDaemonVersePublication(string root)
|
|||
var daemonStateRefsPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeDaemonStateRefs.cs");
|
||||
var daemonGameSurfaceBuilderPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeDaemonGameSurfaceBuilder.cs");
|
||||
var daemonEditorSurfaceBuilderPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeDaemonEditorSurfaceBuilder.cs");
|
||||
var statRecipeSurfaceBuilderPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeStatRecipeSurfaceBuilder.cs");
|
||||
var tradeValuePolicySurfaceBuilderPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeTradeValuePolicySurfaceBuilder.cs");
|
||||
var runtimeCatalogStorePath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeCatalogStore.cs");
|
||||
var daemonSurfaceCommandCatalogPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeDaemonSurfaceCommandCatalog.cs");
|
||||
var committedFactImporterPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeCommittedFactImporter.cs");
|
||||
var daemonHostProjectPath = Path.Combine(root, "Aetheria.State.Daemon", "Aetheria.State.Daemon.csproj");
|
||||
|
|
@ -9642,7 +9644,9 @@ static void RequireDaemonVersePublication(string root)
|
|||
daemonStateRefsPath,
|
||||
daemonGameSurfaceBuilderPath,
|
||||
daemonEditorSurfaceBuilderPath,
|
||||
statRecipeSurfaceBuilderPath,
|
||||
tradeValuePolicySurfaceBuilderPath,
|
||||
runtimeCatalogStorePath,
|
||||
daemonSurfaceCommandCatalogPath,
|
||||
committedFactImporterPath,
|
||||
daemonHostProjectPath,
|
||||
|
|
@ -9675,7 +9679,9 @@ static void RequireDaemonVersePublication(string root)
|
|||
var daemonStateRefs = File.ReadAllText(daemonStateRefsPath);
|
||||
var daemonGameSurfaceBuilder = File.ReadAllText(daemonGameSurfaceBuilderPath);
|
||||
var daemonEditorSurfaceBuilder = File.ReadAllText(daemonEditorSurfaceBuilderPath);
|
||||
var statRecipeSurfaceBuilder = File.ReadAllText(statRecipeSurfaceBuilderPath);
|
||||
var tradeValuePolicySurfaceBuilder = File.ReadAllText(tradeValuePolicySurfaceBuilderPath);
|
||||
var runtimeCatalogStore = File.ReadAllText(runtimeCatalogStorePath);
|
||||
var daemonSurfaceCommandCatalog = File.ReadAllText(daemonSurfaceCommandCatalogPath);
|
||||
var committedFactImporter = File.ReadAllText(committedFactImporterPath);
|
||||
var daemonHostProject = File.ReadAllText(daemonHostProjectPath);
|
||||
|
|
@ -10048,8 +10054,8 @@ static void RequireDaemonVersePublication(string root)
|
|||
"StarbridgeSession",
|
||||
"var catalog = options.Catalog ?? new AetheriaRuntimeCatalogSnapshot(",
|
||||
"AetheriaRuntimeDaemonGameSurfaceBuilder.Build",
|
||||
"AetheriaRuntimeCatalogStore.ProjectStatRecipeSurfaceDocument(catalog)",
|
||||
"AetheriaRuntimeCatalogStore.ProjectTradeValuePolicySurfaceDocument(catalog)",
|
||||
"AetheriaRuntimeStatRecipeSurfaceBuilder.BuildFromCatalog(catalog)",
|
||||
"AetheriaRuntimeTradeValuePolicySurfaceBuilder.BuildFromCatalog(catalog)",
|
||||
"AetheriaRuntimeDaemonEditorSurfaceBuilder.Build",
|
||||
"SoaView = soaView",
|
||||
"ProviderAdvertisement = providerAdvertisement",
|
||||
|
|
@ -10087,6 +10093,8 @@ static void RequireDaemonVersePublication(string root)
|
|||
"AetheriaRuntimeDaemonPublicationStore.PublishGameTuiSurface(",
|
||||
"AetheriaRuntimeDaemonPublicationStore.PublishEditorSurface(",
|
||||
"AetheriaRuntimeDaemonPublicationStore.PublishEditorTuiSurface(",
|
||||
"AetheriaRuntimeCatalogStore.ProjectStatRecipeSurfaceDocument(catalog)",
|
||||
"AetheriaRuntimeCatalogStore.ProjectTradeValuePolicySurfaceDocument(catalog)",
|
||||
"AetheriaRuntimeCatalogStore.ProjectStatRecipeSurfaceDocument(stateFilePath)",
|
||||
"AetheriaRuntimeCatalogStore.ProjectTradeValuePolicySurfaceDocument(stateFilePath)"
|
||||
};
|
||||
|
|
@ -10302,6 +10310,8 @@ static void RequireDaemonVersePublication(string root)
|
|||
var requiredTradeValuePolicySurfaceSymbols = new[]
|
||||
{
|
||||
"public static class AetheriaRuntimeTradeValuePolicySurfaceBuilder",
|
||||
"public static AetheriaRuntimeSurfaceDocument BuildFromCatalog(",
|
||||
"public static AetheriaRuntimeTradeValuePolicySurfaceState ProjectState(",
|
||||
"SurfaceId = \"aetheria.tradeValuePolicy\"",
|
||||
"AetheriaRuntimeTradeValuePolicySurfaceState",
|
||||
"Quality Price Modifier",
|
||||
|
|
@ -10324,6 +10334,44 @@ static void RequireDaemonVersePublication(string root)
|
|||
string.Join(", ", missingTradeValuePolicySurfaceSymbols));
|
||||
}
|
||||
|
||||
var requiredStatRecipeSurfaceProjectionSymbols = new[]
|
||||
{
|
||||
"public static AetheriaRuntimeSurfaceDocument BuildFromCatalog(",
|
||||
"public static AetheriaRuntimeStatRecipeSurfaceState ProjectState(",
|
||||
"SelectMany(ProjectRows)",
|
||||
"AetheriaRuntimeBehaviorMetadataCatalog.Get(behavior.Kind)",
|
||||
"AetheriaRuntimeBehaviorFieldValueKind.PerformanceStat",
|
||||
"new AetheriaRuntimeStatRecipeState(",
|
||||
"new AetheriaRuntimeStatInfluenceState("
|
||||
};
|
||||
var missingStatRecipeSurfaceProjectionSymbols = requiredStatRecipeSurfaceProjectionSymbols
|
||||
.Where(symbol => !statRecipeSurfaceBuilder.Contains(symbol, StringComparison.Ordinal))
|
||||
.ToArray();
|
||||
if (missingStatRecipeSurfaceProjectionSymbols.Length > 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Stat recipe designer surface projection must live on AetheriaRuntimeStatRecipeSurfaceBuilder: " +
|
||||
string.Join(", ", missingStatRecipeSurfaceProjectionSymbols));
|
||||
}
|
||||
|
||||
var forbiddenCatalogStoreSurfaceProjectionSymbols = new[]
|
||||
{
|
||||
"ProjectStatRecipeSurfaceState(",
|
||||
"ProjectTradeValuePolicySurfaceState(",
|
||||
"ProjectStatRecipeRows(",
|
||||
"ProjectStatRecipeRow(",
|
||||
"ProjectStatInfluence("
|
||||
};
|
||||
var catalogStoreSurfaceProjectionHits = forbiddenCatalogStoreSurfaceProjectionSymbols
|
||||
.Where(symbol => runtimeCatalogStore.Contains(symbol, StringComparison.Ordinal))
|
||||
.ToArray();
|
||||
if (catalogStoreSurfaceProjectionHits.Length > 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Runtime catalog store still owns designer surface projection helpers that belong on typed surface builders: " +
|
||||
string.Join(", ", catalogStoreSurfaceProjectionHits));
|
||||
}
|
||||
|
||||
if (stateNode.Contains("DeleteDaemonCommandAsync(", StringComparison.Ordinal) ||
|
||||
daemonHostSource.Contains("DeleteAccountedDaemonCommandsAsync", StringComparison.Ordinal) ||
|
||||
daemonHostSource.Contains("DeleteDaemonCommandAsync(", StringComparison.Ordinal))
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
public static AetheriaRuntimeSurfaceDocument ProjectStatRecipeSurfaceDocument(
|
||||
AetheriaRuntimeCatalogSnapshot? catalog)
|
||||
{
|
||||
return AetheriaRuntimeStatRecipeSurfaceBuilder.Build(ProjectStatRecipeSurfaceState(catalog));
|
||||
return AetheriaRuntimeStatRecipeSurfaceBuilder.BuildFromCatalog(catalog);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument ProjectTradeValuePolicySurfaceDocument(string stateFilePath)
|
||||
|
|
@ -100,79 +100,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
public static AetheriaRuntimeSurfaceDocument ProjectTradeValuePolicySurfaceDocument(
|
||||
AetheriaRuntimeCatalogSnapshot? catalog)
|
||||
{
|
||||
return AetheriaRuntimeTradeValuePolicySurfaceBuilder.Build(ProjectTradeValuePolicySurfaceState(catalog));
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeTradeValuePolicySurfaceState ProjectTradeValuePolicySurfaceState(
|
||||
AetheriaRuntimeCatalogSnapshot? catalog)
|
||||
{
|
||||
return new AetheriaRuntimeTradeValuePolicySurfaceState(
|
||||
catalog?.TradeValueSettings ?? AetheriaRuntimeTradeValueSettings.Default,
|
||||
DateTime.UtcNow.ToString("O"));
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeStatRecipeSurfaceState ProjectStatRecipeSurfaceState(
|
||||
AetheriaRuntimeCatalogSnapshot? catalog)
|
||||
{
|
||||
var recipes = (catalog?.Items ?? Array.Empty<AetheriaRuntimeCatalogItem>())
|
||||
.SelectMany(ProjectStatRecipeRows)
|
||||
.OrderBy(recipe => recipe.StatName, StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
|
||||
var state = new AetheriaRuntimeStatRecipeSurfaceState(
|
||||
recipes,
|
||||
recipes.FirstOrDefault()?.StatName ?? "",
|
||||
AetheriaRuntimeStatRecipePreviewState.Default,
|
||||
DateTime.UtcNow.ToString("O"));
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
private static IEnumerable<AetheriaRuntimeStatRecipeState> ProjectStatRecipeRows(AetheriaRuntimeCatalogItem item)
|
||||
{
|
||||
foreach (var behavior in item.BehaviorPayloads ?? Array.Empty<AetheriaRuntimeBehaviorPayload>())
|
||||
{
|
||||
var metadata = AetheriaRuntimeBehaviorMetadataCatalog.Get(behavior.Kind);
|
||||
foreach (var field in behavior.Fields ?? Array.Empty<AetheriaRuntimeBehaviorField>())
|
||||
{
|
||||
var fieldMetadata = metadata?.DisplayFields.FirstOrDefault(candidate => candidate.Key == field.Key);
|
||||
if (fieldMetadata?.ValueKind != AetheriaRuntimeBehaviorFieldValueKind.PerformanceStat)
|
||||
continue;
|
||||
|
||||
yield return ProjectStatRecipeRow(item, behavior, field, fieldMetadata.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeStatRecipeState ProjectStatRecipeRow(
|
||||
AetheriaRuntimeCatalogItem item,
|
||||
AetheriaRuntimeBehaviorPayload behavior,
|
||||
AetheriaRuntimeBehaviorField field,
|
||||
string fieldName)
|
||||
{
|
||||
var value = field.Value;
|
||||
var recipe = ReadBehaviorStatRecipe(value);
|
||||
var statName = string.Join(
|
||||
" / ",
|
||||
new[] { item.Name, behavior.Kind, fieldName }
|
||||
.Where(part => !string.IsNullOrWhiteSpace(part)));
|
||||
var recipeKey = $"{item.ItemKey}|{behavior.Kind}|{behavior.Group}|{field.Key}";
|
||||
var baseValue = recipe?.BaseValue ?? ReadBehaviorStatBaseValue(value);
|
||||
return new AetheriaRuntimeStatRecipeState(
|
||||
recipeKey,
|
||||
statName,
|
||||
baseValue,
|
||||
(recipe?.Modifiers ?? Array.Empty<AetheriaRuntimeStatRecipeModifier>())
|
||||
.Select(ProjectStatInfluence)
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
private static double ReadBehaviorStatBaseValue(AetheriaRuntimeBehaviorValue value)
|
||||
{
|
||||
if (value?.Children == null || value.Children.Count < 2)
|
||||
return 0;
|
||||
|
||||
return value.Children[1].NumberValue;
|
||||
return AetheriaRuntimeTradeValuePolicySurfaceBuilder.BuildFromCatalog(catalog);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeStatRecipe? ReadBehaviorStatRecipe(AetheriaRuntimeBehaviorValue? value)
|
||||
|
|
@ -223,56 +151,6 @@ namespace GameCult.Aetheria.State.Verse
|
|||
.ToArray();
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeStatInfluenceState ProjectStatInfluence(AetheriaRuntimeStatRecipeModifier modifier)
|
||||
{
|
||||
return new AetheriaRuntimeStatInfluenceState(
|
||||
modifier.Condition,
|
||||
string.IsNullOrWhiteSpace(modifier.Operation) ? AetheriaRuntimeStatRecipeOperations.Add : modifier.Operation,
|
||||
modifier.Amount,
|
||||
CurveLabel(modifier.CurveKeys),
|
||||
SampleCurve(modifier.CurveKeys, AetheriaRuntimeStatRecipePreviewState.Default.GetConditionValue(modifier.Condition)),
|
||||
modifier.Enabled);
|
||||
}
|
||||
|
||||
private static string CurveLabel(IReadOnlyList<AetheriaRuntimeCurveKey> keys)
|
||||
{
|
||||
if (keys == null || keys.Count == 0)
|
||||
return "linear";
|
||||
|
||||
var preset = CurvePresetLabel(keys);
|
||||
return string.IsNullOrWhiteSpace(preset) ? $"{keys.Count} keys" : preset;
|
||||
}
|
||||
|
||||
private static double SampleCurve(IReadOnlyList<AetheriaRuntimeCurveKey> keys, double value)
|
||||
{
|
||||
if (keys == null || keys.Count == 0)
|
||||
return Clamp01(value);
|
||||
|
||||
var ordered = keys.OrderBy(key => key.Time).ToArray();
|
||||
if (value <= ordered[0].Time)
|
||||
return Clamp01(ordered[0].Value);
|
||||
for (var index = 1; index < ordered.Length; index++)
|
||||
{
|
||||
var next = ordered[index];
|
||||
var previous = ordered[index - 1];
|
||||
if (value > next.Time)
|
||||
continue;
|
||||
|
||||
var span = next.Time - previous.Time;
|
||||
var t = span <= double.Epsilon ? 1 : Clamp01((value - previous.Time) / span);
|
||||
return Clamp01(previous.Value + ((next.Value - previous.Value) * t));
|
||||
}
|
||||
|
||||
return Clamp01(ordered[ordered.Length - 1].Value);
|
||||
}
|
||||
|
||||
private static double Clamp01(double value)
|
||||
{
|
||||
if (value < 0)
|
||||
return 0;
|
||||
return value > 1 ? 1 : value;
|
||||
}
|
||||
|
||||
private static string ReadChildString(AetheriaRuntimeBehaviorValue? value, int index)
|
||||
{
|
||||
return ReadChildValue(value, index)?.StringValue ?? "";
|
||||
|
|
|
|||
|
|
@ -215,8 +215,8 @@ namespace GameCult.Aetheria.State.Verse
|
|||
starbridgeSummary);
|
||||
var designerSurfaces = new[]
|
||||
{
|
||||
AetheriaRuntimeCatalogStore.ProjectStatRecipeSurfaceDocument(catalog),
|
||||
AetheriaRuntimeCatalogStore.ProjectTradeValuePolicySurfaceDocument(catalog)
|
||||
AetheriaRuntimeStatRecipeSurfaceBuilder.BuildFromCatalog(catalog),
|
||||
AetheriaRuntimeTradeValuePolicySurfaceBuilder.BuildFromCatalog(catalog)
|
||||
};
|
||||
var editorSurface = AetheriaRuntimeDaemonEditorSurfaceBuilder.Build(
|
||||
providerAdvertisement,
|
||||
|
|
|
|||
|
|
@ -203,6 +203,28 @@ namespace GameCult.Aetheria.State.Verse
|
|||
|
||||
public static class AetheriaRuntimeStatRecipeSurfaceBuilder
|
||||
{
|
||||
public static AetheriaRuntimeSurfaceDocument BuildFromCatalog(
|
||||
AetheriaRuntimeCatalogSnapshot? catalog,
|
||||
long version = 1)
|
||||
{
|
||||
return Build(ProjectState(catalog), version);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeStatRecipeSurfaceState ProjectState(
|
||||
AetheriaRuntimeCatalogSnapshot? catalog)
|
||||
{
|
||||
var recipes = (catalog?.Items ?? Array.Empty<AetheriaRuntimeCatalogItem>())
|
||||
.SelectMany(ProjectRows)
|
||||
.OrderBy(recipe => recipe.StatName, StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
|
||||
return new AetheriaRuntimeStatRecipeSurfaceState(
|
||||
recipes,
|
||||
recipes.FirstOrDefault()?.StatName ?? "",
|
||||
AetheriaRuntimeStatRecipePreviewState.Default,
|
||||
DateTime.UtcNow.ToString("O"));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument Build(
|
||||
AetheriaRuntimeStatRecipeSurfaceState state,
|
||||
long version = 1)
|
||||
|
|
@ -690,6 +712,190 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return Node(id, "control.text", props);
|
||||
}
|
||||
|
||||
private static IEnumerable<AetheriaRuntimeStatRecipeState> ProjectRows(
|
||||
AetheriaRuntimeCatalogItem item)
|
||||
{
|
||||
foreach (var behavior in item.BehaviorPayloads ?? Array.Empty<AetheriaRuntimeBehaviorPayload>())
|
||||
{
|
||||
var metadata = AetheriaRuntimeBehaviorMetadataCatalog.Get(behavior.Kind);
|
||||
foreach (var field in behavior.Fields ?? Array.Empty<AetheriaRuntimeBehaviorField>())
|
||||
{
|
||||
var fieldMetadata = metadata?.DisplayFields.FirstOrDefault(candidate => candidate.Key == field.Key);
|
||||
if (fieldMetadata?.ValueKind != AetheriaRuntimeBehaviorFieldValueKind.PerformanceStat)
|
||||
continue;
|
||||
|
||||
yield return ProjectRow(item, behavior, field, fieldMetadata.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeStatRecipeState ProjectRow(
|
||||
AetheriaRuntimeCatalogItem item,
|
||||
AetheriaRuntimeBehaviorPayload behavior,
|
||||
AetheriaRuntimeBehaviorField field,
|
||||
string fieldName)
|
||||
{
|
||||
var value = field.Value;
|
||||
var recipe = ReadRecipe(value);
|
||||
var statName = string.Join(
|
||||
" / ",
|
||||
new[] { item.Name, behavior.Kind, fieldName }
|
||||
.Where(part => !string.IsNullOrWhiteSpace(part)));
|
||||
var recipeKey = $"{item.ItemKey}|{behavior.Kind}|{behavior.Group}|{field.Key}";
|
||||
var baseValue = recipe?.BaseValue ?? ReadBaseValue(value);
|
||||
return new AetheriaRuntimeStatRecipeState(
|
||||
recipeKey,
|
||||
statName,
|
||||
baseValue,
|
||||
(recipe?.Modifiers ?? Array.Empty<AetheriaRuntimeStatRecipeModifier>())
|
||||
.Select(ProjectInfluence)
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
private static double ReadBaseValue(AetheriaRuntimeBehaviorValue value)
|
||||
{
|
||||
if (value?.Children == null || value.Children.Count < 2)
|
||||
return 0;
|
||||
|
||||
return value.Children[1].NumberValue;
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeStatRecipe? ReadRecipe(AetheriaRuntimeBehaviorValue? value)
|
||||
{
|
||||
if (value?.Children == null || value.Children.Count <= 5)
|
||||
return null;
|
||||
|
||||
var recipeValue = value.Children[5];
|
||||
if (recipeValue?.Children == null || recipeValue.Children.Count == 0)
|
||||
return null;
|
||||
|
||||
var baseValue = recipeValue.Children[0].NumberValue;
|
||||
var modifierValues = recipeValue.Children.Count > 1
|
||||
? recipeValue.Children[1].Children ?? Array.Empty<AetheriaRuntimeBehaviorValue>()
|
||||
: Array.Empty<AetheriaRuntimeBehaviorValue>();
|
||||
var modifiers = modifierValues
|
||||
.Select(ReadModifier)
|
||||
.OfType<AetheriaRuntimeStatRecipeModifier>()
|
||||
.ToArray();
|
||||
return new AetheriaRuntimeStatRecipe(baseValue, modifiers);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeStatRecipeModifier? ReadModifier(
|
||||
AetheriaRuntimeBehaviorValue? value)
|
||||
{
|
||||
if (value?.Children == null)
|
||||
return null;
|
||||
|
||||
return new AetheriaRuntimeStatRecipeModifier(
|
||||
ReadChildString(value, 0),
|
||||
ReadChildString(value, 1),
|
||||
ReadChildNumber(value, 2),
|
||||
ReadCurveKeys(ReadChildValue(value, 3)),
|
||||
value.Children.Count <= 4 || ReadChildValue(value, 4)?.BoolValue != false);
|
||||
}
|
||||
|
||||
private static IReadOnlyList<AetheriaRuntimeCurveKey> ReadCurveKeys(
|
||||
AetheriaRuntimeBehaviorValue? value)
|
||||
{
|
||||
if (value?.Children == null || value.Children.Count == 0)
|
||||
return Array.Empty<AetheriaRuntimeCurveKey>();
|
||||
|
||||
return value.Children
|
||||
.Where(key => key.Children != null && key.Children.Count >= 4)
|
||||
.Select(key => new AetheriaRuntimeCurveKey(
|
||||
ReadChildNumber(key, 0),
|
||||
ReadChildNumber(key, 1),
|
||||
ReadChildNumber(key, 2),
|
||||
ReadChildNumber(key, 3)))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeStatInfluenceState ProjectInfluence(
|
||||
AetheriaRuntimeStatRecipeModifier modifier)
|
||||
{
|
||||
return new AetheriaRuntimeStatInfluenceState(
|
||||
modifier.Condition,
|
||||
string.IsNullOrWhiteSpace(modifier.Operation) ? AetheriaRuntimeStatRecipeOperations.Add : modifier.Operation,
|
||||
modifier.Amount,
|
||||
CurveLabel(modifier.CurveKeys),
|
||||
SampleCurve(modifier.CurveKeys, AetheriaRuntimeStatRecipePreviewState.Default.GetConditionValue(modifier.Condition)),
|
||||
modifier.Enabled);
|
||||
}
|
||||
|
||||
private static string CurvePresetLabel(IReadOnlyList<AetheriaRuntimeCurveKey> keys)
|
||||
{
|
||||
if (keys == null || keys.Count == 0)
|
||||
return "";
|
||||
|
||||
var ordered = keys.OrderBy(key => key.Time).ToArray();
|
||||
if (ordered.Length == 2 &&
|
||||
Math.Abs(ordered[0].Time) < 0.0001 &&
|
||||
Math.Abs(ordered[0].Value) < 0.0001 &&
|
||||
Math.Abs(ordered[1].Time - 1) < 0.0001 &&
|
||||
Math.Abs(ordered[1].Value - 1) < 0.0001)
|
||||
return "linear";
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private static string CurveLabel(IReadOnlyList<AetheriaRuntimeCurveKey> keys)
|
||||
{
|
||||
if (keys == null || keys.Count == 0)
|
||||
return "linear";
|
||||
|
||||
var preset = CurvePresetLabel(keys);
|
||||
return string.IsNullOrWhiteSpace(preset) ? $"{keys.Count} keys" : preset;
|
||||
}
|
||||
|
||||
private static double SampleCurve(
|
||||
IReadOnlyList<AetheriaRuntimeCurveKey> keys,
|
||||
double value)
|
||||
{
|
||||
if (keys == null || keys.Count == 0)
|
||||
return ClampCurveSample(value);
|
||||
|
||||
var ordered = keys.OrderBy(key => key.Time).ToArray();
|
||||
if (value <= ordered[0].Time)
|
||||
return ClampCurveSample(ordered[0].Value);
|
||||
for (var index = 1; index < ordered.Length; index++)
|
||||
{
|
||||
var next = ordered[index];
|
||||
var previous = ordered[index - 1];
|
||||
if (value > next.Time)
|
||||
continue;
|
||||
|
||||
var span = next.Time - previous.Time;
|
||||
var t = span <= double.Epsilon ? 1 : ClampCurveSample((value - previous.Time) / span);
|
||||
return ClampCurveSample(previous.Value + ((next.Value - previous.Value) * t));
|
||||
}
|
||||
|
||||
return ClampCurveSample(ordered[ordered.Length - 1].Value);
|
||||
}
|
||||
|
||||
private static double ClampCurveSample(double value)
|
||||
{
|
||||
if (value < 0)
|
||||
return 0;
|
||||
return value > 1 ? 1 : value;
|
||||
}
|
||||
|
||||
private static string ReadChildString(AetheriaRuntimeBehaviorValue? value, int index)
|
||||
{
|
||||
return ReadChildValue(value, index)?.StringValue ?? "";
|
||||
}
|
||||
|
||||
private static double ReadChildNumber(AetheriaRuntimeBehaviorValue? value, int index)
|
||||
{
|
||||
return ReadChildValue(value, index)?.NumberValue ?? 0;
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeBehaviorValue? ReadChildValue(
|
||||
AetheriaRuntimeBehaviorValue? value,
|
||||
int index)
|
||||
{
|
||||
return value?.Children != null && value.Children.Count > index ? value.Children[index] : null;
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent ButtonRow(
|
||||
string id,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,21 @@ namespace GameCult.Aetheria.State.Verse
|
|||
{
|
||||
public const string SurfaceId = "aetheria.tradeValuePolicy";
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument BuildFromCatalog(
|
||||
AetheriaRuntimeCatalogSnapshot? catalog,
|
||||
long version = 1)
|
||||
{
|
||||
return Build(ProjectState(catalog), version);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeTradeValuePolicySurfaceState ProjectState(
|
||||
AetheriaRuntimeCatalogSnapshot? catalog)
|
||||
{
|
||||
return new AetheriaRuntimeTradeValuePolicySurfaceState(
|
||||
catalog?.TradeValueSettings ?? AetheriaRuntimeTradeValueSettings.Default,
|
||||
DateTime.UtcNow.ToString("O"));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument Build(
|
||||
AetheriaRuntimeTradeValuePolicySurfaceState state,
|
||||
long version = 1)
|
||||
|
|
|
|||
Loading…
Reference in a new issue