public void Initialize(PartListGrid parent, ReferencePart part, int row) { _parent = parent; _part = part; _image.sprite = part.Sprite; _row = row; }
public void ReadReferencePart(ReferenceCommand command, string value) { var part = new ReferencePart(new Dictionary <ReferenceCommand, string> { { command, value } }); Assert.Equal(command, part.Commands.First().Key); Assert.Equal(value, part.Commands.First().Value); }
private void UpdateContextAliases(KeyResolveContext context, ReferencePart reference) { var alias = reference.Commands[ReferenceCommand.Alias]; var @using = reference.Commands[ReferenceCommand.Using]; _logger.LogTrace(WithContext(context, $"adding alias '{alias}'='{@using}'")); context.Tracer.AddCommand(ReferenceCommand.Alias, alias); context.Tracer.AddCommand(ReferenceCommand.Using, @using); context.Aliases[alias] = @using; }
public void CreateDescription(ReferencePart part, EOfferState state) { _descriptionBuilder.Clear(); if (state == EOfferState.Available) { _name.text = part.Name; } else if (state == EOfferState.Bought) { _name.text = "<color=yellow>" + part.Name + "</color>"; } else { _name.text = "<color=red>" + part.Name + "</color>"; } _image.sprite = part.Sprite; _descriptionBuilder.Append("<size=14>" + part.ShortDescription + "</size>\n"); if (state == EOfferState.Available) { _descriptionBuilder.Append("Cost: " + part.Cost.ToString() + " $\n"); } else if (state == EOfferState.Unavailable) { _descriptionBuilder.Append("<color=red>Cost: " + part.Cost.ToString() + " $</color>\n"); } string specDesc = part.GetOfferDescription(); _descriptionBuilder.Append("\n" + specDesc); if (state == EOfferState.Bought) { _descriptionBuilder.Append("\n\n<color=yellow>Owned!</color>"); _descriptionBuilder.Append("\n<size=14><color=yellow>Buy again to get brand new part - fully performant.</color></size>"); } _description.text = _descriptionBuilder.ToString(); }
private async Task <(ReferenceEvaluationType, Dictionary <string, string>)> ResolveReferencePath(KeyResolveContext context, ReferencePart reference) { // this is to check for possible fallback-values, if actual path-resolution goes wrong bool FallbackAction() { if (!reference.Commands.ContainsKey(ReferenceCommand.Fallback)) { return(false); } var fallbackValue = reference.Commands[ReferenceCommand.Fallback]; context.Tracer.AddWarning($"using fallback '{fallbackValue}' after failing to resolve '{context.BasePath}'"); _logger.LogInformation($"using fallback '{fallbackValue}' after failing to resolve '{context.BasePath}'"); return(true); } var resultType = ReferenceEvaluationType.None; var intermediateResult = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); var actualResult = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); var referencePath = ResolvePathAliases(context, reference.Commands[ReferenceCommand.Path]); var(provider, newPath) = SelectConfigValueProvider(context, referencePath); if (provider is null) { _logger.LogWarning(WithContext(context, "could not resolve any ValueProvider")); return(resultType, intermediateResult); } // removes $stuff from the beginning of referencePath, if a suitable provider could be found referencePath = newPath; var rangeTracer = context.Tracer.AddPathResolution(referencePath); if (referencePath.EndsWith('*')) { var result = await provider.TryGetRange(referencePath); if (!result.IsError) { var referenceBase = referencePath.TrimEnd('*').TrimEnd('/'); foreach (var(key, value) in result.Data) { var trimmedKey = key.TrimStart('/'); var compositePath = $"{context.BasePath}/{trimmedKey}"; intermediateResult[compositePath] = value; rangeTracer.AddPathResult($"{referenceBase}/{trimmedKey}", value); } } else { context.Tracer.AddError(result.Message); _logger.LogWarning(WithContext(context, $"could not resolve values: ({result.Code:G}) {result.Message}")); if (FallbackAction()) { var fallbackValue = reference.Commands[ReferenceCommand.Fallback]; intermediateResult[context.BasePath] = fallbackValue; rangeTracer.AddPathResult(fallbackValue); } } resultType = ReferenceEvaluationType.ResolvedRangeQuery; } else { var result = await provider.TryGetValue(referencePath); if (!result.IsError) { intermediateResult[context.BasePath] = result.Data; rangeTracer.AddPathResult(result.Data); } else { var indirectionResolved = false; // path might only make sense if given alternative is de-referenced if (result.Code == ErrorCode.NotFoundPossibleIndirection && !string.IsNullOrWhiteSpace(result.Data)) { var indirectionValueResult = await provider.TryGetValue(result.Data); if (!indirectionValueResult.IsError) { var indirectionResolveResult = await ResolveInternal(new KeyResolveContext(result.Data, indirectionValueResult.Data, rangeTracer, context.Parser)); if (!indirectionResolveResult.IsError && indirectionResolveResult.Data.TryGetValue(referencePath, out var resolvedIndirection)) { // value has been successfully resolved through the indirection intermediateResult[context.BasePath] = resolvedIndirection; rangeTracer.AddPathResult(resolvedIndirection); indirectionResolved = true; } } } if (!indirectionResolved) { context.Tracer.AddError(result.Message); _logger.LogWarning(WithContext(context, $"could not resolve values: ({result.Code:G}) {result.Message}")); if (FallbackAction()) { var fallbackValue = reference.Commands[ReferenceCommand.Fallback]; intermediateResult[context.BasePath] = fallbackValue; rangeTracer.AddPathResult(fallbackValue); } } } resultType = ReferenceEvaluationType.ResolvedDirectReference; } // replace $this while we still know what its supposed to represent // once we leave this stack-frame, we lose the correct context of $this ResolveThisAlias(context, referencePath, intermediateResult); foreach (var(nextKey, nextValue) in intermediateResult) { var nextTracer = context.Tracer.AddPathResolution(nextValue); var nextContext = context.CreateChildContext(nextKey, nextValue, nextTracer); var nextResult = await ResolveInternal(nextContext); // @TODO: should we maybe do something else here instead of continuing on like nothing happened? if (nextResult.IsError) { continue; } foreach (var entry in nextResult.Data) { actualResult[entry.Key] = entry.Value; } } return(resultType, actualResult); }
private async Task <ReferenceEvaluationResult> EvaluateReference(KeyResolveContext context, ReferencePart reference) { var evaluationResult = new ReferenceEvaluationResult { Effects = ReferenceEvaluationType.None, ResultingKeys = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) }; if (reference.Commands.ContainsKey(ReferenceCommand.Alias) && reference.Commands.ContainsKey(ReferenceCommand.Using)) { UpdateContextAliases(context, reference); evaluationResult.Effects |= ReferenceEvaluationType.ModifiedContext; } if (reference.Commands.ContainsKey(ReferenceCommand.Path)) { var(resolveType, resolvedEntries) = await ResolveReferencePath(context, reference); foreach (var(k, v) in resolvedEntries) { evaluationResult.ResultingKeys[k] = v; } evaluationResult.Effects |= resolveType; } return(evaluationResult); }
public ShowPartDescriptionEA(ReferencePart part, EOfferState state) { Part = part; State = state; }