From 26f00d4f54e6ff9376a8a96ec345a62b9bd6af71 Mon Sep 17 00:00:00 2001 From: Legoshi Date: Sat, 22 Jul 2023 11:14:27 +0800 Subject: [PATCH] =?UTF-8?q?[+]=20=E6=96=B0=E5=8A=9F=E8=83=BD(1.5.1):=20sha?= =?UTF-8?q?pe=20=E6=96=B0=E5=A2=9E=E9=80=9A=E8=BF=87=20Char=20=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=20slots?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../parrot/parrotx/ui/config/advance/Shape.kt | 22 ++++++++++++++----- .../parrot/parrotx/ui/extension/Mapped.kt | 1 + 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index b309ce6..6a95e41 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/kotlin/org/serverct/parrot/parrotx/ui/config/advance/Shape.kt b/src/main/kotlin/org/serverct/parrot/parrotx/ui/config/advance/Shape.kt index 5538c24..f03d1af 100644 --- a/src/main/kotlin/org/serverct/parrot/parrotx/ui/config/advance/Shape.kt +++ b/src/main/kotlin/org/serverct/parrot/parrotx/ui/config/advance/Shape.kt @@ -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 { + val indexes = LinkedHashSet() + 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 { val indexes = LinkedHashSet() 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()) { diff --git a/src/main/kotlin/org/serverct/parrot/parrotx/ui/extension/Mapped.kt b/src/main/kotlin/org/serverct/parrot/parrotx/ui/extension/Mapped.kt index f1041b6..1df9b33 100644 --- a/src/main/kotlin/org/serverct/parrot/parrotx/ui/extension/Mapped.kt +++ b/src/main/kotlin/org/serverct/parrot/parrotx/ui/extension/Mapped.kt @@ -45,6 +45,7 @@ class Mapped(title: String) : Menu(title) { val (shape, templates) = config val slots = shape[template].toList() rows(shape.rows) + map(*shape.array) slots(slots) elements { elements().toList() }