-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
RS_PictureTool.js
443 lines (380 loc) · 15 KB
/
RS_PictureTool.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
//================================================================
// RS_PictureTool.js
// ---------------------------------------------------------------
// The MIT License
// Copyright (c) 2018 biud436
// ---------------------------------------------------------------
// Free for commercial and non commercial use.
//================================================================
/*:
* @target MV
* @plugindesc When a picture collides with a specific character sprite, a specific event is fired. <RS_PictureTool>
* @author biud436
*
* @param Delay
* @type number
* @min 1
* @desc if it is less than the time you want a delay to take, it will wait the event to complete.
* @default 200
*
* @help
* =============================================================================
* Script Calls
* =============================================================================
*
* This command will run some event when it collides with certain picture:
*
* RS.PictureTool.runEventCollideWithPicture(picId, eventId);
*
* This command will run the common event when it collides with a picId picture:
*
* RS.PictureTool.runCommonEventCollideWithPicture(picId, eventId, commonEventId);
*
* This command will run a certain event when the picture collides with a game player:
*
* RS.PictureTool.runEventCollideWithPlayer(picId, eventId);
*
* This command will run a certain common event when the picture collides with a game player:
*
* RS.PictureTool.runCommonEventCollideWithPlayer(picId, eventId, commonEventId);
*
* =============================================================================
* Version Log
* =============================================================================
* 2018.04.13 (v1.0.0) - First Release.
* 2018.04.16 (v1.0.1) - Fixed a hanging bug.
* 2018.04.16 (v1.0.2) - Fixed the issue that the save is not working.
* 2018.04.16 (v1.0.3) - Fixed the issue when the picture is deleted
* 2024.06.23 (v1.1.0):
* - Fixed the issue of no response when a picture collides with a specific character sprite
*/
/*:ko
* @target MV
* @plugindesc 그림이 특정 캐릭터 스프라이트와 충돌하면 특정 이벤트가 실행됩니다. <RS_PictureTool>
* @author 러닝은빛(biud436)
*
* @param Delay
* @type number
* @min 1
* @desc 키보드와 마우스 이벤트 업데이트를 위한 딜레이 시간 (간격이 짧으면 키보드와 마우스가 먹통됩니다, 1000ms = 1초)
* @default 200
*
* @help
* =============================================================================
* 스크립트 호출
* =============================================================================
*
* 특정 그림과 특정 이벤트 eventId가 충돌하면 eventId를 실행합니다.
*
* RS.PictureTool.runEventCollideWithPicture(picId, eventId);
*
* 특정 그림과 특정 이벤트 eventId가 충돌하면 특정 커먼 이벤트를 실행합니다.
*
* RS.PictureTool.runCommonEventCollideWithPicture(picId, eventId, commonEventId);
*
* 그림과 플레이어가 충돌하면 특정 이벤트를 실행합니다.
*
* RS.PictureTool.runEventCollideWithPlayer(picId, eventId);
*
* 그림과 플레이어가 충돌하면 특정 커먼 이벤트를 실행합니다.
*
* RS.PictureTool.runCommonEventCollideWithPlayer(picId, eventId, commonEventId);
*
* =============================================================================
* 버전 로그
* =============================================================================
* 2018.04.13 (v1.0.0) - 공개
* 2018.04.16 (v1.0.1) - 멈춤 버그를 수정하였습니다.
* 2018.04.16 (v1.0.2) - 세이브 불가 버그를 수정하였습니다.
* 2018.04.16 (v1.0.3) - 그림 삭제 불가 버그를 수정하였습니다.
* 2024.06.23 (v1.1.0):
* - 충돌해도 아무런 반응이 없는 문제를 수정하였습니다.
*/
var RS = RS || {};
RS.PictureTool = RS.PictureTool || {};
($ => {
'use strict';
let parameters = $plugins.filter(i => {
return i.description.contains('<RS_PictureTool>');
});
parameters = parameters.length > 0 && parameters[0].parameters;
RS.PictureTool.Params = RS.PictureTool.Params || {};
RS.PictureTool.Params.frameTime = performance.now();
RS.PictureTool.Params.FN = {
NONE: -1,
RUN_EVENT_COLLIDE_WITH_PICTURE: 0,
RUN_COMMONEVENT_COLLIDE_WITH_PICTURE: 1,
RUN_EVENT_COLLIDE_WITH_PLAYER: 2,
RUN_COMMONEVENT_COLLIDEWITH_PLAYER: 3,
};
RS.PictureTool.Params.currentFunc = [RS.PictureTool.Params.FN.NONE];
RS.PictureTool.Params.funcArgs = [[]];
RS.PictureTool.Params.isCall = false;
// 멈춤 현상 방지를 위한 고정 딜레이 값 (마우스와 키보드 입력 업데이트가 선행되고 있으므로)
RS.PictureTool.Params.delay = Number(parameters['Delay'] || 200);
// ===========================================================================
// Game_Character
// ===========================================================================
const alias_Game_Character_initMembers =
Game_Character.prototype.initMembers;
Game_Character.prototype.initMembers = function () {
alias_Game_Character_initMembers.call(this);
this._spriteFrame = new Rectangle(0, 0, 48, 48);
};
Game_Character.prototype.getFrame = function () {
return this._spriteFrame;
};
// ===========================================================================
// Sprite_Character
// ===========================================================================
const alias_Sprite_Character_updateFrame =
Sprite_Character.prototype.updateFrame;
Sprite_Character.prototype.updateFrame = function () {
alias_Sprite_Character_updateFrame.call(this);
this.getFrame();
};
Sprite_Character.prototype.getFrame = function () {
let frame;
if (!this._character) return;
const tw = $gameMap.tileWidth();
const th = $gameMap.tileHeight();
const sx = this._character.screenX();
const sy = this._character.screenY();
const width = this.patternWidth();
const height = this.patternHeight();
if (this.frame) {
frame = this.frame;
} else {
frame = new Rectangle(sx - tw / 2, sy - th, width, height);
}
this._character._spriteFrame = frame;
};
// ===========================================================================
// RS.PictureTool
// ===========================================================================
RS.PictureTool.isMap = function () {
return SceneManager._scene instanceof Scene_Map;
};
/**
* Find the piciture from the picture container.
* @param {Number} picId this is a number starts from 1.
*/
RS.PictureTool.findPicture = function (picId) {
let container;
if (!RS.PictureTool.isMap()) return false;
container = SceneManager._scene._spriteset._pictureContainer.children;
if (!container) return false;
return container.find(i => i._pictureId === picId);
};
/**
* Find the frame of the picture sprite.
* @param {Number} picId this is a number starts from 1.
*/
RS.PictureTool.findPictureBound = function (picId) {
const pic = RS.PictureTool.findPicture(picId);
if (!pic) return false;
return new Rectangle(pic.x, pic.y, pic.width, pic.height);
};
/**
* Check whether the picture has been collide with target.
* @param {Rectangle} p specify the frame of the drawing object.
* @param {Rectangle} q specify the frame of the drawing object.
*/
RS.PictureTool.isCheckHit = function (p, q) {
let ret = false;
if (p.x + p.width > q.x && p.x < q.x + q.width) {
if (p.y + p.height > q.y && p.y < q.y + q.height) {
ret = true;
}
}
return ret;
};
RS.PictureTool.isCheckHitWithCircle = function (p, q) {
let ret = false;
let dx, dy, ar, dist;
dx = p.x - q.x;
dy = p.y - q.y;
dist = dx * dx + dy * dy;
// TODO: 임시로 정한 반지름
ar = p.width / 2 + q.width / 2;
if (dist < ar * ar) {
ret = true;
}
return ret;
};
/**
* @param {Number} picId this is a number starts from 1.
* @param {Number} eventId this is a number starts from 1.
* @param {Boolean} isPlayer check whether the target is a player character.
*/
RS.PictureTool.isValid = function (picId, eventId, isPlayer) {
const pic = RS.PictureTool.findPictureBound(picId);
if (!pic) return false;
if (
performance.now() - RS.PictureTool.Params.frameTime <
RS.PictureTool.Params.delay
)
return false;
let frame;
if (isPlayer) {
frame = $gamePlayer.getFrame();
} else {
frame = $gameMap.event(eventId).getFrame();
}
return RS.PictureTool.isCheckHit(frame, pic);
};
RS.PictureTool.runEventCollideWithPicture = function (picId, eventId) {
RS.PictureTool.Params.isCall = true;
RS.PictureTool.Params.currentFunc.push(
RS.PictureTool.Params.FN.RUN_EVENT_COLLIDE_WITH_PICTURE
);
RS.PictureTool.Params.funcArgs.push([picId, eventId]);
};
RS.PictureTool.runCommonEventCollideWithPicture = function (
picId,
eventId,
commonEventId
) {
RS.PictureTool.Params.isCall = true;
RS.PictureTool.Params.currentFunc.push(
RS.PictureTool.Params.FN.RUN_COMMONEVENT_COLLIDE_WITH_PICTURE
);
RS.PictureTool.Params.funcArgs.push([picId, eventId, commonEventId]);
};
RS.PictureTool.runEventCollideWithPlayer = function (picId, eventId) {
RS.PictureTool.Params.isCall = true;
RS.PictureTool.Params.currentFunc.push(
RS.PictureTool.Params.FN.RUN_EVENT_COLLIDE_WITH_PLAYER
);
RS.PictureTool.Params.funcArgs.push([picId, eventId]);
};
RS.PictureTool.runCommonEventCollideWithPlayer = function (
picId,
eventId,
commonEventId
) {
RS.PictureTool.Params.isCall = true;
RS.PictureTool.Params.currentFunc.push(
RS.PictureTool.Params.FN.RUN_COMMONEVENT_COLLIDE_WITH_PLAYER
);
RS.PictureTool.Params.funcArgs.push([picId, eventId, commonEventId]);
};
/**
* 특정 그림과 특정 이벤트 eventId가 충돌하면 eventId를 실행합니다.
*/
RS.PictureTool.runEventCollideWithPictureImpl = function (picId, eventId) {
if (!RS.PictureTool.isValid(picId, eventId)) return false;
const e = $gameMap.event(eventId);
if (!$gameMap.isEventRunning() && !e.isStarting()) {
setTimeout(function () {
e.start();
}, 0);
}
RS.PictureTool.Params.frameTime = performance.now();
return true;
};
/**
* 특정 그림과 특정 이벤트 eventId가 충돌하면 특정 커먼 이벤트를 실행합니다.
*/
RS.PictureTool.runCommonEventCollideWithPictureImpl = function (
picId,
eventId,
commonEventId
) {
if (!RS.PictureTool.isValid(picId, eventId)) return false;
if (!$gameMap.isEventRunning()) {
setTimeout(() => {
$gameTemp.reserveCommonEvent(commonEventId);
}, 0);
}
RS.PictureTool.Params.frameTime = performance.now();
return true;
};
/**
* 그림과 플레이어가 충돌하면 특정 이벤트를 실행합니다.
*/
RS.PictureTool.runEventCollideWithPlayerImpl = function (picId, eventId) {
if (!RS.PictureTool.isValid(picId, eventId, true)) return false;
const e = $gameMap.event(eventId);
if (!$gameMap.isEventRunning() && !e.isStarting()) {
setTimeout(() => {
e.start();
}, 0);
}
RS.PictureTool.Params.frameTime = performance.now();
return true;
};
/**
* 그림과 플레이어가 충돌하면 특정 커먼 이벤트를 실행합니다.
*/
RS.PictureTool.runCommonEventCollideWithPlayerImpl = function (
picId,
eventId,
commonEventId
) {
if (!RS.PictureTool.isValid(picId, eventId, true)) return false;
if (!$gameMap.isEventRunning()) {
setTimeout(() => {
$gameTemp.reserveCommonEvent(commonEventId);
}, 0);
}
RS.PictureTool.Params.frameTime = performance.now();
return true;
};
/**
* 그림의 표시에서 만든 텍스처를 메모리에서 즉각 제거합니다.
*/
RS.PictureTool.deletePicture = function (picId) {
let container;
if (!RS.PictureTool.isMap()) return false;
container = SceneManager._scene._spriteset._pictureContainer;
if (!container) return false;
const picSprite = RS.PictureTool.findPicture(picId);
const sprite = new Sprite_Picture(picId);
container.addChild(sprite);
container.swapChildren(picSprite, sprite);
container.removeChild(picSprite);
picSprite.destroy({ children: true, texture: true });
};
Game_Screen.prototype.erasePicture = function (pictureId) {
const realPictureId = this.realPictureId(pictureId);
this._pictures[realPictureId] = null;
RS.PictureTool.deletePicture(realPictureId);
};
//============================================================================
// Scene_Map
//============================================================================
Scene_Map.prototype.updatePictureTool = function () {
if (!RS.PictureTool.Params.isCall) return;
const args = RS.PictureTool.Params.funcArgs.shift();
const func = RS.PictureTool.Params.currentFunc.shift();
switch (func) {
case RS.PictureTool.Params.FN.RUN_EVENT_COLLIDE_WITH_PICTURE:
RS.PictureTool.runEventCollideWithPictureImpl(args[0], args[1]);
break;
case RS.PictureTool.Params.FN.RUN_COMMONEVENT_COLLIDE_WITH_PICTURE:
RS.PictureTool.runCommonEventCollideWithPictureImpl(
args[0],
args[1],
args[2]
);
break;
case RS.PictureTool.Params.FN.RUN_EVENT_COLLIDE_WITH_PLAYER:
RS.PictureTool.runEventCollideWithPlayerImpl(args[0], args[1]);
break;
case RS.PictureTool.Params.FN.RUN_COMMONEVENT_COLLIDE_WITH_PLAYER:
RS.PictureTool.runCommonEventCollideWithPlayerImpl(
args[0],
args[1],
args[2]
);
break;
}
RS.PictureTool.Params.isCall = false;
};
const alias_Scene_Map_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function () {
alias_Scene_Map_update.call(this);
this.updatePictureTool();
};
})(RS.PictureTool);