码迷,mamicode.com
首页 > 其他好文 > 详细

【工具箱】egret读取自己的配置文件

时间:2019-08-09 23:20:24      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:asi   rem   boolean   gre   ext   return   name   ret   parse   

推荐类库:JSZip

/**
 * Created by d8q8 on 2015/5/25.
 * @class JSZip
 * @constructor
 **/
interface JSZip {
    file(path:string): JSZipObject;
    file(path:RegExp): JSZipObject[];
    file(path:string, data:any, options?:JSZipFileOptions): JSZip;
    folder(name:string): JSZip;
    folder(name:RegExp): JSZipObject[];
    filter(predicate:(relativePath:string, file:JSZipObject) => boolean): JSZipObject[];
    remove(path:string): JSZip;
    generate(options?:JSZipGeneratorOptions): any;
    load(data:any, options:JSZipLoadOptions): JSZip;
}

interface JSZipObject {
    name: string;
    dir: boolean;
    date: Date;
    comment: string;
    options: JSZipObjectOptions;

    asText(): string;
    asBinary(): string;
    asArrayBuffer(): ArrayBuffer;
    asUint8Array(): Uint8Array;
    asNodeBuffer(): Buffer;
}

interface JSZipFileOptions extends JSZipObjectOptions {
    compressionOptions?:Object;
    comment?: string;
    optimizedBinaryString?: boolean;
    createFolders?: boolean;
    unixPermissions?:number;
    dosPermissions?:number;
}

interface JSZipObjectOptions {
    base64?: boolean;
    binary?: boolean;
    dir?: boolean;
    date?: Date;
    compression?: string;
}

interface JSZipGeneratorOptions {
    base64?: boolean;
    compression?: string;
    compressionOptions?:Object;
    type?: string;
    comment?: string;
    mimeType?:string;
    platform?:string;
}

interface JSZipLoadOptions {
    base64?: boolean;
    checkCRC32?: boolean;
    optimizedBinaryString?: boolean;
    createFolders?: boolean;
}

interface JSZipSupport {
    arraybuffer: boolean;
    uint8array: boolean;
    blob: boolean;
    nodebuffer: boolean;
}

interface Buffer {
    data?:any;
    encoding?:string;
}

interface DEFLATE {
    compress(input:string, compressionOptions:{level:number}): Uint8Array;
    compress(input:number[], compressionOptions:{level:number}): Uint8Array;
    compress(input:Uint8Array, compressionOptions:{level:number}): Uint8Array;

    uncompress(input:string): Uint8Array;
    uncompress(input:number[]): Uint8Array;
    uncompress(input:Uint8Array): Uint8Array;
}

declare var JSZip:{
    (): JSZip;
    (data:any, options?:JSZipLoadOptions): JSZip;
    new (): JSZip;
    new (data:any, options?:JSZipLoadOptions): JSZip;

    prototype: JSZip;
    support: JSZipSupport;
    compressions: {
        DEFLATE: DEFLATE;
    }
}

declare module "jszip" {
    export = JSZip;
}

interface FileSaver {
    (data:Blob, filename:string): void
}

declare var saveAs:FileSaver;

StdConfig

class StdConfig {
    public constructor() {

    }
    private static _zip: JSZip;//配置压缩包缓存
    private static _cfgls: Object = new Object();

        public static parseCfg(cfg: string): string {    
        return StdConfig._zip.file(cfg).asText();    
    }        

        public static async parseStd(byte: egret.ByteArray) {
        StdConfig._hasInit = true;
        StdConfig._zip = new JSZip(byte.buffer);
                
                StdConfig.parseFirstPayConfig("fristpayrebate");
                //... ...
        }    

        private static _getFirstPayById: (id) => StdFirstPay;
        private static parseFirstPayConfig(cfg: string) {
          cfg = StdConfig.parseCfg(cfg);
          let payAward: any = JSON.parse(cfg);
          StdConfig._getFirstPayById = function (id): StdFirstPay {
              if (!payAward) {
                  throw new Error("缺少首充奖励配置");
              }
              return payAward[id - 1];
        }
    }                    
}

 

【工具箱】egret读取自己的配置文件

标签:asi   rem   boolean   gre   ext   return   name   ret   parse   

原文地址:https://www.cnblogs.com/harrickheng/p/11329805.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!