/*
文件名:InitAni.nut
路径:Core/BaseClass/ScriptManager/InitAni.nut
创建日期:2024-05-07	17:33
文件用途:初始化Ani
*/

function Get_Ani_Flip_Type(data) {
    switch (data) {
        case 1:
            return "HORIZON";
        case 2:
            return "VERTICAL";
        case 3:
            return "ALL";
        default:
            return "";
    }
}


function Get_Ani_Effect_Type(data) {
    switch (data) {
        case 0:
            return "NONE";
        case 1:
            return "DODGE";
        case 2:
            return "LINEARDODGE";
        case 3:
            return "DARK";
        case 4:
            return "XOR";
        case 5:
            return "MONOCHROME";
        case 6:
            return "SPACEDISTORT";
        default:
            return "";
    }
}

function Get_Ani_Damage_Type(data) {
    switch (data) {
        case 0:
            return "NORMAL";
        case 1:
            return "SUPERARMOR";
        case 2:
            return "UNBREAKABLE";
        default:
            return "";
    }
}

function Get_Ani_Flag(data) {
    switch (data) {
        case 0:
            return "LOOP";
        case 1:
            return "SHADOW";
        case 3:
            return "COORD";
        case 7:
            return "IMAGE_RATE";
        case 8:
            return "IMAGE_ROTATE";
        case 9:
            return "RGBA";
        case 10:
            return "INTERPOLATION";
        case 11:
            return "GRAPHIC_EFFECT";
        case 12:
            return "DELAY";
        case 13:
            return "DAMAGE_TYPE";
        case 14:
            return "DAMAGE_BOX";
        case 15:
            return "ATTACK_BOX";
        case 16:
            return "PLAY_SOUND";
        case 17:
            return "PRELOAD";
        case 18:
            return "SPECTRUM";
        case 23:
            return "SET_FLAG";
        case 24:
            return "FLIP_TYPE";
        case 25:
            return "LOOP_START";
        case 26:
            return "LOOP_END";
        case 27:
            return "CLIP";
        case 28:
            return "OPERATION";
        default:
            return "";
    }
}

