普特莫斯维基 (Purtmars Wikipedia 📖)

“Chemdah 开发者文档:自定义对话主题”的版本间的差异

来自Purtmars Wikipedia —— 普特莫斯维基
第46行: 第46行:
  
 
= 实现 =
 
= 实现 =
 +
首先继承 ThemeSettings 类,若没有特殊需求则不需要额外读取数据。数据来源由 Theme 类决定,可自行定义。
 +
<syntaxhighlight lang="kotlin" line="line">
 +
class ThemeDemoSettings(root: ConfigurationSection) : ThemeSettings(root)
 +
</syntaxhighlight>
  
 +
其次继承 Theme 类,并进行注册与配置定义。
 
<syntaxhighlight lang="kotlin" line="line">
 
<syntaxhighlight lang="kotlin" line="line">
 
class ThemeDemo : Theme<ThemeDemoSettings>() {
 
class ThemeDemo : Theme<ThemeDemoSettings>() {
 +
 +
    init {
 +
        // 注册 demo 对话风格到插件
 +
        register("demo")
 +
    }
 +
   
 +
    /**
 +
    * 初始化配置文件,并将其指向 plugins/Chemdah/core/conversation.yml 文
 +
    */
 +
    override fun getConfig(): ThemeDemoSettings {
 +
        return ThemeDemoSettings(ConversationManager.conf.getConfigurationSection("theme-demo")!!)
 +
    }
  
 
     override fun npcTalk(session: Session, message: List<String>, canReply: Boolean): CompletableFuture<Void> {
 
     override fun npcTalk(session: Session, message: List<String>, canReply: Boolean): CompletableFuture<Void> {
 
         TODO("Not yet implemented")
 
         TODO("Not yet implemented")
 
     }
 
     }
}
 
 
class ThemeDemoSettings(root: ConfigurationSection) : ThemeSettings(root) {
 
 
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

2021年5月5日 (三) 23:42的版本

目录

对话主题

注册自定义对话主题需要分别实现 Theme 与 ThemeSettings 类,在本章文档中我们会从零开始注册一个简单的聊天框对话主题。
ink.ptms.chemdah.core.conversation.theme.Theme

/**
 * 注册到 ChemdahAPI 中
 */
fun register(name)

/**
 * 当配置文件被重载
 */
open fun reloadConfig()

/**
 * 是否支持告别
 * 即结束对话时使用 talk 语句创建没有回复的对话信息
 * 在原版 chat 对话模式中支持告别,而 chest 不支持(会被转换为 Holographic 信息)
 */
open fun allowFarewell()

/**
 * 重置会话时(即 begin 之前)
 * 在原版 chat 对话模式中用于归位玩家所选择的回复序号,而 chest 中没有使用
 */
open fun reset(session: Session): CompletableFuture

/**
 * 会话开始之前,在原版 chat 对话模式中用于播放音效特效等
 * 使用时必须返回 super.begin(session)
 */
open fun begin(session: Session): CompletableFuture

/**
 * 会话结束时,目前未被使用
 */
open fun end(session: Session): CompletableFuture

/**
 * 会话渲染时
 * @param canReply 是否可以回复
 */
abstract fun npcTalk(session: Session, message: List, canReply: Boolean = true): CompletableFuture

实现

首先继承 ThemeSettings 类,若没有特殊需求则不需要额外读取数据。数据来源由 Theme 类决定,可自行定义。

class ThemeDemoSettings(root: ConfigurationSection) : ThemeSettings(root)

其次继承 Theme 类,并进行注册与配置定义。

class ThemeDemo : Theme() {

    init {
        // 注册 demo 对话风格到插件
        register("demo")
    }
    
    /**
     * 初始化配置文件,并将其指向 plugins/Chemdah/core/conversation.yml 文
     */
    override fun getConfig(): ThemeDemoSettings {
        return ThemeDemoSettings(ConversationManager.conf.getConfigurationSection("theme-demo")!!)
    }

    override fun npcTalk(session: Session, message: List, canReply: Boolean): CompletableFuture {
        TODO("Not yet implemented")
    }
}