/* --------------------------------------------------
Author: Anastasios Pallas / tcpallas@gmail.com
Version 1.0
Last Update: 2024-07-08
-------------------------------------------------- */


// Flame (normal)
var assets = [];
var spriteSheet;
var flame = new createjs.Sprite();

function handleFileLoad(event) {
    assets.push(event);
}

function handleComplete() {
    for (var i = 0; i < assets.length; i++) {
        var event = assets[i];
        var result = event.result;

        switch (event.item.id) {
            case 'flame':
                spriteSheet = result;
                break;
        }
    }
    
    initFlame();
}

function initFlame() {
	flame = new createjs.Sprite(spriteSheet, "run");
	flame.scaleY = 0.2;
	flame.scaleX = 0.2;
	flame.x = config.center_x + 305;
	flame.y = config.center_y + 105;
	flame.visible = false;
	stage.addChild(flame);
	stage.setChildIndex(flame, childIndex++);
	stage.update();
}

var manifest = [
    {src: "images/flame.json", id: "flame", type: "spritesheet"}
];

var loader = new createjs.LoadQueue(true, "./");
loader.on("fileload", handleFileLoad);
loader.on("complete", handleComplete);
loader.loadManifest(manifest);


// Flame Yellow
var assetsΥ = [];
var spriteSheetΥ;
var flameY = new createjs.Sprite();

function handleFileLoadΥ(event) {
    assetsΥ.push(event);
}

function handleCompleteY() {
    for (var i = 0; i < assetsΥ.length; i++) {
        var event = assetsΥ[i];
        var result = event.result;

        switch (event.item.id) {
            case 'flameY':
                spriteSheetΥ = result;
                break;
        }
    }
    
    initFlameY();
}

function initFlameY() {
	flameY = new createjs.Sprite(spriteSheetΥ, "run");
	flameY.scaleY = 0.2;
	flameY.scaleX = 0.2;
	flameY.x = config.center_x + 305;
	flameY.y = config.center_y + 105;
	flameY.visible = false;
	stage.addChild(flameY);
	stage.setChildIndex(flameY, childIndex++);
	stage.update();
}

var manifestΥ = [
    {src: "images/flame-yellow.json", id: "flameY", type: "spritesheet"}
];

var loaderΥ = new createjs.LoadQueue(true, "./");
loaderΥ.on("fileload", handleFileLoadΥ);
loaderΥ.on("complete", handleCompleteY);
loaderΥ.loadManifest(manifestΥ);


// Flame Red
var assetsR = [];
var spriteSheetR;
var flameR = new createjs.Sprite();

function handleFileLoadR(event) {
    assetsR.push(event);
}

function handleCompleteR() {
    for (var i = 0; i < assetsR.length; i++) {
        var event = assetsR[i];
        var result = event.result;

        switch (event.item.id) {
            case 'flameR':
                spriteSheetR = result;
                break;
        }
    }
    
    initFlameR();
}

function initFlameR() {
	flameR = new createjs.Sprite(spriteSheetR, "run");
	flameR.scaleY = 0.2;
	flameR.scaleX = 0.2;
	flameR.x = config.center_x + 305;
	flameR.y = config.center_y + 105;
	flameR.visible = false;
	stage.addChild(flameR);
	stage.setChildIndex(flameR, childIndex++);
	stage.update();
}

var manifestR = [
    {src: "images/flame-red.json", id: "flameR", type: "spritesheet"}
];

var loaderR = new createjs.LoadQueue(true, "./");
loaderR.on("fileload", handleFileLoadR);
loaderR.on("complete", handleCompleteR);
loaderR.loadManifest(manifestR);



// Flame Purple
var assetsP = [];
var spriteSheetP;
var flameP = new createjs.Sprite();

function handleFileLoadP(event) {
    assetsP.push(event);
}

function handleCompleteP() {
    for (var i = 0; i < assetsP.length; i++) {
        var event = assetsP[i];
        var result = event.result;

        switch (event.item.id) {
            case 'flameP':
                spriteSheetP = result;
                break;
        }
    }
    
    initFlameP();
}

function initFlameP() {
	flameP = new createjs.Sprite(spriteSheetP, "run");
	flameP.scaleY = 0.2;
	flameP.scaleX = 0.2;
	flameP.x = config.center_x + 305;
	flameP.y = config.center_y + 105;
	flameP.visible = false;
	stage.addChild(flameP);
	stage.setChildIndex(flameP, childIndex++);
	stage.update();
}

var manifestP = [
    {src: "images/flame-purple.json", id: "flameP", type: "spritesheet"}
];

var loaderP = new createjs.LoadQueue(true, "./");
loaderP.on("fileload", handleFileLoadP);
loaderP.on("complete", handleCompleteP);
loaderP.loadManifest(manifestP);


// Flame Green
var assetsG = [];
var spriteSheetG;
var flameG = new createjs.Sprite();

function handleFileLoadG(event) {
    assetsG.push(event);
}

function handleCompleteG() {
    for (var i = 0; i < assetsG.length; i++) {
        var event = assetsG[i];
        var result = event.result;

        switch (event.item.id) {
            case 'flameG':
                spriteSheetG = result;
                break;
        }
    }
    
    initFlameG();
}

function initFlameG() {
	flameG = new createjs.Sprite(spriteSheetG, "run");
	flameG.scaleY = 0.2;
	flameG.scaleX = 0.2;
	flameG.x = config.center_x + 305;
	flameG.y = config.center_y + 105;
	flameG.visible = false;
	stage.addChild(flameG);
	stage.setChildIndex(flameG, childIndex++);
	stage.update();
}

var manifestG = [
    {src: "images/flame-green.json", id: "flameG", type: "spritesheet"}
];

var loaderG = new createjs.LoadQueue(true, "./");
loaderG.on("fileload", handleFileLoadG);
loaderG.on("complete", handleCompleteG);
loaderG.loadManifest(manifestG);



// Flame Light Green
var assetsL = [];
var spriteSheetL;
var flameL = new createjs.Sprite();

function handleFileLoadL(event) {
    assetsL.push(event);
}

function handleCompleteL() {
    for (var i = 0; i < assetsL.length; i++) {
        var event = assetsL[i];
        var result = event.result;

        switch (event.item.id) {
            case 'flameL':
                spriteSheetL = result;
                break;
        }
    }
    
    initFlameL();
}

function initFlameL() {
	flameL = new createjs.Sprite(spriteSheetL, "run");
	flameL.scaleY = 0.2;
	flameL.scaleX = 0.2;
	flameL.x = config.center_x + 305;
	flameL.y = config.center_y + 105;
	flameL.visible = false;
	stage.addChild(flameL);
	stage.setChildIndex(flameL, childIndex++);
	stage.update();
}

var manifestL = [
    {src: "images/flame-light-green.json", id: "flameL", type: "spritesheet"}
];

var loaderL = new createjs.LoadQueue(true, "./");
loaderL.on("fileload", handleFileLoadL);
loaderL.on("complete", handleCompleteL);
loaderL.loadManifest(manifestL);

