修改ConfigManager,定义配置数据继承体系

This commit is contained in:
chen wei bo
2025-09-01 19:07:24 +08:00
parent c9817ea13e
commit 8eb3f01688
12 changed files with 457 additions and 10 deletions
@@ -0,0 +1,50 @@
/**
* Ai角色配置
*/
import { BaseConfig } from "./BaseConfig";
import { ConfigManager } from "../manager/ConfigManager";
export class AiCharacterConfig extends BaseConfig {
public reset(): void {
}
public clear(): void {
}
public destroy(): void {
super.destroy();
}
/**
* 获取所有配置
*/
protected getAllConfig(): any | null {
return ConfigManager.tables.TbAiCharacters;
}
/**
* 获取配置,根据 id
*/
protected getConfigById(id: number): any | null {
let allData = this.getAllConfig();
if (!allData) return null;
return allData.get(id);
}
/** 根据 id 获取基础提示 */
public getBasePromptById(id: number): string | null {
let oneData = this.getConfigById(id);
if (!oneData) return null;
return oneData.basePrompt;
}
/** 根据 id 获取额外提示 */
public getAdditionPromptById(id: number): string | null {
let oneData = this.getConfigById(id);
if (!oneData) return null;
return oneData.additionPrompt;
}
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "82e997ec-36ed-4663-88f5-dc6550348c5d",
"files": [],
"subMetas": {},
"userData": {}
}
@@ -0,0 +1,85 @@
/**
* 技师的简要配置
*/
import { BaseConfig } from "./BaseConfig";
import { ConfigManager } from "../manager/ConfigManager";
export class GirlConfig extends BaseConfig {
public reset(): void {
}
public clear(): void {
}
public destroy(): void {
super.destroy();
}
/**
* 获取所有配置
*/
protected getAllConfig(): any | null {
return ConfigManager.tables.TbGirls;
}
/**
* 获取配置,根据 id
*/
protected getConfigById(id: number): any | null {
let allData = this.getAllConfig();
if (!allData) return null;
return allData.get(id);
}
/** 根据 id 获取名字 */
public getNameById(id: number): string | null {
let oneData = this.getConfigById(id);
if (!oneData) return null;
return oneData.nameKey;
}
/** 根据 id 获取年龄 */
public getAgeById(id: number): string | null {
let oneData = this.getConfigById(id);
if (!oneData) return null;
return oneData.age;
}
/** 根据 id 获取分类 */
public getCategoryById(id: number): number | null {
let oneData = this.getConfigById(id);
if (!oneData) return null;
return oneData.category;
}
/** 根据 id 获取标签键 */
public getTagKeyById(id: number): string | null {
let oneData = this.getConfigById(id);
if (!oneData) return null;
return oneData.tagKey;
}
/** 根据 id 获取付费类型 */
public getPriceTypeById(id: number): number | null {
let oneData = this.getConfigById(id);
if (!oneData) return null;
return oneData.priceType;
}
/** 根据 id 获取头像路径 */
public getAvatarPathById(id: number): string | null {
let oneData = this.getConfigById(id);
if (!oneData) return null;
return oneData.avatarPath;
}
/** 根据 id 获取头像路径 */
public getListAvatarPathPathById(id: number): string | null {
let oneData = this.getConfigById(id);
if (!oneData) return null;
return oneData.listAvatarPath;
}
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "a6f7829d-6d80-405d-8f14-ede4365e8213",
"files": [],
"subMetas": {},
"userData": {}
}
@@ -0,0 +1,105 @@
/**
* 技师的详细配置
*/
import { BaseConfig } from "./BaseConfig";
import { ConfigManager } from "../manager/ConfigManager";
export class GirlDetailConfig extends BaseConfig {
public reset(): void {
}
public clear(): void {
}
public destroy(): void {
super.destroy();
}
/**
* 获取所有配置
*/
protected getAllConfig(): any | null {
return ConfigManager.tables.TbGirlsDetail;
}
/**
* 获取配置,根据 id
*/
protected getConfigById(id: number): any | null {
let allData = this.getAllConfig();
if (!allData) return null;
return allData.get(id);
}
/** 根据 id 获取详细描述 */
public getDetailDescById(id: number): string | null {
let oneData = this.getConfigById(id);
if (!oneData) return null;
return oneData.detailDesc;
}
/** 根据 id 获取 commercialImages */
private getCommercialImagesById(id: number): any | null {
let oneData = this.getConfigById(id);
if (!oneData) return null;
return oneData.commercialImages;
}
/** 根据 id 和 index 获取图片类型 */
public getImageTypeById(id: number, index: number): number | null {
let oneData = this.getCommercialImagesById(id);
if (!oneData) return null;
if (index < 0 || index >= oneData.length) return null;
return oneData[index].imageType;
}
/** 根据 id 和 index 获取图片价格 */
public getImagePriceById(id: number, index: number): number | null {
let oneData = this.getCommercialImagesById(id);
if (!oneData) return null;
if (index < 0 || index >= oneData.length) return null;
return oneData[index].imagePrice;
}
/** 根据 id 和 index 获取图片路径 */
public getImagePathById(id: number, index: number): string | null {
let oneData = this.getCommercialImagesById(id);
if (!oneData) return null;
if (index < 0 || index >= oneData.length) return null;
return oneData[index].path;
}
/** 根据 id 获取 commercialVideos */
private getCommercialVideosById(id: number): any | null {
let oneData = this.getConfigById(id);
if (!oneData) return null;
return oneData.commercialVideos;
}
/** 根据 id 和 index 获取视频路径 */
public getVideoPathById(id: number, index: number): string | null {
let oneData = this.getCommercialVideosById(id);
if (!oneData) return null;
if (index < 0 || index >= oneData.length) return null;
return oneData[index].path;
}
/** 根据 id 和 index 获取关联情绪 */
public getVideoEmotionById(id: number, index: number): number | null {
let oneData = this.getCommercialVideosById(id);
if (!oneData) return null;
if (index < 0 || index >= oneData.length) return null;
return oneData[index].emotion;
}
/** 根据 id 和 index 获取视频价格 */
public getVideoPriceById(id: number, index: number): number | null {
let oneData = this.getCommercialVideosById(id);
if (!oneData) return null;
if (index < 0 || index >= oneData.length) return null;
return oneData[index].videoPrice;
}
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "270f3a20-b633-4dd8-8e91-adc0a57a366c",
"files": [],
"subMetas": {},
"userData": {}
}
@@ -0,0 +1,97 @@
/**
* 全局配置
*/
import { BaseConfig } from "./BaseConfig";
import { ConfigManager } from "../manager/ConfigManager";
export class GlobalConfig extends BaseConfig {
public reset(): void {
}
public clear(): void {
}
public destroy(): void {
super.destroy();
}
/**
* 获取所有配置
*/
protected getAllConfig(): any | null {
return ConfigManager.tables.TbGlobalConfig;
}
/** 获取api键 */
public getApiKey(): string | null {
let oneData = this.getAllConfig();
if (!oneData) return null;
return oneData.ApiKey;
}
/** 获取情绪判断机器人api */
public getEmotionApiKey(): string | null {
let oneData = this.getAllConfig();
if (!oneData) return null;
return oneData.emotionApiKey;
}
/** 获取情绪判断机器人api */
public getModel(): string | null {
let oneData = this.getAllConfig();
if (!oneData) return null;
return oneData.Model;
}
/** Temperature */
public getTemperature(): number | null {
let oneData = this.getAllConfig();
if (!oneData) return null;
return oneData.Temperature;
}
/** 单次聊天最大token */
public getMaxTokens(): number | null {
let oneData = this.getAllConfig();
if (!oneData) return null;
return oneData.MaxTokens;
}
/** 超时时间(微秒) */
public getTimeout(): number | null {
let oneData = this.getAllConfig();
if (!oneData) return null;
return oneData.Timeout;
}
/** 单个角色免费聊天次数 */
public getFreeChatTimes(): number | null {
let oneData = this.getAllConfig();
if (!oneData) return null;
return oneData.FreeChatTimes;
}
/** 游戏名 */
public getGameName(): string | null {
let oneData = this.getAllConfig();
if (!oneData) return null;
return oneData.GameName;
}
/** 情绪评分机器人system_prompt,需拼接角色prompt */
public getEmotionRating(): string | null {
let oneData = this.getAllConfig();
if (!oneData) return null;
return oneData.EmotionRating;
}
/** ai机器人基础规则 */
public getGirlBasePrompt(): string | null {
let oneData = this.getAllConfig();
if (!oneData) return null;
return oneData.girlBasePrompt;
}
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "69d3c6fa-3722-4d8d-adff-9c66f59e9484",
"files": [],
"subMetas": {},
"userData": {}
}
@@ -0,0 +1,50 @@
/**
* 商城配置
*/
import { BaseConfig } from "./BaseConfig";
import { ConfigManager } from "../manager/ConfigManager";
export class PurchaseConfig extends BaseConfig {
public reset(): void {
}
public clear(): void {
}
public destroy(): void {
super.destroy();
}
/**
* 获取所有配置
*/
protected getAllConfig(): any | null {
return ConfigManager.tables.TbPurchaseConfig;
}
/**
* 获取配置,根据 id
*/
protected getConfigById(id: number): any | null {
let allData = this.getAllConfig();
if (!allData) return null;
return allData.get(id);
}
/** 根据商品 id 获取商品名字 */
public getNameById(id: number): string | null {
let oneData = this.getConfigById(id);
if (!oneData) return null;
return oneData.name;
}
/** 根据商品 id 获取商品数量 */
public getCountById(id: number): number | null {
let oneData = this.getConfigById(id);
if (!oneData) return null;
return oneData.count;
}
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "750dc939-fc98-45ad-b3d2-2775cd26c445",
"files": [],
"subMetas": {},
"userData": {}
}
+9 -9
View File
@@ -17,15 +17,15 @@ import { OrderData } from "./OrderData";
* 集中定义数据ID,避免写错字符串
*/
export enum DataId {
Login = "login",
Player = "player",
Account = "account",
Meta = "meta",
NetTime = "netTime",
Theme = "theme",
Wallet = "wallet",
Shop = "shop",
Order = "order",
Login = "login", // 登录数据
Player = "player", // 玩家数据
Account = "account", // 账号数据
Meta = "meta", // 元数据
NetTime = "netTime", // 网络时间数据
Theme = "theme", // 主题数据
Wallet = "wallet", // 钱包数据
Shop = "shop", // 商城数据
Order = "order", // 订单数据
}
/** 构造器类型 */
@@ -8,12 +8,22 @@ import * as cfg from "../../schema/schema";
import ByteBuf from "db://assets/Scripts/luban/ByteBuf";
import { BaseConfig } from "../config/BaseConfig";
import { ThemeConfig } from "../config/ThemeConfig";
import { PurchaseConfig } from "../config/PurchaseConfig";
import { GlobalConfig } from "../config/GlobalConfig";
import { GirlConfig } from "../config/GirlConfig";
import { GirlDetailConfig } from "../config/GirlDetailConfig";
import { AiCharacterConfig } from "../config/AiCharacterConfig";
/**
* 集中定义数据ID,避免写错字符串
*/
export enum ConfigId {
Theme = "theme", // 主题配置
Theme = "theme", // 主题配置
Purchase = "purchase", // 商城配置
Global = "global", // 全局配置
Girl = "girl", // 技师的简要配置
GirlDetail = "girlDetail", // 技师的详细配置
AiCharacter = "aiCharacter", // 技师的详细配置
}
/** 构造器类型 */
@@ -109,6 +119,11 @@ export class ConfigManager {
*/
private registerAll(): void {
this.register(ConfigId.Theme, ThemeConfig);
this.register(ConfigId.Purchase, PurchaseConfig);
this.register(ConfigId.Global, GlobalConfig);
this.register(ConfigId.Girl, GirlConfig);
this.register(ConfigId.GirlDetail, GirlDetailConfig);
this.register(ConfigId.AiCharacter, AiCharacterConfig);
}
/**