//-----------------------------------------------------------------------------
// Spriteset_Fog
//
// The set of sprites of fogs used in map and battle.
function Spriteset_Fog() {
this.initialize(...arguments);
}
Spriteset_Fog.prototype = Object.create(Sprite.prototype);
Spriteset_Fog.prototype.constructor = Spriteset_Fog;
Spriteset_Fog.prototype.initialize = function() {
Sprite.prototype.initialize.call(this);
this.setFrame(0, 0, Graphics.width, Graphics.height);
this.createFogList();
};
Spriteset_Fog.prototype.createFogList = function() {
if (GabeMZ.FogEffects.currentMap == $gameMap.mapId()) {
GabeMZ.FogEffects.fogList.forEach( (fog, id) => {
if (fog) this.createFog(fog.id, id, fog);
});
} else {
GabeMZ.FogEffects.currentMap = $gameMap.mapId()
this.clearList();
const reg = /<addFog\s*(\d+):\s*(\d+)>/g;
let match;
while (match = reg.exec($dataMap.note)) {
this.createFog(match[2], match[1]);
}
}
};
Spriteset_Fog.prototype.update = function() {
Sprite.prototype.update.call(this);
if (GabeMZ.FogEffects.needRefresh) this.refreshFogList();
};
Spriteset_Fog.prototype.createFog = function(id, layer, fog) {
if (layer < 1) return;
const fogSetting = JSON.parse(GabeMZ.FogEffects.fogSettings[id - 1]);
const sprite = new Sprite_Fog(ImageManager.loadFogs(fogSetting.fogFilename));
sprite.move(-96, -96, Graphics.width + 192, Graphics.height + 192);
sprite.opacity = fog ? fog.opacity : parseInt(fogSetting.fogOpacity);
sprite.blendMode = parseInt(fogSetting.fogBlendMode);
sprite.origin.x = -96;
sprite.origin.y = -96;
sprite.speedX = -parseFloat(fogSetting.fogMoveX);
sprite.speedY = -parseFloat(fogSetting.fogMoveY);
sprite.id = id;
sprite.z = layer;
if (fog) {
sprite.constX = fog.constX;
sprite.constY = fog.constY;
sprite._opacityTarget = fog._opacityTarget;
sprite._opacityTime = fog._opacityTime;
sprite._tone = fog._tone;
sprite._toneTarget = fog._toneTarget;
sprite._toneTime = fog._toneTime;
}
this.addChild(sprite);
this._sortChildren();
GabeMZ.FogEffects.fogList[layer] = sprite;
};
Spriteset_Fog.prototype._sortChildren = function() {
this.children.sort(this._compareChildOrder.bind(this));
};
Spriteset_Fog.prototype._compareChildOrder = function(a, b) {
if (a.z !== b.z) {
return a.z - b.z;
} else if (a.y !== b.y) {
return a.y - b.y;
} else {
return a.spriteId - b.spriteId;
}
};
Spriteset_Fog.prototype.refreshFogList = function() {
if (GabeMZ.FogEffects.tempFog.length > 0) {
GabeMZ.FogEffects.tempFog.forEach(fog => {
this.removeChild(GabeMZ.FogEffects.fogList[fog[1]]);
GabeMZ.FogEffects.fogList[fog[1]] = null;
if (fog[0]) this.createFog(fog[0], fog[1]);
});
} else {
this.clearList();
}
GabeMZ.FogEffects.needRefresh = false;
};
Spriteset_Fog.prototype.clearList = function() {
GabeMZ.FogEffects.fogList.forEach(fog => {this.removeChild(fog)});
GabeMZ.FogEffects.fogList = [];
};