-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathRS_VideoVolume.js
135 lines (117 loc) · 4.16 KB
/
RS_VideoVolume.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
//================================================================
// RS_VideoVolume.js
// ---------------------------------------------------------------
// The MIT License
// Copyright (c) 2019 biud436
// ---------------------------------------------------------------
// Free for commercial and non commercial use.
//================================================================
/*:
* @plugindesc <RS_VideoVolume>
* @author biud436
*
* @param Settings
*
* @param Volume
* @parent Settings
* @type number
* @min 0
* @max 100
* @desc Specify the video volume is the percent between 0 and 100.
* @default 100
*
* @param Type
* @parent Settings
* @type string
* @desc Specify the name of the video option button to game option.
* @default Video
*
* @help
* To change the volume of the video element in your game project,
* You can call the plugin command called 'SetVideoVolume' and easy to change.
*
* SetVideoVolume volume
*
* - volume : this value is the number between 0 and 100.
*
* The volume of the video element is saved to global configurable file.
*/
var Imported = Imported || {};
Imported.RS_VideoVolume = true;
var RS = RS || {};
RS.VideoVolume = RS.VideoVolume || {};
(function($) {
"use strict";
var parameters = $plugins.filter(function (i) {
return i.description.contains('<RS_VideoVolume>');
});
parameters = (parameters.length > 0) && parameters[0].parameters;
// Sets this initial value you didn't set up the volume to game option.
var volume = Number(parameters["Volume"]) || 0;
/**
* @method setVideoVolume
* @param {Number} vol the volume is the number between 0 and 100
*/
Graphics.setVideoVolume = function(vol) {
vol = vol || 0;
vol = vol.clamp(0, 100);
if(!this._video) return;
this._video.volume = vol * 0.01;
};
/**
* Get the video volume can invoke in the game option and save it.
* @return {Number} volume the value is the number between 0 and 100
*/
Graphics.getVideoVolume = function() {
if(!this._video) return null;
return this._video.volume * 100;
};
var alias_Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
alias_Game_Interpreter_pluginCommand.call(this, command, args);
if(command === "SetVideoVolume") {
var vol = Number(args[0]) || 0;
Graphics.setVideoVolume(vol);
}
};
//=====================================================================
// ConfigManager
//=====================================================================
Object.defineProperty(ConfigManager, 'videoVolume', {
get: function() {
return Graphics.getVideoVolume();
},
set: function(value) {
Graphics.setVideoVolume(value);
},
configurable: true
});
var alias_makeData = ConfigManager.makeData;
ConfigManager.makeData = function() {
var config = alias_makeData.call(this);
config.videoVolume = this.videoVolume;
return config;
};
var alias_applyData = ConfigManager.applyData;
ConfigManager.applyData = function(config) {
alias_applyData.call(this, config);
this.videoVolume = this.readVideoVolume(config, 'videoVolume');
};
ConfigManager.readVideoVolume = function(config, name) {
var value = config[name];
if (value !== undefined) {
return Number(value).clamp(0, 100);
} else {
// if there is no changes in the game option, it sets with the initial volume you set up.
return volume;
}
};
//=====================================================================
// Window_Options
//=====================================================================
var alias_addVolumeOptions = Window_Options.prototype.addVolumeOptions;
Window_Options.prototype.addVolumeOptions = function() {
alias_addVolumeOptions.call(this);
this.addCommand("Video", 'videoVolume');
};
})(RS.VideoVolume);