Skip to content

Commit

Permalink
Add ability to filter by royalty. Need to fix an issue with dequeuein…
Browse files Browse the repository at this point in the history
…g cells.
  • Loading branch information
Carifio24 committed Dec 13, 2023
1 parent 91b6b91 commit b939ec9
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 60 deletions.
166 changes: 114 additions & 52 deletions Spellbook/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

26 changes: 20 additions & 6 deletions Spellbook/SortFilterStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class SortFilterStatus {
private static let VERBAL_INDEX = 0
private static let SOMATIC_INDEX = 1
private static let MATERIAL_INDEX = 2
private static let ROYALTY_INDEX = 3

private var name: String? = nil

Expand All @@ -73,8 +74,8 @@ class SortFilterStatus {
private var yesConcentration = true
private var noConcentration = true

private var yesComponents = [true, true, true]
private var noComponents = [true, true, true]
private var yesComponents = [true, true, true, true]
private var noComponents = [true, true, true, true]

private var visibleSources = Sourcebook.coreSourcebooks
private var visibleClasses = CasterClass.allCases
Expand Down Expand Up @@ -275,6 +276,10 @@ class SortFilterStatus {
return getComponentFilter(b, index: SortFilterStatus.MATERIAL_INDEX)
}

func getRoyaltyFilter(_ b: Bool) -> Bool {
return getComponentFilter(b, index: SortFilterStatus.ROYALTY_INDEX)
}

private func setComponentFilter(_ tf: Bool, index: Int, value: Bool) {
if (tf) {
yesComponents[index] = value
Expand All @@ -285,6 +290,7 @@ class SortFilterStatus {
func setVerbalFilter(_ tf: Bool, to value: Bool) { setComponentFilter(tf, index: SortFilterStatus.VERBAL_INDEX, value: value) }
func setSomaticFilter(_ tf: Bool, to value: Bool) { setComponentFilter(tf, index: SortFilterStatus.SOMATIC_INDEX, value: value) }
func setMaterialFilter(_ tf: Bool, to value: Bool) { setComponentFilter(tf, index: SortFilterStatus.MATERIAL_INDEX, value: value) }
func setRoyaltyFilter(_ tf: Bool, to value: Bool) { setComponentFilter(tf, index: SortFilterStatus.ROYALTY_INDEX, value: value) }

// Riual and concentration filters

Expand All @@ -305,8 +311,9 @@ class SortFilterStatus {
func toggleRitualFilter(_ tf: Bool) { toggleFilter(tf, getter: getRitualFilter, setter: setRitualFilter) }
func toggleConcentrationFilter(_ tf: Bool) { toggleFilter(tf, getter: getConcentrationFilter, setter: setConcentrationFilter) }
func toggleVerbalFilter(_ tf: Bool) { toggleFilter(tf, getter: getVerbalFilter, setter: setVerbalFilter) }
func toggleSomaticFilter(_ tf: Bool) { toggleFilter(tf, getter: getSomaticFilter, setter: setSomaticFilter )}
func toggleMaterialFilter(_ tf: Bool) { toggleFilter(tf, getter: getMaterialFilter, setter: setMaterialFilter )}
func toggleSomaticFilter(_ tf: Bool) { toggleFilter(tf, getter: getSomaticFilter, setter: setSomaticFilter) }
func toggleMaterialFilter(_ tf: Bool) { toggleFilter(tf, getter: getMaterialFilter, setter: setMaterialFilter) }
func toggleRoyaltyFilter(_ tf: Bool) { toggleFilter(tf, getter: getRoyaltyFilter, setter: setRoyaltyFilter) }

// Status filter
func favoritesSelected() -> Bool { return (statusFilterField == StatusFilterField.Favorites) }
Expand Down Expand Up @@ -502,8 +509,15 @@ class SortFilterStatus {
yesConcentration = sion[SortFilterStatus.concentrationKey].bool ?? true
noConcentration = sion[SortFilterStatus.notConcentrationKey].bool ?? true

yesComponents = sion[SortFilterStatus.componentsFiltersKey].array?.map{ $0.bool ?? true } ?? [true, true, true]
noComponents = sion[SortFilterStatus.notComponentsFiltersKey].array?.map{ $0.bool ?? true } ?? [true, true, true]
yesComponents = sion[SortFilterStatus.componentsFiltersKey].array?.map{ $0.bool ?? true } ?? [true, true, true, true]
noComponents = sion[SortFilterStatus.notComponentsFiltersKey].array?.map{ $0.bool ?? true } ?? [true, true, true, true]

if yesComponents.count < 4 {
yesComponents += Array(repeating: true, count: 4 - yesComponents.count)
}
if noComponents.count < 4 {
noComponents += Array(repeating: true, count: 4 - noComponents.count)
}

let sourcebookArray = sion[SortFilterStatus.sourcebooksKey]
visibleSources = arrayFromSION(sion: sourcebookArray, creator: { Sourcebook.fromCode($0.string) }, defaultArray: Sourcebook.allCases)
Expand Down
9 changes: 8 additions & 1 deletion Spellbook/SortFilterTableController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class SortFilterTableController: UITableViewController {
@IBOutlet weak var verbalLabel: UILabel!
@IBOutlet weak var somaticLabel: UILabel!
@IBOutlet weak var materialLabel: UILabel!
@IBOutlet weak var royaltyLabel: UILabel!
private var labels: [UILabel] = []

// Sort direction arrows
Expand Down Expand Up @@ -107,6 +108,7 @@ class SortFilterTableController: UITableViewController {
@IBOutlet weak var verbalGrid: UICollectionView!
@IBOutlet weak var somaticGrid: UICollectionView!
@IBOutlet weak var materialGrid: UICollectionView!
@IBOutlet weak var royaltyGrid: UICollectionView!

// Constraints governing the bottoms of the quantity type grids
@IBOutlet weak var durationBottomConstraint: NSLayoutConstraint!
Expand Down Expand Up @@ -157,6 +159,10 @@ class SortFilterTableController: UITableViewController {
statusGetter: { tf in return store.state.profile?.sortFilterStatus.getMaterialFilter(tf) ?? true },
actionCreator: ToggleFlagAction.material
)
private let royaltyDelegate = YesNoFilterDelegate(
statusGetter: { tf in return store.state.profile?.sortFilterStatus.getRoyaltyFilter(tf) ?? true },
actionCreator: ToggleFlagAction.royalty
)
private let sourcebookDelegate = FilterGridFeatureDelegate<Sourcebook,ToggleSourcebookAction,FilterAllSourcebooksButAction>(
featuredItems: Sourcebook.coreSourcebooks,
getter: { sb in return store.state.profile?.sortFilterStatus.getVisibility(sb) ?? true },
Expand Down Expand Up @@ -273,6 +279,7 @@ class SortFilterTableController: UITableViewController {
(verbalGrid, verbalDelegate),
(somaticGrid, somaticDelegate),
(materialGrid, materialDelegate),
(royaltyGrid, royaltyDelegate),
(sourcebookGrid, sourcebookDelegate),
(casterGrid, casterDelegate),
(schoolGrid, schoolDelegate),
Expand All @@ -292,7 +299,7 @@ class SortFilterTableController: UITableViewController {

// Set the text color for the labels and the text fields
labels = [
firstLevelLabel, secondLevelLabel, levelRangeLabel, ritualLabel, concentrationLabel, verbalLabel, somaticLabel, materialLabel
firstLevelLabel, secondLevelLabel, levelRangeLabel, ritualLabel, concentrationLabel, verbalLabel, somaticLabel, materialLabel, royaltyLabel
]
for label in labels { label.textColor = defaultFontColor }
textFields = [
Expand Down
1 change: 1 addition & 0 deletions Spellbook/SpellFilter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func filterSpell(spell: Spell, sortFilterStatus: SortFilterStatus, spellFilterSt
toHide = toHide || !sortFilterStatus.getVerbalFilter(spell.verbal)
toHide = toHide || !sortFilterStatus.getSomaticFilter(spell.somatic)
toHide = toHide || !sortFilterStatus.getMaterialFilter(spell.material)
toHide = toHide || !sortFilterStatus.getRoyaltyFilter(spell.royalty)
toHide = toHide || (isText && !spellName.contains(text))
return !toHide
}
Expand Down
4 changes: 3 additions & 1 deletion Spellbook/SpellbookActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ struct SortNeededAction: Action {}
struct FilterNeededAction: Action {}

enum FlagType {
case Ritual, Concentration, Verbal, Somatic, Material
case Ritual, Concentration, Verbal, Somatic, Material, Royalty
}

struct SetFlagAction: Action {
Expand All @@ -156,6 +156,8 @@ struct ToggleFlagAction: Action {
static func verbal(_ value: Bool) -> ToggleFlagAction { return ToggleFlagAction(flag: .Verbal, value: value) }
static func somatic(_ value: Bool) -> ToggleFlagAction { return ToggleFlagAction(flag: .Somatic, value: value) }
static func material(_ value: Bool) -> ToggleFlagAction { return ToggleFlagAction(flag: .Material, value: value) }
static func royalty(_ value: Bool) -> ToggleFlagAction { return ToggleFlagAction(flag: .Royalty, value: value) }

}

struct TogglePropertyAction: Action {
Expand Down
6 changes: 6 additions & 0 deletions Spellbook/SpellbookReducers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ func setFlagFilterReducer(action: SetFlagAction, state: inout SpellbookAppState)
case .Material:
status.setMaterialFilter(action.tf, to: action.value)
break
case .Royalty:
status.setRoyaltyFilter(action.tf, to: action.value)
break
}
state.filterAndSortSpells()
return state
Expand All @@ -280,6 +283,9 @@ func toggleFlagFilterReducer(action: ToggleFlagAction, state: inout SpellbookApp
case .Material:
status.toggleMaterialFilter(action.value)
break
case .Royalty:
status.toggleRoyaltyFilter(action.value)
break
}
state.filterAndSortSpells()
return state
Expand Down
2 changes: 2 additions & 0 deletions Spellbook/YesNoFilterDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class YesNoFilterDelegate: NSObject, FilterGridProtocol {
let item = items[indexPath.row]
let bool = item.bool
cell.backgroundColor = .clear
print(indexPath)
print(actionCreator)
cell.filterView.nameLabel.text = item.displayName
cell.filterView.filterButton.isUserInteractionEnabled = true
//cell.filterView.nameLabel.sizeToFit()
Expand Down
2 changes: 2 additions & 0 deletions SpellbookTests/CharacterProfileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ class CharacterProfileTests: XCTestCase {
XCTAssertEqual(sortFilterStatus.getVerbalFilter(true), false)
XCTAssertEqual(sortFilterStatus.getSomaticFilter(true), true)
XCTAssertEqual(sortFilterStatus.getMaterialFilter(true), true)
XCTAssertEqual(sortFilterStatus.getRoyaltyFilter(true), true)
XCTAssertEqual(sortFilterStatus.getVerbalFilter(false), true)
XCTAssertEqual(sortFilterStatus.getSomaticFilter(false), true)
XCTAssertEqual(sortFilterStatus.getMaterialFilter(false), false)
XCTAssertEqual(sortFilterStatus.getRoyaltyFilter(false), true)
XCTAssertEqual(sortFilterStatus.getConcentrationFilter(true), true)
XCTAssertEqual(sortFilterStatus.getConcentrationFilter(false), true)
XCTAssertEqual(sortFilterStatus.getRitualFilter(true), true)
Expand Down

0 comments on commit b939ec9

Please sign in to comment.