aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/events/DebugDataCollectEvent.kt
blob: 1a4eabb92c76f77a638624c223fe3efdbd59ef47 (plain)
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
package at.hannibal2.skyhanni.events

import at.hannibal2.skyhanni.utils.StringUtils.equalsIgnoreColor

class DebugDataCollectEvent(private val list: MutableList<String>, private val search: String?) : LorenzEvent() {

    var empty = true
    private var currentTitle = ""
    private var ignore = false

    fun title(title: String) {
        if (currentTitle != "") error("Title already set: '$currentTitle'")

        currentTitle = title
    }

    fun ignore(block: MutableList<String>.() -> Unit) {
        val list = mutableListOf<String>()
        block(list)
        ignore(list)
    }

    fun ignore(text: String) {
        ignore(listOf(text))
    }

    private fun ignore(text: List<String>) {
        ignore = true
        addData(text)
    }

    fun addData(block: MutableList<String>.() -> Unit) {
        val list = mutableListOf<String>()
        block(list)
        addData(list)
    }

    fun addData(text: String) {
        addData(listOf(text))
    }

    fun addData(text: List<String>) {
        if (currentTitle == "") error("Title not set")
        writeData(text)
        currentTitle = ""
        ignore = false
    }

    private fun writeData(text: List<String>) {
        if (ignore && search == null) return
        search?.let {
            if (!search.equalsIgnoreColor("all")) {
                if (!currentTitle.contains(search, ignoreCase = true)) {
                    return
                }
            }
        }
        empty = false
        list.add("")
        list.add("== $currentTitle ==")
        for (line in text) {
            list.add(" $line")
        }
    }
}