-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMEC_WorkerLoader.js
More file actions
109 lines (93 loc) · 3.93 KB
/
MEC_WorkerLoader.js
File metadata and controls
109 lines (93 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*:
* @target MZ
* @plugindesc 🧩 Minto Engine Core WorkerLoader v1.12 — 同期ロード完全安全版(構文エラー修正版)
* @author MintoSoft
* @help
* ■ 概要
* - Workerを使用せず、マップデータを安全に同期ロードします。
* - $dataMap が undefined のタイミングでのアクセスを完全防止。
* - MEC_Core が未導入でも構文エラーになりません。
* -------------------------------------------------------
*/
(() => {
console.log("%c[M.E.C.Loader] WorkerLoader v1.12 (Safe Mode)", "color:#00ccff;");
window.MEC = window.MEC || {};
MEC.WorkerLoader = MEC.WorkerLoader || {};
// ------------------------------------------------------
// 数値 → 3桁ゼロ埋め
// ------------------------------------------------------
function padZero(num, len) {
const s = String(num);
return s.padStart(len || 3, "0");
}
// ------------------------------------------------------
// 安全同期ロード
// ------------------------------------------------------
MEC.WorkerLoader.loadMapData = function(mapId) {
if (!mapId) return;
const filename = "Map" + padZero(mapId, 3) + ".json";
const url = "data/" + filename;
console.log("[M.E.C.Loader] Safely loading: " + filename);
const xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.overrideMimeType("application/json");
xhr.onload = function() {
try {
if (xhr.status < 400 && xhr.responseText) {
const data = JSON.parse(xhr.responseText);
DataManager.onLoad(data);
window.$dataMap = data;
if (SceneManager._scene && SceneManager._scene._mapLoaded !== undefined) {
SceneManager._scene._mapLoaded = true;
}
console.log("✅ [M.E.C.Loader] Safe loaded: " + filename);
} else {
console.error("[M.E.C.Loader] Failed to load: " + filename);
}
} catch (e) {
console.error("[M.E.C.Loader] JSON parse error: " + e);
}
};
xhr.onerror = function() {
console.error("[M.E.C.Loader] Network error while loading " + filename);
};
xhr.send();
};
// ------------------------------------------------------
// 各クラスの安全化パッチ
// ------------------------------------------------------
const _Game_Player_startMapEvent = Game_Player.prototype.startMapEvent;
Game_Player.prototype.startMapEvent = function(x, y, triggers, normal) {
if (!window.$gameMap || !window.$dataMap) return false;
return _Game_Player_startMapEvent.call(this, x, y, triggers, normal);
};
const _Game_Map_update = Game_Map.prototype.update;
Game_Map.prototype.update = function(sceneActive) {
if (!window.$dataMap) return;
_Game_Map_update.call(this, sceneActive);
};
const _Scene_Map_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function() {
if (!window.$gameMap || !window.$dataMap) return;
_Scene_Map_update.call(this);
};
const _Spriteset_Map_update = Spriteset_Map.prototype.update;
Spriteset_Map.prototype.update = function() {
if (!window.$gameMap || !window.$dataMap) return;
_Spriteset_Map_update.call(this);
};
// ------------------------------------------------------
// ループ判定安全化
// ------------------------------------------------------
const _Game_Map_isLoopHorizontal = Game_Map.prototype.isLoopHorizontal;
Game_Map.prototype.isLoopHorizontal = function() {
if (!window.$dataMap) return false;
return _Game_Map_isLoopHorizontal.call(this);
};
const _Game_Map_isLoopVertical = Game_Map.prototype.isLoopVertical;
Game_Map.prototype.isLoopVertical = function() {
if (!window.$dataMap) return false;
return _Game_Map_isLoopVertical.call(this);
};
console.log("%c[M.E.C.Loader] Safe Mode active — Worker threads disabled.", "color:#33ff99;");
})();