Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Unwrap a one-liner #301

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions Yafc/Workspace/ProductionTable/ModuleCustomizationScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ public override void Build(ImGui gui) {
template.RecordUndo().name = newName;
}
}

gui.BuildText("Filter by crafting buildings (Optional):");
using var grid = gui.EnterInlineGrid(2f, 1f);

for (int i = 0; i < template.filterEntities.Count; i++) {
var entity = template.filterEntities[i];
grid.Next();
Expand All @@ -62,16 +64,25 @@ public override void Build(ImGui gui) {
template.RecordUndo().filterEntities.RemoveAt(i);
}
}

grid.Next();

if (gui.BuildButton(Icon.Plus, SchemeColor.Primary, SchemeColor.PrimaryAlt, size: 1.5f)) {
// TODO (shpaass/yafc-ce/issues/256): unwrap it into something more readable
SelectSingleObjectPanel.Select(Database.allCrafters.Where(x => x.allowedEffects != AllowedEffects.None && !template.filterEntities.Contains(x)),
"Add module template filter", sel => {
template.RecordUndo().filterEntities.Add(sel);
gui.Rebuild();
});
bool canBeAffected(EntityCrafter x) => x.allowedEffects != AllowedEffects.None;
bool isNotSelected(EntityCrafter x) => !template.filterEntities.Contains(x);
bool isSuitable(EntityCrafter x) => canBeAffected(x) && isNotSelected(x);

void doToSelectedItem(EntityCrafter selectedCrafter) {
template.RecordUndo().filterEntities.Add(selectedCrafter);
gui.Rebuild();
}

SelectSingleObjectPanel.Select(Database.allCrafters.Where(isSuitable),
"Add module template filter",
doToSelectedItem);
}
}

if (modules == null) {
if (gui.BuildButton("Enable custom modules")) {
modules = new ModuleTemplateBuilder();
Expand All @@ -87,7 +98,9 @@ public override void Build(ImGui gui) {
else {
gui.BuildText("This building doesn't have module slots, but can be affected by beacons");
}

gui.BuildText("Beacon modules:", Font.subheader);

if (modules.beacon == null) {
gui.BuildText("Use default parameters");
if (gui.BuildButton("Override beacons as well")) {
Expand Down