Skip to content

Commit

Permalink
[+] 新功能(1.5.1): shape 新增通过 Char 获取 slots
Browse files Browse the repository at this point in the history
  • Loading branch information
Polar-Pumpkin committed Jul 22, 2023
1 parent c3a7b05 commit 26f00d4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# suppress inspection "UnusedProperty" for whole file
group=org.tabooproject.taboolib
version=1.5.0
version=1.5.1

version-common=6.1.0-pre3
kotlin.incremental=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,27 @@ class ShapeConfiguration(val holder: MenuConfiguration) {

operator fun get(slot: Int): Char = requireNotNull(flatten.elementAtOrNull(slot)) { "尝试获取越界槽位的字符: $slot" }

operator fun get(ref: Char, empty: Boolean = false, multi: Boolean = true): Set<Int> {
val indexes = LinkedHashSet<Int>()
flatten.forEachIndexed { index, char ->
if (char == ref) {
indexes += index
}
}
if (!empty && indexes.isEmpty()) {
MenuPart.SHAPE incorrect "未映射字符 $ref"
}
if (!multi && indexes.size > 1) {
MenuPart.SHAPE incorrect "字符 $ref 映射了多个位置"
}
return indexes
}

operator fun get(keyword: String, empty: Boolean = false, multi: Boolean = true): Set<Int> {
val indexes = LinkedHashSet<Int>()
val ref = holder.keywords[keyword]
if (ref != null) {
flatten.forEachIndexed { index, char ->
if (char == ref) {
indexes += index
}
}
indexes.addAll(get(ref, empty = true, multi = true))
}

if (!empty && indexes.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Mapped<E>(title: String) : Menu(title) {
val (shape, templates) = config
val slots = shape[template].toList()
rows(shape.rows)
map(*shape.array)
slots(slots)
elements { elements().toList() }

Expand Down

0 comments on commit 26f00d4

Please sign in to comment.