Skip to content

Commit 63ee573

Browse files
committed
Handle double woth
1 parent 3885c29 commit 63ee573

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

tracker/hints.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,25 @@ import (
1212
"github.com/lithammer/fuzzysearch/fuzzy"
1313
)
1414

15+
const doubleWOTHMarker = "*"
16+
1517
func (tracker *Tracker) AddWOTH(str string) bool {
1618
if len(tracker.woths) >= 5 {
1719
log.Printf("warning: WotHs maxed out at 5")
1820
return false
1921
}
2022

23+
// Handle Double-WOTH
24+
// Each hint is doubled, two WoTH mean you have either seen all of them
25+
// _or_ there might be two WoTH hints for the same area.
26+
// A third WOTH will add a new line.
27+
for k, v := range tracker.woths {
28+
if v == str {
29+
tracker.woths[k] += doubleWOTHMarker
30+
return true
31+
}
32+
}
33+
2134
tracker.woths = append(tracker.woths, str)
2235
return true
2336
}

tracker/undo.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package tracker
22

3-
import "log"
3+
import (
4+
"log"
5+
"strings"
6+
)
47

58
// undoStackEntry represents an action (upgrade/downgrade) that happened on an item.
69
type undoStackEntry struct {
@@ -47,7 +50,7 @@ func (tracker *Tracker) undo() {
4750
if entry.IsHint {
4851
switch entry.HintType {
4952
case hintTypeWOTH:
50-
tracker.woths = tracker.woths[:len(tracker.woths)-1]
53+
tracker.undoWOTH(entry)
5154
case hintTypeBarren:
5255
tracker.barrens = tracker.barrens[:len(tracker.barrens)-1]
5356
case hintTypeSometimes:
@@ -66,6 +69,19 @@ func (tracker *Tracker) undo() {
6669
}
6770
}
6871

72+
func (tracker *Tracker) undoWOTH(entry undoStackEntry) {
73+
// Clear last added double woth or last woth
74+
double := entry.HintText + doubleWOTHMarker
75+
for i := len(tracker.woths) - 1; i >= 0; i-- {
76+
if tracker.woths[i] == double {
77+
tracker.woths[i] = strings.TrimSuffix(tracker.woths[i], doubleWOTHMarker)
78+
return
79+
}
80+
}
81+
82+
tracker.woths = tracker.woths[:len(tracker.woths)-1]
83+
}
84+
6985
func (tracker *Tracker) redo() {
7086
if len(tracker.redoStack) == 0 {
7187
log.Printf("no action to redo")

0 commit comments

Comments
 (0)