HeadInfo.lua 1.78 KB
cc.exports.HeadInfo = {}

local xml = require("core.utils.pl.xml")

local headList = {};
local headFrameList = {};
local create_reward = "";

function init()
    local configStr = cc.FileUtils:getInstance():getStringFromFile("res/config/head.xml");
    local data = xml.parse(configStr, false, true);

    headList = {};
    headFrameList = {};
    for k,v in pairs(data) do
        if k ~= "attr" and k ~= "tag" then
            if v.tag == "head" then
                headList[#headList+1] = {id=tonumber(v.attr.id),needCard=tonumber(v.attr.needCard),sex=tonumber(v.attr.sex)};
            elseif v.tag == "headFrame" then
                local needScore = 0;
                local needCharm = 0;
                if v.attr.needScore then
                    needScore = tonumber(v.attr.needScore);
                end
                if v.attr.needCharm then
                    needCharm = tonumber(v.attr.needCharm);
                end
                headFrameList[#headFrameList+1] = {id=tonumber(v.attr.id),needScore=needScore,needCharm=needCharm};
            end
        end
    end
end
init();

--通过ID获取头像信息
function HeadInfo.getHeadInfo(id)
    local info = nil;
    for i,v in ipairs(headList) do
        if v.id == id then
            info = v;
        end
    end
    return info;
end

--通过头像列表
function HeadInfo.headList()
    return headList;
end

function HeadInfo.freeHeadList()
    local arr = {};
    for i,v in ipairs(headList) do
        if v.needCard == 0 then
            arr[#arr + 1] = v;
        end
    end
    return arr;
end

--通过ID获取头像信息
function HeadInfo.getHeadFrameInfo(id)
    local info = nil;
    for i,v in ipairs(headFrameList) do
        if v.id == id then
            info = v;
        end
    end
    return info;
end

return HeadInfo