Skip to content

Commit

Permalink
Improves group features.
Browse files Browse the repository at this point in the history
- Always show group name when sort mode is by-size.
- Add ineffective group support.
  • Loading branch information
mntone committed Jan 20, 2024
1 parent f26c733 commit ddb685b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/App/ViewModels/GameGroupViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ enum GameGroupType: Hashable {
}
}

var isValidType: Bool {
switch self {
case .type, .weakness:
return true
default:
return false
}
}

var isType: Bool {
if case .type = self {
return true
Expand Down
17 changes: 15 additions & 2 deletions src/App/ViewModels/GameViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,48 +281,61 @@ final class GameViewModel: ObservableObject {
.sorted()
case .weakness:
groups = baseMonsters
.reduce(into: [:]) { (result: inout [Attack: [GameItemViewModel]], next: GameItemViewModel) in
.reduce(into: [:]) { (result: inout [Attack?: [GameItemViewModel]], next: GameItemViewModel) in
guard let weaknesses = next.weaknesses else { return }

var added: Bool = false
if weaknesses.contains(where: { $0.1.fire >= .effective }) {
if let items = result[.fire] {
result[.fire] = items + [next]
} else {
result[.fire] = [next]
}
added = true
}
if weaknesses.contains(where: { $0.1.water >= .effective }) {
if let items = result[.water] {
result[.water] = items + [next]
} else {
result[.water] = [next]
}
added = true
}
if weaknesses.contains(where: { $0.1.thunder >= .effective }) {
if let items = result[.thunder] {
result[.thunder] = items + [next]
} else {
result[.thunder] = [next]
}
added = true
}
if weaknesses.contains(where: { $0.1.ice >= .effective }) {
if let items = result[.ice] {
result[.ice] = items + [next]
} else {
result[.ice] = [next]
}
added = true
}
if weaknesses.contains(where: { $0.1.dragon >= .effective }) {
if let items = result[.dragon] {
result[.dragon] = items + [next]
} else {
result[.dragon] = [next]
}
added = true
}
if !added {
if let items = result[.none] {
result[.none] = items + [next]
} else {
result[.none] = [next]
}
}
}
.map { element, baseItems in
let items = baseItems.map { monster in
IdentifyHolder(monster, prefix: element.prefix)
IdentifyHolder(monster, prefix: element?.prefix ?? "n")
}
return GameGroupViewModel(gameID: gameID, type: .weakness(element: element), items: items)
}
Expand Down
2 changes: 1 addition & 1 deletion src/App/Views/MonsterLists/MonsterList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct MonsterList<ItemView: View>: View {

var body: some View {
let items = viewModel.items
let isHeaderShow = items.count > 1 || items.first?.type.isType == true
let isHeaderShow = items.count > 1 || items.first?.type.isValidType == true
List(items) { group in
Section {
ForEach(group.items) { item in
Expand Down
2 changes: 1 addition & 1 deletion src/App/Views/MonsterLists/MonsterListColumn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct MonsterListColumn: View {

var body: some View {
let items = viewModel.items
let isHeaderShow = items.count > 1 || items.first?.type.isType == true
let isHeaderShow = items.count > 1 || items.first?.type.isValidType == true
List(items, id: \.id, selection: $selectedMonsterID) { group in
Section {
ForEach(group.items) { item in
Expand Down

0 comments on commit ddb685b

Please sign in to comment.