From f060e1bbc5b17764755bbf39579e7d59eb8f423c Mon Sep 17 00:00:00 2001 From: ManApart Date: Fri, 19 Jan 2024 08:11:40 -0500 Subject: [PATCH] basic package validation passes --- src/commonMain/kotlin/core/ai/packages/AIPackageTemplate.kt | 4 ++-- .../kotlin/core/ai/packages/AIPackageTemplateBuilder.kt | 6 ++++-- .../kotlin/resources/ai/packages/CommonPackages.kt | 4 ---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/commonMain/kotlin/core/ai/packages/AIPackageTemplate.kt b/src/commonMain/kotlin/core/ai/packages/AIPackageTemplate.kt index 812a219a..1180eb46 100644 --- a/src/commonMain/kotlin/core/ai/packages/AIPackageTemplate.kt +++ b/src/commonMain/kotlin/core/ai/packages/AIPackageTemplate.kt @@ -10,8 +10,8 @@ data class AIPackageTemplate(val name: String, val subPackages: List, va ?: subPackage.flatten(reference, flattenedReference).also { flattenedReference[subPackage.name] = it }.ideas.values.flatten() }.map { idea -> priorityOverride[it.name]?.let { idea.copy(priority = it) } ?: idea - } - AIPackage(name, ideas + subIdeas) + }.map { it.copy(name = "$name-${it.name}")} + AIPackage(name, ideas + subIdeas).also { flattenedReference[name] = it } } } } \ No newline at end of file diff --git a/src/commonMain/kotlin/core/ai/packages/AIPackageTemplateBuilder.kt b/src/commonMain/kotlin/core/ai/packages/AIPackageTemplateBuilder.kt index 3e6bf30c..747d8d9f 100644 --- a/src/commonMain/kotlin/core/ai/packages/AIPackageTemplateBuilder.kt +++ b/src/commonMain/kotlin/core/ai/packages/AIPackageTemplateBuilder.kt @@ -1,6 +1,7 @@ package core.ai.packages import core.thing.Thing +import core.utility.map //Build all the templates, but don't flatten them //Using the dependency injection, we could have many things producing the templates @@ -16,7 +17,8 @@ class AIPackageTemplateBuilder(val name: String) { private val priorityOverride = mutableMapOf() fun build(): AIPackageTemplate { - return AIPackageTemplate(name, templates, priorityOverride, ideas.map { it.build(name) }) + val childIdeas = criteriaChildren.flatMap { (parentCriteria, builder) -> builder.getChildren(parentCriteria) } + return AIPackageTemplate(name, templates, priorityOverride, (ideas + childIdeas).map { it.build(name) }) } fun template(vararg names: String) = this.templates.addAll(names) @@ -25,7 +27,7 @@ class AIPackageTemplateBuilder(val name: String) { Override the priority of an idea inherited from a template. */ fun priority(ideaName: String, newPriority: Int){ - + priorityOverride[ideaName] = newPriority } fun idea(name: String, priority: Int = 20, initializer: IdeaBuilder.() -> Unit = {}) { diff --git a/src/commonMain/kotlin/resources/ai/packages/CommonPackages.kt b/src/commonMain/kotlin/resources/ai/packages/CommonPackages.kt index d7404474..01818a8a 100644 --- a/src/commonMain/kotlin/resources/ai/packages/CommonPackages.kt +++ b/src/commonMain/kotlin/resources/ai/packages/CommonPackages.kt @@ -18,10 +18,6 @@ class CommonPackages: AIPackageTemplateResource { criteria { !it.isSafe() } action { EatFoodEvent(it, it) } } - idea("wait") { - criteria { !it.isSafe() } - action { EatFoodEvent(it, it) } - } } } }