Squashed commit of the following:
commit8d3548006dAuthor: chen wei bo <1025839511@qq.com> Date: Fri Sep 12 16:00:29 2025 +0800 更新语言表 commit0d66f72c61Author: chen wei bo <1025839511@qq.com> Date: Fri Sep 12 15:19:32 2025 +0800 支付相关 commit8372d3b489Author: chen wei bo <1025839511@qq.com> Date: Fri Sep 12 11:29:11 2025 +0800 登录之后获取全局数据
This commit is contained in:
@@ -8,11 +8,13 @@ import { LoginData } from "../../chat18x/data/LoginData";
|
||||
import { PlayerData } from "../../chat18x/data/PlayerData";
|
||||
import { AccountData } from "../../chat18x/data/AccountData";
|
||||
import { WalletData } from "../../chat18x/data/WalletData";
|
||||
import { GlobalData } from "../../chat18x/data/GlobalData";
|
||||
import { EnvData } from "../../chat18x/data/EnvData";
|
||||
import DeviceIdService from "db://assets/Scripts/chat18x/foundation/identity/DeviceIdService";
|
||||
import MachineInfoService from "db://assets/Scripts/chat18x/foundation/identity/MachineInfoService";
|
||||
import { AuthService } from "db://assets/Scripts/chat18x/network/services/AuthService";
|
||||
import { PlayerDataService } from "db://assets/Scripts/chat18x/network/services/PlayerDataService";
|
||||
import { CommonService } from "db://assets/Scripts/chat18x/network/services/CommonService";
|
||||
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -66,9 +68,11 @@ export class LoginUI extends li_BaseView {
|
||||
|
||||
this.loginFinish = true;
|
||||
this.reqMyInfo();
|
||||
this.reqGlobalData();
|
||||
}
|
||||
}
|
||||
|
||||
// 请求个人数据
|
||||
private async reqMyInfo() {
|
||||
const reqData = {};
|
||||
let res = await PlayerDataService.I.reqMyInfo(reqData);
|
||||
@@ -81,6 +85,19 @@ export class LoginUI extends li_BaseView {
|
||||
}
|
||||
}
|
||||
|
||||
// 请求全局数据
|
||||
private async reqGlobalData() {
|
||||
const reqData = {
|
||||
resName: "TbGlobalConfig",
|
||||
};
|
||||
let res = await CommonService.I.reqResConfig(reqData);
|
||||
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
||||
// 保存数据
|
||||
const globalData = DataManager.I.getDataById<GlobalData>(DataId.Global);
|
||||
globalData.globals = res.data;
|
||||
}
|
||||
}
|
||||
|
||||
private enterGame() {
|
||||
ResManager.I.goMainScene();
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ export class GlobalConfig extends BaseConfig {
|
||||
return oneData.emotionApiKey;
|
||||
}
|
||||
|
||||
/** 获取情绪判断机器人api */
|
||||
/** 获取ai模型 */
|
||||
public getModel(): string | null {
|
||||
let oneData = this.getAllConfig();
|
||||
if (!oneData) return null;
|
||||
|
||||
@@ -5,24 +5,155 @@ import { BaseData } from "./BaseData";
|
||||
import proto from 'db://assets/Scripts/proto/proto.pb.js';
|
||||
|
||||
export class GlobalData extends BaseData {
|
||||
|
||||
// api键
|
||||
private _apiKey: string = "";
|
||||
// 情绪判断机器人api
|
||||
private _emotionApiKey: string = "";
|
||||
// ai模型
|
||||
private _model: string = "";
|
||||
// Temperature
|
||||
private _temperature: number = 0;
|
||||
// 单次聊天最大token
|
||||
private _maxTokens: number = 0;
|
||||
// 超时时间(微秒)
|
||||
private _timeout: number = 0;
|
||||
// 单个角色免费聊天次数
|
||||
private _freeChatTimes: number = 0;
|
||||
// 单次对话增长好感度
|
||||
private _onceChatAddScore: number = 0;
|
||||
// 好感度等级兑换比例
|
||||
private _scoreExchangeStarLevel: number = 0;
|
||||
// 游戏名
|
||||
private _gameName: string = "";
|
||||
// 情绪评分机器人system_prompt,需拼接角色prompt
|
||||
private _emotionRating: string = "";
|
||||
// ai机器人基础规则
|
||||
private _girlBasePrompt: string = "";
|
||||
|
||||
public reset(): void {
|
||||
|
||||
this._apiKey = "";
|
||||
this._emotionApiKey = "";
|
||||
this._model = "";
|
||||
this._temperature = 0;
|
||||
this._maxTokens = 0;
|
||||
this._timeout = 0;
|
||||
this._freeChatTimes = 0;
|
||||
this._onceChatAddScore = 0;
|
||||
this._scoreExchangeStarLevel = 0;
|
||||
this._gameName = "";
|
||||
this._emotionRating = "";
|
||||
this._girlBasePrompt = "";
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
|
||||
this._apiKey = "";
|
||||
this._emotionApiKey = "";
|
||||
this._model = "";
|
||||
this._temperature = 0;
|
||||
this._maxTokens = 0;
|
||||
this._timeout = 0;
|
||||
this._freeChatTimes = 0;
|
||||
this._onceChatAddScore = 0;
|
||||
this._scoreExchangeStarLevel = 0;
|
||||
this._gameName = "";
|
||||
this._emotionRating = "";
|
||||
this._girlBasePrompt = "";
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
super.destroy();
|
||||
this._apiKey = null;
|
||||
this._emotionApiKey = null;
|
||||
this._model = null;
|
||||
this._temperature = null;
|
||||
this._maxTokens = null;
|
||||
this._timeout = null;
|
||||
this._freeChatTimes = null;
|
||||
this._onceChatAddScore = null;
|
||||
this._scoreExchangeStarLevel = null;
|
||||
this._gameName = null;
|
||||
this._emotionRating = null;
|
||||
this._girlBasePrompt = null;
|
||||
}
|
||||
|
||||
/** 设置全局数据 */
|
||||
public set globals(res: proto.cs.ICSGetResConfigRes) {
|
||||
|
||||
|
||||
console.log("设置全局数据:");
|
||||
public set globals(data: proto.cs.ICSGetResConfigRes) {
|
||||
const parsed = JSON.parse(data.data);
|
||||
if (Array.isArray(parsed) && parsed.length > 0) {
|
||||
const obj = parsed[0];
|
||||
this._apiKey = obj.ApiKey;
|
||||
this._emotionApiKey = obj.emotionApiKey;
|
||||
this._model = obj.Model;
|
||||
this._temperature = obj.Temperature;
|
||||
this._maxTokens = obj.MaxTokens;
|
||||
this._timeout = obj.Timeout;
|
||||
this._freeChatTimes = obj.FreeChatTimes;
|
||||
this._onceChatAddScore = obj.OnceChatAddScore;
|
||||
this._scoreExchangeStarLevel = obj.ScoreExchangeStarLevel;
|
||||
this._gameName = obj.GameName;
|
||||
this._emotionRating = obj.EmotionRating;
|
||||
this._girlBasePrompt = obj.girlBasePrompt;
|
||||
console.log("设置全局数据: ", this._gameName);
|
||||
}
|
||||
}
|
||||
|
||||
/** 获取api键 */
|
||||
public getApiKey(): string {
|
||||
return this._apiKey;
|
||||
}
|
||||
|
||||
/** 获取情绪判断机器人api */
|
||||
public getEmotionApiKey(): string {
|
||||
return this._emotionApiKey;
|
||||
}
|
||||
|
||||
/** 获取ai模型 */
|
||||
public getModel(): string {
|
||||
return this._model;
|
||||
}
|
||||
|
||||
/** Temperature */
|
||||
public getTemperature(): number {
|
||||
return this._temperature;
|
||||
}
|
||||
|
||||
/** 单次聊天最大token */
|
||||
public getMaxTokens(): number {
|
||||
return this._maxTokens;
|
||||
}
|
||||
|
||||
/** 超时时间(微秒) */
|
||||
public getTimeout(): number {
|
||||
return this._timeout;
|
||||
}
|
||||
|
||||
/** 单个角色免费聊天次数 */
|
||||
public getFreeChatTimes(): number {
|
||||
return this._freeChatTimes;
|
||||
}
|
||||
|
||||
/** 单次对话增长好感度 */
|
||||
public getOnceChatAddScore(): number {
|
||||
return this._onceChatAddScore;
|
||||
}
|
||||
|
||||
/** 好感度等级兑换比例 */
|
||||
public getScoreExchangeStarLevel(): number {
|
||||
return this._scoreExchangeStarLevel;
|
||||
}
|
||||
|
||||
/** 游戏名 */
|
||||
public getGameName(): string {
|
||||
return this._gameName;
|
||||
}
|
||||
|
||||
/** 情绪评分机器人system_prompt,需拼接角色prompt */
|
||||
public getEmotionRating(): string {
|
||||
return this._emotionRating;
|
||||
}
|
||||
|
||||
/** ai机器人基础规则 */
|
||||
public getGirlBasePrompt(): string {
|
||||
return this._girlBasePrompt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { HttpCommonService } from "./HttpCommonService";
|
||||
import { MockCommonService } from "./MockCommonService";
|
||||
|
||||
// 模拟开关
|
||||
const USE_MOCK = true;
|
||||
const USE_MOCK = false;
|
||||
|
||||
export class CommonService implements ICommonService {
|
||||
private static _I: CommonService | null = null;
|
||||
|
||||
@@ -10,27 +10,11 @@ import proto from 'db://assets/Scripts/proto/proto.pb.js';
|
||||
import { DataManager, DataId } from "db://assets/Scripts/chat18x/data/DataManager";
|
||||
import { OrderData } from "db://assets/Scripts/chat18x/data/OrderData";
|
||||
|
||||
export const PaymentEvents = {
|
||||
Started: "pay-started", // { orderId }
|
||||
UrlOpened: "pay-url-opened",
|
||||
PollTick: "pay-poll-tick", // { orderId, status }
|
||||
Finished: "pay-finished",
|
||||
};
|
||||
|
||||
export class PaymentService {
|
||||
private static _I: PaymentService | null = null;
|
||||
static get I() { return this._I ?? (this._I = new PaymentService()); }
|
||||
private constructor() {}
|
||||
|
||||
private bus = new EventTarget();
|
||||
|
||||
on(event: string, cb: (...args: any[]) => void, target?: any) {
|
||||
this.bus.on(event, cb, target);
|
||||
}
|
||||
off(event: string, cb: (...args: any[]) => void, target?: any) {
|
||||
this.bus.off(event, cb, target);
|
||||
}
|
||||
|
||||
/** 发起支付:创建订单→打开URL→回到App后开始轮询 */
|
||||
async startPayment(req: proto.cs.ICSCreateOrderReq, open: OpenStrategy = "system"): Promise<proto.cs.ICSQueryOrderRes> {
|
||||
// 下单
|
||||
@@ -40,7 +24,6 @@ export class PaymentService {
|
||||
return { status: -1, retCode: -1, balance: 0, vipExpire: 0};
|
||||
}
|
||||
const { orderId, payUrl } = create.data;
|
||||
this.bus.emit(PaymentEvents.Started, { orderId });
|
||||
|
||||
// 保存订单数据
|
||||
const orderData = DataManager.I.getDataById<OrderData>(DataId.Order);
|
||||
@@ -48,7 +31,6 @@ export class PaymentService {
|
||||
|
||||
// 打开支付页
|
||||
await PaymentOpenerFactory.create(open).open(payUrl);
|
||||
this.bus.emit(PaymentEvents.UrlOpened, { orderId });
|
||||
|
||||
// 等待回到前台(系统浏览器策略下)
|
||||
// - 如果是 inapp/minigame,可在 WebView/回跳时立即开始轮询;
|
||||
@@ -62,12 +44,11 @@ export class PaymentService {
|
||||
startIntervalMs: 2000,
|
||||
maxIntervalMs: 10000,
|
||||
jitter: true,
|
||||
}, (d) => this.bus.emit(PaymentEvents.PollTick, { orderId, status: d.status }));
|
||||
}, (d) => console.log());
|
||||
|
||||
// 刷新订单数据
|
||||
orderData.applyQueryOrder(orderId, data);
|
||||
// 返回结果
|
||||
this.bus.emit(PaymentEvents.Finished, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -81,7 +62,6 @@ export class PaymentService {
|
||||
const r = await this.startPollingOnly(o);
|
||||
if (r && r.status !== 1) {
|
||||
orderData.applyQueryOrder(o, r);
|
||||
this.bus.emit(PaymentEvents.Finished, r);
|
||||
}
|
||||
// r === null(轮询超时)时保留在仓库,等待下一次 resume 再查
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import { ThemeData } from "../../data/ThemeData";
|
||||
import { GirlData } from "../../data/GirlData";
|
||||
import { WalletData } from "../../data/WalletData";
|
||||
import { AccountData } from "../../data/AccountData";
|
||||
|
||||
import { ShopData } from "../../data/ShopData";
|
||||
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||
import GameRootUI from "../../../Main/Common/GameRootUI";
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user