function InitPvfAni(Ro) {
    local AniObject = {
        Img_List = [],
        Frame = [],
        Flag = {}
    };

    local Frame_Max = Ro.GetUShort();
    local Img_Count = Ro.GetUShort();

    //Img的路径读取 存入数组
    for (local index = 0; index< Img_Count; index++) {
        local Buf = Ro.GetInt();
        local ImgPath = Ro.GetString(Buf);
        //有可能Img有空路径
        AniObject.Img_List.append(ImgPath);
    }
    //Ani头部标签数量
    local Ani_H_Item_Count = Ro.GetUShort();

    //处理标签
    for (local index = 0; index< Ani_H_Item_Count; index++) {
        //标签类型
        local Type = Ro.GetUShort();

        switch (Type) {
            case 0:
            case 1: {
                local Key = Get_Ani_Flag(Type);
                local Value = Ro.readn('c');
                AniObject.Flag.rawset(Key, Value);
                break;
            }
            case 3:
            case 28: {
                local Key = Get_Ani_Flag(Type);
                local Value = Ro.GetUShort();
                AniObject.Flag.rawset(Key, Value);
                break;
            }
            case 18:
                // print("残影解析");
                //此处无解析 暂时先保证运行  残影功能暂时用不上
                Ro.readn('c');
                Ro.GetInt();
                Ro.GetInt();
                Ro.GetInt();
                Ro.Get256();
                Ro.Get256();
                Ro.Get256();
                Ro.Get256();
                Ro.GetUShort();
                break;
            default:
                break;
        }
    }

    //读取每一个Img
    for (local index = 0; index< Frame_Max; index++) {
        //帧结构体对象
        local FrameObject = {
            AttackBox = [],
            DamageBox = [],
            Flag = {},
        };

        //碰撞框项目数量
        local Ani_Box_Item_Count = Ro.GetUShort();
        for (local _i = 0; _i< Ani_Box_Item_Count; _i++) {
            local Box_Type = Ro.GetUShort();
            local D_Box_b = [];
            for (local _k = 0; _k< 6; _k++) {
                D_Box_b.append(Ro.readn('i'));
            }
            if (Box_Type == 15) {
                FrameObject.AttackBox.append(D_Box_b);
            } else {
                FrameObject.DamageBox.append(D_Box_b);
            }
            // //0是攻击框 1是受击框
            // FrameObject.Box.rawset(15 - Box_Type, D_Box_b);
        }

        //调用的第几个Img
        local Index_Buf = Ro.GetShort();
        //如果等于-1说明是img路径为空
        if (Index_Buf != 65535) {
            FrameObject.Img_Path <- AniObject.Img_List[Index_Buf].tolower();
            //Img中的PNG下标
            FrameObject.Img_Index <- Ro.GetUShort();
        } else {
            FrameObject.Img_Path <- "";
            FrameObject.Img_Index <- 0;
        }

        //坐标
        FrameObject.Pos <- {
            x = Ro.readn('i'),
            y = Ro.readn('i'),
        };

        //Img中的项目数量
        local Img_Flag_Count = Ro.GetUShort();
        for (local _o = 0; _o< Img_Flag_Count; _o++) {
            local Img_Flag_Type = Ro.GetUShort();
            local Key;
            local Value;
            switch (Img_Flag_Type) {
                case 0:
                case 1:
                case 10:
                    Key = Get_Ani_Flag(Img_Flag_Type);
                    Value = Ro.readn('c');
                    FrameObject.Flag.rawset(Key, Value);
                    break;
                case 3:
                    Key = "COORD";
                    Value = Ro.GetUShort();
                    FrameObject.Flag.rawset(Key, Value);
                    break;
                case 17:
                    Key = "PRELOAD";
                    Value = 1;
                    FrameObject.Flag.rawset(Key, Value);
                    break;
                case 7:
                    Key = "IMAGE_RATE";
                    Value = {
                        x = Ro.GetFloat(),
                        y = Ro.GetFloat()
                    };
                    FrameObject.Flag.rawset(Key, Value);
                    break;
                case 8:
                    Key = "IMAGE_ROTATE";
                    Value = Ro.GetFloat();
                    FrameObject.Flag.rawset(Key, Value);
                    break;
                case 9:
                    Key = "RGBA";
                    Value = [
                        Ro.Get256(),
                        Ro.Get256(),
                        Ro.Get256(),
                        Ro.Get256(),
                    ];
                    FrameObject.Flag.rawset(Key, Value);
                    break;
                case 11:
                    local Effect_Type = Ro.GetUShort();
                    Key = "GRAPHIC_EFFECT_" + Get_Ani_Effect_Type(Effect_Type);
                    switch (Effect_Type) {
                        case 5:
                            Value = [Ro.Get256(), Ro.Get256(), Ro.Get256()];
                            break;
                        case 6:
                            Value = [Ro.GetShort(), Ro.GetShort()];
                            break;
                    }
                    FrameObject.Flag.rawset(Key, Value);
                    break;
                case 12:
                    Value = Ro.GetInt();
                    FrameObject.Delay <- Value;
                    break;
                case 13:
                    Key = "DAMAGE_TYPE";
                    Value = Get_Ani_Damage_Type(Ro.GetUShort());
                    FrameObject.Flag.rawset(Key, Value);
                    break;
                case 16:
                    local SoundTempSize = Ro.GetInt();
                    Key = "PLAY_SOUND";
                    Value = Ro.GetString(SoundTempSize);
                    FrameObject.Flag.rawset(Key, Value);
                    break;
                case 23:
                    Key = "SET_FLAG";
                    Value = Ro.GetInt();
                    FrameObject.Flag.rawset(Key, Value);
                    break;
                case 24:
                    Key = "FLIP_TYPE";
                    Value = Get_Ani_Flip_Type(Ro.GetUShort());
                    FrameObject.Flag.rawset(Key, Value);
                    break;
                case 25:
                    Key = "LOOP_START";
                    FrameObject.Flag.rawset(Key, 1);
                    break;
                case 26:
                    Key = "LOOP_END";
                    Value = Ro.GetInt();
                    FrameObject.Flag.rawset(Key, Value);
                    break;
                case 27:
                    Key = "CLIP";
                    Value = [
                        Ro.GetShort(),
                        Ro.GetShort(),
                        Ro.GetShort(),
                        Ro.GetShort(),
                    ];
                    FrameObject.Flag.rawset(Key, Value);
                    break;
                default:
                    break;
            }
        }

        //每一帧都是一个结构体 存入数组中
        AniObject.Frame.append(FrameObject);
    }
    return AniObject;
}