This repository was archived by the owner on Apr 21, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicTilesetManager.js
More file actions
85 lines (75 loc) · 2.79 KB
/
DynamicTilesetManager.js
File metadata and controls
85 lines (75 loc) · 2.79 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
/*:
* @target MV
* @plugindesc Allows dynamically changing the tileset of any map (MV/MZ version).
* @author Kyonides Arkanthes (original) / Davyd Maker (MV reimplementation)
* @help
* ------------------------------------------------------------------
* Script Commands:
* ------------------------------------------------------------------
* $gameMap.changeTileset(mapId, tilesetId);
* → Changes the tileset of the map "mapId" to the tileset "tilesetId"
*
* $gameMap.resetTileset(mapId);
* → Restores the original tileset of the map "mapId"
*
* ------------------------------------------------------------------
* Example:
* $gameMap.changeTileset($gameMap.mapId(), 5);
* → Changes the current tileset to the ID 5.
*
* ------------------------------------------------------------------
* Original Implementation (RPG Maker XP):
* https://forums.rpgmakerweb.com/index.php?threads/switching-tilesets-while-making-the-map.157060/#post-1345100
*
* ------------------------------------------------------------------
* Notes:
* - Works even if the player is still on the map.
* - Does not change the saved map in the editor, only at runtime.
* - Changes are saved together with the game save.
* ------------------------------------------------------------------
*/
(() => {
const _Game_Map_initialize = Game_Map.prototype.initialize;
Game_Map.prototype.initialize = function () {
_Game_Map_initialize.call(this);
this._tilesetOverrides = this._tilesetOverrides || {};
};
Game_Map.prototype.changeTileset = function (mapId, tilesetId) {
if (!tilesetId || !$dataTilesets[tilesetId]) {
console.warn(`Tileset ID ${tilesetId} invalid!`);
return;
}
this._tilesetOverrides[mapId] = tilesetId;
if (this._mapId === mapId) this.refreshTileset();
};
Game_Map.prototype.resetTileset = function (mapId) {
delete this._tilesetOverrides[mapId];
if (this._mapId === mapId) this.refreshTileset();
};
Game_Map.prototype.getTilesetIdOverride = function () {
return (
this._tilesetOverrides[this._mapId] ||
this._map?.tilesetId ||
this._tilesetId
);
};
Game_Map.prototype.refreshTileset = function () {
const newId = this.getTilesetIdOverride();
if (newId === this._tilesetId) return;
this._tilesetId = newId;
this._tileset = $dataTilesets[newId];
this.requestRefresh();
if (SceneManager._scene instanceof Scene_Map) {
SceneManager._scene._spriteset.loadTileset();
}
};
const _Game_Map_setup = Game_Map.prototype.setup;
Game_Map.prototype.setup = function (mapId) {
_Game_Map_setup.call(this, mapId);
const override = this._tilesetOverrides[mapId];
if (override && $dataTilesets[override]) {
this._tilesetId = override;
this._tileset = $dataTilesets[override];
}
};
})();