示例#1
0
文件: LReadCSV.cs 项目: xggxnn/Tool
    public void Generate()
    {
        Debug.Log(oldFile);
        return;

        string csvPath = "D:/tt/csv/achievement.csv";


        CsvData csv   = new CsvData().ReadFile(csvPath);
        int     count = csv.LineCount;

        Dictionary <string, int> heads = new Dictionary <string, int>();

        string[] line = csv.GetLine(0);
        for (int i = 0; i < line.Length; i++)
        {
            heads.Add(line[i], i);
        }

        StringWriter idSW = new StringWriter();

        string note = @"// ======================================
// 该文件自动生成,,不要修改,否则会替换
// --------------------------------------			
";

        idSW.WriteLine(note);
        //idSW.WriteLine("\n\n");

        idSW.WriteLine(@"
export default class " + @"achievement" + @"
{
");
        idSW.WriteLine(@"    private static _hash: Object = {};
    private static _list: Array<string> = [];

    /**
     * 安装csv文件
     */
    public static installCSV(csv: CSV): void {
        this._hash = {};
        var data = csv.getAllData();
        for (var id in data) {
            this._hash[id] = new AchievementInfo(data[id]);
            this._list.push(id);
        }
    }
    /**
     * 获取数据数量
     */
    public static getCount(): number {
        return this._list.length;
    }
    /**
     * 通过id获取achievementInfo
     */
    public static getInfo(id: any): AchievementInfo {
        id = String(id);
        if (this._hash.hasOwnProperty(id)) {
            return this._hash[id];
        }
        return null;
    }
    /**
     * 通过index获取AchievementInfo
     */
    public static getInfoFromIndex(index: number): AchievementInfo {
        try {
            let id = this._list[index];
            return this.getInfo(id);
        } catch (error) {
            return null;
        }
    }
");
        idSW.WriteLine(@"    private constructor(obj: Object) {");
        foreach (var item in heads)
        {
            idSW.WriteLine(string.Format("        this._{0} = {1}(obj[{0}]);", item.Key, toInt));
        }
        idSW.WriteLine("    }");
        idSW.WriteLine("\n");
        foreach (var item in heads)
        {
            string keys = item.Key;
            idSW.WriteLine("    private _" + keys + ": number;");
            idSW.WriteLine("    public get " + keys + "(): number {");
            idSW.WriteLine("        return this._" + keys + ";");
            idSW.WriteLine("    }");
            idSW.WriteLine("    public set " + keys + "(v: number) {");
            idSW.WriteLine("        this._" + keys + " = v;");
            idSW.WriteLine("    }");
            idSW.WriteLine("\n");
        }



        idSW.WriteLine(@"

}
");



        string outPath = "D:/tt/Ts/achievement.ts";

        File.WriteAllText(outPath, idSW.ToString());
        Debug.Log(outPath + "创建成功");
    }