Source: AnimationManager.js

/**
 * You will notice I use "path", "fileType", and "bossBattle" in my configs. You can ignore those. Those properties will never be used by a modder.
 * @typedef AnimationManager.animationConfig
 * @property {string} ID
 * @property {number} frameRate
 * @property {function|array} frames - Pass the createFrames function or a completed Phaser frames array into this parameter
 */

/**
 * @typedef AnimationManager.galleryObject
 * @property {string} thumbnail - The texture key of the thumbnail that is going to be used in the gallery, usually the first frame of the animation
 * @property {'Animation'|'Image'} type - The type of animation. Either a still "Image" or an "Animation"
 * @property {string} animationID - The animation ID for playing the animation
 */

/**
 * This class will let you handle all of the sex scenes
 * @class AnimationManager
 */
class AnimationManager {
    constructor() {
        this._animations = {};
        this._gallery = [];
    }

    /**
     * @method createAnimation
     * @memberOf AnimationManager
     * @instance
     * @param {AnimationManager.animationConfig} config
     * @example
     * // 27 frame animation. QueenThroatdefault00000 to QueenThroatdefault00026
     * GAME.animation.createAnimation({
     *     ID: "QueenThroatdefault",
     *     frameRate: 24,
     *     frames: () => {
     *          GAME.animation.createFrames('QueenThroatdefault', 0, 26, 5);
     *     }
     * });
     * @example
     * // Only one image in animation
     * GAME.animation.createAnimation({
     *     ID: "townFuckQuest3",
     *     frameRate: 1,
     *     frames: [{key: "townFuckQuest3"}]
     * }
     * @example
     * // Only two images in animation
     * GAME.animation.createAnimation({
     *     ID: "forestBeastQuest1",
     *     frameRate: 1,
     *     frames: [{key: 'forestBeastQuest1'}, {key: 'forestBeastQuest2'}]
     * }
     */
    createAnimation(config) {
        this._animations[config.ID] = {};
        this._animations[config.ID].ID = config.ID;
        this._animations[config.ID].frameRate = config.frameRate;

        if (typeof config.frames === "function") {
            this._animations[config.ID].frames = config.frames();
        } else {
            this._animations[config.ID].frames = config.frames;
        }

        if (config.hasOwnProperty('path')) {
            this._animations[config.ID].path = config.path;
        }

        if (config.hasOwnProperty('fileType')) {
            this._animations[config.ID].fileType = config.fileType;
        }

        if (config.hasOwnProperty('bossBattle')) {
            this._animations[config.ID].bossBattle = config.bossBattle;
        }
    }

    /**
     * Returns an animation object that Phaser can use
     * @method getAnimation
     * @memberOf AnimationManager
     * @instance
     * @param {string} animationID
     * @return {object}
     */
    getAnimation(animationID) {
        if (this._animations.hasOwnProperty(animationID)) {

            return {
                key: 'video',
                repeat: -1,
                frameRate: this._animations[animationID].frameRate,
                frames: this._animations[animationID].frames
            };
        } else {
            return false;
        }
    }

    /**
     * Launches the animation scene and plays the animation. Returns a promise so don't forget to resolve it
     * @method playAnimation
     * @memberOf AnimationManager
     * @instance
     * @param {string} animationID
     * @return {Promise<any>}
     */
    playAnimation(animationID) {
        return new Promise((resolve) => {
            game.scene.start('PlayVideo', {pauseAllScenes: true, video: animationID});
            game.scene.getScene('PlayVideo').events.once('shutdown', resolve);
        });
    }

    /**
     * Creates the frames array for the animation
     * @method createFrames
     * @memberOf AnimationManager
     * @instance
     * @param {string} animationID
     * @param {number} start - The starting frame of the animation, usually 0
     * @param {number} stop - The stopping frame of the animation. For example QueenThroatdefault ends on frame 26
     * @param {number} [pad=5] - Padding is how many 0s there are in the picture files. For example QueenThroatdefault00001 has 5 padding.
     * @return {Array}
     */
    createFrames(animationID, start, stop, pad) {
        pad = pad || 5;
        let frames = [];
        for (start; start <= stop; start++) {
            frames.push({key: animationID + start.toString().padStart(pad, "0")});
        }
        return frames;
    }


    /**
     * Returns an array of available gallery animations
     * @method getGallery
     * @memberOf AnimationManager
     * @instance
     * @return {Array}
     */
    getGallery() {
        let gallery = [];
        for (let i in this._gallery) {
            let array = this._gallery[i]();

            for (let obj in array) {
                gallery.push(array[obj]);
            }
        }
        return gallery;
    }

    /**
     * Add a function that returns an array of {@link AnimationManager.galleryObject}
     * @method addToGallery
     * @memberOf AnimationManager
     * @instance
     * @param {function} callback - Function must return an array
     */
    addToGallery(callback) {
        this._gallery.push(callback);
    }

