From b49fb14e915188e66f54d2923b0f689e56604212 Mon Sep 17 00:00:00 2001 From: zhl Date: Fri, 21 Aug 2020 11:10:39 +0800 Subject: [PATCH] remove bom --- .gitignore | 3 +- app/main.js | 2 +- copy.bat | 2 +- libs/easyui/jquery.easyui.min.js | 2 +- src/Main.ts | 100 ++++++++++++++--------------- src/game/animation/AniInfo.ts | 32 +++++----- src/game/animation/PstInfo.ts | 105 ++++++++++++++++--------------- 7 files changed, 124 insertions(+), 122 deletions(-) diff --git a/.gitignore b/.gitignore index 779701e..3457bc3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .wing/ bin-debug/ -bin-release/ \ No newline at end of file +bin-release/ +.idea/ diff --git a/app/main.js b/app/main.js index 3f3e9a2..2389dd1 100644 --- a/app/main.js +++ b/app/main.js @@ -23,7 +23,7 @@ function createWindow() { win.loadURL("http://127.0.0.1:12346/index.html"); // Open the DevTools. - win.webContents.openDevTools(); + // win.webContents.openDevTools(); // Emitted when the window is closed. win.on('closed', () => { diff --git a/copy.bat b/copy.bat index e3b10cd..bb938a9 100644 --- a/copy.bat +++ b/copy.bat @@ -1,4 +1,4 @@ -echo 开始copy +echo 开始copy robocopy .\bin-release\web\r\js ..\..\release\avatertools\js /MIR robocopy .\bin-release\web\r\resource ..\..\release\avatertools\resource /MIR diff --git a/libs/easyui/jquery.easyui.min.js b/libs/easyui/jquery.easyui.min.js index b6edf3f..78ebd7b 100644 --- a/libs/easyui/jquery.easyui.min.js +++ b/libs/easyui/jquery.easyui.min.js @@ -1,4 +1,4 @@ -/** +/** * jQuery EasyUI 1.4.5 * * Copyright (c) 2009-2016 www.jeasyui.com. All rights reserved. diff --git a/src/Main.ts b/src/Main.ts index 8e67f94..098386a 100644 --- a/src/Main.ts +++ b/src/Main.ts @@ -6,7 +6,7 @@ class Main extends egret.DisplayObjectContainer { protected dragDele: junyou.tools.DragDele; - protected grid:grid.GridSprite; + protected grid: grid.GridSprite; private cPst: jgame.AniInfo; @@ -14,10 +14,10 @@ class Main extends egret.DisplayObjectContainer { public constructor() { super(); - this.addEventListener(egret.Event.ADDED_TO_STAGE,this.onAddToStage,this); + this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this); window["saveCallback"] = this.saveCallback; $(document).ready(() => { - $("#btnSave").on("click",this.saveCallback.bind(this)); + $("#btnSave").on("click", this.saveCallback.bind(this)); }); } @@ -25,54 +25,54 @@ class Main extends egret.DisplayObjectContainer { let pst = this.cPst; let frames = pst.frames; let obj = {}; - for(let a in frames) { + for (let a in frames) { let aInfo = frames[a]; - if(aInfo && aInfo.totalFrame) { + if (aInfo && aInfo.totalFrame) { let m = []; obj[a] = m; let fs = []; m[0] = fs; - if(aInfo.isCircle) { + if (aInfo.isCircle) { m[1] = 1; } let aF = aInfo.frames; let len = aF.length; - for(let i = 0;i < len;i++) { + for (let i = 0; i < len; i++) { let frame = aF[i]; - let data: any[] = [+frame.a,+frame.f,+frame.t]; - if(frame.e || frame.d != -1) {//一般情况有事件的可能性多余有特定方向的,所以先e,后d + let data: any[] = [+frame.a, +frame.f, +frame.t]; + if (frame.e || frame.d != -1) {//一般情况有事件的可能性多余有特定方向的,所以先e,后d data.push(frame.e || 0); - if(frame.d != -1) { + if (frame.d != -1) { data.push(+frame.d); } } - fs[i]=data; + fs[i] = data; } } } let rawData = pst.rawData; rawData[0][0] = obj; // 将数据写回文件 - + let require = window["nodeRequire"]; let fs = require("fs"); - fs.writeFileSync(this.dataFile,JSON.stringify(rawData)); + fs.writeFileSync(this.dataFile, JSON.stringify(rawData)); } private onAddToStage(event: egret.Event) { // 绘制中心线 let sp = new egret.Shape(); - + let g = sp.graphics; let sw = this.stage.stageWidth; let sh = this.stage.stageHeight; let hh = sh >> 1; let hw = sw >> 1; - g.lineStyle(1,0xff0000); - g.moveTo(0,hh); - g.lineTo(sw,hh); - g.moveTo(hw,0); - g.lineTo(hw,sh); + g.lineStyle(1, 0xff0000); + g.moveTo(0, hh); + g.lineTo(sw, hh); + g.moveTo(hw, 0); + g.lineTo(hw, sh); this.grid = new grid.GridSprite(); this.addChild(this.grid); @@ -80,22 +80,22 @@ class Main extends egret.DisplayObjectContainer { this.dragDele = new junyou.tools.DragDele; this.addChild(this.dragDele); this.addChild(sp); - window.addEventListener("dragover",e => { + window.addEventListener("dragover", e => { e.preventDefault(); return false }); - - window.addEventListener("drop",async(e) => { + + window.addEventListener("drop", async (e) => { e.preventDefault(); let goted = this.checkFile(e.dataTransfer.files); - if(goted) { // 一定是 Electron 环境才能取到值 + if (goted) { // 一定是 Electron 环境才能取到值 // 加载数据 let require = window["nodeRequire"]; let path = require("path"); let fs = require("fs"); - let str = fs.readFileSync(goted.data,"utf8"); + let str = fs.readFileSync(goted.data, "utf8"); let data = JSON.parse(str); let rawData = JSON.parse(str); let aniRender = new jgame.AniRender(); @@ -108,20 +108,20 @@ class Main extends egret.DisplayObjectContainer { // let bmd = egret.$toBitmapData(img); let bmd = new egret.Bitmap(); await tools.readImageSync(goted.img, bmd); - pst.init(goted.key,data,bmd.$bitmapData); + pst.init(goted.key, data, bmd.$bitmapData); pst.rawData = rawData; aniRender._aniInfo = pst; let chkCircle = $("#chkCircle"); chkCircle.removeAttr("disabled"); - pst.actionInfo.isCircle ? chkCircle.attr("checked","checked") : chkCircle.removeAttr("checked"); - chkCircle.on("change",(e) => { + pst.actionInfo.isCircle ? chkCircle.attr("checked", "checked") : chkCircle.removeAttr("checked"); + chkCircle.on("change", (e) => { pst.actionInfo.isCircle = chkCircle[0]["checked"]; }); let dis = new jgame.ResourceBitmap; aniRender.display = dis; dis.res = pst.getResource(); aniRender.play(); - this.dragDele.setStartPoint(hw,hh); + this.dragDele.setStartPoint(hw, hh); this.dragDele.aniInfo = pst; this.dataFile = goted.data; this.dragDele.addChild(dis); @@ -129,7 +129,7 @@ class Main extends egret.DisplayObjectContainer { } else { alert("数据不符"); } - + }); } @@ -137,9 +137,9 @@ class Main extends egret.DisplayObjectContainer { protected addRender(aniRender: jgame.AniRender) { let old = this.currentRender; - if(old) { + if (old) { let dis = old.display; - if(dis.parent) { + if (dis.parent) { dis.parent.removeChild(dis); } old.onRecycle(); @@ -147,15 +147,15 @@ class Main extends egret.DisplayObjectContainer { this.currentRender = aniRender; let pst = aniRender._aniInfo; let dg = $('#dg'); - dg["datagrid"]('loadData',pst.frames[0].frames); + dg["datagrid"]('loadData', pst.frames[0].frames); } - - + + /** * 检查文件列表,看是否目录结构一致 * @param files */ - private checkFile(files: FileArray,parent: string = "") { + private checkFile(files: FileArray, parent: string = "") { // 先检查 pdir中的数据 // let v; // try{ @@ -170,9 +170,9 @@ class Main extends egret.DisplayObjectContainer { // } // let imgReg = new RegExp(v.image[0]); // let cfgReg = new RegExp(v.config[0]); - let path,fs; + let path, fs; let require = window["nodeRequire"]; - if(typeof require === "function") { //是Electron环境 + if (typeof require === "function") { //是Electron环境 path = require("path"); fs = require("fs"); } @@ -181,37 +181,37 @@ class Main extends egret.DisplayObjectContainer { let img = null; let data = null; // 遍历文件,检查文件是否匹配 - for(let i = 0,len = files.length;i < len;i++) { + for (let i = 0, len = files.length; i < len; i++) { let file = files[i]; - if(path) { // 如果是Electron环境 + if (path) { // 如果是Electron环境 let p: string; - if(typeof file === "string") { - p = path.join(parent,file); + if (typeof file === "string") { + p = path.join(parent, file); } else { // 检查路径 p = file["path"]; } - p = p.replace(/\\/g,"/"); + p = p.replace(/\\/g, "/"); let fstats = fs.statSync(p); // 如果是文件夹 - if(fstats.isDirectory()) { - goted = this.checkFile.call(this,fs.readdirSync(p),p); - } else if(fstats.isFile()) {// 检查文件 + if (fstats.isDirectory()) { + goted = this.checkFile.call(this, fs.readdirSync(p), p); + } else if (fstats.isFile()) {// 检查文件 let re = path.parse(p); - if(re.ext == ".png") { + if (re.ext == ".png") { img = p; - } else if(re.base == "d.json") { + } else if (re.base == "d.json") { data = p; } - if(img && data) { + if (img && data) { // 得到上级目录 let dirs = re.dir.split(path.sep); let key = dirs[dirs.length - 1]; - goted = { img: img,data: data,key: key }; + goted = { img: img, data: data, key: key }; } } - if(goted) { + if (goted) { return goted; } } diff --git a/src/game/animation/AniInfo.ts b/src/game/animation/AniInfo.ts index 95c5595..a0f30dc 100644 --- a/src/game/animation/AniInfo.ts +++ b/src/game/animation/AniInfo.ts @@ -5,25 +5,25 @@ module junyou.game { * */ export class AniInfo extends PstInfo { - public rawData:any[]; - public constructor() { - super(); + public rawData: any[]; + public constructor() { + super(); } - - public init(key: string,data: any[],bmd:egret.BitmapData) { + + public init(key: string, data: any[], bmd: egret.BitmapData) { console.log(data); - super.init(key,data[0],bmd); - var res: UnitResource = new UnitResource(key,this.splitInfo,bmd); - res.decodeData(data[1]); - this._resources = res; - } - - getResource(uri:string=null):UnitResource{ - return this._resources; + super.init(key, data[0], bmd); + var res: UnitResource = new UnitResource(key, this.splitInfo, bmd); + res.decodeData(data[1]); + this._resources = res; } - - public get actionInfo(): ActionInfo{ - return this.frames[0] + + getResource(uri: string = null): UnitResource { + return this._resources; + } + + public get actionInfo(): ActionInfo { + return this.frames[0] } } } diff --git a/src/game/animation/PstInfo.ts b/src/game/animation/PstInfo.ts index 4f54a35..78fd905 100644 --- a/src/game/animation/PstInfo.ts +++ b/src/game/animation/PstInfo.ts @@ -1,5 +1,5 @@ module junyou.game { - + /** * 打包类型 */ @@ -18,13 +18,13 @@ module junyou.game { PAK_ONE_A_D = 4 } - var parsers: { [index: number]: { new (key: string): SplitInfo } }; - + var parsers: { [index: number]: { new(key: string): SplitInfo } }; + /** * 获取处理器 */ - function getParsers(t: number): { new (key: string): SplitInfo } { - if(!parsers) { + function getParsers(t: number): { new(key: string): SplitInfo } { + if (!parsers) { parsers = {}; parsers[PakSaveType.PAK_BY_ACTION] = ActionSInfo; parsers[PakSaveType.PAK_ONE_A_D] = OneADSInfo; @@ -32,23 +32,24 @@ module junyou.game { } return parsers[t]; } - + /** * 存储pst信息 * - */ export class PstInfo { + */ + export class PstInfo { /** * 图片数据字典
* Key string 存储图片数据的key
* Value UnitResource
*/ protected _resources: { [index: string]: UnitResource } | UnitResource; - + /** * pst的唯一标识 */ public key: string; - + /** * 动作信息,帧的播放信息的数组
* key {number} 动作标识
@@ -62,7 +63,7 @@ module junyou.game { } - public init(key: string,data: any[],img: egret.BitmapData) { + public init(key: string, data: any[], img: egret.BitmapData) { this.key = key; this._resources = {}; // var t = data[0]; @@ -75,27 +76,27 @@ module junyou.game { } } - + /** * 资源打包分隔信息 */ export class SplitInfo { - + /** * 资源字典 */ protected _resDict: { [index: number]: string }; - + /** * 子资源列表 */ protected _subReses: string[]; - + /** * key */ protected _key: string; - + /** * 动作/方向的字典
* key {string} 资源uri
@@ -104,7 +105,7 @@ module junyou.game { */ public adDict: { [index: string]: number[] }; - + /** * 处理分隔信息 * @param data @@ -116,21 +117,21 @@ module junyou.game { constructor(key: string) { this._key = key; } - + /** * 处理帧数据 * @param data */ public parseFrameData(data: any[]): { [index: number]: ActionInfo } { var frames: { [index: number]: ActionInfo } = {}; - for(let a in data) { - frames[a] = ActionInfo.fromData(data[a],a); + for (let a in data) { + frames[a] = ActionInfo.fromData(data[a], a); } return frames; } - - + + /** * 获取文件名字 */ @@ -142,11 +143,11 @@ module junyou.game { * @param direction 方向 * @param action 动作 */ - public getResource(direction: number,action: number): string { + public getResource(direction: number, action: number): string { return null; } - public static getADKey(action: any,direction: number): number { + public static getADKey(action: any, direction: number): number { return action << 8 | direction; } @@ -159,23 +160,23 @@ module junyou.game { } } - + /** * 单方向单动作分隔数据 */ export class OneADSInfo extends SplitInfo { - public static _a = function() { + public static _a = function () { let a = []; - function m(f: number,t: number) { - for(let i = f;i < t;i++) { + function m(f: number, t: number) { + for (let i = f; i < t; i++) { a.push(String.fromCharCode(i)); } } - m(97,122); - m(65,90); + m(97, 122); + m(65, 90); return a; - } (); + }(); protected _n: string; protected _a: any[]; @@ -186,11 +187,11 @@ module junyou.game { var _adDict: { [index: string]: number[] } = {}; this.adDict = _adDict; var frames: { [index: number]: ActionInfo } = {}; - for(let a in data) { - frames[a] = ActionInfo.fromData(data[a],a); - for(let d = 0;d < 5;d++) { - let res = this.getResource(d,a); - _adDict[res] = [SplitInfo.getADKey(a,d)]; + for (let a in data) { + frames[a] = ActionInfo.fromData(data[a], a); + for (let d = 0; d < 5; d++) { + let res = this.getResource(d, a); + _adDict[res] = [SplitInfo.getADKey(a, d)]; } } return frames; @@ -202,24 +203,24 @@ module junyou.game { this._d = infos["d"]; } - getResource(direction: number,action: any): string { - let key = SplitInfo.getADKey(action,direction); + getResource(direction: number, action: any): string { + let key = SplitInfo.getADKey(action, direction); let res = this._resDict[key]; - if(!res) { - this._resDict[key] = res = this._n.replace(/\{f\}/g,this._key).replace(/\{d\}/g,this.getRep(direction,this._d)).replace(/\{a\}/g,this.getRep(action,this._a)); + if (!res) { + this._resDict[key] = res = this._n.replace(/\{f\}/g, this._key).replace(/\{d\}/g, this.getRep(direction, this._d)).replace(/\{a\}/g, this.getRep(action, this._a)); } return res; } - getRep(data: number,repArr: any[]): string { + getRep(data: number, repArr: any[]): string { var str = data + ""; - if(repArr && (data in repArr)) { + if (repArr && (data in repArr)) { str = repArr[data]; } return str; } } - + /** * 基于动作打包的分隔数据 */ @@ -227,7 +228,7 @@ module junyou.game { parseSplitInfo(infos: any[]) { var flag = true; - if(infos) { + if (infos) { this._resDict = {}; this._subReses = []; var _adDict: { [index: string]: number[] } = {}; @@ -235,33 +236,33 @@ module junyou.game { var _resDict = this._resDict; var _subReses = this._subReses; var len = infos.length; - for(let i = 0;i < len;i++) { + for (let i = 0; i < len; i++) { let pak = infos[i][0]; let acts = pak.a; - if(acts) { + if (acts) { let dlen = acts.length; - if(dlen) { + if (dlen) { flag = false; let res = this.getFileName(pak); let arr = _adDict[res]; - if(!arr) { + if (!arr) { arr = []; _adDict[res] = arr; } - if(res && _subReses.indexOf(res) == -1) { + if (res && _subReses.indexOf(res) == -1) { _subReses.push(res); } - for(let j = 0;j < dlen;j++) { + for (let j = 0; j < dlen; j++) { let a = acts[j]; _resDict[a] = res; //push所有动作的数据 - arr.push(SplitInfo.getADKey(a,0),SplitInfo.getADKey(a,1),SplitInfo.getADKey(a,2),SplitInfo.getADKey(a,3),SplitInfo.getADKey(a,4)); + arr.push(SplitInfo.getADKey(a, 0), SplitInfo.getADKey(a, 1), SplitInfo.getADKey(a, 2), SplitInfo.getADKey(a, 3), SplitInfo.getADKey(a, 4)); } } } } } - if(flag) { + if (flag) { throw new Error("no pak split info"); } } @@ -272,7 +273,7 @@ module junyou.game { return PakSaveType.PAK_BY_ACTION + "-" + dirs.join("_"); } - getResource(direction: number,action: number): string { + getResource(direction: number, action: number): string { return this._resDict[action]; } }