-
Notifications
You must be signed in to change notification settings - Fork 0
/
OperatorModules.linq
149 lines (125 loc) · 4.58 KB
/
OperatorModules.linq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<Query Kind="Program" />
// Arknights operators modules missions.
#nullable enable
#load "./lib/Context.linq"
#load "./lib/Extensions.linq"
#load "./lib/Images.linq"
#load "./lib/Operators.linq"
#load "./lib/Parsable.linq"
#load "./lib/WikiHyperlinq.linq"
#define DUMP_UNKNOWN_OPERATORS
/*
#define DUMP_OPERATORS
#define DUMP_ALL_OPERATOR_MODULES
//*/
void Main()
{
// TODO: Add operator(s) with (optionally) X or Y modules.
var operators = new OperatorModules("""
// name <tab> type (X, Y, D or empty for all)
""")
#if DUMP_OPERATORS
.OrderBy(static op => op.Name)
.Dump("Operators")
#endif
;
var operatorModules = OperatorData.Value
#if !DUMP_ALL_OPERATOR_MODULES
.OnlyFor(operators)
#endif
.OrderBy(static v => v.Name)
.GroupBy(static v => v.Stage)
.Select( static v => new
{
Stage = v.Key,
Names = v.JoinStrings(static v => v.Name),
Operators = v.Select(Pass),
Stars = v.JoinStrings(static v => v.Stars),
MaxStars = v.Max(static v => v.Stars),
Total = v.Count()
})
.OrderByDescending(static v => v.Total)
.ThenByDescending( static v => v.MaxStars)
.ThenBy(static v => v.Names)
.Select((v, i) => HighlightIf(v.Total > 1, new
{
ID = i + 1,
Stage = new WikiHyperlinq(v.Stage),
Operator = VerticalRun(v.Operators.Select(static v => new WikiHyperlinq(v.Uri, v.Name))),
Class = VerticalRun(v.Operators.Select(static v => new WikiHyperlinq(v.Class))),
v.Stars,
Module = VerticalRun(v.Operators.Select(static v => new WikiHyperlinq($"{v.Uri}#{v.Module}", v.Module))),
v.Total,
Paradox = VerticalRun(v.Operators.Select(static v => v.Paradox ? GetParadoxHyperlinq(v.Name) : Empty)),
E2Materials = VerticalRun(v.Operators.Select(static v => GetMaterials(v.Uri, v.E2Materials)))
}))
.ToArray();
#if DUMP_UNKNOWN_OPERATORS
var unknownOperators = operators.Select(static op => op.Name)
.Except(OperatorData.Value.Select(static om => om.Name), StringComparer.OrdinalIgnoreCase)
.Select(static (name, i) => new
{
ID = i + 1,
Name = new WikiHyperlinq(name),
Paradox = GetParadoxHyperlinq(name)
})
.ToArray();
if(unknownOperators.Any())
{
const string unknownOperatorsTitle = "Unknown Operators";
unknownOperators.Dump(unknownOperatorsTitle);
unknownOperatorsTitle.AsHyperlink(new WikiHyperlinq("Operator").Uri);
}
#endif
const string title = "Joined Operators Modules";
Context = new();
HorizontalRun(false,
(operatorModules.Any() ? (object)operatorModules : "No operators modules found."),
Context.Containers.Image
).Dump(title);
new DumpContainer(){ Style = $"height: {DumpContext.Document.MarginBottom}" }.Dump();
title.AsHyperlink(new WikiHyperlinq("Operator_Module", "List").Uri);
static T Pass<T>(T t) => t;
}
static object GetParadoxHyperlinq(string name) =>
VideoHostings.YouTube.GetSearchHyperlinqs(name, "paradox", "simulation");
static object GetMaterials(string op, string materials)
{
const StringSplitOptions StringSplitOptions = StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries;
return HorizontalRun(false,
materials
.Split(OperatorData.MaterialSeparator, StringSplitOptions)
.SelectMany(GetMaterialLinks)
.InsertAfterEach(3, OperatorData.MaterialSeparator)
);
IEnumerable<object> GetMaterialLinks(string materialCount)
{
var material = materialCount.Split(OperatorData.CountSeparator, StringSplitOptions);
yield return ItemImage.GetHyperlink(material.First());
yield return OperatorData.CountSeparator;
yield return new WikiHyperlinq($"{op}#Promotion", material.Last());
}
}
static partial class CollectionExtensions
{
public static IEnumerable<Operator> OnlyFor(this IEnumerable<Operator> operatorModules, IEnumerable<OperatorModule> operators)
{
var stringComparer = StringComparer.OrdinalIgnoreCase;
var stringComparison = StringComparison.OrdinalIgnoreCase;
var operatorsModuleTypes = operators
.ToLookup(static op => op.Name, static op => op.ModuleType, stringComparer)
.ToDictionary(static g => g.Key, static g => g, stringComparer);
return operatorModules.Where(operatorModule =>
operatorsModuleTypes.TryGetValue(operatorModule.Name, out var moduleTypes) &&
moduleTypes.Any(moduleType => HasModule(moduleType, operatorModule.Module)));
bool HasModule(ModuleType moduleType, string module) =>
moduleType switch
{
ModuleType.All or ModuleType.Unknown => true,
ModuleType.X when module.EndsWith("X", stringComparison) => true,
ModuleType.Y when module.EndsWith("Y", stringComparison) => true,
ModuleType.D when module.EndsWith("Δ", stringComparison) => true,
_ => false
};
}
}