-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathGabeMZ_MessageCharacterSound.js
206 lines (183 loc) · 6.11 KB
/
GabeMZ_MessageCharacterSound.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
//============================================================================
// Gabe MZ - Message Character Sound
//----------------------------------------------------------------------------
// 11/08/21 | Version: 1.0.0 | Released
//----------------------------------------------------------------------------
// This software is released under the zlib License.
//============================================================================
/*:
* @target MZ
* @plugindesc [v1.0.0] Allows to play a character SE during the game messages.
* @author Gabe (Gabriel Nascimento)
* @url http://patreon.com/gabriel_nfd
*
* @help Gabe MZ - Message Character Sound
* - This plugin is released under the zlib License.
*
* This plugin allows you to play a character SE during the game messages.
*
* For support and new plugins join our Discord server:
* https://discord.gg/GG85QRz
*
* @param seSettings
* @text Message SE Settings
*
* @param seList
* @parent seSettings
* @text SE List
* @desc Set a list of SE settings to be used.
* @type struct<seListStruct>[]
* @default ["{\"filename\":\"Cursor1\",\"frequency\":\"4\",\"volume\":\"25\",\"pitch\":\"100\",\"pan\":\"0\"}","{\"filename\":\"Cursor2\",\"frequency\":\"3\",\"volume\":\"25\",\"pitch\":\"100\",\"pan\":\"0\"}"]
*
* @param defaultSEId
* @parent seSettings
* @text Default SE ID
* @desc Set the default SE ID.
* @type number
* @min 1
* @default 1
*
* @command setState
* @text Set Message Character Sound State
* @desc Set the message character sound state.
*
* @arg state
* @text State
* @desc Set the current state of the message character sound.
* @type boolean
* @default true
*
* @command setId
* @text Set Current Message Character Sound
* @desc Set the current message character sound id.
*
* @arg id
* @text Id
* @desc Set the id of the current message character sound.
* @type number
* @min 1
* @default 1
*/
/*~struct~seListStruct:
* @param filename
* @text SE Filename
* @desc Set the SE filename.
* @type file
* @dir audio/se/
*
* @param frequency
* @text Frequency
* @desc Set the SE frequency.
* @type number
* @min 1
* @max 100
* @default 2
*
* @param volume
* @text Volume
* @desc Set the SE volume.
* @type number
* @min 0
* @max 100
* @default 25
*
* @param pitch
* @text Pitch
* @desc Set the SE pitch.
* @type number
* @min 50
* @max 150
* @default 100
*
* @param pan
* @text Pan
* @desc Set the SE pan.
* @type number
* @min -100
* @max 100
* @default 0
*/
var Imported = Imported || {};
Imported.GMZ_MessageCharacterSound = true;
var GabeMZ = GabeMZ || {};
GabeMZ.MessageCharacterSound = GabeMZ.MessageCharacterSound || {};
GabeMZ.MessageCharacterSound.VERSION = [1, 0, 0];
(() => {
const pluginName = "GabeMZ_MessageCharacterSound";
const params = PluginManager.parameters(pluginName);
GabeMZ.MessageCharacterSound.seList = [];
GabeMZ.MessageCharacterSound.defaultSEId = parseInt(params.defaultSEId);
for (const setting of JSON.parse(params.seList)) {
GabeMZ.MessageCharacterSound.seList.push(JSON.parse(setting));
}
//-----------------------------------------------------------------------------
// PluginManager
//
// The static class that manages the plugins.
PluginManager.registerCommand(pluginName, "setState", args => {
const state = args.state == "true";
$gameSystem.setMessageCharacterSoundState(state);
});
PluginManager.registerCommand(pluginName, "setId", args => {
const id = parseInt(args.id);
$gameSystem.setMessageChracterSoundSEId(id);
});
//-----------------------------------------------------------------------------
// Game_System
//
// The game object class for the system data.
const _Game_System_initialize = Game_System.prototype.initialize;
Game_System.prototype.initialize = function() {
_Game_System_initialize.call(this);
this._messageCharacterSoundState = true;
this._messageChracterSoundSEId = GabeMZ.MessageCharacterSound.defaultSEId;
};
Game_System.prototype.messageCharacterSoundState = function() {
return this._messageCharacterSoundState;
};
Game_System.prototype.messageChracterSoundSEId = function() {
return this._messageChracterSoundSEId;
};
Game_System.prototype.setMessageCharacterSoundState = function(state) {
this._messageCharacterSoundState = state;
};
Game_System.prototype.setMessageChracterSoundSEId = function(id) {
this._messageChracterSoundSEId = id;
};
//-----------------------------------------------------------------------------
// Window_Message
//
// The window for displaying text messages.
const _Window_Message_initMembers = Window_Message.prototype.initMembers;
Window_Message.prototype.initMembers = function() {
_Window_Message_initMembers.call(this, ...arguments);
this._characterIndex = 0;
};
const _Window_Message_newPage = Window_Message.prototype.newPage;
Window_Message.prototype.newPage = function() {
_Window_Message_newPage.call(this, ...arguments)
this._characterIndex = 0;
};
const _Window_Message_processCharacter = Window_Message.prototype.processCharacter;
Window_Message.prototype.processCharacter = function() {
_Window_Message_processCharacter.call(this, ...arguments);
this._characterIndex++;
if (!$gameSystem.messageCharacterSoundState()) return;
const seSettings = GabeMZ.MessageCharacterSound.seList[$gameSystem.messageChracterSoundSEId() - 1];
const frequency = seSettings.frequency;
if (!(this._characterIndex % frequency)) this.playCharacterSound(seSettings);
};
Window_Message.prototype.playCharacterSound = function(seSettings) {
const name = seSettings.filename;
const volume = seSettings.volume;
const pitch = seSettings.pitch;
const pan = seSettings.pan;
const se = {
name: name,
volume: volume,
pitch: pitch,
pan: pan
}
AudioManager.playSe(se);
};
})();