#28 parselayers方法修改

This commit is contained in:
YHH
2020-08-13 22:23:02 +08:00
parent 4290a10d5d
commit 9111b69cee
8 changed files with 73 additions and 48 deletions
+1
View File
@@ -995,6 +995,7 @@ declare module es {
} }
declare class ObjectUtils { declare class ObjectUtils {
static clone<T>(p: any, c?: T): T; static clone<T>(p: any, c?: T): T;
static elements(p: {}): any[];
} }
declare module es { declare module es {
interface IRenderable { interface IRenderable {
+25 -19
View File
@@ -4579,6 +4579,13 @@ var ObjectUtils = (function () {
} }
return c; return c;
}; };
ObjectUtils.elements = function (p) {
var c = [];
for (var i in p) {
c.push(p[i]);
}
return c;
};
return ObjectUtils; return ObjectUtils;
}()); }());
var es; var es;
@@ -7851,48 +7858,47 @@ var es;
}; };
TiledMapLoader.parseLayers = function (container, xEle, map, width, height) { TiledMapLoader.parseLayers = function (container, xEle, map, width, height) {
return __awaiter(this, void 0, void 0, function () { return __awaiter(this, void 0, void 0, function () {
var _a, _b, _i, i, layer, _c, tileLayer, objectgroup, imagelayer, newGroup; var _i, _a, e, layer, _b, tileLayer, objectgroup, imagelayer, newGroup;
return __generator(this, function (_d) { return __generator(this, function (_c) {
switch (_d.label) { switch (_c.label) {
case 0: case 0:
_a = []; _i = 0, _a = ObjectUtils.elements(xEle).where(function (x) {
for (_b in xEle) return x.name == "layer" || x.name == "objectgroup" || x.name == "imagelayer" || x.name == "group";
_a.push(_b); });
_i = 0; _c.label = 1;
_d.label = 1;
case 1: case 1:
if (!(_i < _a.length)) return [3, 10]; if (!(_i < _a.length)) return [3, 10];
i = _a[_i]; e = _a[_i];
layer = void 0; layer = void 0;
_c = i; _b = e.name;
switch (_c) { switch (_b) {
case "layers": return [3, 2]; case "layer": return [3, 2];
case "objectgroups": return [3, 3]; case "objectgroup": return [3, 3];
case "imagelayer": return [3, 4]; case "imagelayer": return [3, 4];
case "group": return [3, 6]; case "group": return [3, 6];
} }
return [3, 7]; return [3, 7];
case 2: case 2:
tileLayer = this.loadTmxLayer(new es.TmxLayer(), map, xEle[i], width, height); tileLayer = this.loadTmxLayer(new es.TmxLayer(), map, e, width, height);
layer = tileLayer; layer = tileLayer;
if (container instanceof es.TmxMap || container instanceof es.TmxGroup) if (container instanceof es.TmxMap || container instanceof es.TmxGroup)
container.tileLayers.push(tileLayer); container.tileLayers.push(tileLayer);
return [3, 8]; return [3, 8];
case 3: case 3:
objectgroup = this.loadTmxObjectGroup(new es.TmxObjectGroup(), map, xEle[i]); objectgroup = this.loadTmxObjectGroup(new es.TmxObjectGroup(), map, e);
layer = objectgroup; layer = objectgroup;
if (container instanceof es.TmxMap || container instanceof es.TmxGroup) if (container instanceof es.TmxMap || container instanceof es.TmxGroup)
container.objectGroups.push(objectgroup); container.objectGroups.push(objectgroup);
return [3, 8]; return [3, 8];
case 4: return [4, this.loadTmxImageLayer(new es.TmxImageLayer(), map, xEle[i])]; case 4: return [4, this.loadTmxImageLayer(new es.TmxImageLayer(), map, e)];
case 5: case 5:
imagelayer = _d.sent(); imagelayer = _c.sent();
layer = imagelayer; layer = imagelayer;
if (container instanceof es.TmxMap || container instanceof es.TmxGroup) if (container instanceof es.TmxMap || container instanceof es.TmxGroup)
container.imageLayers.push(imagelayer); container.imageLayers.push(imagelayer);
return [3, 8]; return [3, 8];
case 6: case 6:
newGroup = this.loadTmxGroup(new es.TmxGroup(), map, xEle[i], width, height); newGroup = this.loadTmxGroup(new es.TmxGroup(), map, e, width, height);
layer = newGroup; layer = newGroup;
if (container instanceof es.TmxMap || container instanceof es.TmxGroup) if (container instanceof es.TmxMap || container instanceof es.TmxGroup)
container.groups.push(newGroup); container.groups.push(newGroup);
@@ -7901,7 +7907,7 @@ var es;
case 8: case 8:
if (container instanceof es.TmxMap || container instanceof es.TmxGroup) if (container instanceof es.TmxMap || container instanceof es.TmxGroup)
container.layers.push(layer); container.layers.push(layer);
_d.label = 9; _c.label = 9;
case 9: case 9:
_i++; _i++;
return [3, 1]; return [3, 1];
File diff suppressed because one or more lines are too long
+1
View File
@@ -995,6 +995,7 @@ declare module es {
} }
declare class ObjectUtils { declare class ObjectUtils {
static clone<T>(p: any, c?: T): T; static clone<T>(p: any, c?: T): T;
static elements(p: {}): any[];
} }
declare module es { declare module es {
interface IRenderable { interface IRenderable {
+25 -19
View File
@@ -4579,6 +4579,13 @@ var ObjectUtils = (function () {
} }
return c; return c;
}; };
ObjectUtils.elements = function (p) {
var c = [];
for (var i in p) {
c.push(p[i]);
}
return c;
};
return ObjectUtils; return ObjectUtils;
}()); }());
var es; var es;
@@ -7851,48 +7858,47 @@ var es;
}; };
TiledMapLoader.parseLayers = function (container, xEle, map, width, height) { TiledMapLoader.parseLayers = function (container, xEle, map, width, height) {
return __awaiter(this, void 0, void 0, function () { return __awaiter(this, void 0, void 0, function () {
var _a, _b, _i, i, layer, _c, tileLayer, objectgroup, imagelayer, newGroup; var _i, _a, e, layer, _b, tileLayer, objectgroup, imagelayer, newGroup;
return __generator(this, function (_d) { return __generator(this, function (_c) {
switch (_d.label) { switch (_c.label) {
case 0: case 0:
_a = []; _i = 0, _a = ObjectUtils.elements(xEle).where(function (x) {
for (_b in xEle) return x.name == "layer" || x.name == "objectgroup" || x.name == "imagelayer" || x.name == "group";
_a.push(_b); });
_i = 0; _c.label = 1;
_d.label = 1;
case 1: case 1:
if (!(_i < _a.length)) return [3, 10]; if (!(_i < _a.length)) return [3, 10];
i = _a[_i]; e = _a[_i];
layer = void 0; layer = void 0;
_c = i; _b = e.name;
switch (_c) { switch (_b) {
case "layers": return [3, 2]; case "layer": return [3, 2];
case "objectgroups": return [3, 3]; case "objectgroup": return [3, 3];
case "imagelayer": return [3, 4]; case "imagelayer": return [3, 4];
case "group": return [3, 6]; case "group": return [3, 6];
} }
return [3, 7]; return [3, 7];
case 2: case 2:
tileLayer = this.loadTmxLayer(new es.TmxLayer(), map, xEle[i], width, height); tileLayer = this.loadTmxLayer(new es.TmxLayer(), map, e, width, height);
layer = tileLayer; layer = tileLayer;
if (container instanceof es.TmxMap || container instanceof es.TmxGroup) if (container instanceof es.TmxMap || container instanceof es.TmxGroup)
container.tileLayers.push(tileLayer); container.tileLayers.push(tileLayer);
return [3, 8]; return [3, 8];
case 3: case 3:
objectgroup = this.loadTmxObjectGroup(new es.TmxObjectGroup(), map, xEle[i]); objectgroup = this.loadTmxObjectGroup(new es.TmxObjectGroup(), map, e);
layer = objectgroup; layer = objectgroup;
if (container instanceof es.TmxMap || container instanceof es.TmxGroup) if (container instanceof es.TmxMap || container instanceof es.TmxGroup)
container.objectGroups.push(objectgroup); container.objectGroups.push(objectgroup);
return [3, 8]; return [3, 8];
case 4: return [4, this.loadTmxImageLayer(new es.TmxImageLayer(), map, xEle[i])]; case 4: return [4, this.loadTmxImageLayer(new es.TmxImageLayer(), map, e)];
case 5: case 5:
imagelayer = _d.sent(); imagelayer = _c.sent();
layer = imagelayer; layer = imagelayer;
if (container instanceof es.TmxMap || container instanceof es.TmxGroup) if (container instanceof es.TmxMap || container instanceof es.TmxGroup)
container.imageLayers.push(imagelayer); container.imageLayers.push(imagelayer);
return [3, 8]; return [3, 8];
case 6: case 6:
newGroup = this.loadTmxGroup(new es.TmxGroup(), map, xEle[i], width, height); newGroup = this.loadTmxGroup(new es.TmxGroup(), map, e, width, height);
layer = newGroup; layer = newGroup;
if (container instanceof es.TmxMap || container instanceof es.TmxGroup) if (container instanceof es.TmxMap || container instanceof es.TmxGroup)
container.groups.push(newGroup); container.groups.push(newGroup);
@@ -7901,7 +7907,7 @@ var es;
case 8: case 8:
if (container instanceof es.TmxMap || container instanceof es.TmxGroup) if (container instanceof es.TmxMap || container instanceof es.TmxGroup)
container.layers.push(layer); container.layers.push(layer);
_d.label = 9; _c.label = 9;
case 9: case 9:
_i++; _i++;
return [3, 1]; return [3, 1];
+1 -1
View File
File diff suppressed because one or more lines are too long
+9
View File
@@ -16,4 +16,13 @@ class ObjectUtils {
} }
return c; return c;
} }
public static elements(p: {}){
let c = [];
for (let i in p){
c.push(p[i]);
}
return c;
}
} }
+10 -8
View File
@@ -58,32 +58,34 @@ module es {
* @param height * @param height
*/ */
public static async parseLayers(container: any, xEle: any, map: TmxMap, width: number, height: number) { public static async parseLayers(container: any, xEle: any, map: TmxMap, width: number, height: number) {
for (let i in xEle) { for (let e of ObjectUtils.elements(xEle).where(x => {
return x.name == "layer" || x.name == "objectgroup" || x.name == "imagelayer" || x.name == "group"
})) {
let layer: ITmxLayer; let layer: ITmxLayer;
switch (i) { switch (e.name) {
case "layers": case "layer":
let tileLayer = this.loadTmxLayer(new TmxLayer(), map, xEle[i], width, height); let tileLayer = this.loadTmxLayer(new TmxLayer(), map, e, width, height);
layer = tileLayer; layer = tileLayer;
if (container instanceof TmxMap || container instanceof TmxGroup) if (container instanceof TmxMap || container instanceof TmxGroup)
container.tileLayers.push(tileLayer); container.tileLayers.push(tileLayer);
break; break;
case "objectgroups": case "objectgroup":
let objectgroup = this.loadTmxObjectGroup(new TmxObjectGroup(), map, xEle[i]); let objectgroup = this.loadTmxObjectGroup(new TmxObjectGroup(), map, e);
layer = objectgroup; layer = objectgroup;
if (container instanceof TmxMap || container instanceof TmxGroup) if (container instanceof TmxMap || container instanceof TmxGroup)
container.objectGroups.push(objectgroup); container.objectGroups.push(objectgroup);
break; break;
case "imagelayer": case "imagelayer":
let imagelayer = await this.loadTmxImageLayer(new TmxImageLayer(), map, xEle[i]); let imagelayer = await this.loadTmxImageLayer(new TmxImageLayer(), map, e);
layer = imagelayer; layer = imagelayer;
if (container instanceof TmxMap || container instanceof TmxGroup) if (container instanceof TmxMap || container instanceof TmxGroup)
container.imageLayers.push(imagelayer); container.imageLayers.push(imagelayer);
break; break;
case "group": case "group":
let newGroup = this.loadTmxGroup(new TmxGroup(), map, xEle[i], width, height); let newGroup = this.loadTmxGroup(new TmxGroup(), map, e, width, height);
layer = newGroup; layer = newGroup;
if (container instanceof TmxMap || container instanceof TmxGroup) if (container instanceof TmxMap || container instanceof TmxGroup)