sakura-gozen/js/plugins/iii/IIIRepeatSprite.js
2025-01-14 14:06:54 -06:00

295 lines
8.5 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//=============================================================================
// IIIRepeatSprite.js
// ----------------------------------------------------------------------------
// (C) 2020 III
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
// ----------------------------------------------------------------------------
/*:ja
* @target MZ
* @plugindesc 画像の繰り返し表示機能
* @author iii
* @base PluginCommonBase
* @base TorigoyaMZ_FrameTween
*
* @param ByX
* @type number
* @desc 表示位置からの移動量X
* @default 0
*
* @param ByY
* @type number
* @desc 表示位置からの移動量Y
* @default -30
*
* @param InFrameCount
* @type number
* @desc 表示までのフレーム数1/60秒
* @default 60
*
* @param WaitFrameCount
* @type number
* @desc 表示した状態で待つフレーム数1/60秒
* @default 120
*
* @param OutFrameCount
* @type number
* @desc 非表示までのフレーム数1/60秒
* @default 60
*
* @param RepeatFrameCount
* @type number
* @desc 再表示までのフレーム数1/60秒
* @default 120
*
* @param HideSwitch
* @type switch
* @desc sss
* @default 0
*
* @command repeat
* @text 表示
* @desc 実行した分だけ表示されます
* @arg imageName
* @text 画像
* @type file
* @dir img/effect_sprite
*
* @arg pos
* @text 表示位置
* @type struct<Position>
*
* @command clear
* @text 表示されているすべての画像のクリア
*
* @help
* ・別プラグインのTorigoyaMZ_FrameTweenを利用させて頂いているのでそちらも設定お願いします。
* ・プラグインコマンドで画像を任意の位置に繰り返し表示します。
* ・移動時間はプラグインパラメータで指定しているInFrameCount, WaitFrameCount, OutFrameCountの合計フレーム数をかけて移動します。
* ・画像クリアのプラグインコマンドを実行しないと画面に残り続けます。
* ・MV標準のピクチャ管理とはまるっきり別のところで動かしているので、MVでのウエイトコマンドなどの影響を受けません。
* ・現状、マップ画面でのみ有効にしています。メニュー画面・バトル画面などで本プラグインコマンドを実行しても表示されません。
* ・このプラグインの利用にはベースプラグイン『PluginCommonBase.js』が必要です。
*  『PluginCommonBase.js』は、RPGツクールMZのインストールフォルダ配下の
*  以下のフォルダに格納されています。
*  dlc/BasicResources/plugins/official
*
*/
/*~struct~Position:
*
* @param x
* @text x座標
* @type number
* @default 0
* @param y
* @text y座標
* @type number
* @default 0
* ......
*/
(function () {
"use strict";
//
var $iiiRepeatSpriteContainer = null;
/**
* PluginCommand
*/
const script = document.currentScript;
const parameters = PluginManagerEx.createParameter(script);
PluginManagerEx.registerCommand(script, "repeat", (args) => {
let iniX = args.pos.x;
let iniY = args.pos.y;
let spriteName = args.imageName;
let byX = parameters.ByX;
let byY = parameters.ByY;
let inTime = parameters.InFrameCount;
let waitTime = parameters.WaitFrameCount;
let outTime = parameters.OutFrameCount;
let repeatTime = parameters.RepeatFrameCount;
let hideSwNo = parameters.HideSwitch;
if (hideSwNo > 0 && $gameSwitches.value(hideSwNo)) {
return;
}
$iiiRepeatSpriteContainer.addRepeatSprite(
spriteName,
iniX,
iniY,
byX,
byY,
inTime,
waitTime,
outTime,
repeatTime
);
});
PluginManagerEx.registerCommand(script, "clear", (args) => {
$iiiRepeatSpriteContainer.clearRepeatSprite();
});
//-----------------------------------------------------------------------------
// ImageManager
//
ImageManager.loadEffectSprite = function (filename, hue) {
return this.loadBitmap("img/effect_sprite/", filename, hue, true);
};
//-----------------------------------------------------------------------------
// Repeat_Sprite_Container
//
function Repeat_Sprite_Container() {
this.initialize.apply(this, arguments);
}
Repeat_Sprite_Container.prototype = Object.create(Sprite.prototype);
Repeat_Sprite_Container.prototype.constructor = Repeat_Sprite_Container;
Repeat_Sprite_Container.prototype.initialize = function (
battler,
standParams
) {
Sprite.prototype.initialize.call(this);
this._repeatSprites = [];
};
Repeat_Sprite_Container.prototype.addRepeatSprite = function (
spriteName,
iniX,
iniY,
byX,
byY,
inTime,
waitTime,
outTime,
repeatTime
) {
var sprite = new Repeat_Sprite(
spriteName,
iniX,
iniY,
byX,
byY,
inTime,
waitTime,
outTime,
repeatTime
);
this._repeatSprites.push(sprite);
this.addChild(sprite);
sprite.playRepeat();
};
Repeat_Sprite_Container.prototype.clearRepeatSprite = function () {
this._repeatSprites.forEach(function (sprite) {
sprite.stopRepeat();
this.removeChild(sprite);
}, this);
this._repeatSprites = [];
};
//-----------------------------------------------------------------------------
// Fade_Sprite
//
function Repeat_Sprite() {
this.initialize.apply(this, arguments);
}
Repeat_Sprite.prototype = Object.create(Sprite.prototype);
Repeat_Sprite.prototype.constructor = Repeat_Sprite;
Repeat_Sprite.prototype.initialize = function (
spriteName,
iniX,
iniY,
byX,
byY,
inTime,
waitTime,
outTime,
repeatTime
) {
Sprite.prototype.initialize.call(this);
this._initX = iniX | 0;
this._initY = iniY | 0;
this._offsetX = byX | 0;
this._offsetY = byY | 0;
this._inTime = inTime | 0;
this._waitTime = waitTime | 0;
this._outTime = outTime | 0;
this._repeatTime = repeatTime | 0;
this._anims = [];
this.bitmap = ImageManager.loadEffectSprite(spriteName);
this.anchor.x = 0.5;
this.anchor.y = 0.5;
this.opacity = 0;
this.x = this._initX;
this.y = this._initY;
};
Repeat_Sprite.prototype.playRepeat = function (onComplete) {
this.stopRepeat();
this._playRepeatTween();
};
Repeat_Sprite.prototype.stopRepeat = function (onComplete) {
if (this._anims && this._anims.length > 0) {
this._anims.forEach(function (anim) {
anim.abort();
});
}
this._anims = [];
};
Repeat_Sprite.prototype._playRepeatTween = function () {
this._anims = this._createRepeatTween();
this._anims.forEach(function (anim) {
anim.start();
});
};
Repeat_Sprite.prototype._createRepeatTween = function () {
const tw = Torigoya.FrameTween;
const twe = Torigoya.FrameTween.Easing;
var animTime = this._inTime + this._waitTime + this._outTime;
var fadeAnim = tw
.create(this)
.to({ opacity: 0 }, 0)
.to({ opacity: 255 }, this._inTime, twe.liner)
.wait(this._waitTime)
.to({ opacity: 0 }, this._outTime, twe.liner);
var moveAnim = tw
.create(this)
.to({ x: this._initX, y: this._initY }, 0)
.to(
{ x: this._initX + this._offsetX, y: this._initY + this._offsetY },
animTime,
twe.liner
);
var waitAnim = tw
.create(this)
.wait(animTime + this._repeatTime)
.call(
function () {
this.playRepeat();
}.bind(this)
);
return [fadeAnim, moveAnim, waitAnim];
};
//-----------------------------------------------------------------------------
// Scene_Map
//
var IIIScene_Map_prototype_start = Scene_Map.prototype.start;
Scene_Map.prototype.start = function () {
IIIScene_Map_prototype_start.call(this);
if ($iiiRepeatSpriteContainer == null) {
$iiiRepeatSpriteContainer = new Repeat_Sprite_Container();
} else {
$iiiRepeatSpriteContainer.clearRepeatSprite();
this.removeChild($iiiRepeatSpriteContainer);
$iiiRepeatSpriteContainer = new Repeat_Sprite_Container();
}
this.addChild($iiiRepeatSpriteContainer);
};
})();