DebugViewPresenter.ts 2.68 KB
import { SDK } from "simba-sdk";
import { GameRecord, PlotManager } from "../../../avg/AVG";
import { Presenter } from "../../../common/classbase/PresenterBase";
import { UIManager } from "../../../common/gameplay/managers/UIManager";
import UnlockSpecialPlotEventManager from "../../model/UnlockSpecialPlotEventManager";
import { UnlockSpecialPlotModelManager } from "../../model/UnlockSpecialPlotModelManager";
import { RegPresenter } from "../PresenterCCViewFactory";
import { DebugView, DebugViewProps, DebugViewType } from "../view/type/DebugView";

@RegPresenter(DebugViewType)
export default class DebugViewPresenter extends Presenter<undefined, DebugView>{
    static uuid = "DebugViewPresenter";
    private _viewProps: DebugViewProps;

    constructor() {
        super();
        this._viewProps = {
            playerID: SDK.getLoginInfo()?.playerId + "",
            onCopyIdBtnClickCallback: this.onCopyIdBtnClickCallback,
            onClearRecordBtnClickCallback: this.onClearRecordBtnClickCallback,
            onCopyRecordBtnClickCallback: this.onCopyRecordBtnClickCallback,
            onYouHuaBtnClickCallback: this.onYouHuaBtnClickCallback,
            onShouBiaoBtnClickCallback: this.onShouBiaoBtnClickCallback,
        };
    }

    onOpen() {
        super.onOpen(undefined);
        this.view.setProps(this._viewProps);
    }

    onCopyIdBtnClickCallback = async () => {
        try {
            await SDK.setClipboardData(this._viewProps.playerID);
            UIManager.showToast("复制ID成功!");
        } catch (error) {
            console.error(error);
        }
    }

    onClearRecordBtnClickCallback = () => {
        try {
            PlotManager.stop();
            GameRecord.emptyRecords();
            UIManager.showToast("清除成功,1秒后退出游戏!");
            setTimeout(() => {
                SDK.exit();
            }, 1000);
        } catch (error) {
            console.error(error);
        }
    }

    onCopyRecordBtnClickCallback = async () => {
        try {
            await SDK.setClipboardData(GameRecord.getRecordAsString());
            UIManager.showToast("复制存档成功!");
        } catch (error) {
            console.error(error);
        }
    }

    onYouHuaBtnClickCallback = () => {
        UnlockSpecialPlotEventManager.getInstance().cdKeyUnlockSpecialPlot(1, 1);
        UIManager.showSceneToast("解锁了新的番外,记得去卧室查看哦~");
    }

    onShouBiaoBtnClickCallback = () => {
        UnlockSpecialPlotModelManager.saveUnlockedSpecialPlotIdByItemIdToGameRecord(4);
        UIManager.showSceneToast("解锁了新的番外,记得去卧室查看哦~");
    }
}