forked from Trivel/RMMV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMrTS_DarkRoomCovers.js
168 lines (150 loc) · 6.07 KB
/
MrTS_DarkRoomCovers.js
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//=============================================================================
// MrTS_DarkRoomCovers.js
//=============================================================================
/*:
* @plugindesc Hides or reveals regions.
* @author Mr. Trivel
*
* @param Tile Size
* @desc How big are map tiles? X Y
* Default: 48 48
* @default 48 48
*
* @help
* --------------------------------------------------------------------------------
* Terms of Use
* --------------------------------------------------------------------------------
* Don't remove the header or claim that you wrote this plugin.
* Credit Mr. Trivel if using this plugin in your project.
* Free for commercial and non-commercial projects.
* --------------------------------------------------------------------------------
* Version 1.1
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Map Property Tags
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Plugin Commands
* --------------------------------------------------------------------------------
* RegionReveal [ID] - Reveals tiles of specific region
* RegionHide [ID] - Hides tiles of specific region
* RegionReset - Resets all open regions
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Version History
* --------------------------------------------------------------------------------
* 1.1 - Performance issues fixed, code cleanup
* 1.0 - Release
*/
(function() {
var parameters = PluginManager.parameters('MrTS_DarkRoomCovers');
var paramTileSize = String(parameters['Tile Size'] || "48 48").split(' ');
var tileSizeX = Number(paramTileSize[0]);
var tileSizeY = Number(paramTileSize[1]);
//--------------------------------------------------------------------------
// Game_Interpreter
//
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command.toLowerCase() === "regionreveal") {
$gameMap.addToCurrentlyOpenRegions(Number(args[0]));
} else if (command.toLowerCase() === "regionhide") {
$gameMap.removeFromCurrentlyOpenRegions(Number(args[0]));
} else if (command.toLowerCase() === "regionreset") {
$gameMap.resetCurrentlyOpenRegions();
}
};
//----------------------------------------------------------------------------
// Game_Map
//
// currentlyOpenRegions
Game_Map.prototype.currentlyOpenRegions = function() {
if (!this._openRegionIds) this._openRegionIds = [0];
return this._openRegionIds;
};
Game_Map.prototype.addToCurrentlyOpenRegions = function(id) {
if (!this._openRegionIds) this._openRegionIds = [0];
if (!this._openRegionIds.contains(id)) this._openRegionIds.push(id);
};
Game_Map.prototype.removeFromCurrentlyOpenRegions = function(id) {
if (!this._openRegionIds) return;
this._openRegionIds.splice(this._openRegionIds.indexOf(id), 1);
};
Game_Map.prototype.resetCurrentlyOpenRegions = function() {
this._openRegionIds = [0];
};
//----------------------------------------------------------------------------
// Scene_Map
//
var _SceneMap_createDisplayObjects = Scene_Map.prototype.createDisplayObjects;
Scene_Map.prototype.createDisplayObjects = function() {
_SceneMap_createDisplayObjects.call(this);
this.createDarkCover();
};
Scene_Map.prototype.createDarkCover = function() {
this._darkCover = new Spriteset_DarkCover();
this._spriteset.addChild(this._darkCover);
};
//--------------------------------------------------------------------------
// Spriteset_DarkCover
//
// Covers regions with dark dark darkness.
function Spriteset_DarkCover() {
this.initialize.apply(this, arguments);
};
Spriteset_DarkCover.prototype = Object.create(Sprite.prototype);
Spriteset_DarkCover.prototype.constructor = Spriteset_DarkCover;
Spriteset_DarkCover.prototype.initialize = function() {
Sprite.prototype.initialize.call(this);
this.setFrame(0, 0, Graphics.width, Graphics.height);
this._tone = [0, 0, 0, 0];
this.opaque = true;
this._darkCovers = [];
this._displayX = 0;
this._displayY = 0;
this._regions = $gameMap.currentlyOpenRegions().clone();
this.createDarkCovers();
this.update();
};
Spriteset_DarkCover.prototype.createDarkCovers = function() {
var bitmap = new Bitmap(tileSizeX, tileSizeY);
bitmap.fillAll('#000000');
for (var j = -1; j < Math.ceil(Graphics.boxHeight/tileSizeY)+2; j++) {
this._darkCovers.push([]);
for (var i = -1; i < Math.ceil(Graphics.boxWidth/tileSizeX)+2; i++) {
var cover = new Sprite(bitmap);
cover.x = i * tileSizeX;
cover.y = j * tileSizeY;
var regionId = $gameMap.regionId(i+this._displayX, j+this._displayY);
cover.visible = !(this._regions.contains(regionId));
this._darkCovers[j+1].push(cover);
this.addChild(cover);
}
}
};
Spriteset_DarkCover.prototype.update = function() {
Sprite.prototype.update.call(this);
this.x = (-$gameMap.displayX() + Math.floor($gameMap.displayX())) * tileSizeX;
this.y = (-$gameMap.displayY() + Math.floor($gameMap.displayY())) * tileSizeY;
if (Math.floor($gameMap.displayX()) !== this._displayX ||
Math.floor($gameMap.displayY()) !== this._displayY ||
!$gameMap.currentlyOpenRegions().equals(this._regions))
{
this._displayX = Math.floor($gameMap.displayX());
this._displayY = Math.floor($gameMap.displayY());
this._regions = $gameMap.currentlyOpenRegions().clone();
for (var j = -1; j < Math.ceil(Graphics.boxHeight/tileSizeY)+2; j++) {
for (var i = -1; i < Math.ceil(Graphics.boxWidth/tileSizeX)+2; i++) {
var regionId = $gameMap.regionId(i+this._displayX, j+this._displayY);
this._darkCovers[j+1][i+1].visible = !(this._regions.contains(regionId));
}
}
}
};
})();