    /**
     * The game's animations. Use this as a template for your own animations
     * @method _initAnimations
     * @memberOf AnimationManager
     * @instance
     * @private
     */
    _initAnimations() {
        // Will leave this method here as an example for mods
        // path, fileType, and "bossBattle" properties will never be used by modders, they are used for dynamic loading
        this.createAnimation({
            ID: 'battleNullImage',
            frameRate: 1,
            frames: [{key: 'battleNullImage'}],
            path: "assets/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'QueenThroatdefault',
            frameRate: 24,
            frames: this.createFrames('QueenThroatdefault', 0, 26, 5),
            path: "https://queens-brothel.s3.amazonaws.com/QueenThroatdefault/",
            fileType: ".jpg"
        });
        this.createAnimation({
            ID: 'townFuckQuest3',
            frameRate: 1,
            frames: [{key: 'townFuckQuest3'}],
            path: "assets/images/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'forestBeastQuest1',
            frameRate: 1,
            frames: [{key: 'forestBeastQuest1'}, {key: 'forestBeastQuest2'}],
            path: "assets/images/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'forestBeastQuest3',
            frameRate: 1,
            frames: [{key: 'forestBeastQuest3'}, {key: 'forestBeastQuest4'}],
            path: "assets/images/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'forestBeastQuest5',
            frameRate: 1,
            frames: [{key: 'forestBeastQuest5'}, {key: 'forestBeastQuest6'}],
            path: "assets/images/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'nirvokkLubeQuest1',
            frameRate: 1,
            frames: [{key: 'nirvokkLubeQuest1'}],
            path: "assets/images/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'sukiQuest1',
            frameRate: 1,
            frames: [{key: 'sukiQuest1'}],
            path: "assets/images/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'sukiQuest2',
            frameRate: 1,
            frames: [{key: 'sukiQuest2'}, {key: 'sukiQuest3'}],
            path: "assets/images/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'sukiQuest4',
            frameRate: 1,
            frames: [{key: 'sukiQuest4'}, {key: 'sukiQuest5'}],
            path: "assets/images/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'sukiQuest6',
            frameRate: 1,
            frames: [{key: 'sukiQuest6'}],
            path: "assets/images/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'sukiQuest7',
            frameRate: 1,
            frames: [{key: 'sukiQuest7'}],
            path: "assets/images/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'sukiQuest8',
            frameRate: 1,
            frames: [{key: 'sukiQuest8'}],
            path: "assets/images/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'enterMorassQuest1',
            frameRate: 1,
            frames: [{key: 'enterMorassQuest1'}],
            path: "assets/images/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'enterMorassQuest2',
            frameRate: 1,
            frames: [{key: 'enterMorassQuest2'}, {key: 'enterMorassQuest3'}],
            path: "assets/images/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'enterMorassQuest4',
            frameRate: 1,
            frames: [{key: 'enterMorassQuest4'}, {key: 'enterMorassQuest5'}],
            path: "assets/images/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'principalHandjobQuest1',
            frameRate: 1,
            frames: [{key: 'principalHandjobQuest1'}],
            path: "assets/images/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'principalFeetQuest1',
            frameRate: 1,
            frames: [{key: 'principalFeetQuest1'}],
            path: "assets/images/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'principalFeetQuest2',
            frameRate: 1,
            frames: [{key: 'principalFeetQuest2'}, {key: 'principalFeetQuest3'}],
            path: "assets/images/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'morassInnCumKiss1',
            frameRate: 1,
            frames: [{key: 'morassInnCumKiss1'}],
            path: "assets/images/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'swampBeastQuest5',
            frameRate: 1,
            frames: [{key: 'swampBeastQuest5'}, {key: 'swampBeastQuest6'}],
            path: "assets/images/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'swampBeastQuest7',
            frameRate: 1,
            frames: [{key: 'swampBeastQuest7'}],
            path: "assets/images/",
            fileType: ".png"
        });
        this.createAnimation({
            ID: 'forestBeastQuestBoss1',
            frameRate: 1,
            frames: [{key: 'forestBeastQuestBoss1'}, {key: 'forestBeastQuestBoss2'}],
            path: "assets/images/",
            fileType: ".png",
            bossBattle: "forestBeastQuest"
        });
        this.createAnimation({
            ID: 'forestBeastQuestBoss3',
            frameRate: 1,
            frames: [{key: 'forestBeastQuestBoss3'}, {key: 'forestBeastQuestBoss4'}],
            path: "assets/images/",
            fileType: ".png",
            bossBattle: "forestBeastQuest"
        });
        this.createAnimation({
            ID: 'forestBeastQuestBoss5',
            frameRate: 1,
            frames: [{key: 'forestBeastQuestBoss5'}, {key: 'forestBeastQuestBoss6'}],
            path: "assets/images/",
            fileType: ".png",
            bossBattle: "forestBeastQuest"
        });
        this.createAnimation({
            ID: 'wildGoblinFasterPussy',
            frameRate: 24,
            frames: this.createFrames('wildGoblinFasterPussy', 0, 13, 5),
            path: "https://queens-brothel.s3.amazonaws.com/GoblinBoss/",
            fileType: ".jpg",
            bossBattle: "swampBeastQuest"
        });
        this.createAnimation({
            ID: 'wildGoblinFasterFeet',
            frameRate: 24,
            frames: this.createFrames('wildGoblinFasterFeet', 0, 12, 5),
            path: "https://queens-brothel.s3.amazonaws.com/GoblinBoss/",
            fileType: ".jpg",
            bossBattle: "swampBeastQuest"
        });
        this.createAnimation({
            ID: 'peasantKingsQuestFuck',
            frameRate: 24,
            frames: this.createFrames('kingsQuestBossFuck', 0, 18, 5),
            path: "https://queens-brothel.s3.amazonaws.com/KingBoss/",
            fileType: ".jpg",
            bossBattle: "peasantKingsQuest"
        });
        this.createAnimation({
            ID: 'kingsQuestBossFuck',
            frameRate: 24,
            frames: this.createFrames('kingsQuestBossFuck', 0, 18, 5),
            path: "https://queens-brothel.s3.amazonaws.com/KingBoss/",
            fileType: ".jpg",
            bossBattle: "kingsQuest"
        });
        this.createAnimation({
            ID: 'kingsQuestBossFuckMilk',
            frameRate: 24,
            frames: this.createFrames('kingsQuestBossFuckMilk', 0, 18, 5),
            path: "https://queens-brothel.s3.amazonaws.com/KingBoss/",
            fileType: ".jpg",
            bossBattle: "kingsQuest"
        });
        this.createAnimation({
            ID: 'kingsQuestBossSuck',
            frameRate: 24,
            frames: this.createFrames('kingsQuestBossSuck', 0, 16, 5),
            path: "https://queens-brothel.s3.amazonaws.com/KingBoss/",
            fileType: ".jpg",
            bossBattle: "kingsQuest"
        });
        this.createAnimation({
            ID: 'aviaGuard2Fuck',
            frameRate: 24,
            frames: this.createFrames('aviaGuard2Fuck', 0, 18, 5),
            path: "https://queens-brothel.s3.amazonaws.com/BattleOrcs/",
            fileType: ".jpg",
            bossBattle: "battleOrcs"
        });
        this.createAnimation({
            ID: 'aviaGuard2Cum',
            frameRate: 24,
            frames: this.createFrames('aviaGuard2Cum', 0, 75, 5),
            path: "https://queens-brothel.s3.amazonaws.com/BattleOrcs/",
            fileType: ".jpg",
            bossBattle: "battleOrcs"
        });
    }

