// This method loads the player character
        // Recieves a line of serialized player data
        private void LoadPlayer(string line)
        {
            InvokeOnMain(() =>
            {
                // Create variables to store character properties.
                // Order of serialized is:
                // Class,HeldWeapon,Armor,Health,MaxHealth,Score,X,Y,Z
                string[] props      = line.Split(',');
                var playerClass     = props[0];
                var playerWeapon    = props[1];
                var playerArmor     = props[2];
                var playerHealth    = props[3];
                var playerMaxHealth = props[4];
                var playerScore     = props[5];

                string[] position = props.Skip(6).Take(3).ToArray();
                float x           = float.Parse(position[0], CultureInfo.InvariantCulture.NumberFormat);
                float y           = float.Parse(position[1], CultureInfo.InvariantCulture.NumberFormat);
                float z           = float.Parse(position[2], CultureInfo.InvariantCulture.NumberFormat);

                // Determine CharacterClass
                switch (playerClass)
                {
                case "Gunner":
                    charClass = CharacterClass.Gunner;
                    break;

                case "Support":
                    charClass = CharacterClass.Support;
                    break;

                case "Tank":
                    charClass = CharacterClass.Tank;
                    break;
                }

                // Create default player with correct class
                CreatePlayer(x, y);

                // Determine HeldWeapon
                Weapon heldWeapon = new WeaponKnife();
                switch (playerWeapon)
                {
                case "Royale_Platformer.Model.WeaponKnife":
                    heldWeapon = new WeaponKnife();
                    break;

                case "Royale_Platformer.Model.WeaponPistol":
                    heldWeapon = new WeaponPistol();
                    PlayerCharacter.PlayerSpriteAttack = PlayerCharacter.PlayerImage2;
                    break;

                case "Royale_Platformer.Model.WeaponPistolShield":
                    heldWeapon = new WeaponPistolShield();
                    PlayerCharacter.PlayerSpriteAttack = PlayerCharacter.PlayerImage2;
                    break;

                case "Royale_Platformer.Model.WeaponShotgun":
                    heldWeapon = new WeaponShotgun();
                    PlayerCharacter.PlayerSpriteAttack = PlayerCharacter.PlayerImage2;
                    break;

                case "Royale_Platformer.Model.WeaponAdvancedShotgun":
                    heldWeapon = new WeaponAdvancedShotgun();
                    PlayerCharacter.PlayerSpriteAttack = PlayerCharacter.PlayerImage2;
                    break;

                case "Royale_Platformer.Model.WeaponAR":
                    heldWeapon = new WeaponAR();
                    PlayerCharacter.PlayerSpriteAttack = PlayerCharacter.PlayerImage2;
                    break;

                case "Royale_Platformer.Model.WeaponAdvancedAR":
                    heldWeapon = new WeaponAdvancedAR();
                    PlayerCharacter.PlayerSpriteAttack = PlayerCharacter.PlayerImage2;
                    break;
                }

                // Update Player
                PlayerCharacter.MaxHealth  = Convert.ToInt32(playerMaxHealth);
                PlayerCharacter.Position   = new Vector3(x, y, z);
                PlayerCharacter.Health     = Convert.ToInt32(playerHealth);
                PlayerCharacter.HeldWeapon = heldWeapon;
                PlayerCharacter.Armor      = playerArmor == "True" ? true : false;
                PlayerCharacter.Score      = Convert.ToInt32(playerScore);

                // Update Camera
                cameraNode.Parent   = PlayerCharacter.WorldNode;
                cameraNode.Position = new Vector3(x, y, -1);
            });
        }
        // This method loads the enemy characters
        // Recieves a line of serialized character data
        private void LoadEnemies(string line)
        {
            InvokeOnMain(() =>
            {
                // Load each enemy
                string[] enemiesSplit = line.Split(';');
                foreach (var enemy in enemiesSplit.Take(enemiesSplit.Length - 1))
                {
                    // Create variables to store character properties.
                    // Order of serialized is:
                    // Class,HeldWeapon,Armor,Health,MaxHealth,Score,X,Y,Z
                    string[] props     = enemy.Split(',');
                    var enemyClass     = props[0];
                    var enemyWeapon    = props[1];
                    var enemyArmor     = props[2];
                    var enemyHealth    = props[3];
                    var enemyMaxHealth = props[4];
                    var enemyScore     = props[5];

                    string[] position = props.Skip(6).Take(3).ToArray();
                    float x           = float.Parse(position[0], CultureInfo.InvariantCulture.NumberFormat);
                    float y           = float.Parse(position[1], CultureInfo.InvariantCulture.NumberFormat);
                    float z           = float.Parse(position[2], CultureInfo.InvariantCulture.NumberFormat);

                    // Determine CharacterClass
                    CharacterClass charClass = CharacterClass.Gunner;
                    switch (enemyClass)
                    {
                    case "Gunner":
                        charClass = CharacterClass.Gunner;
                        break;

                    case "Support":
                        charClass = CharacterClass.Support;
                        break;

                    case "Tank":
                        charClass = CharacterClass.Tank;
                        break;
                    }

                    // Determine HeldWeapon
                    Weapon heldWeapon = new WeaponKnife();
                    switch (enemyWeapon)
                    {
                    case "Royale_Platformer.Model.WeaponKnife":
                        heldWeapon = new WeaponKnife();
                        break;

                    case "Royale_Platformer.Model.WeaponPistol":
                        heldWeapon = new WeaponPistol();
                        break;

                    case "Royale_Platformer.Model.WeaponPistolShield":
                        heldWeapon = new WeaponPistolShield();
                        break;

                    case "Royale_Platformer.Model.WeaponShotgun":
                        heldWeapon = new WeaponShotgun();
                        break;

                    case "Royale_Platformer.Model.WeaponAdvancedShotgun":
                        heldWeapon = new WeaponAdvancedShotgun();
                        break;

                    case "Royale_Platformer.Model.WeaponAR":
                        heldWeapon = new WeaponAR();
                        break;
                    }

                    // Create new Character
                    CharacterEnemy enemyPlayer = new CharacterEnemy(
                        charClass,
                        Convert.ToInt32(enemyMaxHealth),
                        new Vector3(x, y, z)
                        );
                    enemyPlayer.Health     = Convert.ToInt32(enemyHealth);
                    enemyPlayer.HeldWeapon = heldWeapon;
                    enemyPlayer.Armor      = enemyArmor == "True" ? true : false;
                    enemyPlayer.Score      = Convert.ToInt32(enemyScore);

                    Sprite2D shieldSprite = ResourceCache.GetSprite2D("shield.png");

                    // Load Enemy
                    //AnimationSet2D sprite = ResourceCache.GetAnimationSet2D(enemyPlayer.GetSprite());
                    Sprite2D sprite = ResourceCache.GetSprite2D(enemyPlayer.GetSprite());
                    if (sprite == null)
                    {
                        throw new Exception("Enemy sprite not found");
                    }
                    enemyPlayer.CreateNode(scene, sprite, shieldSprite, new Vector2(enemyPlayer.Position.X, enemyPlayer.Position.Y));
                    Characters.Add(enemyPlayer);
                }
            });
        }