File size: 10,614 Bytes
99b0de1 | 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 | /*=============================================================================
AnimationMv.js
----------------------------------------------------------------------------
(C)2020 Triacontane
This software is released under the MIT License.
http://opensource.org/licenses/mit-license.php
----------------------------------------------------------------------------
Version
1.2.3 2021/02/14 使用素材リストのパラメータに効果音を追加
1.2.2 2020/11/30 英訳版ヘルプをご提供いただいて追加
1.2.1 2020/11/07 1.2.0の修正によりコピー用のプロジェクトを指定しないとエラーになる問題を修正
1.2.0 2020/10/16 コピー処理を非同期処理に変更。MVプロジェクトからの自動移行が高速になりました。
VisuMZ_1_BattleCore.js利用時、画面全体に表示するアニメーションが左上に表示されるバグを代わりに修正
1.1.1 2020/08/29 1.1.0の修正でブラウザ実行でエラーになっていた問題を修正
1.1.0 2020/08/16 MVプロジェクトを指定するだけで必要ファイルを自動コピーできる機能を追加
1.0.0 2020/06/15 初版
----------------------------------------------------------------------------
[Blog] : https://triacontane.blogspot.jp/
[Twitter]: https://twitter.com/triacontane/
[GitHub] : https://github.com/triacontane/
=============================================================================*/
/*:
* @target MZ
* @plugindesc MV Animation Plugin
* @author Triacontane
* @base PluginCommonBase
* @orderAfter PluginCommonBase
* @url https://github.com/triacontane/RPGMakerMV/tree/mz_master/AnimationMv.js
*
* @param AnimationList
* @text Animation List
* @desc The list of the animation material to be used. Registering it will exclude it from the "Exclude unused files" option.
* @default []
* @dir img/animations/
* @type file[]
*
* @param SeList
* @text SE List
* @desc The list of the SE material to be used. Registering it will exclude it from the "Exclude unused files" option.
* @default []
* @dir audio/se/
* @type file[]
*
* @param MvProjectPathText
* @text The absolute path of MV project.
* @desc The path of the MV project to edit the animation. If you leave it empty, auto-copying will be disabled.
* @default
*
* @param NoCopyImageFile
* @text Images do not copy
* @desc No longer auto-copy animated image files. Useful if the copying is taking a long time.
* @default false
* @type boolean
*
* @help AnimationMv.js
* It can be used in conjunction with the new MZ playback method with the MV animation playback method.
*
* Editing the animation data in the editor of RPGMaker MV
* Specify the path to your MV project from the parameter.
* During test play, the images under "img/animations" and "data/Animations.json"
* will be stored in it will be copied automatically into your MZ project.
* Animations.json" will be copied to "mv/Animations.json".
*
* Particle Effects, Sound Effects, and Flash in the MZ database.
* If it is created with everything empty (i.e., newly created), it will play the animation of the MV.
*
* This plugin uses the global variable "$dataMvAnimations".
*
* User Agreement:
* You may alter or redistribute the plugin without permission. There are no restrictions on usage format
* (such as adult- or commercial-use only).
* This plugin is now all yours.
*/
/*:ja
* @target MZ
* @plugindesc MVアニメーションプラグイン
* @author トリアコンタン
* @base PluginCommonBase
* @orderAfter PluginCommonBase
* @url https://github.com/triacontane/RPGMakerMV/tree/mz_master/AnimationMv.js
*
* @param AnimationList
* @text アニメーションリスト
* @desc 使用するアニメーション素材のリストです。登録しておけば未使用素材削除の対象から外れます。
* @default []
* @dir img/animations/
* @type file[]
*
* @param SeList
* @text 効果音リスト
* @desc 使用する効果音素材のリストです。登録しておけば未使用素材削除の対象から外れます。
* @default []
* @dir audio/se/
* @type file[]
*
* @param MvProjectPathText
* @text MVプロジェクトの絶対パス
* @desc アニメーションを編集するMVプロジェクトのパスです。空にすると自動コピーが無効になります。
* @default
*
* @param NoCopyImageFile
* @text 画像はコピーしない
* @desc アニメーション画像ファイルを自動コピーしなくなります。コピーに時間が掛かっている場合に有効です。
* @default false
* @type boolean
*
* @help AnimationMv.js
* RPGツクールMVのアニメーション再生方式と新しいMZの再生方式との併用できます。
*
* RPGツクールMVのエディタでアニメーションデータを編集して、
* パラメータからMVプロジェクトのパスを指定してください。
* テストプレー時に『img/animations』以下の画像と『data/Animations.json』が
* MZプロジェクトに自動でコピーされます。
* 『Animations.json』は『mv/Animations.json』にコピーされます。
*
* MZ側のデータベースで『パーティクルエフェクト』『効果音』『フラッシュ』を
* 全て空の状態(新規作成の状態)で作成すると、MVのアニメーションを再生します。
*
* 本プラグインはグローバル変数『$dataMvAnimations』を使用します。
*
* 利用規約:
* 作者に無断で改変、再配布が可能で、利用形態(商用、18禁利用等)
* についても制限はありません。
* このプラグインはもうあなたのものです。
*/
(() => {
'use strict';
const script = document.currentScript;
const param = PluginManagerEx.createParameter(script);
const variableName = '$dataMvAnimations';
const variableSrc = 'mv/Animations.json';
/**
* MvFileCopyUtil
* MVのプロジェクトからファイルをコピーするユーティリティクラスです。
*/
class MvFileCopyUtil {
static async copyMvAnimationData() {
if (!this.isAnyTest() || !param.MvProjectPathText) {
DataManager.loadDataFile(variableName, variableSrc);
return false;
}
await this.copyAllFiles('data/', 'data/mv/', /Animations.json/);
DataManager.loadDataFile(variableName, variableSrc);
if (!param.NoCopyImageFile) {
await this.copyAllFiles('img/animations/', 'img/animations/');
}
return true;
}
static fileDirectoryPath(directory) {
const path = require('path');
const base = path.dirname(process.mainModule.filename);
return path.join(base, `${directory}/`);
}
static async copyAllFiles(src, dist, regExp) {
const srcPath = require('path').join(param.MvProjectPathText, src);
const destPath = this.fileDirectoryPath(dist);
const copyModel = new FileCopyModel(srcPath, destPath);
await copyModel.copyAllFiles(regExp);
}
static isAnyTest() {
return Utils.isNwjs() &&
(Utils.isOptionValid('test') || DataManager.isBattleTest() || DataManager.isEventTest());
}
}
/**
* FileCopyModel
* 再帰的な非同期ファイルコピーを実装します。
*/
class FileCopyModel {
constructor(src, dist) {
this._fs = require('fs').promises;
this._src = src;
this._dist = dist;
}
async copyAllFiles(fileReqExp = null) {
await this._fs.mkdir(this._dist, {recursive: true});
const dirents = await this._fs.readdir(this._src, {withFileTypes: true});
for (const dirent of dirents) {
const name = dirent.name;
if (fileReqExp && !fileReqExp.test(name)) {
continue;
}
if (dirent.isDirectory()) {
await this._copyDirectory(name + '/');
} else {
await this._copyFile(name);
}
}
}
async _copyDirectory(dirName) {
const path = require('path');
const src = path.join(this._src, dirName);
const dist = path.join(this._dist, dirName);
await this._fs.mkdir(dist, {recursive: true});
const subCopyModel = new FileCopyModel(src, dist);
await subCopyModel.copyAllFiles();
}
async _copyFile(fileName) {
const src = this._src + fileName;
const dist = this._dist + fileName;
await this._fs.copyFile(src, dist);
}
}
const _DataManager_loadDatabase = DataManager.loadDatabase;
DataManager.loadDatabase = function() {
this.loadAnimationData();
_DataManager_loadDatabase.apply(this, arguments);
};
DataManager.loadAnimationData = function() {
MvFileCopyUtil.copyMvAnimationData().then(result => {
if (result) {
console.log('Animation file copy complete.');
}
}).catch(error => {
if (error.code === 'ENOENT') {
PluginManagerEx.throwError(`Invalid MV Project Path :${param.MvProjectPathText}`, script);
} else {
throw error;
}
});
};
const _Spriteset_Base_createAnimation = Spriteset_Base.prototype.createAnimation;
Spriteset_Base.prototype.createAnimation = function(request) {
const mzAnimations = $dataAnimations;
if (isEmptyAnimation($dataAnimations[request.animationId])) {
$dataAnimations = window[variableName];
}
_Spriteset_Base_createAnimation.apply(this, arguments);
$dataAnimations = mzAnimations;
};
function isEmptyAnimation(animation) {
return animation &&
!animation.effectName &&
animation.flashTimings.length === 0 &&
animation.soundTimings.length === 0;
}
const _Sprite_AnimationMV_updatePosition = Sprite_AnimationMV.prototype.updatePosition;
Sprite_AnimationMV.prototype.updatePosition = function() {
_Sprite_AnimationMV_updatePosition.apply(this, arguments);
if (this._animation.position === 3) {
this.x = Graphics.boxWidth / 2;
this.y = Graphics.boxHeight / 2;
}
}
})();
|