Skip to content

Commit

Permalink
修复微信小游戏报错
Browse files Browse the repository at this point in the history
  • Loading branch information
1226085293 committed Jun 29, 2024
1 parent faeec30 commit 00efeb7
Show file tree
Hide file tree
Showing 22 changed files with 136 additions and 88 deletions.
8 changes: 6 additions & 2 deletions assets/decorator.meta
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
"isBundle": true,
"bundleName": "decorator",
"bundleConfigID": "auto_84uGKf/pZAibOdPqiVyqYV",
"compressionType": {},
"isRemoteBundle": {}
"compressionType": {
"wechatgame": "subpackage"
},
"isRemoteBundle": {
"wechatgame": false
}
}
}
8 changes: 6 additions & 2 deletions assets/hot_update.meta
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {},
"compressionType": {
"wechatgame": "subpackage"
},
"isRemoteBundle": {
"wechatgame": false
},
"isBundle": true
}
}
4 changes: 3 additions & 1 deletion assets/resources.meta
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"priority": 8,
"bundleConfigID": "auto_9c5OxVe2xPW4dKkOvzzxYi",
"compressionType": {},
"isRemoteBundle": {}
"isRemoteBundle": {
"wechatgame": false
}
}
}
8 changes: 6 additions & 2 deletions assets/tool.meta
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
"bundleName": "tool",
"isBundle": true,
"bundleConfigID": "auto_cagccLCvVAlLJ3yBwnWXog",
"compressionType": {},
"isRemoteBundle": {}
"compressionType": {
"wechatgame": "subpackage"
},
"isRemoteBundle": {
"wechatgame": false
}
}
}
2 changes: 1 addition & 1 deletion extensions/MKFramework/@types/mk-framework/mk.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ declare namespace mk {
* 音频基类
* @noInheritDoc
*/
declare abstract class mk_audio_base extends instance_base {
declare abstract class mk_audio_base {
constructor();
/** 日志 */
protected abstract _log: logger;
Expand Down
9 changes: 7 additions & 2 deletions extensions/MKFramework/assets/mk-framework/@config.meta
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
"bundleName": "config",
"isBundle": true,
"bundleConfigID": "auto_76Sx2i+y5M8KR2hpWAvu34",
"compressionType": {},
"isRemoteBundle": {}
"compressionType": {
"wechatgame": "subpackage"
},
"isRemoteBundle": {
"wechatgame": false
},
"priority": 20
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ namespace global_config {
}

if (DEBUG) {
self["global_config"] = global_config;
window["global_config"] = global_config;
}

export default global_config;
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class event<CT> extends cc.EventTarget {
const global_event = new event<global_event_protocol>();

if (DEBUG) {
self["global_event"] = global_event;
window["global_event"] = global_event;
}

export default global_event;
9 changes: 7 additions & 2 deletions extensions/MKFramework/assets/mk-framework/@framework.meta
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
"bundleName": "framework",
"isBundle": true,
"bundleConfigID": "auto_96xxa0QS9BT7BEcM9qNNM3",
"compressionType": {},
"isRemoteBundle": {}
"compressionType": {
"wechatgame": "subpackage"
},
"isRemoteBundle": {
"wechatgame": false
},
"priority": 20
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class node_extends {
this._ui_opacity = v;
} else if (v instanceof cc.UITransform) {
this.transform = v;
} else if (v instanceof cc.Animation) {
} else if (cc.Animation && v instanceof cc.Animation) {
this.animation = v;
} else if (v instanceof cc.EditBox) {
this.edit_box = v;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ const { ccclass, property } = cc._decorator;
* 音频基类
* @noInheritDoc
*/
abstract class mk_audio_base extends mk_instance_base {
abstract class mk_audio_base {
constructor() {
super();
global_event.on(global_event.key.restart, this._event_restart, this);
}

Expand Down Expand Up @@ -365,11 +364,14 @@ export namespace mk_audio_base_ {

/* --------------- 属性 --------------- */
/** 音频资源 */
@property({ displayName: "音频资源", type: cc.AudioClip })
@property({ displayName: "音频资源", type: cc.AudioClip ?? null })
clip: cc.AudioClip | null = null;

/** 音频类型 */
@property({ displayName: "音频类型", type: cc.Enum(global_config.audio.type) })
@property({
displayName: "音频类型",
type: cc.Enum(global_config.audio.type),
})
type = global_config.audio.type.effect;

/* --------------- public --------------- */
Expand Down Expand Up @@ -732,7 +734,9 @@ export namespace mk_audio_base_ {
}
}

export const unit = _unit as any as Omit<unit, keyof Function> & { new (init_?: Partial<unit>): Omit<unit, keyof Function> };
export const unit = _unit as any as Omit<unit, keyof Function> & {
new (init_?: Partial<unit>): Omit<unit, keyof Function>;
};
}

export default mk_audio_base;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export { default as audio } from "./mk_audio_base";
export { mk_audio_base_ as mk_audio_ } from "./mk_audio_base";

// 重定义 audio_,保持类型不变
Object.assign(mk_audio_base_, self.wx ? mk_audio_wx_ : mk_audio_common_);
Object.assign(mk_audio_base_, window.wx ? mk_audio_wx_ : mk_audio_common_);

/**
* 音频管理器
Expand All @@ -21,4 +21,4 @@ Object.assign(mk_audio_base_, self.wx ? mk_audio_wx_ : mk_audio_common_);
*
* - 通用版本超出播放数量限制后停止当前音频而不是之前的
*/
export const mk_audio: mk_audio_base = self.wx ? audio_wx : audio_common;
export const mk_audio: mk_audio_base = window.wx ? new audio_wx() : new audio_common();
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ const { ccclass } = cc._decorator;
class mk_audio_common extends mk_audio_base {
constructor() {
super();
mk_audio_common._instance = this;
this._constructor();
}

/* --------------- static --------------- */
/** @internal */
static _instance: mk_audio_common;
/* --------------- protected --------------- */
/** 日志 */
protected _log = new mk_logger("audio_common");
Expand Down Expand Up @@ -367,7 +370,7 @@ export namespace mk_audio_common_ {
new_audio._loop_b = this._loop_b;
new_audio._init_b = this._init_b;
this.group_ns.forEach((v_n) => {
mk_audio_common.instance().get_group(v_n).add_audio(new_audio);
mk_audio_common._instance.get_group(v_n).add_audio(new_audio);
});

return new_audio;
Expand Down Expand Up @@ -398,7 +401,7 @@ export namespace mk_audio_common_ {

// 更新真实音量
this.real_volume_n = this.group_ns.reduce(
(pre_n, curr_n) => pre_n * mk_audio_common.instance().get_group(curr_n).volume_n,
(pre_n, curr_n) => pre_n * mk_audio_common._instance.get_group(curr_n).volume_n,
this._volume_n
);

Expand Down Expand Up @@ -458,4 +461,4 @@ export namespace mk_audio_common_ {
export const unit = _unit;
}

export default mk_audio_common.instance();
export default mk_audio_common;
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ const { ccclass } = cc._decorator;
* @noInheritDoc
*/
class mk_audio_wx extends mk_audio_base {
constructor() {
super();
mk_audio_wx._instance = this;
}
/* --------------- static --------------- */
/** @internal */
static _instance: mk_audio_wx;
/* --------------- protected --------------- */
/** 日志 */
protected _log = new mk_logger("audio_wx");
Expand Down Expand Up @@ -178,7 +185,7 @@ export namespace mk_audio_wx_ {
new_audio._loop_b = this._loop_b;
new_audio._init_b = this._init_b;
this.group_ns.forEach((v_n) => {
mk_audio_wx.instance().get_group(v_n).add_audio(new_audio);
mk_audio_wx._instance.get_group(v_n).add_audio(new_audio);
});

return new_audio;
Expand Down Expand Up @@ -218,7 +225,7 @@ export namespace mk_audio_wx_ {

// 更新真实音量
this.real_volume_n = this.group_ns.reduce(
(pre_n, curr_n) => pre_n * mk_audio_wx.instance().get_group(curr_n).volume_n,
(pre_n, curr_n) => pre_n * mk_audio_wx._instance.get_group(curr_n).volume_n,
this._volume_n
);

Expand All @@ -231,4 +238,4 @@ export namespace mk_audio_wx_ {
export const unit = _unit;
}

export default mk_audio_wx.instance();
export default mk_audio_wx;
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ if (!EDITOR) {
// 显示调试信息
cc.director.once(cc.Director.EVENT_AFTER_SCENE_LAUNCH, () => {
if (global_config.constant.show_debug_info_b) {
cc.profiler.showStats();
cc.profiler?.showStats();
} else {
cc.profiler.hideStats();
cc.profiler?.hideStats();
}
});

Expand All @@ -28,7 +28,7 @@ if (!EDITOR) {

// 注册到全局
if (DEBUG) {
self["mk"] = mk;
window["mk"] = mk;
}

let temp: any = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
self.load_bundle_ss = self.load_bundle_ss ?? (self.load_bundle_ss = []);
window.load_bundle_ss = window.load_bundle_ss ?? (window.load_bundle_ss = []);
{
/** 原函数 */
let old_load_f = self.cc.assetManager.loadBundle;
let old_load_f = window.cc.assetManager.loadBundle;
/** 初始化任务 */
let init_task = null;

// 拦截首次加载
if (self.cc.assetManager.loadBundle) {
self.cc.assetManager.loadBundle = async function (...args_as) {
if (window.cc.assetManager.loadBundle) {
window.cc.assetManager.loadBundle = async function (...args_as) {
if (init_task) {
await init_task;
}
Expand All @@ -17,14 +17,14 @@ self.load_bundle_ss = self.load_bundle_ss ?? (self.load_bundle_ss = []);
let load_bundle_ss = ["config", "framework"];

// 添加其他需要加载的 bundle
load_bundle_ss.push(...self.load_bundle_ss);
self.load_bundle_ss = undefined;
load_bundle_ss.push(...window.load_bundle_ss);
window.load_bundle_ss = undefined;

init_task = load_bundle_ss
.reduce((pre, name) => {
return pre.then(() => {
return new Promise((resolve, reject) => {
old_load_f.call(self.cc.assetManager, name, (err, bundle) => {
old_load_f.call(window.cc.assetManager, name, (err, bundle) => {
if (err) {
return reject(err);
}
Expand All @@ -36,12 +36,12 @@ self.load_bundle_ss = self.load_bundle_ss ?? (self.load_bundle_ss = []);
}, Promise.resolve())
.then((pre) => {
// 还原 loadBundle
self.cc.assetManager.loadBundle = old_load_f;
window.cc.assetManager.loadBundle = old_load_f;
});
}

// 恢复加载步骤
self.cc.assetManager.loadBundle(...args_as);
window.cc.assetManager.loadBundle(...args_as);
};
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as cc from "cc";
import { EDITOR } from "cc/env";
import global_config from "../../@config/global_config";
import dynamic_module from "../mk_dynamic_module";
import mk_dynamic_module from "../mk_dynamic_module";
import mk_logger from "../mk_logger";
import monitor from "../mk_monitor";
import mk_monitor from "../mk_monitor";
import mk_status_task from "../task/mk_status_task";
import mk_layer from "./mk_layer";
import mk_tool from "../@private/tool/mk_tool";
import { mk_audio, mk_audio_ } from "../audio/mk_audio_export";
import mk_release, { mk_release_ } from "../mk_release";
import { mk_asset_ } from "../resources/mk_asset";
const ui_manage = dynamic_module.default(import("../mk_ui_manage"));
const ui_manage = mk_dynamic_module.default(import("../mk_ui_manage"));
const { ccclass, property } = cc._decorator;

export namespace _mk_life_cycle {
Expand Down Expand Up @@ -296,7 +296,7 @@ export class mk_life_cycle extends mk_layer implements mk_asset_.type_follow_rel
// 取消所有定时器
this.unscheduleAllCallbacks();
// 取消数据监听事件
monitor.clear(this);
mk_monitor.clear(this);
// 释放资源
this._release_manage.release_all();
// 重置数据
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import * as cc from "cc";
import { EDITOR } from "cc/env";
import mk_tool from "../@private/tool/mk_tool";
import { mk_life_cycle, _mk_life_cycle } from "./mk_life_cycle";
import dynamic_module from "../mk_dynamic_module";
import mk_dynamic_module from "../mk_dynamic_module";
import type { mk_ui_manage_ } from "../mk_ui_manage";
import mk_asset from "../resources/mk_asset";
import mk_game from "../mk_game";
import global_config from "../../@config/global_config";
const ui_manage = dynamic_module.default(import("../mk_ui_manage"));
const ui_manage = mk_dynamic_module.default(import("../mk_ui_manage"));
const { ccclass, property } = cc._decorator;

namespace _mk_view_base {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class mk_http extends mk_instance_base {
data += String.fromCharCode(buf[k_n]);
}

result = "data:image/png;base64," + globalThis.btoa(data);
result = "data:image/png;base64," + window.btoa(data);
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,14 @@ export class mk_asset extends mk_instance_base {
// 远程
if (remote_b) {
// eslint-disable-next-line @typescript-eslint/naming-convention
cc.assetManager.loadRemote(path_s_, { onFileProgress: get_config.progress_f, ...(get_config.remote_option ?? {}) }, completed_f);
cc.assetManager.loadRemote(
path_s_,
{
onFileProgress: get_config.progress_f,
...(get_config.remote_option ?? {}),
},
completed_f
);
}
// 编辑器
else if (EDITOR) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ export class mk_bundle extends mk_instance_base {
/** bundle 脚本表 */
const bundle_script_tab: Record<string, any> = {};
/** js 系统 */
const system_js = self["System"];
const system_js = window["System"];
/** 脚本缓存表 */
const script_cache_tab: Record<string, any> = system_js[Reflect.ownKeys(system_js).find((v) => typeof v === "symbol")!];

Expand Down
Loading

0 comments on commit 00efeb7

Please sign in to comment.