    /**
     * The game's gallery functions. Use this as a template for your own gallery conditions
     * @method _initGallery
     * @memberOf AnimationManager
     * @instance
     * @private
     */
    _initGallery() {
        this.addToGallery(function () {
            // Town Fuck Quest
            if (GAME.quest.isComplete('townFuckQuest', 'Completed') === true) {
                return [{
                    thumbnail: 'QueenThroatdefault00000',
                    type: 'Animation',
                    animationID: 'QueenThroatdefault'
                }, {
                    thumbnail: 'townFuckQuest3',
                    type: 'Image',
                    animationID: 'townFuckQuest3'
                }];
            }
        });
        this.addToGallery(function () {
            // Forest Beast Quest
            if (GAME.quest.isComplete('forestBeastQuest', 'Completed') === true) {
                return [{
                    thumbnail: 'forestBeastQuest1',
                    type: 'Animation',
                    animationID: 'forestBeastQuest1'
                }, {
                    thumbnail: 'forestBeastQuest3',
                    type: 'Animation',
                    animationID: 'forestBeastQuest3'
                }, {
                    thumbnail: 'forestBeastQuest5',
                    type: 'Animation',
                    animationID: 'forestBeastQuest5'
                }];
            }
        });
        this.addToGallery(function () {
            // Nirvokk Lube Quest
            if (GAME.quest.isComplete('nirvokkLubeQuest', 'Completed') === true) {
                return [{
                    thumbnail: 'nirvokkLubeQuest1',
                    type: 'Image',
                    animationID: 'nirvokkLubeQuest1'
                }];
            }
        });
        this.addToGallery(function () {
            // Principal Handjob Quest
            if (GAME.quest.isComplete('principalHandjobQuest', 'Completed') === true) {
                return [{
                    thumbnail: 'principalHandjobQuest1',
                    type: 'Image',
                    animationID: 'principalHandjobQuest1'
                }];
            }
        });
        this.addToGallery(function () {
            // Suki Quest
            if (GAME.quest.isComplete('sukiQuest', 'Completed') === true) {
                return [{
                    thumbnail: 'sukiQuest1',
                    type: 'Image',
                    animationID: 'sukiQuest1'
                }, {
                    thumbnail: 'sukiQuest2',
                    type: 'Animation',
                    animationID: 'sukiQuest2'
                }, {
                    thumbnail: 'sukiQuest4',
                    type: 'Animation',
                    animationID: 'sukiQuest4'
                }, {
                    thumbnail: 'sukiQuest6',
                    type: 'Image',
                    animationID: 'sukiQuest6'
                }, {
                    thumbnail: 'sukiQuest7',
                    type: 'Image',
                    animationID: 'sukiQuest7'
                }, {
                    thumbnail: 'sukiQuest8',
                    type: 'Image',
                    animationID: 'sukiQuest8'
                }];
            }
        });
        this.addToGallery(function () {
            // Enter Morass Quest
            if (GAME.quest.isComplete('enterMorassQuest', 'Completed') === true) {
                return [{
                    thumbnail: 'enterMorassQuest1',
                    type: 'Image',
                    animationID: 'enterMorassQuest1'
                }, {
                    thumbnail: 'enterMorassQuest2',
                    type: 'Animation',
                    animationID: 'enterMorassQuest2'
                }, {
                    thumbnail: 'enterMorassQuest4',
                    type: 'Animation',
                    animationID: 'enterMorassQuest4'
                }];
            }
        });
        this.addToGallery(function () {
            // Principal Feet Quest
            if (GAME.quest.isComplete('principalFeetQuest', 'Completed') === true) {
                return [{
                    thumbnail: 'principalFeetQuest1',
                    type: 'Image',
                    animationID: 'principalFeetQuest1'
                }, {
                    thumbnail: 'principalFeetQuest2',
                    type: 'Animation',
                    animationID: 'principalFeetQuest2'
                }];
            }
        });
        this.addToGallery(function () {
            // Morass Cum Kiss
            if (GAME.quest.isComplete('morassInnCumKiss', 'Completed') === true) {
                return [{
                    thumbnail: 'morassInnCumKiss1',
                    type: 'Image',
                    animationID: 'morassInnCumKiss1'
                }];
            }
        });
        this.addToGallery(function () {
            // Swamp Beast Quest
            if (GAME.quest.isComplete('swampBeastQuest', 'Completed') === true) {
                return [{
                    thumbnail: 'swampBeastQuest5',
                    type: 'Animation',
                    animationID: 'swampBeastQuest5'
                }, {
                    thumbnail: 'swampBeastQuest7',
                    type: 'Image',
                    animationID: 'swampBeastQuest7'
                }, {
                    thumbnail: 'wildGoblinFasterPussy00000',
                    type: 'Animation',
                    animationID: 'wildGoblinFasterPussy'
                }, {
                    thumbnail: 'wildGoblinFasterFeet00000',
                    type: 'Animation',
                    animationID: 'wildGoblinFasterFeet'
                }];
            }
        });
        this.addToGallery(function () {
            // Kings Quest
            if (GAME.quest.isComplete('kingsQuest', 'Completed') === true) {
                return [{
                    thumbnail: 'kingsQuestBossFuck00000',
                    type: 'Animation',
                    animationID: 'kingsQuestBossFuck'
                }, {
                    thumbnail: 'kingsQuestBossFuckMilk00000',
                    type: 'Animation',
                    animationID: 'kingsQuestBossFuckMilk'
                }, {
                    thumbnail: 'kingsQuestBossSuck00000',
                    type: 'Animation',
                    animationID: 'kingsQuestBossSuck'
                }];
            }
        });
        this.addToGallery(function () {
            // Battle Orcs
            if (GAME.quest.isComplete('battleOrcs', 'Completed') === true) {
                return [{
                    thumbnail: 'aviaGuard2Fuck00000',
                    type: 'Animation',
                    animationID: 'aviaGuard2Fuck'
                }, {
                    thumbnail: 'aviaGuard2Cum00000',
                    type: 'Animation',
                    animationID: 'aviaGuard2Cum'
                }];
            }
        });
    }

    /**
     * Returns the animations used for a boss battle
     * @method getBossAnimations
     * @memberOf AnimationManager
     * @instance
     * @param {string} bossID
     */
    getBossAnimations(bossID) {
        let array = [];

        for (let i in GAME.animation._animations) {
            if (GAME.animation._animations[i].hasOwnProperty('bossBattle')) {
                if (GAME.animation._animations[i].bossBattle === bossID) {
                    array.push(GAME.animation._animations[i]);
                }
            }
        }

        return array;
    }
}