Unlimited and Optimized Pictures handle

Unlimited and Optimized Pictures handle​

Introduction
These are just some modifications in the original script.

Features
Remove the auto created (100 default) image objects, and create the image objects dynamically, and when the "erase Picture" is called, it also erase the object.

This doesn't create a object with empty values, it only relocate space for the used images.
So, even if you use, "$gameScreen.showPicture(9999999,"Image_Name", 0, x, y, 100, 100, 255, 0);" it will not make the variable size 9999999.


How to Use
Just save the script as a .js file and add it to your project.

Plugin Commands / Script Calls
The same from original.
As the engine has a limite of 100 when calling throug "Show Picture", use "$gameScreen.showPicture" function.
Example:
JavaScript:
$gameScreen.showPicture(
  id, name, origin, x, y, scaleX, scaleY, opacity, blendMode);
//Like
$gameScreen.showPicture(9999999,"Image_Name", 0, x, y, 100, 100, 255, 0);
You can use any "id" you want.
Like:
JavaScript:
$gameScreen.showPicture("Nun","People2_6", 1, 0, 0, 100, 100, 255, 0);
$gameScreen.showPicture("Doggy","Nature_1", 1, 0, 0, 100, 100, 255, 0);

Script
JavaScript:
var ImageController = undefined;

Game_Screen.prototype.maxPictures = function() {
    return 0;  // Added Line to remove the auto created pictures object
};

Spriteset_Base.prototype.initialize = function() {
    Sprite.prototype.initialize.call(this);
    this.setFrame(0, 0, Graphics.width, Graphics.height);
    this.loadSystemImages();
    this.createLowerLayer();
    this.createUpperLayer();
    this._animationSprites = [];
    ImageController = this; //Added line only to set the ImageController variable
};

Game_Screen.prototype.showPicture = function(pictureId, name, origin, x, y, scaleX, scaleY, opacity, blendMode) {
    const realPictureId = this.realPictureId(pictureId);
    if(ImageController._pictureContainer.children.find(picture => picture._pictureId == realPictureId) == undefined) {//Added line to check if the picture already exist
        ImageController._pictureContainer.addChild(new Sprite_Picture(realPictureId))  //Added line to create the picture object and add it to the container
        const picture = new Game_Picture();
        picture.show(name, origin, x, y, scaleX, scaleY, opacity, blendMode);
        picture.id = realPictureId;
        if(this._pictures.length > 0)
            {
                const ThisPictureIndex = this._pictures.indexOf(this._pictures.find(picture => picture === undefined));
                if(ThisPictureIndex != -1) {
                    this._pictures[ThisPictureIndex] = picture;
                    return;
                } else {
                    this._pictures.push(picture);
                    return;
                }
            }
        else
            this._pictures.push(picture)
    } else {
        $gameScreen.erasePicture(realPictureId);
        $gameScreen.showPicture(pictureId, name, origin, x, y, scaleX, scaleY, opacity, blendMode);
    }
};

Game_Screen.prototype.picture = function(pictureId) {
    const realPictureId = this.realPictureId(pictureId);
    return this._pictures.find(function(picture) {
        if(picture)
            return picture.id === realPictureId
        else
            return false;
    });
};

Sprite_Picture.prototype.remove = function() {
    this.parent.removeChild(this);
};

Game_Screen.prototype.erasePicture = function(pictureId) {
    const realPictureId = this.realPictureId(pictureId);
    this._pictures[this._pictures.indexOf($gameScreen.picture(realPictureId))] = undefined;
    //this._pictures[realPictureId] = null;
    const picture = ImageController._pictureContainer.children.find(picture => picture._pictureId == realPictureId);
    if(picture)
        picture.remove(); //Added line to remove the picture object from the container
};

Game_Screen.prototype.realPictureId = function(pictureId) {
    return pictureId;   //This was changed to only return the same pictureId inserted, function was not removed to keep compatibility with other plugins
};

Terms and Credits
Use it however you like, no need to give me credit, since it's just a modification of the original script.
Update to wait for approval.
would this work in MV too? or is it slightly different?
if it is, would you make that version too for MV users?

as it can be extremely usefull 🙂
would this work in MV too? or is it slightly different?
if it is, would you make that version too for MV users?

as it can be extremely usefull 🙂

I'm not really sure about it, gonna download the engine and check it, if isn't gonna try make a MV version of it.

Original thread: https://forums.rpgmakerweb.com/threads/unlimited-and-optimized-pictures-handle.147871/