#28 tiled 数据解析与渲染
This commit is contained in:
Vendored
+71
-35
@@ -252,6 +252,7 @@ declare module es {
|
|||||||
declare module es {
|
declare module es {
|
||||||
class Core extends egret.DisplayObjectContainer {
|
class Core extends egret.DisplayObjectContainer {
|
||||||
static emitter: Emitter<CoreEvents>;
|
static emitter: Emitter<CoreEvents>;
|
||||||
|
static debugRenderEndabled: boolean;
|
||||||
static graphicsDevice: GraphicsDevice;
|
static graphicsDevice: GraphicsDevice;
|
||||||
static content: ContentManager;
|
static content: ContentManager;
|
||||||
static _instance: Core;
|
static _instance: Core;
|
||||||
@@ -1551,11 +1552,11 @@ declare module es {
|
|||||||
properties: Map<string, string>;
|
properties: Map<string, string>;
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
name: string;
|
name: string;
|
||||||
layers: TmxList<any>;
|
layers: ITmxLayer[];
|
||||||
tileLayers: TmxList<TmxLayer>;
|
tileLayers: TmxLayer[];
|
||||||
objectGroups: TmxList<TmxObjectGroup>;
|
objectGroups: TmxObjectGroup[];
|
||||||
imageLayers: TmxList<TmxImageLayer>;
|
imageLayers: TmxImageLayer[];
|
||||||
groups: TmxList<TmxGroup>;
|
groups: TmxGroup[];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
@@ -1618,19 +1619,15 @@ declare module es {
|
|||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
class TmxDocument {
|
class TmxDocument {
|
||||||
TmxDirectory: string;
|
tmxDirectory: string;
|
||||||
constructor();
|
constructor();
|
||||||
}
|
}
|
||||||
interface ITmxElement {
|
interface ITmxElement {
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
class TmxList<T extends ITmxElement> extends Map<string, T> {
|
|
||||||
_nameCount: Map<string, number>;
|
|
||||||
add(t: T): void;
|
|
||||||
protected getKeyForItem(item: T): string;
|
|
||||||
}
|
|
||||||
class TmxImage {
|
class TmxImage {
|
||||||
texture: egret.Texture;
|
bitmap: egret.Bitmap;
|
||||||
|
readonly texture: egret.Texture;
|
||||||
source: string;
|
source: string;
|
||||||
format: string;
|
format: string;
|
||||||
data: any;
|
data: any;
|
||||||
@@ -1657,12 +1654,12 @@ declare module es {
|
|||||||
renderOrder: RenderOrderType;
|
renderOrder: RenderOrderType;
|
||||||
backgroundColor: number;
|
backgroundColor: number;
|
||||||
nextObjectID?: number;
|
nextObjectID?: number;
|
||||||
layers: TmxList<any>;
|
layers: ITmxLayer[];
|
||||||
tilesets: TmxList<TmxTileset>;
|
tilesets: TmxTileset[];
|
||||||
tileLayers: TmxList<TmxLayer>;
|
tileLayers: TmxLayer[];
|
||||||
objectGroups: TmxList<TmxObjectGroup>;
|
objectGroups: TmxLayer[];
|
||||||
imageLayers: TmxList<TmxImageLayer>;
|
imageLayers: TmxImageLayer[];
|
||||||
groups: TmxList<TmxGroup>;
|
groups: TmxGroup[];
|
||||||
properties: Map<string, string>;
|
properties: Map<string, string>;
|
||||||
maxTileWidth: number;
|
maxTileWidth: number;
|
||||||
maxTileHeight: number;
|
maxTileHeight: number;
|
||||||
@@ -1707,12 +1704,14 @@ declare module es {
|
|||||||
offsetY: number;
|
offsetY: number;
|
||||||
color: number;
|
color: number;
|
||||||
drawOrder: DrawOrderType;
|
drawOrder: DrawOrderType;
|
||||||
objects: TmxList<TmxObject>;
|
objects: TmxObject[];
|
||||||
properties: Map<string, string>;
|
properties: Map<string, string>;
|
||||||
}
|
}
|
||||||
class TmxObject implements ITmxElement {
|
class TmxObject implements ITmxElement {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
|
shape: egret.Shape;
|
||||||
|
textField: egret.TextField;
|
||||||
objectType: TmxObjectType;
|
objectType: TmxObjectType;
|
||||||
type: string;
|
type: string;
|
||||||
x: number;
|
x: number;
|
||||||
@@ -1725,6 +1724,7 @@ declare module es {
|
|||||||
text: TmxText;
|
text: TmxText;
|
||||||
points: Vector2[];
|
points: Vector2[];
|
||||||
properties: Map<string, string>;
|
properties: Map<string, string>;
|
||||||
|
constructor();
|
||||||
}
|
}
|
||||||
class TmxText {
|
class TmxText {
|
||||||
fontFamily: string;
|
fontFamily: string;
|
||||||
@@ -1769,14 +1769,40 @@ declare module es {
|
|||||||
bottom = 2
|
bottom = 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
declare module es {
|
||||||
|
class TiledMapLoader {
|
||||||
|
static loadTmxMap(map: TmxMap, filePath: string): Promise<TmxMap>;
|
||||||
|
static loadTmxMapData(map: TmxMap, xMap: any): Promise<TmxMap>;
|
||||||
|
static parseLayers(container: any, xEle: any, map: TmxMap, width: number, height: number, tmxDirectory: string): void;
|
||||||
|
private static updateMaxTileSizes;
|
||||||
|
static parseOrientationType(type: string): OrientationType;
|
||||||
|
static parseStaggerAxisType(type: string): StaggerAxisType;
|
||||||
|
static parseStaggerIndexType(type: string): StaggerIndexType;
|
||||||
|
static parseRenderOrderType(type: string): RenderOrderType;
|
||||||
|
static parsePropertyDict(prop: any): Map<string, string>;
|
||||||
|
static parseTmxTileset(map: TmxMap, xTileset: any): Promise<TmxTileset>;
|
||||||
|
static loadTmxTileset(tileset: TmxTileset, map: TmxMap, xTileset: any, firstGid: number): Promise<TmxTileset>;
|
||||||
|
static loadTmxTilesetTile(tile: TmxTilesetTile, tileset: TmxTileset, xTile: any, terrains: TmxTerrain[]): Promise<TmxTilesetTile>;
|
||||||
|
static loadTmxAnimationFrame(frame: TmxAnimationFrame, xFrame: any): TmxAnimationFrame;
|
||||||
|
static loadTmxObjectGroup(group: TmxObjectGroup, map: TmxMap, xObjectGroup: any): TmxObjectGroup;
|
||||||
|
static loadTmxObject(obj: TmxObject, map: TmxMap, xObject: any): TmxObject;
|
||||||
|
static loadTmxText(text: TmxText, xText: any): TmxText;
|
||||||
|
static loadTmxAlignment(alignment: TmxAlignment, xText: any): TmxAlignment;
|
||||||
|
static parsePoints(xPoints: any): any[];
|
||||||
|
static parsePoint(s: string): Vector2;
|
||||||
|
static parseTmxTerrain(xTerrain: any): TmxTerrain;
|
||||||
|
static parseTmxTileOffset(xTileOffset: any): TmxTileOffset;
|
||||||
|
static loadTmxImage(image: TmxImage, xImage: any): Promise<TmxImage>;
|
||||||
|
}
|
||||||
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
class TiledRendering {
|
class TiledRendering {
|
||||||
static renderMap(map: TmxMap, position: Vector2, scale: Vector2, layerDepth: number): void;
|
static renderMap(map: TmxMap, container: egret.DisplayObjectContainer, position: Vector2, scale: Vector2, layerDepth: number): void;
|
||||||
static renderLayer(layer: TmxLayer, position: Vector2, scale: Vector2, layerDepth: number): void;
|
static renderLayer(layer: TmxLayer, container: egret.DisplayObjectContainer, position: Vector2, scale: Vector2, layerDepth: number): void;
|
||||||
static renderImageLayer(layer: TmxImageLayer, position: Vector2, scale: Vector2, layerDepth: number): void;
|
static renderImageLayer(layer: TmxImageLayer, container: egret.DisplayObjectContainer, position: Vector2, scale: Vector2, layerDepth: number): void;
|
||||||
static renderObjectGroup(objGroup: TmxObjectGroup, position: Vector2, scale: Vector2, layerDepth: number): void;
|
static renderObjectGroup(objGroup: TmxObjectGroup, container: egret.DisplayObjectContainer, position: Vector2, scale: Vector2, layerDepth: number): void;
|
||||||
static renderGroup(group: TmxGroup, position: Vector2, scale: Vector2, layerDepth: number): void;
|
static renderGroup(group: TmxGroup, container: egret.DisplayObjectContainer, position: Vector2, scale: Vector2, layerDepth: number): void;
|
||||||
static renderTile(tile: TmxLayerTile, position: Vector2, scale: Vector2, tileWidth: number, tileHeight: number, color: Color, layerDepth: number): void;
|
static renderTile(tile: TmxLayerTile, container: egret.DisplayObjectContainer, position: Vector2, scale: Vector2, tileWidth: number, tileHeight: number, color: egret.ColorMatrixFilter, layerDepth: number): void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
@@ -1794,7 +1820,7 @@ declare module es {
|
|||||||
tileOffset: TmxTileOffset;
|
tileOffset: TmxTileOffset;
|
||||||
properties: Map<string, string>;
|
properties: Map<string, string>;
|
||||||
image: TmxImage;
|
image: TmxImage;
|
||||||
terrains: TmxList<TmxTerrain>;
|
terrains: TmxTerrain[];
|
||||||
tileRegions: Map<number, Rectangle>;
|
tileRegions: Map<number, Rectangle>;
|
||||||
update(): void;
|
update(): void;
|
||||||
}
|
}
|
||||||
@@ -1817,7 +1843,7 @@ declare module es {
|
|||||||
type: string;
|
type: string;
|
||||||
properties: Map<string, string>;
|
properties: Map<string, string>;
|
||||||
image: TmxImage;
|
image: TmxImage;
|
||||||
objectGroups: TmxList<TmxObjectGroup>;
|
objectGroups: TmxObjectGroup[];
|
||||||
animationFrames: TmxAnimationFrame[];
|
animationFrames: TmxAnimationFrame[];
|
||||||
readonly currentAnimationFrameGid: number;
|
readonly currentAnimationFrameGid: number;
|
||||||
_animationElapsedTime: number;
|
_animationElapsedTime: number;
|
||||||
@@ -1835,6 +1861,12 @@ declare module es {
|
|||||||
duration: number;
|
duration: number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
declare module es {
|
||||||
|
class TmxUtils {
|
||||||
|
static decode(data: any, encoding: any, compression: string): Array<number>;
|
||||||
|
static color16ToUnit($color: string): number;
|
||||||
|
}
|
||||||
|
}
|
||||||
declare class ArrayUtils {
|
declare class ArrayUtils {
|
||||||
static bubbleSort(ary: number[]): void;
|
static bubbleSort(ary: number[]): void;
|
||||||
static insertionSort(ary: number[]): void;
|
static insertionSort(ary: number[]): void;
|
||||||
@@ -1850,15 +1882,16 @@ declare class ArrayUtils {
|
|||||||
static equals(ary1: number[], ary2: number[]): Boolean;
|
static equals(ary1: number[], ary2: number[]): Boolean;
|
||||||
static insert(ary: any[], index: number, value: any): any;
|
static insert(ary: any[], index: number, value: any): any;
|
||||||
}
|
}
|
||||||
declare class Base64Utils {
|
declare module es {
|
||||||
private static _keyNum;
|
class Base64Utils {
|
||||||
private static _keyStr;
|
private static _keyStr;
|
||||||
private static _keyAll;
|
static readonly nativeBase64: boolean;
|
||||||
static encode: (input: any) => string;
|
static decode(input: string): string;
|
||||||
static decode(input: any, isNotStr?: boolean): string;
|
static encode(input: string): string;
|
||||||
private static _utf8_encode;
|
static decodeBase64AsArray(input: string, bytes: number): Uint32Array;
|
||||||
private static _utf8_decode;
|
static decompress(data: string, decoded: any, compression: string): any;
|
||||||
private static getConfKey;
|
static decodeCSV(input: string): Array<number>;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
class Color {
|
class Color {
|
||||||
@@ -1882,6 +1915,9 @@ declare module es {
|
|||||||
declare module es {
|
declare module es {
|
||||||
class DrawUtils {
|
class DrawUtils {
|
||||||
static drawLine(shape: egret.Shape, start: Vector2, end: Vector2, color: number, thickness?: number): void;
|
static drawLine(shape: egret.Shape, start: Vector2, end: Vector2, color: number, thickness?: number): void;
|
||||||
|
static drawCircle(shape: egret.Shape, position: Vector2, radius: number, color: number): void;
|
||||||
|
static drawPoints(shape: egret.Shape, position: Vector2, points: Vector2[], color: number, closePoly?: boolean, thickness?: number): void;
|
||||||
|
static drawString(textField: egret.TextField, text: string, position: Vector2, color: number, rotation: number, origin: Vector2, scale: number): void;
|
||||||
static drawLineAngle(shape: egret.Shape, start: Vector2, radians: number, length: number, color: number, thickness?: number): void;
|
static drawLineAngle(shape: egret.Shape, start: Vector2, radians: number, length: number, color: number, thickness?: number): void;
|
||||||
static drawHollowRect(shape: egret.Shape, rect: Rectangle, color: number, thickness?: number): void;
|
static drawHollowRect(shape: egret.Shape, rect: Rectangle, color: number, thickness?: number): void;
|
||||||
static drawHollowRectR(shape: egret.Shape, x: number, y: number, width: number, height: number, color: number, thickness?: number): void;
|
static drawHollowRectR(shape: egret.Shape, x: number, y: number, width: number, height: number, color: number, thickness?: number): void;
|
||||||
|
|||||||
+634
-148
@@ -1284,6 +1284,7 @@ var es;
|
|||||||
es.Input.initialize();
|
es.Input.initialize();
|
||||||
this.initialize();
|
this.initialize();
|
||||||
};
|
};
|
||||||
|
Core.debugRenderEndabled = false;
|
||||||
return Core;
|
return Core;
|
||||||
}(egret.DisplayObjectContainer));
|
}(egret.DisplayObjectContainer));
|
||||||
es.Core = Core;
|
es.Core = Core;
|
||||||
@@ -3296,8 +3297,9 @@ var es;
|
|||||||
_this.physicsLayer = 1 << 0;
|
_this.physicsLayer = 1 << 0;
|
||||||
_this.tiledMap = tiledMap;
|
_this.tiledMap = tiledMap;
|
||||||
_this._shouldCreateColliders = shouldCreateColliders;
|
_this._shouldCreateColliders = shouldCreateColliders;
|
||||||
|
_this.displayObject = new egret.DisplayObjectContainer();
|
||||||
if (collisionLayerName) {
|
if (collisionLayerName) {
|
||||||
_this.collisionLayer = tiledMap.tileLayers.get(collisionLayerName);
|
_this.collisionLayer = tiledMap.tileLayers[collisionLayerName];
|
||||||
}
|
}
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
@@ -3333,7 +3335,7 @@ var es;
|
|||||||
var layerType = this.tiledMap.getLayer(layerName);
|
var layerType = this.tiledMap.getLayer(layerName);
|
||||||
for (var layer in this.tiledMap.layers) {
|
for (var layer in this.tiledMap.layers) {
|
||||||
if (this.tiledMap.layers.hasOwnProperty(layer) &&
|
if (this.tiledMap.layers.hasOwnProperty(layer) &&
|
||||||
this.tiledMap.layers.get(layer) == layerType) {
|
this.tiledMap.layers[layer] == layerType) {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3364,12 +3366,12 @@ var es;
|
|||||||
};
|
};
|
||||||
TiledMapRenderer.prototype.render = function (camera) {
|
TiledMapRenderer.prototype.render = function (camera) {
|
||||||
if (!this.layerIndicesToRender) {
|
if (!this.layerIndicesToRender) {
|
||||||
es.TiledRendering.renderMap(this.tiledMap, es.Vector2.add(this.entity.transform.position, this._localOffset), this.transform.scale, this.renderLayer);
|
es.TiledRendering.renderMap(this.tiledMap, this.displayObject, es.Vector2.add(this.entity.transform.position, this._localOffset), this.transform.scale, this.renderLayer);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (var i = 0; i < this.tiledMap.layers.size; i++) {
|
for (var i = 0; i < this.tiledMap.layers.length; i++) {
|
||||||
if (this.tiledMap.layers.get(i.toString()).visible && this.layerIndicesToRender.contains(i))
|
if (this.tiledMap.layers[i].visible && this.layerIndicesToRender.contains(i))
|
||||||
es.TiledRendering.renderLayer(this.tiledMap.layers.get(i.toString()), es.Vector2.add(this.entity.transform.position, this._localOffset), this.transform.scale, this.renderLayer);
|
es.TiledRendering.renderLayer(this.tiledMap.layers[i], this.displayObject, es.Vector2.add(this.entity.transform.position, this._localOffset), this.transform.scale, this.renderLayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -7606,45 +7608,25 @@ var es;
|
|||||||
(function (es) {
|
(function (es) {
|
||||||
var TmxDocument = (function () {
|
var TmxDocument = (function () {
|
||||||
function TmxDocument() {
|
function TmxDocument() {
|
||||||
this.TmxDirectory = "";
|
this.tmxDirectory = "";
|
||||||
}
|
}
|
||||||
return TmxDocument;
|
return TmxDocument;
|
||||||
}());
|
}());
|
||||||
es.TmxDocument = TmxDocument;
|
es.TmxDocument = TmxDocument;
|
||||||
var TmxList = (function (_super) {
|
|
||||||
__extends(TmxList, _super);
|
|
||||||
function TmxList() {
|
|
||||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
||||||
_this._nameCount = new Map();
|
|
||||||
return _this;
|
|
||||||
}
|
|
||||||
TmxList.prototype.add = function (t) {
|
|
||||||
var tName = t.name;
|
|
||||||
if (this.has(tName))
|
|
||||||
this._nameCount.set(tName, this._nameCount.get(tName) + 1);
|
|
||||||
else
|
|
||||||
this._nameCount.set(tName, 0);
|
|
||||||
};
|
|
||||||
TmxList.prototype.getKeyForItem = function (item) {
|
|
||||||
var name = item.name;
|
|
||||||
var count = this._nameCount.get(name);
|
|
||||||
var dupes = 0;
|
|
||||||
while (this.has(name)) {
|
|
||||||
name = name + es.Enumerable.repeat("_", dupes).toString() + count.toString();
|
|
||||||
dupes++;
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
};
|
|
||||||
return TmxList;
|
|
||||||
}(Map));
|
|
||||||
es.TmxList = TmxList;
|
|
||||||
var TmxImage = (function () {
|
var TmxImage = (function () {
|
||||||
function TmxImage() {
|
function TmxImage() {
|
||||||
}
|
}
|
||||||
|
Object.defineProperty(TmxImage.prototype, "texture", {
|
||||||
|
get: function () {
|
||||||
|
return this.bitmap.texture;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
TmxImage.prototype.dispose = function () {
|
TmxImage.prototype.dispose = function () {
|
||||||
if (this.texture) {
|
if (this.bitmap) {
|
||||||
this.texture.dispose();
|
this.texture.dispose();
|
||||||
this.texture = null;
|
this.bitmap = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return TmxImage;
|
return TmxImage;
|
||||||
@@ -7682,9 +7664,9 @@ var es;
|
|||||||
TmxMap.prototype.getTilesetForTileGid = function (gid) {
|
TmxMap.prototype.getTilesetForTileGid = function (gid) {
|
||||||
if (gid == 0)
|
if (gid == 0)
|
||||||
return null;
|
return null;
|
||||||
for (var i = this.tilesets.size - 1; i >= 0; i--) {
|
for (var i = this.tilesets.length - 1; i >= 0; i--) {
|
||||||
if (this.tilesets.get(i.toString()).firstGid <= gid)
|
if (this.tilesets[i].firstGid <= gid)
|
||||||
return this.tilesets.get(i.toString());
|
return this.tilesets[i];
|
||||||
}
|
}
|
||||||
console.error("tile gid" + gid + "\u672A\u5728\u4EFB\u4F55tileset\u4E2D\u627E\u5230");
|
console.error("tile gid" + gid + "\u672A\u5728\u4EFB\u4F55tileset\u4E2D\u627E\u5230");
|
||||||
};
|
};
|
||||||
@@ -7703,7 +7685,7 @@ var es;
|
|||||||
return es.MathHelper.clamp(tileY, 0, this.height - 1);
|
return es.MathHelper.clamp(tileY, 0, this.height - 1);
|
||||||
};
|
};
|
||||||
TmxMap.prototype.getLayer = function (name) {
|
TmxMap.prototype.getLayer = function (name) {
|
||||||
return this.layers.get(name);
|
return this.layers[name];
|
||||||
};
|
};
|
||||||
TmxMap.prototype.update = function () {
|
TmxMap.prototype.update = function () {
|
||||||
this.tilesets.forEach(function (tileset) { tileset.update(); });
|
this.tilesets.forEach(function (tileset) { tileset.update(); });
|
||||||
@@ -7759,6 +7741,8 @@ var es;
|
|||||||
es.TmxObjectGroup = TmxObjectGroup;
|
es.TmxObjectGroup = TmxObjectGroup;
|
||||||
var TmxObject = (function () {
|
var TmxObject = (function () {
|
||||||
function TmxObject() {
|
function TmxObject() {
|
||||||
|
this.shape = new egret.Shape();
|
||||||
|
this.textField = new egret.TextField();
|
||||||
}
|
}
|
||||||
return TmxObject;
|
return TmxObject;
|
||||||
}());
|
}());
|
||||||
@@ -7806,103 +7790,562 @@ var es;
|
|||||||
})(TmxVerticalAlignment = es.TmxVerticalAlignment || (es.TmxVerticalAlignment = {}));
|
})(TmxVerticalAlignment = es.TmxVerticalAlignment || (es.TmxVerticalAlignment = {}));
|
||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
|
(function (es) {
|
||||||
|
var Bitmap = egret.Bitmap;
|
||||||
|
var TiledMapLoader = (function () {
|
||||||
|
function TiledMapLoader() {
|
||||||
|
}
|
||||||
|
TiledMapLoader.loadTmxMap = function (map, filePath) {
|
||||||
|
var xMap = RES.getRes(filePath);
|
||||||
|
return this.loadTmxMapData(map, xMap);
|
||||||
|
};
|
||||||
|
TiledMapLoader.loadTmxMapData = function (map, xMap) {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var _i, _a, e, tileset;
|
||||||
|
return __generator(this, function (_b) {
|
||||||
|
switch (_b.label) {
|
||||||
|
case 0:
|
||||||
|
map.version = xMap["version"];
|
||||||
|
map.tiledVersion = xMap["tiledversion"];
|
||||||
|
map.width = xMap["width"];
|
||||||
|
map.height = xMap["height"];
|
||||||
|
map.tileWidth = xMap["tilewidth"];
|
||||||
|
map.tileHeight = xMap["tileheight"];
|
||||||
|
map.hexSideLength = xMap["hexsidelength"];
|
||||||
|
map.orientation = this.parseOrientationType(xMap["orientation"]);
|
||||||
|
map.staggerAxis = this.parseStaggerAxisType(xMap["staggeraxis"]);
|
||||||
|
map.staggerIndex = this.parseStaggerIndexType(xMap["staggerindex"]);
|
||||||
|
map.renderOrder = this.parseRenderOrderType(xMap["renderorder"]);
|
||||||
|
map.nextObjectID = xMap["nextobjectid"];
|
||||||
|
map.backgroundColor = es.TmxUtils.color16ToUnit(xMap["color"]);
|
||||||
|
map.properties = this.parsePropertyDict(xMap["properties"]);
|
||||||
|
map.maxTileWidth = map.tileWidth;
|
||||||
|
map.maxTileHeight = map.tileHeight;
|
||||||
|
map.tilesets = [];
|
||||||
|
_i = 0, _a = xMap["tilesets"];
|
||||||
|
_b.label = 1;
|
||||||
|
case 1:
|
||||||
|
if (!(_i < _a.length)) return [3, 4];
|
||||||
|
e = _a[_i];
|
||||||
|
return [4, this.parseTmxTileset(map, e)];
|
||||||
|
case 2:
|
||||||
|
tileset = _b.sent();
|
||||||
|
map.tilesets.push(tileset);
|
||||||
|
this.updateMaxTileSizes(tileset);
|
||||||
|
_b.label = 3;
|
||||||
|
case 3:
|
||||||
|
_i++;
|
||||||
|
return [3, 1];
|
||||||
|
case 4:
|
||||||
|
map.layers = [];
|
||||||
|
map.tileLayers = [];
|
||||||
|
map.objectGroups = [];
|
||||||
|
map.imageLayers = [];
|
||||||
|
map.groups = [];
|
||||||
|
this.parseLayers(map, xMap, map, map.width, map.height, map.tmxDirectory);
|
||||||
|
return [2, map];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
TiledMapLoader.parseLayers = function (container, xEle, map, width, height, tmxDirectory) {
|
||||||
|
};
|
||||||
|
TiledMapLoader.updateMaxTileSizes = function (tileset) {
|
||||||
|
tileset.tiles.forEach(function (tile) {
|
||||||
|
if (tile.image) {
|
||||||
|
if (tile.image.width > tileset.map.maxTileWidth)
|
||||||
|
tileset.map.maxTileWidth = tile.image.width;
|
||||||
|
if (tile.image.height > tileset.map.maxTileHeight)
|
||||||
|
tileset.map.maxTileHeight = tile.image.height;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tileset.tileRegions.forEach(function (region) {
|
||||||
|
var width = region.width;
|
||||||
|
var height = region.height;
|
||||||
|
if (width > tileset.map.maxTileWidth)
|
||||||
|
tileset.map.maxTileWidth = width;
|
||||||
|
if (width > tileset.map.maxTileHeight)
|
||||||
|
tileset.map.maxTileHeight = height;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
TiledMapLoader.parseOrientationType = function (type) {
|
||||||
|
if (type == "unknown")
|
||||||
|
return es.OrientationType.unknown;
|
||||||
|
if (type == "orthogonal")
|
||||||
|
return es.OrientationType.orthogonal;
|
||||||
|
if (type == "isometric")
|
||||||
|
return es.OrientationType.isometric;
|
||||||
|
if (type == "staggered")
|
||||||
|
return es.OrientationType.staggered;
|
||||||
|
if (type == "hexagonal")
|
||||||
|
return es.OrientationType.hexagonal;
|
||||||
|
return es.OrientationType.unknown;
|
||||||
|
};
|
||||||
|
TiledMapLoader.parseStaggerAxisType = function (type) {
|
||||||
|
if (type == "y")
|
||||||
|
return es.StaggerAxisType.y;
|
||||||
|
return es.StaggerAxisType.x;
|
||||||
|
};
|
||||||
|
TiledMapLoader.parseStaggerIndexType = function (type) {
|
||||||
|
if (type == "even")
|
||||||
|
return es.StaggerIndexType.even;
|
||||||
|
return es.StaggerIndexType.odd;
|
||||||
|
};
|
||||||
|
TiledMapLoader.parseRenderOrderType = function (type) {
|
||||||
|
if (type == "right-up")
|
||||||
|
return es.RenderOrderType.rightUp;
|
||||||
|
if (type == "left-down")
|
||||||
|
return es.RenderOrderType.leftDown;
|
||||||
|
if (type == "left-up")
|
||||||
|
return es.RenderOrderType.leftUp;
|
||||||
|
return es.RenderOrderType.rightDown;
|
||||||
|
};
|
||||||
|
TiledMapLoader.parsePropertyDict = function (prop) {
|
||||||
|
if (!prop)
|
||||||
|
return null;
|
||||||
|
var dict = new Map();
|
||||||
|
for (var _i = 0, _a = prop["property"]; _i < _a.length; _i++) {
|
||||||
|
var p = _a[_i];
|
||||||
|
var pname = p["name"];
|
||||||
|
var valueAttr = p["value"];
|
||||||
|
var pval = valueAttr ? valueAttr : p;
|
||||||
|
dict.set(pname, pval);
|
||||||
|
}
|
||||||
|
return dict;
|
||||||
|
};
|
||||||
|
TiledMapLoader.parseTmxTileset = function (map, xTileset) {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var xFirstGid, firstGid, source, xDocTileset, tileset;
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0:
|
||||||
|
xFirstGid = xTileset["firstgid"];
|
||||||
|
firstGid = xFirstGid;
|
||||||
|
source = xTileset["image"];
|
||||||
|
if (!!source) return [3, 2];
|
||||||
|
source = "resource/assets/" + source;
|
||||||
|
return [4, RES.getResByUrl(source, null, this, RES.ResourceItem.TYPE_IMAGE)];
|
||||||
|
case 1:
|
||||||
|
xDocTileset = _a.sent();
|
||||||
|
tileset = this.loadTmxTileset(new es.TmxTileset(), map, xDocTileset["tileset"], firstGid);
|
||||||
|
return [2, tileset];
|
||||||
|
case 2: return [2, this.loadTmxTileset(new es.TmxTileset(), map, xTileset, firstGid)];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
TiledMapLoader.loadTmxTileset = function (tileset, map, xTileset, firstGid) {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var xImage, _a, xTerrainType, _i, _b, e, _c, _d, xTile, tile, id, y, column, x;
|
||||||
|
return __generator(this, function (_e) {
|
||||||
|
switch (_e.label) {
|
||||||
|
case 0:
|
||||||
|
tileset.map = map;
|
||||||
|
tileset.firstGid = firstGid;
|
||||||
|
tileset.name = xTileset["name"];
|
||||||
|
tileset.tileWidth = xTileset["tilewidth"];
|
||||||
|
tileset.tileHeight = xTileset["tileheight"];
|
||||||
|
tileset.spacing = xTileset["spacing"] != undefined ? xTileset["spacing"] : 0;
|
||||||
|
tileset.margin = xTileset["margin"] != undefined ? xTileset["margin"] : 0;
|
||||||
|
tileset.columns = xTileset["columns"];
|
||||||
|
tileset.tileCount = xTileset["tilecount"];
|
||||||
|
tileset.tileOffset = this.parseTmxTileOffset(xTileset["tileoffset"]);
|
||||||
|
xImage = xTileset["image"];
|
||||||
|
if (!xImage) return [3, 2];
|
||||||
|
_a = tileset;
|
||||||
|
return [4, this.loadTmxImage(new es.TmxImage(), xTileset)];
|
||||||
|
case 1:
|
||||||
|
_a.image = _e.sent();
|
||||||
|
_e.label = 2;
|
||||||
|
case 2:
|
||||||
|
xTerrainType = xTileset["terraintypes"];
|
||||||
|
if (xTerrainType) {
|
||||||
|
tileset.terrains = [];
|
||||||
|
for (_i = 0, _b = xTerrainType["terrains"]; _i < _b.length; _i++) {
|
||||||
|
e = _b[_i];
|
||||||
|
tileset.terrains.push(this.parseTmxTerrain(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tileset.tiles = new Map();
|
||||||
|
_c = 0, _d = xTileset["tiles"];
|
||||||
|
_e.label = 3;
|
||||||
|
case 3:
|
||||||
|
if (!(_c < _d.length)) return [3, 6];
|
||||||
|
xTile = _d[_c];
|
||||||
|
return [4, this.loadTmxTilesetTile(new es.TmxTilesetTile(), tileset, xTile, tileset.terrains)];
|
||||||
|
case 4:
|
||||||
|
tile = _e.sent();
|
||||||
|
tileset.tiles[tile.id] = tile;
|
||||||
|
_e.label = 5;
|
||||||
|
case 5:
|
||||||
|
_c++;
|
||||||
|
return [3, 3];
|
||||||
|
case 6:
|
||||||
|
tileset.properties = this.parsePropertyDict(xTileset["properties"]);
|
||||||
|
tileset.tileRegions = new Map();
|
||||||
|
if (tileset.image) {
|
||||||
|
id = firstGid;
|
||||||
|
for (y = tileset.margin; y < tileset.image.height - tileset.margin; y += tileset.tileHeight + tileset.spacing) {
|
||||||
|
column = 0;
|
||||||
|
for (x = tileset.margin; x < tileset.image.width - tileset.margin; x += tileset.tileWidth + tileset.spacing) {
|
||||||
|
tileset.tileRegions.set(id++, new es.Rectangle(x, y, tileset.tileWidth, tileset.tileHeight));
|
||||||
|
if (++column >= tileset.columns)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tileset.tiles.forEach(function (tile) {
|
||||||
|
tileset.tileRegions.set(firstGid + tile.id, new es.Rectangle(0, 0, tile.image.width, tile.image.height));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return [2, tileset];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
TiledMapLoader.loadTmxTilesetTile = function (tile, tileset, xTile, terrains) {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var xImage, _a, _i, _b, e, _c, _d, e;
|
||||||
|
return __generator(this, function (_e) {
|
||||||
|
switch (_e.label) {
|
||||||
|
case 0:
|
||||||
|
tile.tileset = tileset;
|
||||||
|
tile.id = xTile["id"];
|
||||||
|
tile.terrainEdges = xTile["terrain"];
|
||||||
|
tile.probability = xTile["probability"] != undefined ? xTile["probability"] : 1;
|
||||||
|
tile.type = xTile["type"];
|
||||||
|
xImage = xTile["image"];
|
||||||
|
if (!xImage) return [3, 2];
|
||||||
|
_a = tile;
|
||||||
|
return [4, this.loadTmxImage(new es.TmxImage(), xImage)];
|
||||||
|
case 1:
|
||||||
|
_a.image = _e.sent();
|
||||||
|
_e.label = 2;
|
||||||
|
case 2:
|
||||||
|
tile.objectGroups = [];
|
||||||
|
if (xTile["objectgroup"])
|
||||||
|
for (_i = 0, _b = xTile["objectgroup"]; _i < _b.length; _i++) {
|
||||||
|
e = _b[_i];
|
||||||
|
tile.objectGroups.push(this.loadTmxObjectGroup(new es.TmxObjectGroup(), tileset.map, e));
|
||||||
|
}
|
||||||
|
tile.animationFrames = [];
|
||||||
|
if (xTile["animation"]) {
|
||||||
|
for (_c = 0, _d = xTile["animation"]["frame"]; _c < _d.length; _c++) {
|
||||||
|
e = _d[_c];
|
||||||
|
tile.animationFrames.push(this.loadTmxAnimationFrame(new es.TmxAnimationFrame(), e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tile.properties = this.parsePropertyDict(xTile["properties"]);
|
||||||
|
if (tile.properties)
|
||||||
|
tile.processProperties();
|
||||||
|
return [2, tile];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
TiledMapLoader.loadTmxAnimationFrame = function (frame, xFrame) {
|
||||||
|
frame.gid = xFrame["tileid"];
|
||||||
|
frame.duration = xFrame["duration"] / 1000;
|
||||||
|
return frame;
|
||||||
|
};
|
||||||
|
TiledMapLoader.loadTmxObjectGroup = function (group, map, xObjectGroup) {
|
||||||
|
group.map = map;
|
||||||
|
group.name = xObjectGroup["name"] != undefined ? xObjectGroup["name"] : "";
|
||||||
|
group.color = es.TmxUtils.color16ToUnit(xObjectGroup["color"]);
|
||||||
|
group.opacity = xObjectGroup["opacity"] != undefined ? xObjectGroup["opacity"] : 1;
|
||||||
|
group.visible = xObjectGroup["visible"] != undefined ? xObjectGroup["visible"] : true;
|
||||||
|
group.offsetX = xObjectGroup["offsetx"] != undefined ? xObjectGroup["offsetx"] : 0;
|
||||||
|
group.offsetY = xObjectGroup["offsety"] != undefined ? xObjectGroup["offsety"] : 0;
|
||||||
|
var drawOrderDict = new Map();
|
||||||
|
drawOrderDict.set("unknown", es.DrawOrderType.unkownOrder);
|
||||||
|
drawOrderDict.set("topdown", es.DrawOrderType.IndexOrder);
|
||||||
|
drawOrderDict.set("index", es.DrawOrderType.TopDown);
|
||||||
|
var drawOrderValue = xObjectGroup["draworder"];
|
||||||
|
if (drawOrderValue)
|
||||||
|
group.drawOrder = drawOrderDict[drawOrderValue];
|
||||||
|
group.objects = [];
|
||||||
|
for (var _i = 0, _a = xObjectGroup["object"]; _i < _a.length; _i++) {
|
||||||
|
var e = _a[_i];
|
||||||
|
group.objects.push(this.loadTmxObject(new es.TmxObject(), map, e));
|
||||||
|
}
|
||||||
|
group.properties = this.parsePropertyDict(xObjectGroup["properties"]);
|
||||||
|
return group;
|
||||||
|
};
|
||||||
|
TiledMapLoader.loadTmxObject = function (obj, map, xObject) {
|
||||||
|
obj.id = xObject["id"] != undefined ? xObject["id"] : 0;
|
||||||
|
obj.name = xObject["name"] != undefined ? xObject["name"] : "";
|
||||||
|
obj.x = xObject["x"];
|
||||||
|
obj.y = xObject["y"];
|
||||||
|
obj.width = xObject["width"] != undefined ? xObject["width"] : 0;
|
||||||
|
obj.height = xObject["height"] != undefined ? xObject["height"] : 0;
|
||||||
|
obj.type = xObject["type"] != undefined ? xObject["type"] : "";
|
||||||
|
obj.visible = xObject["visible"] != undefined ? xObject["visible"] : true;
|
||||||
|
obj.rotation = xObject["rotation"] != undefined ? xObject["rotation"] : 0;
|
||||||
|
var xGid = xObject["gid"];
|
||||||
|
var xEllipse = xObject["ellipse"];
|
||||||
|
var xPolygon = xObject["polygon"];
|
||||||
|
var xPolyline = xObject["polyline"];
|
||||||
|
var xText = xObject["text"];
|
||||||
|
var xPoint = xObject["point"];
|
||||||
|
if (xGid) {
|
||||||
|
obj.tile = new es.TmxLayerTile(map, xGid, Math.round(obj.x), Math.round(obj.y));
|
||||||
|
obj.objectType = es.TmxObjectType.tile;
|
||||||
|
}
|
||||||
|
else if (xEllipse) {
|
||||||
|
obj.objectType = es.TmxObjectType.ellipse;
|
||||||
|
}
|
||||||
|
else if (xPolygon) {
|
||||||
|
obj.points = this.parsePoints(xPolygon);
|
||||||
|
obj.objectType = es.TmxObjectType.polygon;
|
||||||
|
}
|
||||||
|
else if (xPolyline) {
|
||||||
|
obj.points = this.parsePoints(xPolyline);
|
||||||
|
obj.objectType = es.TmxObjectType.polyline;
|
||||||
|
}
|
||||||
|
else if (xText) {
|
||||||
|
obj.text = this.loadTmxText(new es.TmxText(), xText);
|
||||||
|
obj.objectType = es.TmxObjectType.text;
|
||||||
|
}
|
||||||
|
else if (xPoint) {
|
||||||
|
obj.objectType = es.TmxObjectType.point;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
obj.objectType = es.TmxObjectType.basic;
|
||||||
|
}
|
||||||
|
obj.properties = this.parsePropertyDict(xObject["properties"]);
|
||||||
|
return obj;
|
||||||
|
};
|
||||||
|
TiledMapLoader.loadTmxText = function (text, xText) {
|
||||||
|
text.fontFamily = xText["fontfamily"] != undefined ? xText["fontfamily"] : "sans-serif";
|
||||||
|
text.pixelSize = xText["pixelsize"] != undefined ? xText["pixelsize"] : 16;
|
||||||
|
text.wrap = xText["wrap"] != undefined ? xText["wrap"] : false;
|
||||||
|
text.color = es.TmxUtils.color16ToUnit(xText["color"]);
|
||||||
|
text.bold = xText["bold"] ? xText["bold"] : false;
|
||||||
|
text.italic = xText["italic"] ? xText["italic"] : false;
|
||||||
|
text.underline = xText["underline"] ? xText["underline"] : false;
|
||||||
|
text.strikeout = xText["strikeout"] ? xText["strikeout"] : false;
|
||||||
|
text.kerning = xText["kerning"] ? xText["kerning"] : true;
|
||||||
|
text.alignment = this.loadTmxAlignment(new es.TmxAlignment(), xText);
|
||||||
|
text.value = xText;
|
||||||
|
return text;
|
||||||
|
};
|
||||||
|
TiledMapLoader.loadTmxAlignment = function (alignment, xText) {
|
||||||
|
function firstLetterToUpperCase(str) {
|
||||||
|
if (!str || str == "")
|
||||||
|
return str;
|
||||||
|
return str[0].toString().toUpperCase() + str.substr(1);
|
||||||
|
}
|
||||||
|
var xHorizontal = xText["halign"] != undefined ? xText["halign"] : "left";
|
||||||
|
alignment.horizontal = es.TmxHorizontalAlignment[firstLetterToUpperCase(xHorizontal)];
|
||||||
|
var xVertical = xText["valign"] != undefined ? xText["valign"] : "top";
|
||||||
|
alignment.vertical = es.TmxVerticalAlignment[firstLetterToUpperCase((xVertical))];
|
||||||
|
return alignment;
|
||||||
|
};
|
||||||
|
TiledMapLoader.parsePoints = function (xPoints) {
|
||||||
|
var pointString = xPoints["points"];
|
||||||
|
var pointStringPair = pointString.split(' ');
|
||||||
|
var points = [];
|
||||||
|
var index = 0;
|
||||||
|
for (var _i = 0, pointStringPair_1 = pointStringPair; _i < pointStringPair_1.length; _i++) {
|
||||||
|
var s = pointStringPair_1[_i];
|
||||||
|
points[index++] = this.parsePoint(s);
|
||||||
|
}
|
||||||
|
return points;
|
||||||
|
};
|
||||||
|
TiledMapLoader.parsePoint = function (s) {
|
||||||
|
var pt = s.split(',');
|
||||||
|
var x = Number(pt[0]);
|
||||||
|
var y = Number(pt[1]);
|
||||||
|
return new es.Vector2(x, y);
|
||||||
|
};
|
||||||
|
TiledMapLoader.parseTmxTerrain = function (xTerrain) {
|
||||||
|
var terrain = new es.TmxTerrain();
|
||||||
|
terrain.name = xTerrain["name"];
|
||||||
|
terrain.tile = xTerrain["tile"];
|
||||||
|
terrain.properties = this.parsePropertyDict(xTerrain["properties"]);
|
||||||
|
return terrain;
|
||||||
|
};
|
||||||
|
TiledMapLoader.parseTmxTileOffset = function (xTileOffset) {
|
||||||
|
var tmxTileOffset = new es.TmxTileOffset();
|
||||||
|
if (!xTileOffset) {
|
||||||
|
tmxTileOffset.x = 0;
|
||||||
|
tmxTileOffset.y = 0;
|
||||||
|
return tmxTileOffset;
|
||||||
|
}
|
||||||
|
tmxTileOffset.x = xTileOffset["x"];
|
||||||
|
tmxTileOffset.y = xTileOffset["y"];
|
||||||
|
return tmxTileOffset;
|
||||||
|
};
|
||||||
|
TiledMapLoader.loadTmxImage = function (image, xImage) {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var xSource, _a, _b, xData;
|
||||||
|
return __generator(this, function (_c) {
|
||||||
|
switch (_c.label) {
|
||||||
|
case 0:
|
||||||
|
xSource = xImage["image"];
|
||||||
|
if (!xSource) return [3, 2];
|
||||||
|
image.source = "resource/assets/" + xSource;
|
||||||
|
_a = image;
|
||||||
|
_b = Bitmap.bind;
|
||||||
|
return [4, RES.getResByUrl(image.source, null, this, RES.ResourceItem.TYPE_IMAGE)];
|
||||||
|
case 1:
|
||||||
|
_a.bitmap = new (_b.apply(Bitmap, [void 0, _c.sent()]))();
|
||||||
|
return [3, 3];
|
||||||
|
case 2:
|
||||||
|
image.format = xImage["format"];
|
||||||
|
xData = xImage["data"];
|
||||||
|
image.data = es.TmxUtils.decode(xData, xData["encoding"], xData["compression"]);
|
||||||
|
_c.label = 3;
|
||||||
|
case 3:
|
||||||
|
image.trans = es.TmxUtils.color16ToUnit(xImage["trans"]);
|
||||||
|
image.width = xImage["width"] != undefined ? xImage["width"] : 0;
|
||||||
|
image.height = xImage["height"] != undefined ? xImage["height"] : 0;
|
||||||
|
return [2, image];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
return TiledMapLoader;
|
||||||
|
}());
|
||||||
|
es.TiledMapLoader = TiledMapLoader;
|
||||||
|
})(es || (es = {}));
|
||||||
|
var es;
|
||||||
(function (es) {
|
(function (es) {
|
||||||
var TiledRendering = (function () {
|
var TiledRendering = (function () {
|
||||||
function TiledRendering() {
|
function TiledRendering() {
|
||||||
}
|
}
|
||||||
TiledRendering.renderMap = function (map, position, scale, layerDepth) {
|
TiledRendering.renderMap = function (map, container, position, scale, layerDepth) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
map.layers.forEach(function (layer) {
|
map.layers.forEach(function (layer) {
|
||||||
if (layer instanceof es.TmxLayer && layer.visible) {
|
if (layer instanceof es.TmxLayer && layer.visible) {
|
||||||
_this.renderLayer(layer, position, scale, layerDepth);
|
_this.renderLayer(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
else if (layer instanceof es.TmxImageLayer && layer.visible) {
|
else if (layer instanceof es.TmxImageLayer && layer.visible) {
|
||||||
_this.renderImageLayer(layer, position, scale, layerDepth);
|
_this.renderImageLayer(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
else if (layer instanceof es.TmxGroup && layer.visible) {
|
else if (layer instanceof es.TmxGroup && layer.visible) {
|
||||||
_this.renderGroup(layer, position, scale, layerDepth);
|
_this.renderGroup(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
else if (layer instanceof es.TmxObjectGroup && layer.visible) {
|
else if (layer instanceof es.TmxObjectGroup && layer.visible) {
|
||||||
_this.renderObjectGroup(layer, position, scale, layerDepth);
|
_this.renderObjectGroup(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
TiledRendering.renderLayer = function (layer, position, scale, layerDepth) {
|
TiledRendering.renderLayer = function (layer, container, position, scale, layerDepth) {
|
||||||
if (!layer.visible)
|
if (!layer.visible)
|
||||||
return;
|
return;
|
||||||
var tileWidth = layer.map.tileWidth * scale.x;
|
var tileWidth = layer.map.tileWidth * scale.x;
|
||||||
var tileHeight = layer.map.tileHeight * scale.y;
|
var tileHeight = layer.map.tileHeight * scale.y;
|
||||||
var color = new es.Color(0, 0, 0, layer.opacity * 255);
|
var color = es.DrawUtils.getColorMatrix(0x000000);
|
||||||
for (var i = 0; i < layer.tiles.length; i++) {
|
for (var i = 0; i < layer.tiles.length; i++) {
|
||||||
var tile = layer.tiles[i];
|
var tile = layer.tiles[i];
|
||||||
if (!tile)
|
if (!tile)
|
||||||
continue;
|
continue;
|
||||||
this.renderTile(tile, position, scale, tileWidth, tileHeight, color, layerDepth);
|
this.renderTile(tile, container, position, scale, tileWidth, tileHeight, color, layerDepth);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
TiledRendering.renderImageLayer = function (layer, position, scale, layerDepth) {
|
TiledRendering.renderImageLayer = function (layer, container, position, scale, layerDepth) {
|
||||||
if (!layer.visible)
|
if (!layer.visible)
|
||||||
return;
|
return;
|
||||||
var color = new es.Color(0, 0, 0, layer.opacity * 255);
|
var color = es.DrawUtils.getColorMatrix(0x000000);
|
||||||
var pos = es.Vector2.add(position, new es.Vector2(layer.offsetX, layer.offsetY).multiply(scale));
|
var pos = es.Vector2.add(position, new es.Vector2(layer.offsetX, layer.offsetY).multiply(scale));
|
||||||
|
if (!layer.image.bitmap.parent)
|
||||||
|
container.addChild(layer.image.bitmap);
|
||||||
|
layer.image.bitmap.x = pos.x;
|
||||||
|
layer.image.bitmap.y = pos.y;
|
||||||
|
layer.image.bitmap.scaleX = scale.x;
|
||||||
|
layer.image.bitmap.scaleY = scale.y;
|
||||||
|
layer.image.bitmap.filters = [color];
|
||||||
};
|
};
|
||||||
TiledRendering.renderObjectGroup = function (objGroup, position, scale, layerDepth) {
|
TiledRendering.renderObjectGroup = function (objGroup, container, position, scale, layerDepth) {
|
||||||
if (!objGroup.visible)
|
if (!objGroup.visible)
|
||||||
return;
|
return;
|
||||||
for (var object in objGroup.objects) {
|
for (var object in objGroup.objects) {
|
||||||
var obj = objGroup.objects.get(object);
|
var obj = objGroup.objects[object];
|
||||||
if (!obj.visible)
|
if (!obj.visible)
|
||||||
continue;
|
continue;
|
||||||
|
if (!es.Core.debugRenderEndabled) {
|
||||||
|
if (obj.objectType != es.TmxObjectType.tile && obj.objectType != es.TmxObjectType.text)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
var pos = es.Vector2.add(position, new es.Vector2(obj.x, obj.y).multiply(scale));
|
var pos = es.Vector2.add(position, new es.Vector2(obj.x, obj.y).multiply(scale));
|
||||||
switch (obj.objectType) {
|
switch (obj.objectType) {
|
||||||
case es.TmxObjectType.basic:
|
case es.TmxObjectType.basic:
|
||||||
|
if (!obj.shape.parent)
|
||||||
|
container.addChild(obj.shape);
|
||||||
|
var rect = new es.Rectangle(pos.x, pos.y, obj.width * scale.x, obj.height * scale.y);
|
||||||
|
es.DrawUtils.drawHollowRect(obj.shape, rect, objGroup.color);
|
||||||
break;
|
break;
|
||||||
case es.TmxObjectType.point:
|
case es.TmxObjectType.point:
|
||||||
var size = objGroup.map.tileWidth * 0.5;
|
var size = objGroup.map.tileWidth * 0.5;
|
||||||
pos.x -= size * 0.5;
|
pos.x -= size * 0.5;
|
||||||
pos.y -= size * 0.5;
|
pos.y -= size * 0.5;
|
||||||
|
if (!obj.shape.parent)
|
||||||
|
container.addChild(obj.shape);
|
||||||
|
es.DrawUtils.drawPixel(obj.shape, pos, objGroup.color, size);
|
||||||
break;
|
break;
|
||||||
case es.TmxObjectType.tile:
|
case es.TmxObjectType.tile:
|
||||||
var tileset = objGroup.map.getTilesetForTileGid(obj.tile.gid);
|
var tileset = objGroup.map.getTilesetForTileGid(obj.tile.gid);
|
||||||
var sourceRect = tileset.tileRegions[obj.tile.gid];
|
var sourceRect = tileset.tileRegions[obj.tile.gid];
|
||||||
pos.y -= obj.tile.tilesetTile.image.height;
|
pos.y -= obj.tile.tilesetTile.image.height;
|
||||||
|
if (!obj.tile.tilesetTile.image.bitmap)
|
||||||
|
container.addChild(obj.tile.tilesetTile.image.bitmap);
|
||||||
|
obj.tile.tilesetTile.image.bitmap.x = pos.x;
|
||||||
|
obj.tile.tilesetTile.image.bitmap.y = pos.y;
|
||||||
|
obj.tile.tilesetTile.image.bitmap.filters = [];
|
||||||
|
obj.tile.tilesetTile.image.bitmap.rotation = 0;
|
||||||
|
obj.tile.tilesetTile.image.bitmap.scaleX = scale.x;
|
||||||
|
obj.tile.tilesetTile.image.bitmap.scaleY = scale.y;
|
||||||
break;
|
break;
|
||||||
case es.TmxObjectType.ellipse:
|
case es.TmxObjectType.ellipse:
|
||||||
pos = new es.Vector2(obj.x + obj.width * 0.5, obj.y + obj.height * 0.5).multiply(scale);
|
pos = new es.Vector2(obj.x + obj.width * 0.5, obj.y + obj.height * 0.5).multiply(scale);
|
||||||
|
if (!obj.shape.parent)
|
||||||
|
container.addChild(obj.shape);
|
||||||
|
es.DrawUtils.drawCircle(obj.shape, pos, obj.width * 0.5, objGroup.color);
|
||||||
break;
|
break;
|
||||||
case es.TmxObjectType.polygon:
|
case es.TmxObjectType.polygon:
|
||||||
case es.TmxObjectType.polyline:
|
case es.TmxObjectType.polyline:
|
||||||
var points = [];
|
var points = [];
|
||||||
for (var i = 0; i < obj.points.length; i++)
|
for (var i = 0; i < obj.points.length; i++)
|
||||||
points[i] = es.Vector2.multiply(obj.points[i], scale);
|
points[i] = es.Vector2.multiply(obj.points[i], scale);
|
||||||
|
es.DrawUtils.drawPoints(obj.shape, pos, points, objGroup.color, obj.objectType == es.TmxObjectType.polygon);
|
||||||
break;
|
break;
|
||||||
case es.TmxObjectType.text:
|
case es.TmxObjectType.text:
|
||||||
|
if (!obj.textField.parent)
|
||||||
|
container.addChild(obj.textField);
|
||||||
|
es.DrawUtils.drawString(obj.textField, obj.text.value, pos, obj.text.color, es.MathHelper.toRadians(obj.rotation), es.Vector2.zero, 1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
if (es.Core.debugRenderEndabled) {
|
||||||
|
if (!obj.textField.parent)
|
||||||
|
container.addChild(obj.textField);
|
||||||
|
es.DrawUtils.drawString(obj.textField, obj.name + "(" + obj.type + ")", es.Vector2.subtract(pos, new es.Vector2(0, 15)), 0xffffff, 0, es.Vector2.zero, 1);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
TiledRendering.renderGroup = function (group, position, scale, layerDepth) {
|
TiledRendering.renderGroup = function (group, container, position, scale, layerDepth) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
if (!group.visible)
|
if (!group.visible)
|
||||||
return;
|
return;
|
||||||
group.layers.forEach(function (layer) {
|
group.layers.forEach(function (layer) {
|
||||||
if (layer instanceof es.TmxGroup) {
|
if (layer instanceof es.TmxGroup) {
|
||||||
_this.renderGroup(layer, position, scale, layerDepth);
|
_this.renderGroup(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
if (layer instanceof es.TmxObjectGroup) {
|
if (layer instanceof es.TmxObjectGroup) {
|
||||||
_this.renderObjectGroup(layer, position, scale, layerDepth);
|
_this.renderObjectGroup(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
if (layer instanceof es.TmxLayer) {
|
if (layer instanceof es.TmxLayer) {
|
||||||
_this.renderLayer(layer, position, scale, layerDepth);
|
_this.renderLayer(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
if (layer instanceof es.TmxImageLayer) {
|
if (layer instanceof es.TmxImageLayer) {
|
||||||
_this.renderImageLayer(layer, position, scale, layerDepth);
|
_this.renderImageLayer(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
TiledRendering.renderTile = function (tile, position, scale, tileWidth, tileHeight, color, layerDepth) {
|
TiledRendering.renderTile = function (tile, container, position, scale, tileWidth, tileHeight, color, layerDepth) {
|
||||||
var gid = tile.gid;
|
var gid = tile.gid;
|
||||||
var tilesetTile = tile.tilesetTile;
|
var tilesetTile = tile.tilesetTile;
|
||||||
if (tilesetTile && tilesetTile.animationFrames.length > 0)
|
if (tilesetTile && tilesetTile.animationFrames.length > 0)
|
||||||
@@ -7935,8 +8378,24 @@ var es;
|
|||||||
ty += (tileHeight - sourceRect.height * scale.y);
|
ty += (tileHeight - sourceRect.height * scale.y);
|
||||||
var pos = new es.Vector2(tx, ty).add(position);
|
var pos = new es.Vector2(tx, ty).add(position);
|
||||||
if (tile.tileset.image) {
|
if (tile.tileset.image) {
|
||||||
|
if (!tile.tilesetTile.image.bitmap.parent)
|
||||||
|
container.addChild(tile.tilesetTile.image.bitmap);
|
||||||
|
tile.tilesetTile.image.bitmap.x = pos.x;
|
||||||
|
tile.tilesetTile.image.bitmap.y = pos.y;
|
||||||
|
tile.tilesetTile.image.bitmap.scaleX = scale.x;
|
||||||
|
tile.tilesetTile.image.bitmap.scaleY = scale.y;
|
||||||
|
tile.tilesetTile.image.bitmap.rotation = rotation;
|
||||||
|
tile.tilesetTile.image.bitmap.filters = [color];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (!tilesetTile.image.bitmap)
|
||||||
|
container.addChild(tilesetTile.image.bitmap);
|
||||||
|
tilesetTile.image.bitmap.x = pos.x;
|
||||||
|
tilesetTile.image.bitmap.y = pos.y;
|
||||||
|
tilesetTile.image.bitmap.scaleX = scale.x;
|
||||||
|
tilesetTile.image.bitmap.scaleY = scale.y;
|
||||||
|
tilesetTile.image.bitmap.rotation = rotation;
|
||||||
|
tilesetTile.image.bitmap.filters = [color];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return TiledRendering;
|
return TiledRendering;
|
||||||
@@ -8020,6 +8479,41 @@ var es;
|
|||||||
}());
|
}());
|
||||||
es.TmxAnimationFrame = TmxAnimationFrame;
|
es.TmxAnimationFrame = TmxAnimationFrame;
|
||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
|
var es;
|
||||||
|
(function (es) {
|
||||||
|
var TmxUtils = (function () {
|
||||||
|
function TmxUtils() {
|
||||||
|
}
|
||||||
|
TmxUtils.decode = function (data, encoding, compression) {
|
||||||
|
compression = compression || "none";
|
||||||
|
encoding = encoding || "none";
|
||||||
|
var text = data.children[0].text;
|
||||||
|
switch (encoding) {
|
||||||
|
case "base64":
|
||||||
|
var decoded = es.Base64Utils.decodeBase64AsArray(text, 4);
|
||||||
|
return (compression === "none") ? decoded : es.Base64Utils.decompress(text, decoded, compression);
|
||||||
|
case "csv":
|
||||||
|
return es.Base64Utils.decodeCSV(text);
|
||||||
|
case "none":
|
||||||
|
var datas = [];
|
||||||
|
for (var i = 0; i < data.children.length; i++) {
|
||||||
|
datas[i] = +data.children[i].attributes.gid;
|
||||||
|
}
|
||||||
|
return datas;
|
||||||
|
default:
|
||||||
|
throw new Error("未定义的编码:" + encoding);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
TmxUtils.color16ToUnit = function ($color) {
|
||||||
|
if (!$color)
|
||||||
|
return 0x000000;
|
||||||
|
var colorStr = "0x" + $color.slice(1);
|
||||||
|
return parseInt(colorStr, 16);
|
||||||
|
};
|
||||||
|
return TmxUtils;
|
||||||
|
}());
|
||||||
|
es.TmxUtils = TmxUtils;
|
||||||
|
})(es || (es = {}));
|
||||||
var ArrayUtils = (function () {
|
var ArrayUtils = (function () {
|
||||||
function ArrayUtils() {
|
function ArrayUtils() {
|
||||||
}
|
}
|
||||||
@@ -8184,106 +8678,52 @@ var ArrayUtils = (function () {
|
|||||||
};
|
};
|
||||||
return ArrayUtils;
|
return ArrayUtils;
|
||||||
}());
|
}());
|
||||||
|
var es;
|
||||||
|
(function (es) {
|
||||||
var Base64Utils = (function () {
|
var Base64Utils = (function () {
|
||||||
function Base64Utils() {
|
function Base64Utils() {
|
||||||
}
|
}
|
||||||
Base64Utils.decode = function (input, isNotStr) {
|
Object.defineProperty(Base64Utils, "nativeBase64", {
|
||||||
if (isNotStr === void 0) { isNotStr = true; }
|
get: function () {
|
||||||
var output = "";
|
return (typeof (window.atob) === "function");
|
||||||
var chr1, chr2, chr3;
|
},
|
||||||
var enc1, enc2, enc3, enc4;
|
enumerable: true,
|
||||||
var i = 0;
|
configurable: true
|
||||||
input = this.getConfKey(input);
|
});
|
||||||
|
Base64Utils.decode = function (input) {
|
||||||
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
||||||
|
if (this.nativeBase64) {
|
||||||
|
return window.atob(input);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var output = [], chr1, chr2, chr3, enc1, enc2, enc3, enc4, i = 0;
|
||||||
while (i < input.length) {
|
while (i < input.length) {
|
||||||
enc1 = this._keyAll.indexOf(input.charAt(i++));
|
enc1 = this._keyStr.indexOf(input.charAt(i++));
|
||||||
enc2 = this._keyAll.indexOf(input.charAt(i++));
|
enc2 = this._keyStr.indexOf(input.charAt(i++));
|
||||||
enc3 = this._keyAll.indexOf(input.charAt(i++));
|
enc3 = this._keyStr.indexOf(input.charAt(i++));
|
||||||
enc4 = this._keyAll.indexOf(input.charAt(i++));
|
enc4 = this._keyStr.indexOf(input.charAt(i++));
|
||||||
chr1 = (enc1 << 2) | (enc2 >> 4);
|
chr1 = (enc1 << 2) | (enc2 >> 4);
|
||||||
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
||||||
chr3 = ((enc3 & 3) << 6) | enc4;
|
chr3 = ((enc3 & 3) << 6) | enc4;
|
||||||
output = output + String.fromCharCode(chr1);
|
output.push(String.fromCharCode(chr1));
|
||||||
if (enc3 != 64) {
|
if (enc3 !== 64) {
|
||||||
if (chr2 == 0) {
|
output.push(String.fromCharCode(chr2));
|
||||||
if (isNotStr)
|
|
||||||
output = output + String.fromCharCode(chr2);
|
|
||||||
}
|
}
|
||||||
else {
|
if (enc4 !== 64) {
|
||||||
output = output + String.fromCharCode(chr2);
|
output.push(String.fromCharCode(chr3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (enc4 != 64) {
|
output = output.join("");
|
||||||
if (chr3 == 0) {
|
|
||||||
if (isNotStr)
|
|
||||||
output = output + String.fromCharCode(chr3);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
output = output + String.fromCharCode(chr3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
output = this._utf8_decode(output);
|
|
||||||
return output;
|
return output;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
Base64Utils._utf8_encode = function (string) {
|
|
||||||
string = string.replace(/\r\n/g, "\n");
|
|
||||||
var utftext = "";
|
|
||||||
for (var n = 0; n < string.length; n++) {
|
|
||||||
var c = string.charCodeAt(n);
|
|
||||||
if (c < 128) {
|
|
||||||
utftext += String.fromCharCode(c);
|
|
||||||
}
|
|
||||||
else if ((c > 127) && (c < 2048)) {
|
|
||||||
utftext += String.fromCharCode((c >> 6) | 192);
|
|
||||||
utftext += String.fromCharCode((c & 63) | 128);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
utftext += String.fromCharCode((c >> 12) | 224);
|
|
||||||
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
|
||||||
utftext += String.fromCharCode((c & 63) | 128);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return utftext;
|
|
||||||
};
|
|
||||||
Base64Utils._utf8_decode = function (utftext) {
|
|
||||||
var string = "";
|
|
||||||
var i = 0;
|
|
||||||
var c = 0;
|
|
||||||
var c1 = 0;
|
|
||||||
var c2 = 0;
|
|
||||||
var c3 = 0;
|
|
||||||
while (i < utftext.length) {
|
|
||||||
c = utftext.charCodeAt(i);
|
|
||||||
if (c < 128) {
|
|
||||||
string += String.fromCharCode(c);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
else if ((c > 191) && (c < 224)) {
|
|
||||||
c2 = utftext.charCodeAt(i + 1);
|
|
||||||
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
|
|
||||||
i += 2;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
c2 = utftext.charCodeAt(i + 1);
|
|
||||||
c3 = utftext.charCodeAt(i + 2);
|
|
||||||
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
|
|
||||||
i += 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return string;
|
|
||||||
};
|
|
||||||
Base64Utils.getConfKey = function (key) {
|
|
||||||
return key.slice(1, key.length);
|
|
||||||
};
|
|
||||||
Base64Utils._keyNum = "0123456789+/";
|
|
||||||
Base64Utils._keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
||||||
Base64Utils._keyAll = Base64Utils._keyNum + Base64Utils._keyStr;
|
|
||||||
Base64Utils.encode = function (input) {
|
Base64Utils.encode = function (input) {
|
||||||
var output = "";
|
input = input.replace(/\r\n/g, "\n");
|
||||||
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
|
if (this.nativeBase64) {
|
||||||
var i = 0;
|
window.btoa(input);
|
||||||
input = this._utf8_encode(input);
|
}
|
||||||
|
else {
|
||||||
|
var output = [], chr1, chr2, chr3, enc1, enc2, enc3, enc4, i = 0;
|
||||||
while (i < input.length) {
|
while (i < input.length) {
|
||||||
chr1 = input.charCodeAt(i++);
|
chr1 = input.charCodeAt(i++);
|
||||||
chr2 = input.charCodeAt(i++);
|
chr2 = input.charCodeAt(i++);
|
||||||
@@ -8298,14 +8738,43 @@ var Base64Utils = (function () {
|
|||||||
else if (isNaN(chr3)) {
|
else if (isNaN(chr3)) {
|
||||||
enc4 = 64;
|
enc4 = 64;
|
||||||
}
|
}
|
||||||
output = output +
|
output.push(this._keyStr.charAt(enc1));
|
||||||
this._keyAll.charAt(enc1) + this._keyAll.charAt(enc2) +
|
output.push(this._keyStr.charAt(enc2));
|
||||||
this._keyAll.charAt(enc3) + this._keyAll.charAt(enc4);
|
output.push(this._keyStr.charAt(enc3));
|
||||||
|
output.push(this._keyStr.charAt(enc4));
|
||||||
|
}
|
||||||
|
output = output.join("");
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
return this._keyStr.charAt(Math.floor((Math.random() * this._keyStr.length))) + output;
|
|
||||||
};
|
};
|
||||||
|
Base64Utils.decodeBase64AsArray = function (input, bytes) {
|
||||||
|
bytes = bytes || 1;
|
||||||
|
var dec = Base64Utils.decode(input), i, j, len;
|
||||||
|
var ar = new Uint32Array(dec.length / bytes);
|
||||||
|
for (i = 0, len = dec.length / bytes; i < len; i++) {
|
||||||
|
ar[i] = 0;
|
||||||
|
for (j = bytes - 1; j >= 0; --j) {
|
||||||
|
ar[i] += dec.charCodeAt((i * bytes) + j) << (j << 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
Base64Utils.decompress = function (data, decoded, compression) {
|
||||||
|
throw new Error("GZIP/ZLIB compressed TMX Tile Map not supported!");
|
||||||
|
};
|
||||||
|
Base64Utils.decodeCSV = function (input) {
|
||||||
|
var entries = input.replace("\n", "").trim().split(",");
|
||||||
|
var result = [];
|
||||||
|
for (var i = 0; i < entries.length; i++) {
|
||||||
|
result.push(+entries[i]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
Base64Utils._keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||||
return Base64Utils;
|
return Base64Utils;
|
||||||
}());
|
}());
|
||||||
|
es.Base64Utils = Base64Utils;
|
||||||
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
(function (es) {
|
(function (es) {
|
||||||
var Color = (function () {
|
var Color = (function () {
|
||||||
@@ -8433,6 +8902,23 @@ var es;
|
|||||||
if (thickness === void 0) { thickness = 1; }
|
if (thickness === void 0) { thickness = 1; }
|
||||||
this.drawLineAngle(shape, start, es.MathHelper.angleBetweenVectors(start, end), es.Vector2.distance(start, end), color, thickness);
|
this.drawLineAngle(shape, start, es.MathHelper.angleBetweenVectors(start, end), es.Vector2.distance(start, end), color, thickness);
|
||||||
};
|
};
|
||||||
|
DrawUtils.drawCircle = function (shape, position, radius, color) {
|
||||||
|
shape.graphics.beginFill(color);
|
||||||
|
shape.graphics.drawCircle(position.x, position.y, radius);
|
||||||
|
shape.graphics.endFill();
|
||||||
|
};
|
||||||
|
DrawUtils.drawPoints = function (shape, position, points, color, closePoly, thickness) {
|
||||||
|
if (closePoly === void 0) { closePoly = true; }
|
||||||
|
if (thickness === void 0) { thickness = 1; }
|
||||||
|
if (points.length < 2)
|
||||||
|
return;
|
||||||
|
for (var i = 1; i < points.length; i++)
|
||||||
|
this.drawLine(shape, es.Vector2.add(position, points[i - 1]), es.Vector2.add(position, points[i]), color, thickness);
|
||||||
|
if (closePoly)
|
||||||
|
this.drawLine(shape, es.Vector2.add(position, points[points.length - 1]), es.Vector2.add(position, points[0]), color, thickness);
|
||||||
|
};
|
||||||
|
DrawUtils.drawString = function (textField, text, position, color, rotation, origin, scale) {
|
||||||
|
};
|
||||||
DrawUtils.drawLineAngle = function (shape, start, radians, length, color, thickness) {
|
DrawUtils.drawLineAngle = function (shape, start, radians, length, color, thickness) {
|
||||||
if (thickness === void 0) { thickness = 1; }
|
if (thickness === void 0) { thickness = 1; }
|
||||||
shape.graphics.beginFill(color);
|
shape.graphics.beginFill(color);
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -0,0 +1,345 @@
|
|||||||
|
{ "height":25,
|
||||||
|
"infinite":false,
|
||||||
|
"layers":[
|
||||||
|
{
|
||||||
|
"data":[24, 24, 23, 11, 19, 19, 12, 23, 24, 24, 23, 7, 2, 2, 1, 4, 2, 2, 3, 4, 4, 1, 3, 4, 1, 24, 23, 23, 14, 3, 3, 8, 12, 24, 24, 18, 4, 1, 3, 1, 3, 3, 4, 4, 1, 3, 1, 4, 3, 4, 11, 15, 15, 7, 1, 4, 3, 20, 23, 11, 7, 2, 1, 3, 1, 3, 4, 4, 3, 2, 2, 3, 4, 2, 1, 18, 4, 3, 2, 2, 4, 3, 8, 12, 18, 2, 4, 4, 3, 3, 1, 4, 2, 1, 4, 4, 4, 1, 1, 1, 14, 2, 1, 4, 2, 1, 4, 2, 8, 7, 5, 17, 6, 3, 3, 3, 4, 3, 4, 4, 3, 2, 4, 3, 4, 10, 6, 2, 1, 4, 4, 1, 3, 4, 3, 8, 12, 10, 6, 2, 1, 1, 1, 1, 2, 1, 4, 2, 1, 1, 24, 18, 1, 2, 4, 3, 3, 5, 6, 5, 13, 9, 11, 7, 3, 4, 1, 3, 1, 3, 4, 2, 4, 4, 4, 24, 14, 4, 2, 5, 6, 2, 8, 22, 9, 23, 24, 10, 6, 2, 1, 3, 1, 5, 6, 2, 3, 4, 4, 2, 19, 7, 3, 1, 8, 7, 4, 1, 8, 12, 24, 23, 23, 10, 17, 6, 3, 1, 8, 7, 1, 3, 3, 3, 1, 1, 2, 4, 2, 2, 3, 3, 4, 3, 20, 24, 23, 23, 23, 23, 18, 2, 2, 3, 1, 4, 4, 1, 1, 1, 3, 3, 5, 13, 6, 1, 2, 2, 5, 9, 23, 23, 24, 23, 24, 14, 1, 3, 1, 1, 3, 3, 4, 4, 4, 2, 4, 16, 24, 10, 6, 2, 4, 20, 23, 23, 24, 23, 23, 24, 14, 2, 4, 2, 4, 5, 6, 4, 3, 1, 3, 1, 20, 23, 24, 10, 6, 3, 8, 12, 24, 23, 23, 23, 24, 14, 1, 2, 1, 5, 9, 18, 4, 3, 4, 4, 2, 8, 12, 23, 24, 18, 4, 3, 16, 24, 24, 24, 23, 24, 18, 1, 3, 1, 16, 24, 14, 1, 3, 2, 4, 1, 2, 8, 12, 24, 14, 4, 1, 8, 15, 12, 24, 23, 11, 7, 2, 1, 2, 16, 23, 18, 1, 4, 2, 3, 4, 3, 2, 8, 19, 7, 2, 2, 3, 3, 8, 15, 19, 7, 3, 1, 2, 5, 9, 24, 14, 1, 2, 3, 2, 2, 1, 4, 4, 1, 2, 5, 6, 2, 2, 2, 1, 3, 4, 3, 5, 13, 9, 24, 24, 18, 4, 3, 4, 1, 4, 1, 3, 2, 5, 13, 9, 14, 3, 1, 3, 2, 4, 4, 5, 21, 19, 12, 24, 11, 7, 1, 2, 3, 2, 1, 3, 3, 3, 20, 23, 24, 18, 4, 4, 2, 3, 1, 1, 8, 7, 5, 9, 23, 18, 1, 3, 4, 2, 4, 2, 4, 1, 2, 8, 15, 19, 7, 4, 5, 6, 4, 2, 4, 5, 17, 9, 23, 11, 22, 13, 6, 4, 1, 3, 2, 2, 4, 4, 3, 2, 1, 4, 2, 8, 7, 4, 2, 3, 16, 24, 23, 11, 7, 16, 23, 18, 3, 1, 1, 3, 1, 2, 3, 3, 3, 4, 2, 1, 3, 2, 3, 4, 3, 8, 15, 15, 7, 4, 8, 19, 7, 3, 4, 1, 2, 3, 4, 1, 3, 4, 4, 4, 1, 4, 4, 3, 2, 3, 4, 1, 2, 4, 2, 1, 2, 2, 4, 1, 4, 2, 3, 2, 1, 4, 2, 2, 1, 2, 2, 2, 4, 3, 3, 2, 3, 3, 2, 3, 2, 4, 1, 3, 1, 1, 1, 1, 4, 1, 3, 3, 2, 1, 4, 2, 1, 3, 1, 3, 3, 4, 3, 4, 2, 1, 2, 3, 1, 1],
|
||||||
|
"height":25,
|
||||||
|
"id":1,
|
||||||
|
"name":"Tile Layer 1",
|
||||||
|
"opacity":1,
|
||||||
|
"type":"tilelayer",
|
||||||
|
"visible":true,
|
||||||
|
"width":25,
|
||||||
|
"x":0,
|
||||||
|
"y":0
|
||||||
|
}],
|
||||||
|
"nextlayerid":2,
|
||||||
|
"nextobjectid":1,
|
||||||
|
"orientation":"isometric",
|
||||||
|
"renderorder":"right-down",
|
||||||
|
"tiledversion":"1.2.1",
|
||||||
|
"tileheight":32,
|
||||||
|
"tilesets":[
|
||||||
|
{
|
||||||
|
"columns":4,
|
||||||
|
"firstgid":1,
|
||||||
|
"grid":
|
||||||
|
{
|
||||||
|
"height":32,
|
||||||
|
"orientation":"isometric",
|
||||||
|
"width":64
|
||||||
|
},
|
||||||
|
"image":"isometric_grass_and_water.png",
|
||||||
|
"imageheight":384,
|
||||||
|
"imagewidth":256,
|
||||||
|
"margin":0,
|
||||||
|
"name":"isometric_grass_and_water",
|
||||||
|
"spacing":0,
|
||||||
|
"terrains":[
|
||||||
|
{
|
||||||
|
"name":"Grass",
|
||||||
|
"tile":0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"Water",
|
||||||
|
"tile":22
|
||||||
|
}],
|
||||||
|
"tilecount":24,
|
||||||
|
"tileheight":64,
|
||||||
|
"tileoffset":
|
||||||
|
{
|
||||||
|
"x":0,
|
||||||
|
"y":16
|
||||||
|
},
|
||||||
|
"tiles":[
|
||||||
|
{
|
||||||
|
"id":0,
|
||||||
|
"terrain":[0, 0, 0, 0]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":1,
|
||||||
|
"terrain":[0, 0, 0, 0]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":2,
|
||||||
|
"terrain":[0, 0, 0, 0]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":3,
|
||||||
|
"terrain":[0, 0, 0, 0]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":4,
|
||||||
|
"terrain":[0, 0, 0, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":5,
|
||||||
|
"terrain":[0, 0, 1, 0]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":6,
|
||||||
|
"terrain":[1, 0, 0, 0]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":7,
|
||||||
|
"terrain":[0, 1, 0, 0]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":8,
|
||||||
|
"terrain":[0, 1, 1, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":9,
|
||||||
|
"terrain":[1, 0, 1, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":10,
|
||||||
|
"terrain":[1, 1, 1, 0]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":11,
|
||||||
|
"terrain":[1, 1, 0, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":12,
|
||||||
|
"terrain":[0, 0, 1, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":13,
|
||||||
|
"terrain":[1, 0, 1, 0]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":14,
|
||||||
|
"terrain":[1, 1, 0, 0]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":15,
|
||||||
|
"terrain":[0, 1, 0, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":16,
|
||||||
|
"terrain":[0, 0, 1, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":17,
|
||||||
|
"terrain":[1, 0, 1, 0]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":18,
|
||||||
|
"terrain":[1, 1, 0, 0]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":19,
|
||||||
|
"terrain":[0, 1, 0, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":20,
|
||||||
|
"terrain":[0, 1, 1, 0]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":21,
|
||||||
|
"terrain":[1, 0, 0, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":22,
|
||||||
|
"terrain":[1, 1, 1, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":23,
|
||||||
|
"terrain":[1, 1, 1, 1]
|
||||||
|
}],
|
||||||
|
"tilewidth":64,
|
||||||
|
"wangsets":[
|
||||||
|
{
|
||||||
|
"cornercolors":[
|
||||||
|
{
|
||||||
|
"color":"#8ab022",
|
||||||
|
"name":"Grass",
|
||||||
|
"probability":1,
|
||||||
|
"tile":0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"color":"#378dc2",
|
||||||
|
"name":"Water",
|
||||||
|
"probability":1,
|
||||||
|
"tile":23
|
||||||
|
}],
|
||||||
|
"edgecolors":[],
|
||||||
|
"name":"Grass and Water",
|
||||||
|
"tile":15,
|
||||||
|
"wangtiles":[
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":0,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 1, 0, 1, 0, 1, 0, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":1,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 1, 0, 1, 0, 1, 0, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":2,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 1, 0, 1, 0, 1, 0, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":3,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 1, 0, 1, 0, 1, 0, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":4,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 1, 0, 2, 0, 1, 0, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":5,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 1, 0, 1, 0, 2, 0, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":6,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 1, 0, 1, 0, 1, 0, 2]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":7,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 2, 0, 1, 0, 1, 0, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":8,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 2, 0, 2, 0, 2, 0, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":9,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 1, 0, 2, 0, 2, 0, 2]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":10,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 2, 0, 1, 0, 2, 0, 2]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":11,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 2, 0, 2, 0, 1, 0, 2]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":12,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 1, 0, 2, 0, 2, 0, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":13,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 1, 0, 1, 0, 2, 0, 2]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":14,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 2, 0, 1, 0, 1, 0, 2]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":15,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 2, 0, 2, 0, 1, 0, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":16,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 1, 0, 2, 0, 2, 0, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":17,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 1, 0, 1, 0, 2, 0, 2]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":18,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 2, 0, 1, 0, 1, 0, 2]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":19,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 2, 0, 2, 0, 1, 0, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":20,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 2, 0, 1, 0, 2, 0, 1]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":21,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 1, 0, 2, 0, 1, 0, 2]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":22,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 2, 0, 2, 0, 2, 0, 2]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dflip":false,
|
||||||
|
"hflip":false,
|
||||||
|
"tileid":23,
|
||||||
|
"vflip":false,
|
||||||
|
"wangid":[0, 2, 0, 2, 0, 2, 0, 2]
|
||||||
|
}]
|
||||||
|
}]
|
||||||
|
}],
|
||||||
|
"tilewidth":64,
|
||||||
|
"type":"map",
|
||||||
|
"version":1.2,
|
||||||
|
"width":25
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 102 KiB |
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"groups": [
|
"groups": [
|
||||||
{
|
{
|
||||||
"keys": "checkbox_select_disabled_png,checkbox_select_down_png,checkbox_select_up_png,checkbox_unselect_png,selected_png,border_png,header_png,radiobutton_select_disabled_png,radiobutton_select_down_png,radiobutton_select_up_png,radiobutton_unselect_png,roundthumb_png,thumb_png,track_png,tracklight_png,handle_png,off_png,on_png,button_down_png,button_up_png,thumb_pb_png,track_pb_png,track_sb_png,bg_jpg,egret_icon_png,description_json",
|
"keys": "checkbox_select_disabled_png,checkbox_select_down_png,checkbox_select_up_png,checkbox_unselect_png,selected_png,border_png,header_png,radiobutton_select_disabled_png,radiobutton_select_down_png,radiobutton_select_up_png,radiobutton_unselect_png,roundthumb_png,thumb_png,track_png,tracklight_png,handle_png,off_png,on_png,button_down_png,button_up_png,thumb_pb_png,track_pb_png,track_sb_png,bg_jpg,egret_icon_png,description_json,isometric_grass_and_water_json",
|
||||||
"name": "preload"
|
"name": "preload"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ module scene {
|
|||||||
// player2.addComponent(new es.BoxCollider());
|
// player2.addComponent(new es.BoxCollider());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let map = new es.TmxMap();
|
||||||
|
let mapData = await es.TiledMapLoader.loadTmxMap(map, "isometric_grass_and_water_json");
|
||||||
|
console.log(mapData);
|
||||||
|
|
||||||
|
|
||||||
let pool = new es.ComponentPool<component.SimplePooled>(component.SimplePooled);
|
let pool = new es.ComponentPool<component.SimplePooled>(component.SimplePooled);
|
||||||
let c1 = pool.obtain();
|
let c1 = pool.obtain();
|
||||||
|
|||||||
Vendored
+71
-35
@@ -252,6 +252,7 @@ declare module es {
|
|||||||
declare module es {
|
declare module es {
|
||||||
class Core extends egret.DisplayObjectContainer {
|
class Core extends egret.DisplayObjectContainer {
|
||||||
static emitter: Emitter<CoreEvents>;
|
static emitter: Emitter<CoreEvents>;
|
||||||
|
static debugRenderEndabled: boolean;
|
||||||
static graphicsDevice: GraphicsDevice;
|
static graphicsDevice: GraphicsDevice;
|
||||||
static content: ContentManager;
|
static content: ContentManager;
|
||||||
static _instance: Core;
|
static _instance: Core;
|
||||||
@@ -1551,11 +1552,11 @@ declare module es {
|
|||||||
properties: Map<string, string>;
|
properties: Map<string, string>;
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
name: string;
|
name: string;
|
||||||
layers: TmxList<any>;
|
layers: ITmxLayer[];
|
||||||
tileLayers: TmxList<TmxLayer>;
|
tileLayers: TmxLayer[];
|
||||||
objectGroups: TmxList<TmxObjectGroup>;
|
objectGroups: TmxObjectGroup[];
|
||||||
imageLayers: TmxList<TmxImageLayer>;
|
imageLayers: TmxImageLayer[];
|
||||||
groups: TmxList<TmxGroup>;
|
groups: TmxGroup[];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
@@ -1618,19 +1619,15 @@ declare module es {
|
|||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
class TmxDocument {
|
class TmxDocument {
|
||||||
TmxDirectory: string;
|
tmxDirectory: string;
|
||||||
constructor();
|
constructor();
|
||||||
}
|
}
|
||||||
interface ITmxElement {
|
interface ITmxElement {
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
class TmxList<T extends ITmxElement> extends Map<string, T> {
|
|
||||||
_nameCount: Map<string, number>;
|
|
||||||
add(t: T): void;
|
|
||||||
protected getKeyForItem(item: T): string;
|
|
||||||
}
|
|
||||||
class TmxImage {
|
class TmxImage {
|
||||||
texture: egret.Texture;
|
bitmap: egret.Bitmap;
|
||||||
|
readonly texture: egret.Texture;
|
||||||
source: string;
|
source: string;
|
||||||
format: string;
|
format: string;
|
||||||
data: any;
|
data: any;
|
||||||
@@ -1657,12 +1654,12 @@ declare module es {
|
|||||||
renderOrder: RenderOrderType;
|
renderOrder: RenderOrderType;
|
||||||
backgroundColor: number;
|
backgroundColor: number;
|
||||||
nextObjectID?: number;
|
nextObjectID?: number;
|
||||||
layers: TmxList<any>;
|
layers: ITmxLayer[];
|
||||||
tilesets: TmxList<TmxTileset>;
|
tilesets: TmxTileset[];
|
||||||
tileLayers: TmxList<TmxLayer>;
|
tileLayers: TmxLayer[];
|
||||||
objectGroups: TmxList<TmxObjectGroup>;
|
objectGroups: TmxLayer[];
|
||||||
imageLayers: TmxList<TmxImageLayer>;
|
imageLayers: TmxImageLayer[];
|
||||||
groups: TmxList<TmxGroup>;
|
groups: TmxGroup[];
|
||||||
properties: Map<string, string>;
|
properties: Map<string, string>;
|
||||||
maxTileWidth: number;
|
maxTileWidth: number;
|
||||||
maxTileHeight: number;
|
maxTileHeight: number;
|
||||||
@@ -1707,12 +1704,14 @@ declare module es {
|
|||||||
offsetY: number;
|
offsetY: number;
|
||||||
color: number;
|
color: number;
|
||||||
drawOrder: DrawOrderType;
|
drawOrder: DrawOrderType;
|
||||||
objects: TmxList<TmxObject>;
|
objects: TmxObject[];
|
||||||
properties: Map<string, string>;
|
properties: Map<string, string>;
|
||||||
}
|
}
|
||||||
class TmxObject implements ITmxElement {
|
class TmxObject implements ITmxElement {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
|
shape: egret.Shape;
|
||||||
|
textField: egret.TextField;
|
||||||
objectType: TmxObjectType;
|
objectType: TmxObjectType;
|
||||||
type: string;
|
type: string;
|
||||||
x: number;
|
x: number;
|
||||||
@@ -1725,6 +1724,7 @@ declare module es {
|
|||||||
text: TmxText;
|
text: TmxText;
|
||||||
points: Vector2[];
|
points: Vector2[];
|
||||||
properties: Map<string, string>;
|
properties: Map<string, string>;
|
||||||
|
constructor();
|
||||||
}
|
}
|
||||||
class TmxText {
|
class TmxText {
|
||||||
fontFamily: string;
|
fontFamily: string;
|
||||||
@@ -1769,14 +1769,40 @@ declare module es {
|
|||||||
bottom = 2
|
bottom = 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
declare module es {
|
||||||
|
class TiledMapLoader {
|
||||||
|
static loadTmxMap(map: TmxMap, filePath: string): Promise<TmxMap>;
|
||||||
|
static loadTmxMapData(map: TmxMap, xMap: any): Promise<TmxMap>;
|
||||||
|
static parseLayers(container: any, xEle: any, map: TmxMap, width: number, height: number, tmxDirectory: string): void;
|
||||||
|
private static updateMaxTileSizes;
|
||||||
|
static parseOrientationType(type: string): OrientationType;
|
||||||
|
static parseStaggerAxisType(type: string): StaggerAxisType;
|
||||||
|
static parseStaggerIndexType(type: string): StaggerIndexType;
|
||||||
|
static parseRenderOrderType(type: string): RenderOrderType;
|
||||||
|
static parsePropertyDict(prop: any): Map<string, string>;
|
||||||
|
static parseTmxTileset(map: TmxMap, xTileset: any): Promise<TmxTileset>;
|
||||||
|
static loadTmxTileset(tileset: TmxTileset, map: TmxMap, xTileset: any, firstGid: number): Promise<TmxTileset>;
|
||||||
|
static loadTmxTilesetTile(tile: TmxTilesetTile, tileset: TmxTileset, xTile: any, terrains: TmxTerrain[]): Promise<TmxTilesetTile>;
|
||||||
|
static loadTmxAnimationFrame(frame: TmxAnimationFrame, xFrame: any): TmxAnimationFrame;
|
||||||
|
static loadTmxObjectGroup(group: TmxObjectGroup, map: TmxMap, xObjectGroup: any): TmxObjectGroup;
|
||||||
|
static loadTmxObject(obj: TmxObject, map: TmxMap, xObject: any): TmxObject;
|
||||||
|
static loadTmxText(text: TmxText, xText: any): TmxText;
|
||||||
|
static loadTmxAlignment(alignment: TmxAlignment, xText: any): TmxAlignment;
|
||||||
|
static parsePoints(xPoints: any): any[];
|
||||||
|
static parsePoint(s: string): Vector2;
|
||||||
|
static parseTmxTerrain(xTerrain: any): TmxTerrain;
|
||||||
|
static parseTmxTileOffset(xTileOffset: any): TmxTileOffset;
|
||||||
|
static loadTmxImage(image: TmxImage, xImage: any): Promise<TmxImage>;
|
||||||
|
}
|
||||||
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
class TiledRendering {
|
class TiledRendering {
|
||||||
static renderMap(map: TmxMap, position: Vector2, scale: Vector2, layerDepth: number): void;
|
static renderMap(map: TmxMap, container: egret.DisplayObjectContainer, position: Vector2, scale: Vector2, layerDepth: number): void;
|
||||||
static renderLayer(layer: TmxLayer, position: Vector2, scale: Vector2, layerDepth: number): void;
|
static renderLayer(layer: TmxLayer, container: egret.DisplayObjectContainer, position: Vector2, scale: Vector2, layerDepth: number): void;
|
||||||
static renderImageLayer(layer: TmxImageLayer, position: Vector2, scale: Vector2, layerDepth: number): void;
|
static renderImageLayer(layer: TmxImageLayer, container: egret.DisplayObjectContainer, position: Vector2, scale: Vector2, layerDepth: number): void;
|
||||||
static renderObjectGroup(objGroup: TmxObjectGroup, position: Vector2, scale: Vector2, layerDepth: number): void;
|
static renderObjectGroup(objGroup: TmxObjectGroup, container: egret.DisplayObjectContainer, position: Vector2, scale: Vector2, layerDepth: number): void;
|
||||||
static renderGroup(group: TmxGroup, position: Vector2, scale: Vector2, layerDepth: number): void;
|
static renderGroup(group: TmxGroup, container: egret.DisplayObjectContainer, position: Vector2, scale: Vector2, layerDepth: number): void;
|
||||||
static renderTile(tile: TmxLayerTile, position: Vector2, scale: Vector2, tileWidth: number, tileHeight: number, color: Color, layerDepth: number): void;
|
static renderTile(tile: TmxLayerTile, container: egret.DisplayObjectContainer, position: Vector2, scale: Vector2, tileWidth: number, tileHeight: number, color: egret.ColorMatrixFilter, layerDepth: number): void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
@@ -1794,7 +1820,7 @@ declare module es {
|
|||||||
tileOffset: TmxTileOffset;
|
tileOffset: TmxTileOffset;
|
||||||
properties: Map<string, string>;
|
properties: Map<string, string>;
|
||||||
image: TmxImage;
|
image: TmxImage;
|
||||||
terrains: TmxList<TmxTerrain>;
|
terrains: TmxTerrain[];
|
||||||
tileRegions: Map<number, Rectangle>;
|
tileRegions: Map<number, Rectangle>;
|
||||||
update(): void;
|
update(): void;
|
||||||
}
|
}
|
||||||
@@ -1817,7 +1843,7 @@ declare module es {
|
|||||||
type: string;
|
type: string;
|
||||||
properties: Map<string, string>;
|
properties: Map<string, string>;
|
||||||
image: TmxImage;
|
image: TmxImage;
|
||||||
objectGroups: TmxList<TmxObjectGroup>;
|
objectGroups: TmxObjectGroup[];
|
||||||
animationFrames: TmxAnimationFrame[];
|
animationFrames: TmxAnimationFrame[];
|
||||||
readonly currentAnimationFrameGid: number;
|
readonly currentAnimationFrameGid: number;
|
||||||
_animationElapsedTime: number;
|
_animationElapsedTime: number;
|
||||||
@@ -1835,6 +1861,12 @@ declare module es {
|
|||||||
duration: number;
|
duration: number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
declare module es {
|
||||||
|
class TmxUtils {
|
||||||
|
static decode(data: any, encoding: any, compression: string): Array<number>;
|
||||||
|
static color16ToUnit($color: string): number;
|
||||||
|
}
|
||||||
|
}
|
||||||
declare class ArrayUtils {
|
declare class ArrayUtils {
|
||||||
static bubbleSort(ary: number[]): void;
|
static bubbleSort(ary: number[]): void;
|
||||||
static insertionSort(ary: number[]): void;
|
static insertionSort(ary: number[]): void;
|
||||||
@@ -1850,15 +1882,16 @@ declare class ArrayUtils {
|
|||||||
static equals(ary1: number[], ary2: number[]): Boolean;
|
static equals(ary1: number[], ary2: number[]): Boolean;
|
||||||
static insert(ary: any[], index: number, value: any): any;
|
static insert(ary: any[], index: number, value: any): any;
|
||||||
}
|
}
|
||||||
declare class Base64Utils {
|
declare module es {
|
||||||
private static _keyNum;
|
class Base64Utils {
|
||||||
private static _keyStr;
|
private static _keyStr;
|
||||||
private static _keyAll;
|
static readonly nativeBase64: boolean;
|
||||||
static encode: (input: any) => string;
|
static decode(input: string): string;
|
||||||
static decode(input: any, isNotStr?: boolean): string;
|
static encode(input: string): string;
|
||||||
private static _utf8_encode;
|
static decodeBase64AsArray(input: string, bytes: number): Uint32Array;
|
||||||
private static _utf8_decode;
|
static decompress(data: string, decoded: any, compression: string): any;
|
||||||
private static getConfKey;
|
static decodeCSV(input: string): Array<number>;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
class Color {
|
class Color {
|
||||||
@@ -1882,6 +1915,9 @@ declare module es {
|
|||||||
declare module es {
|
declare module es {
|
||||||
class DrawUtils {
|
class DrawUtils {
|
||||||
static drawLine(shape: egret.Shape, start: Vector2, end: Vector2, color: number, thickness?: number): void;
|
static drawLine(shape: egret.Shape, start: Vector2, end: Vector2, color: number, thickness?: number): void;
|
||||||
|
static drawCircle(shape: egret.Shape, position: Vector2, radius: number, color: number): void;
|
||||||
|
static drawPoints(shape: egret.Shape, position: Vector2, points: Vector2[], color: number, closePoly?: boolean, thickness?: number): void;
|
||||||
|
static drawString(textField: egret.TextField, text: string, position: Vector2, color: number, rotation: number, origin: Vector2, scale: number): void;
|
||||||
static drawLineAngle(shape: egret.Shape, start: Vector2, radians: number, length: number, color: number, thickness?: number): void;
|
static drawLineAngle(shape: egret.Shape, start: Vector2, radians: number, length: number, color: number, thickness?: number): void;
|
||||||
static drawHollowRect(shape: egret.Shape, rect: Rectangle, color: number, thickness?: number): void;
|
static drawHollowRect(shape: egret.Shape, rect: Rectangle, color: number, thickness?: number): void;
|
||||||
static drawHollowRectR(shape: egret.Shape, x: number, y: number, width: number, height: number, color: number, thickness?: number): void;
|
static drawHollowRectR(shape: egret.Shape, x: number, y: number, width: number, height: number, color: number, thickness?: number): void;
|
||||||
|
|||||||
+634
-148
@@ -1284,6 +1284,7 @@ var es;
|
|||||||
es.Input.initialize();
|
es.Input.initialize();
|
||||||
this.initialize();
|
this.initialize();
|
||||||
};
|
};
|
||||||
|
Core.debugRenderEndabled = false;
|
||||||
return Core;
|
return Core;
|
||||||
}(egret.DisplayObjectContainer));
|
}(egret.DisplayObjectContainer));
|
||||||
es.Core = Core;
|
es.Core = Core;
|
||||||
@@ -3296,8 +3297,9 @@ var es;
|
|||||||
_this.physicsLayer = 1 << 0;
|
_this.physicsLayer = 1 << 0;
|
||||||
_this.tiledMap = tiledMap;
|
_this.tiledMap = tiledMap;
|
||||||
_this._shouldCreateColliders = shouldCreateColliders;
|
_this._shouldCreateColliders = shouldCreateColliders;
|
||||||
|
_this.displayObject = new egret.DisplayObjectContainer();
|
||||||
if (collisionLayerName) {
|
if (collisionLayerName) {
|
||||||
_this.collisionLayer = tiledMap.tileLayers.get(collisionLayerName);
|
_this.collisionLayer = tiledMap.tileLayers[collisionLayerName];
|
||||||
}
|
}
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
@@ -3333,7 +3335,7 @@ var es;
|
|||||||
var layerType = this.tiledMap.getLayer(layerName);
|
var layerType = this.tiledMap.getLayer(layerName);
|
||||||
for (var layer in this.tiledMap.layers) {
|
for (var layer in this.tiledMap.layers) {
|
||||||
if (this.tiledMap.layers.hasOwnProperty(layer) &&
|
if (this.tiledMap.layers.hasOwnProperty(layer) &&
|
||||||
this.tiledMap.layers.get(layer) == layerType) {
|
this.tiledMap.layers[layer] == layerType) {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3364,12 +3366,12 @@ var es;
|
|||||||
};
|
};
|
||||||
TiledMapRenderer.prototype.render = function (camera) {
|
TiledMapRenderer.prototype.render = function (camera) {
|
||||||
if (!this.layerIndicesToRender) {
|
if (!this.layerIndicesToRender) {
|
||||||
es.TiledRendering.renderMap(this.tiledMap, es.Vector2.add(this.entity.transform.position, this._localOffset), this.transform.scale, this.renderLayer);
|
es.TiledRendering.renderMap(this.tiledMap, this.displayObject, es.Vector2.add(this.entity.transform.position, this._localOffset), this.transform.scale, this.renderLayer);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (var i = 0; i < this.tiledMap.layers.size; i++) {
|
for (var i = 0; i < this.tiledMap.layers.length; i++) {
|
||||||
if (this.tiledMap.layers.get(i.toString()).visible && this.layerIndicesToRender.contains(i))
|
if (this.tiledMap.layers[i].visible && this.layerIndicesToRender.contains(i))
|
||||||
es.TiledRendering.renderLayer(this.tiledMap.layers.get(i.toString()), es.Vector2.add(this.entity.transform.position, this._localOffset), this.transform.scale, this.renderLayer);
|
es.TiledRendering.renderLayer(this.tiledMap.layers[i], this.displayObject, es.Vector2.add(this.entity.transform.position, this._localOffset), this.transform.scale, this.renderLayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -7606,45 +7608,25 @@ var es;
|
|||||||
(function (es) {
|
(function (es) {
|
||||||
var TmxDocument = (function () {
|
var TmxDocument = (function () {
|
||||||
function TmxDocument() {
|
function TmxDocument() {
|
||||||
this.TmxDirectory = "";
|
this.tmxDirectory = "";
|
||||||
}
|
}
|
||||||
return TmxDocument;
|
return TmxDocument;
|
||||||
}());
|
}());
|
||||||
es.TmxDocument = TmxDocument;
|
es.TmxDocument = TmxDocument;
|
||||||
var TmxList = (function (_super) {
|
|
||||||
__extends(TmxList, _super);
|
|
||||||
function TmxList() {
|
|
||||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
||||||
_this._nameCount = new Map();
|
|
||||||
return _this;
|
|
||||||
}
|
|
||||||
TmxList.prototype.add = function (t) {
|
|
||||||
var tName = t.name;
|
|
||||||
if (this.has(tName))
|
|
||||||
this._nameCount.set(tName, this._nameCount.get(tName) + 1);
|
|
||||||
else
|
|
||||||
this._nameCount.set(tName, 0);
|
|
||||||
};
|
|
||||||
TmxList.prototype.getKeyForItem = function (item) {
|
|
||||||
var name = item.name;
|
|
||||||
var count = this._nameCount.get(name);
|
|
||||||
var dupes = 0;
|
|
||||||
while (this.has(name)) {
|
|
||||||
name = name + es.Enumerable.repeat("_", dupes).toString() + count.toString();
|
|
||||||
dupes++;
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
};
|
|
||||||
return TmxList;
|
|
||||||
}(Map));
|
|
||||||
es.TmxList = TmxList;
|
|
||||||
var TmxImage = (function () {
|
var TmxImage = (function () {
|
||||||
function TmxImage() {
|
function TmxImage() {
|
||||||
}
|
}
|
||||||
|
Object.defineProperty(TmxImage.prototype, "texture", {
|
||||||
|
get: function () {
|
||||||
|
return this.bitmap.texture;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
TmxImage.prototype.dispose = function () {
|
TmxImage.prototype.dispose = function () {
|
||||||
if (this.texture) {
|
if (this.bitmap) {
|
||||||
this.texture.dispose();
|
this.texture.dispose();
|
||||||
this.texture = null;
|
this.bitmap = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return TmxImage;
|
return TmxImage;
|
||||||
@@ -7682,9 +7664,9 @@ var es;
|
|||||||
TmxMap.prototype.getTilesetForTileGid = function (gid) {
|
TmxMap.prototype.getTilesetForTileGid = function (gid) {
|
||||||
if (gid == 0)
|
if (gid == 0)
|
||||||
return null;
|
return null;
|
||||||
for (var i = this.tilesets.size - 1; i >= 0; i--) {
|
for (var i = this.tilesets.length - 1; i >= 0; i--) {
|
||||||
if (this.tilesets.get(i.toString()).firstGid <= gid)
|
if (this.tilesets[i].firstGid <= gid)
|
||||||
return this.tilesets.get(i.toString());
|
return this.tilesets[i];
|
||||||
}
|
}
|
||||||
console.error("tile gid" + gid + "\u672A\u5728\u4EFB\u4F55tileset\u4E2D\u627E\u5230");
|
console.error("tile gid" + gid + "\u672A\u5728\u4EFB\u4F55tileset\u4E2D\u627E\u5230");
|
||||||
};
|
};
|
||||||
@@ -7703,7 +7685,7 @@ var es;
|
|||||||
return es.MathHelper.clamp(tileY, 0, this.height - 1);
|
return es.MathHelper.clamp(tileY, 0, this.height - 1);
|
||||||
};
|
};
|
||||||
TmxMap.prototype.getLayer = function (name) {
|
TmxMap.prototype.getLayer = function (name) {
|
||||||
return this.layers.get(name);
|
return this.layers[name];
|
||||||
};
|
};
|
||||||
TmxMap.prototype.update = function () {
|
TmxMap.prototype.update = function () {
|
||||||
this.tilesets.forEach(function (tileset) { tileset.update(); });
|
this.tilesets.forEach(function (tileset) { tileset.update(); });
|
||||||
@@ -7759,6 +7741,8 @@ var es;
|
|||||||
es.TmxObjectGroup = TmxObjectGroup;
|
es.TmxObjectGroup = TmxObjectGroup;
|
||||||
var TmxObject = (function () {
|
var TmxObject = (function () {
|
||||||
function TmxObject() {
|
function TmxObject() {
|
||||||
|
this.shape = new egret.Shape();
|
||||||
|
this.textField = new egret.TextField();
|
||||||
}
|
}
|
||||||
return TmxObject;
|
return TmxObject;
|
||||||
}());
|
}());
|
||||||
@@ -7806,103 +7790,562 @@ var es;
|
|||||||
})(TmxVerticalAlignment = es.TmxVerticalAlignment || (es.TmxVerticalAlignment = {}));
|
})(TmxVerticalAlignment = es.TmxVerticalAlignment || (es.TmxVerticalAlignment = {}));
|
||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
|
(function (es) {
|
||||||
|
var Bitmap = egret.Bitmap;
|
||||||
|
var TiledMapLoader = (function () {
|
||||||
|
function TiledMapLoader() {
|
||||||
|
}
|
||||||
|
TiledMapLoader.loadTmxMap = function (map, filePath) {
|
||||||
|
var xMap = RES.getRes(filePath);
|
||||||
|
return this.loadTmxMapData(map, xMap);
|
||||||
|
};
|
||||||
|
TiledMapLoader.loadTmxMapData = function (map, xMap) {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var _i, _a, e, tileset;
|
||||||
|
return __generator(this, function (_b) {
|
||||||
|
switch (_b.label) {
|
||||||
|
case 0:
|
||||||
|
map.version = xMap["version"];
|
||||||
|
map.tiledVersion = xMap["tiledversion"];
|
||||||
|
map.width = xMap["width"];
|
||||||
|
map.height = xMap["height"];
|
||||||
|
map.tileWidth = xMap["tilewidth"];
|
||||||
|
map.tileHeight = xMap["tileheight"];
|
||||||
|
map.hexSideLength = xMap["hexsidelength"];
|
||||||
|
map.orientation = this.parseOrientationType(xMap["orientation"]);
|
||||||
|
map.staggerAxis = this.parseStaggerAxisType(xMap["staggeraxis"]);
|
||||||
|
map.staggerIndex = this.parseStaggerIndexType(xMap["staggerindex"]);
|
||||||
|
map.renderOrder = this.parseRenderOrderType(xMap["renderorder"]);
|
||||||
|
map.nextObjectID = xMap["nextobjectid"];
|
||||||
|
map.backgroundColor = es.TmxUtils.color16ToUnit(xMap["color"]);
|
||||||
|
map.properties = this.parsePropertyDict(xMap["properties"]);
|
||||||
|
map.maxTileWidth = map.tileWidth;
|
||||||
|
map.maxTileHeight = map.tileHeight;
|
||||||
|
map.tilesets = [];
|
||||||
|
_i = 0, _a = xMap["tilesets"];
|
||||||
|
_b.label = 1;
|
||||||
|
case 1:
|
||||||
|
if (!(_i < _a.length)) return [3, 4];
|
||||||
|
e = _a[_i];
|
||||||
|
return [4, this.parseTmxTileset(map, e)];
|
||||||
|
case 2:
|
||||||
|
tileset = _b.sent();
|
||||||
|
map.tilesets.push(tileset);
|
||||||
|
this.updateMaxTileSizes(tileset);
|
||||||
|
_b.label = 3;
|
||||||
|
case 3:
|
||||||
|
_i++;
|
||||||
|
return [3, 1];
|
||||||
|
case 4:
|
||||||
|
map.layers = [];
|
||||||
|
map.tileLayers = [];
|
||||||
|
map.objectGroups = [];
|
||||||
|
map.imageLayers = [];
|
||||||
|
map.groups = [];
|
||||||
|
this.parseLayers(map, xMap, map, map.width, map.height, map.tmxDirectory);
|
||||||
|
return [2, map];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
TiledMapLoader.parseLayers = function (container, xEle, map, width, height, tmxDirectory) {
|
||||||
|
};
|
||||||
|
TiledMapLoader.updateMaxTileSizes = function (tileset) {
|
||||||
|
tileset.tiles.forEach(function (tile) {
|
||||||
|
if (tile.image) {
|
||||||
|
if (tile.image.width > tileset.map.maxTileWidth)
|
||||||
|
tileset.map.maxTileWidth = tile.image.width;
|
||||||
|
if (tile.image.height > tileset.map.maxTileHeight)
|
||||||
|
tileset.map.maxTileHeight = tile.image.height;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tileset.tileRegions.forEach(function (region) {
|
||||||
|
var width = region.width;
|
||||||
|
var height = region.height;
|
||||||
|
if (width > tileset.map.maxTileWidth)
|
||||||
|
tileset.map.maxTileWidth = width;
|
||||||
|
if (width > tileset.map.maxTileHeight)
|
||||||
|
tileset.map.maxTileHeight = height;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
TiledMapLoader.parseOrientationType = function (type) {
|
||||||
|
if (type == "unknown")
|
||||||
|
return es.OrientationType.unknown;
|
||||||
|
if (type == "orthogonal")
|
||||||
|
return es.OrientationType.orthogonal;
|
||||||
|
if (type == "isometric")
|
||||||
|
return es.OrientationType.isometric;
|
||||||
|
if (type == "staggered")
|
||||||
|
return es.OrientationType.staggered;
|
||||||
|
if (type == "hexagonal")
|
||||||
|
return es.OrientationType.hexagonal;
|
||||||
|
return es.OrientationType.unknown;
|
||||||
|
};
|
||||||
|
TiledMapLoader.parseStaggerAxisType = function (type) {
|
||||||
|
if (type == "y")
|
||||||
|
return es.StaggerAxisType.y;
|
||||||
|
return es.StaggerAxisType.x;
|
||||||
|
};
|
||||||
|
TiledMapLoader.parseStaggerIndexType = function (type) {
|
||||||
|
if (type == "even")
|
||||||
|
return es.StaggerIndexType.even;
|
||||||
|
return es.StaggerIndexType.odd;
|
||||||
|
};
|
||||||
|
TiledMapLoader.parseRenderOrderType = function (type) {
|
||||||
|
if (type == "right-up")
|
||||||
|
return es.RenderOrderType.rightUp;
|
||||||
|
if (type == "left-down")
|
||||||
|
return es.RenderOrderType.leftDown;
|
||||||
|
if (type == "left-up")
|
||||||
|
return es.RenderOrderType.leftUp;
|
||||||
|
return es.RenderOrderType.rightDown;
|
||||||
|
};
|
||||||
|
TiledMapLoader.parsePropertyDict = function (prop) {
|
||||||
|
if (!prop)
|
||||||
|
return null;
|
||||||
|
var dict = new Map();
|
||||||
|
for (var _i = 0, _a = prop["property"]; _i < _a.length; _i++) {
|
||||||
|
var p = _a[_i];
|
||||||
|
var pname = p["name"];
|
||||||
|
var valueAttr = p["value"];
|
||||||
|
var pval = valueAttr ? valueAttr : p;
|
||||||
|
dict.set(pname, pval);
|
||||||
|
}
|
||||||
|
return dict;
|
||||||
|
};
|
||||||
|
TiledMapLoader.parseTmxTileset = function (map, xTileset) {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var xFirstGid, firstGid, source, xDocTileset, tileset;
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0:
|
||||||
|
xFirstGid = xTileset["firstgid"];
|
||||||
|
firstGid = xFirstGid;
|
||||||
|
source = xTileset["image"];
|
||||||
|
if (!!source) return [3, 2];
|
||||||
|
source = "resource/assets/" + source;
|
||||||
|
return [4, RES.getResByUrl(source, null, this, RES.ResourceItem.TYPE_IMAGE)];
|
||||||
|
case 1:
|
||||||
|
xDocTileset = _a.sent();
|
||||||
|
tileset = this.loadTmxTileset(new es.TmxTileset(), map, xDocTileset["tileset"], firstGid);
|
||||||
|
return [2, tileset];
|
||||||
|
case 2: return [2, this.loadTmxTileset(new es.TmxTileset(), map, xTileset, firstGid)];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
TiledMapLoader.loadTmxTileset = function (tileset, map, xTileset, firstGid) {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var xImage, _a, xTerrainType, _i, _b, e, _c, _d, xTile, tile, id, y, column, x;
|
||||||
|
return __generator(this, function (_e) {
|
||||||
|
switch (_e.label) {
|
||||||
|
case 0:
|
||||||
|
tileset.map = map;
|
||||||
|
tileset.firstGid = firstGid;
|
||||||
|
tileset.name = xTileset["name"];
|
||||||
|
tileset.tileWidth = xTileset["tilewidth"];
|
||||||
|
tileset.tileHeight = xTileset["tileheight"];
|
||||||
|
tileset.spacing = xTileset["spacing"] != undefined ? xTileset["spacing"] : 0;
|
||||||
|
tileset.margin = xTileset["margin"] != undefined ? xTileset["margin"] : 0;
|
||||||
|
tileset.columns = xTileset["columns"];
|
||||||
|
tileset.tileCount = xTileset["tilecount"];
|
||||||
|
tileset.tileOffset = this.parseTmxTileOffset(xTileset["tileoffset"]);
|
||||||
|
xImage = xTileset["image"];
|
||||||
|
if (!xImage) return [3, 2];
|
||||||
|
_a = tileset;
|
||||||
|
return [4, this.loadTmxImage(new es.TmxImage(), xTileset)];
|
||||||
|
case 1:
|
||||||
|
_a.image = _e.sent();
|
||||||
|
_e.label = 2;
|
||||||
|
case 2:
|
||||||
|
xTerrainType = xTileset["terraintypes"];
|
||||||
|
if (xTerrainType) {
|
||||||
|
tileset.terrains = [];
|
||||||
|
for (_i = 0, _b = xTerrainType["terrains"]; _i < _b.length; _i++) {
|
||||||
|
e = _b[_i];
|
||||||
|
tileset.terrains.push(this.parseTmxTerrain(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tileset.tiles = new Map();
|
||||||
|
_c = 0, _d = xTileset["tiles"];
|
||||||
|
_e.label = 3;
|
||||||
|
case 3:
|
||||||
|
if (!(_c < _d.length)) return [3, 6];
|
||||||
|
xTile = _d[_c];
|
||||||
|
return [4, this.loadTmxTilesetTile(new es.TmxTilesetTile(), tileset, xTile, tileset.terrains)];
|
||||||
|
case 4:
|
||||||
|
tile = _e.sent();
|
||||||
|
tileset.tiles[tile.id] = tile;
|
||||||
|
_e.label = 5;
|
||||||
|
case 5:
|
||||||
|
_c++;
|
||||||
|
return [3, 3];
|
||||||
|
case 6:
|
||||||
|
tileset.properties = this.parsePropertyDict(xTileset["properties"]);
|
||||||
|
tileset.tileRegions = new Map();
|
||||||
|
if (tileset.image) {
|
||||||
|
id = firstGid;
|
||||||
|
for (y = tileset.margin; y < tileset.image.height - tileset.margin; y += tileset.tileHeight + tileset.spacing) {
|
||||||
|
column = 0;
|
||||||
|
for (x = tileset.margin; x < tileset.image.width - tileset.margin; x += tileset.tileWidth + tileset.spacing) {
|
||||||
|
tileset.tileRegions.set(id++, new es.Rectangle(x, y, tileset.tileWidth, tileset.tileHeight));
|
||||||
|
if (++column >= tileset.columns)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tileset.tiles.forEach(function (tile) {
|
||||||
|
tileset.tileRegions.set(firstGid + tile.id, new es.Rectangle(0, 0, tile.image.width, tile.image.height));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return [2, tileset];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
TiledMapLoader.loadTmxTilesetTile = function (tile, tileset, xTile, terrains) {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var xImage, _a, _i, _b, e, _c, _d, e;
|
||||||
|
return __generator(this, function (_e) {
|
||||||
|
switch (_e.label) {
|
||||||
|
case 0:
|
||||||
|
tile.tileset = tileset;
|
||||||
|
tile.id = xTile["id"];
|
||||||
|
tile.terrainEdges = xTile["terrain"];
|
||||||
|
tile.probability = xTile["probability"] != undefined ? xTile["probability"] : 1;
|
||||||
|
tile.type = xTile["type"];
|
||||||
|
xImage = xTile["image"];
|
||||||
|
if (!xImage) return [3, 2];
|
||||||
|
_a = tile;
|
||||||
|
return [4, this.loadTmxImage(new es.TmxImage(), xImage)];
|
||||||
|
case 1:
|
||||||
|
_a.image = _e.sent();
|
||||||
|
_e.label = 2;
|
||||||
|
case 2:
|
||||||
|
tile.objectGroups = [];
|
||||||
|
if (xTile["objectgroup"])
|
||||||
|
for (_i = 0, _b = xTile["objectgroup"]; _i < _b.length; _i++) {
|
||||||
|
e = _b[_i];
|
||||||
|
tile.objectGroups.push(this.loadTmxObjectGroup(new es.TmxObjectGroup(), tileset.map, e));
|
||||||
|
}
|
||||||
|
tile.animationFrames = [];
|
||||||
|
if (xTile["animation"]) {
|
||||||
|
for (_c = 0, _d = xTile["animation"]["frame"]; _c < _d.length; _c++) {
|
||||||
|
e = _d[_c];
|
||||||
|
tile.animationFrames.push(this.loadTmxAnimationFrame(new es.TmxAnimationFrame(), e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tile.properties = this.parsePropertyDict(xTile["properties"]);
|
||||||
|
if (tile.properties)
|
||||||
|
tile.processProperties();
|
||||||
|
return [2, tile];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
TiledMapLoader.loadTmxAnimationFrame = function (frame, xFrame) {
|
||||||
|
frame.gid = xFrame["tileid"];
|
||||||
|
frame.duration = xFrame["duration"] / 1000;
|
||||||
|
return frame;
|
||||||
|
};
|
||||||
|
TiledMapLoader.loadTmxObjectGroup = function (group, map, xObjectGroup) {
|
||||||
|
group.map = map;
|
||||||
|
group.name = xObjectGroup["name"] != undefined ? xObjectGroup["name"] : "";
|
||||||
|
group.color = es.TmxUtils.color16ToUnit(xObjectGroup["color"]);
|
||||||
|
group.opacity = xObjectGroup["opacity"] != undefined ? xObjectGroup["opacity"] : 1;
|
||||||
|
group.visible = xObjectGroup["visible"] != undefined ? xObjectGroup["visible"] : true;
|
||||||
|
group.offsetX = xObjectGroup["offsetx"] != undefined ? xObjectGroup["offsetx"] : 0;
|
||||||
|
group.offsetY = xObjectGroup["offsety"] != undefined ? xObjectGroup["offsety"] : 0;
|
||||||
|
var drawOrderDict = new Map();
|
||||||
|
drawOrderDict.set("unknown", es.DrawOrderType.unkownOrder);
|
||||||
|
drawOrderDict.set("topdown", es.DrawOrderType.IndexOrder);
|
||||||
|
drawOrderDict.set("index", es.DrawOrderType.TopDown);
|
||||||
|
var drawOrderValue = xObjectGroup["draworder"];
|
||||||
|
if (drawOrderValue)
|
||||||
|
group.drawOrder = drawOrderDict[drawOrderValue];
|
||||||
|
group.objects = [];
|
||||||
|
for (var _i = 0, _a = xObjectGroup["object"]; _i < _a.length; _i++) {
|
||||||
|
var e = _a[_i];
|
||||||
|
group.objects.push(this.loadTmxObject(new es.TmxObject(), map, e));
|
||||||
|
}
|
||||||
|
group.properties = this.parsePropertyDict(xObjectGroup["properties"]);
|
||||||
|
return group;
|
||||||
|
};
|
||||||
|
TiledMapLoader.loadTmxObject = function (obj, map, xObject) {
|
||||||
|
obj.id = xObject["id"] != undefined ? xObject["id"] : 0;
|
||||||
|
obj.name = xObject["name"] != undefined ? xObject["name"] : "";
|
||||||
|
obj.x = xObject["x"];
|
||||||
|
obj.y = xObject["y"];
|
||||||
|
obj.width = xObject["width"] != undefined ? xObject["width"] : 0;
|
||||||
|
obj.height = xObject["height"] != undefined ? xObject["height"] : 0;
|
||||||
|
obj.type = xObject["type"] != undefined ? xObject["type"] : "";
|
||||||
|
obj.visible = xObject["visible"] != undefined ? xObject["visible"] : true;
|
||||||
|
obj.rotation = xObject["rotation"] != undefined ? xObject["rotation"] : 0;
|
||||||
|
var xGid = xObject["gid"];
|
||||||
|
var xEllipse = xObject["ellipse"];
|
||||||
|
var xPolygon = xObject["polygon"];
|
||||||
|
var xPolyline = xObject["polyline"];
|
||||||
|
var xText = xObject["text"];
|
||||||
|
var xPoint = xObject["point"];
|
||||||
|
if (xGid) {
|
||||||
|
obj.tile = new es.TmxLayerTile(map, xGid, Math.round(obj.x), Math.round(obj.y));
|
||||||
|
obj.objectType = es.TmxObjectType.tile;
|
||||||
|
}
|
||||||
|
else if (xEllipse) {
|
||||||
|
obj.objectType = es.TmxObjectType.ellipse;
|
||||||
|
}
|
||||||
|
else if (xPolygon) {
|
||||||
|
obj.points = this.parsePoints(xPolygon);
|
||||||
|
obj.objectType = es.TmxObjectType.polygon;
|
||||||
|
}
|
||||||
|
else if (xPolyline) {
|
||||||
|
obj.points = this.parsePoints(xPolyline);
|
||||||
|
obj.objectType = es.TmxObjectType.polyline;
|
||||||
|
}
|
||||||
|
else if (xText) {
|
||||||
|
obj.text = this.loadTmxText(new es.TmxText(), xText);
|
||||||
|
obj.objectType = es.TmxObjectType.text;
|
||||||
|
}
|
||||||
|
else if (xPoint) {
|
||||||
|
obj.objectType = es.TmxObjectType.point;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
obj.objectType = es.TmxObjectType.basic;
|
||||||
|
}
|
||||||
|
obj.properties = this.parsePropertyDict(xObject["properties"]);
|
||||||
|
return obj;
|
||||||
|
};
|
||||||
|
TiledMapLoader.loadTmxText = function (text, xText) {
|
||||||
|
text.fontFamily = xText["fontfamily"] != undefined ? xText["fontfamily"] : "sans-serif";
|
||||||
|
text.pixelSize = xText["pixelsize"] != undefined ? xText["pixelsize"] : 16;
|
||||||
|
text.wrap = xText["wrap"] != undefined ? xText["wrap"] : false;
|
||||||
|
text.color = es.TmxUtils.color16ToUnit(xText["color"]);
|
||||||
|
text.bold = xText["bold"] ? xText["bold"] : false;
|
||||||
|
text.italic = xText["italic"] ? xText["italic"] : false;
|
||||||
|
text.underline = xText["underline"] ? xText["underline"] : false;
|
||||||
|
text.strikeout = xText["strikeout"] ? xText["strikeout"] : false;
|
||||||
|
text.kerning = xText["kerning"] ? xText["kerning"] : true;
|
||||||
|
text.alignment = this.loadTmxAlignment(new es.TmxAlignment(), xText);
|
||||||
|
text.value = xText;
|
||||||
|
return text;
|
||||||
|
};
|
||||||
|
TiledMapLoader.loadTmxAlignment = function (alignment, xText) {
|
||||||
|
function firstLetterToUpperCase(str) {
|
||||||
|
if (!str || str == "")
|
||||||
|
return str;
|
||||||
|
return str[0].toString().toUpperCase() + str.substr(1);
|
||||||
|
}
|
||||||
|
var xHorizontal = xText["halign"] != undefined ? xText["halign"] : "left";
|
||||||
|
alignment.horizontal = es.TmxHorizontalAlignment[firstLetterToUpperCase(xHorizontal)];
|
||||||
|
var xVertical = xText["valign"] != undefined ? xText["valign"] : "top";
|
||||||
|
alignment.vertical = es.TmxVerticalAlignment[firstLetterToUpperCase((xVertical))];
|
||||||
|
return alignment;
|
||||||
|
};
|
||||||
|
TiledMapLoader.parsePoints = function (xPoints) {
|
||||||
|
var pointString = xPoints["points"];
|
||||||
|
var pointStringPair = pointString.split(' ');
|
||||||
|
var points = [];
|
||||||
|
var index = 0;
|
||||||
|
for (var _i = 0, pointStringPair_1 = pointStringPair; _i < pointStringPair_1.length; _i++) {
|
||||||
|
var s = pointStringPair_1[_i];
|
||||||
|
points[index++] = this.parsePoint(s);
|
||||||
|
}
|
||||||
|
return points;
|
||||||
|
};
|
||||||
|
TiledMapLoader.parsePoint = function (s) {
|
||||||
|
var pt = s.split(',');
|
||||||
|
var x = Number(pt[0]);
|
||||||
|
var y = Number(pt[1]);
|
||||||
|
return new es.Vector2(x, y);
|
||||||
|
};
|
||||||
|
TiledMapLoader.parseTmxTerrain = function (xTerrain) {
|
||||||
|
var terrain = new es.TmxTerrain();
|
||||||
|
terrain.name = xTerrain["name"];
|
||||||
|
terrain.tile = xTerrain["tile"];
|
||||||
|
terrain.properties = this.parsePropertyDict(xTerrain["properties"]);
|
||||||
|
return terrain;
|
||||||
|
};
|
||||||
|
TiledMapLoader.parseTmxTileOffset = function (xTileOffset) {
|
||||||
|
var tmxTileOffset = new es.TmxTileOffset();
|
||||||
|
if (!xTileOffset) {
|
||||||
|
tmxTileOffset.x = 0;
|
||||||
|
tmxTileOffset.y = 0;
|
||||||
|
return tmxTileOffset;
|
||||||
|
}
|
||||||
|
tmxTileOffset.x = xTileOffset["x"];
|
||||||
|
tmxTileOffset.y = xTileOffset["y"];
|
||||||
|
return tmxTileOffset;
|
||||||
|
};
|
||||||
|
TiledMapLoader.loadTmxImage = function (image, xImage) {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var xSource, _a, _b, xData;
|
||||||
|
return __generator(this, function (_c) {
|
||||||
|
switch (_c.label) {
|
||||||
|
case 0:
|
||||||
|
xSource = xImage["image"];
|
||||||
|
if (!xSource) return [3, 2];
|
||||||
|
image.source = "resource/assets/" + xSource;
|
||||||
|
_a = image;
|
||||||
|
_b = Bitmap.bind;
|
||||||
|
return [4, RES.getResByUrl(image.source, null, this, RES.ResourceItem.TYPE_IMAGE)];
|
||||||
|
case 1:
|
||||||
|
_a.bitmap = new (_b.apply(Bitmap, [void 0, _c.sent()]))();
|
||||||
|
return [3, 3];
|
||||||
|
case 2:
|
||||||
|
image.format = xImage["format"];
|
||||||
|
xData = xImage["data"];
|
||||||
|
image.data = es.TmxUtils.decode(xData, xData["encoding"], xData["compression"]);
|
||||||
|
_c.label = 3;
|
||||||
|
case 3:
|
||||||
|
image.trans = es.TmxUtils.color16ToUnit(xImage["trans"]);
|
||||||
|
image.width = xImage["width"] != undefined ? xImage["width"] : 0;
|
||||||
|
image.height = xImage["height"] != undefined ? xImage["height"] : 0;
|
||||||
|
return [2, image];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
return TiledMapLoader;
|
||||||
|
}());
|
||||||
|
es.TiledMapLoader = TiledMapLoader;
|
||||||
|
})(es || (es = {}));
|
||||||
|
var es;
|
||||||
(function (es) {
|
(function (es) {
|
||||||
var TiledRendering = (function () {
|
var TiledRendering = (function () {
|
||||||
function TiledRendering() {
|
function TiledRendering() {
|
||||||
}
|
}
|
||||||
TiledRendering.renderMap = function (map, position, scale, layerDepth) {
|
TiledRendering.renderMap = function (map, container, position, scale, layerDepth) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
map.layers.forEach(function (layer) {
|
map.layers.forEach(function (layer) {
|
||||||
if (layer instanceof es.TmxLayer && layer.visible) {
|
if (layer instanceof es.TmxLayer && layer.visible) {
|
||||||
_this.renderLayer(layer, position, scale, layerDepth);
|
_this.renderLayer(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
else if (layer instanceof es.TmxImageLayer && layer.visible) {
|
else if (layer instanceof es.TmxImageLayer && layer.visible) {
|
||||||
_this.renderImageLayer(layer, position, scale, layerDepth);
|
_this.renderImageLayer(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
else if (layer instanceof es.TmxGroup && layer.visible) {
|
else if (layer instanceof es.TmxGroup && layer.visible) {
|
||||||
_this.renderGroup(layer, position, scale, layerDepth);
|
_this.renderGroup(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
else if (layer instanceof es.TmxObjectGroup && layer.visible) {
|
else if (layer instanceof es.TmxObjectGroup && layer.visible) {
|
||||||
_this.renderObjectGroup(layer, position, scale, layerDepth);
|
_this.renderObjectGroup(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
TiledRendering.renderLayer = function (layer, position, scale, layerDepth) {
|
TiledRendering.renderLayer = function (layer, container, position, scale, layerDepth) {
|
||||||
if (!layer.visible)
|
if (!layer.visible)
|
||||||
return;
|
return;
|
||||||
var tileWidth = layer.map.tileWidth * scale.x;
|
var tileWidth = layer.map.tileWidth * scale.x;
|
||||||
var tileHeight = layer.map.tileHeight * scale.y;
|
var tileHeight = layer.map.tileHeight * scale.y;
|
||||||
var color = new es.Color(0, 0, 0, layer.opacity * 255);
|
var color = es.DrawUtils.getColorMatrix(0x000000);
|
||||||
for (var i = 0; i < layer.tiles.length; i++) {
|
for (var i = 0; i < layer.tiles.length; i++) {
|
||||||
var tile = layer.tiles[i];
|
var tile = layer.tiles[i];
|
||||||
if (!tile)
|
if (!tile)
|
||||||
continue;
|
continue;
|
||||||
this.renderTile(tile, position, scale, tileWidth, tileHeight, color, layerDepth);
|
this.renderTile(tile, container, position, scale, tileWidth, tileHeight, color, layerDepth);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
TiledRendering.renderImageLayer = function (layer, position, scale, layerDepth) {
|
TiledRendering.renderImageLayer = function (layer, container, position, scale, layerDepth) {
|
||||||
if (!layer.visible)
|
if (!layer.visible)
|
||||||
return;
|
return;
|
||||||
var color = new es.Color(0, 0, 0, layer.opacity * 255);
|
var color = es.DrawUtils.getColorMatrix(0x000000);
|
||||||
var pos = es.Vector2.add(position, new es.Vector2(layer.offsetX, layer.offsetY).multiply(scale));
|
var pos = es.Vector2.add(position, new es.Vector2(layer.offsetX, layer.offsetY).multiply(scale));
|
||||||
|
if (!layer.image.bitmap.parent)
|
||||||
|
container.addChild(layer.image.bitmap);
|
||||||
|
layer.image.bitmap.x = pos.x;
|
||||||
|
layer.image.bitmap.y = pos.y;
|
||||||
|
layer.image.bitmap.scaleX = scale.x;
|
||||||
|
layer.image.bitmap.scaleY = scale.y;
|
||||||
|
layer.image.bitmap.filters = [color];
|
||||||
};
|
};
|
||||||
TiledRendering.renderObjectGroup = function (objGroup, position, scale, layerDepth) {
|
TiledRendering.renderObjectGroup = function (objGroup, container, position, scale, layerDepth) {
|
||||||
if (!objGroup.visible)
|
if (!objGroup.visible)
|
||||||
return;
|
return;
|
||||||
for (var object in objGroup.objects) {
|
for (var object in objGroup.objects) {
|
||||||
var obj = objGroup.objects.get(object);
|
var obj = objGroup.objects[object];
|
||||||
if (!obj.visible)
|
if (!obj.visible)
|
||||||
continue;
|
continue;
|
||||||
|
if (!es.Core.debugRenderEndabled) {
|
||||||
|
if (obj.objectType != es.TmxObjectType.tile && obj.objectType != es.TmxObjectType.text)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
var pos = es.Vector2.add(position, new es.Vector2(obj.x, obj.y).multiply(scale));
|
var pos = es.Vector2.add(position, new es.Vector2(obj.x, obj.y).multiply(scale));
|
||||||
switch (obj.objectType) {
|
switch (obj.objectType) {
|
||||||
case es.TmxObjectType.basic:
|
case es.TmxObjectType.basic:
|
||||||
|
if (!obj.shape.parent)
|
||||||
|
container.addChild(obj.shape);
|
||||||
|
var rect = new es.Rectangle(pos.x, pos.y, obj.width * scale.x, obj.height * scale.y);
|
||||||
|
es.DrawUtils.drawHollowRect(obj.shape, rect, objGroup.color);
|
||||||
break;
|
break;
|
||||||
case es.TmxObjectType.point:
|
case es.TmxObjectType.point:
|
||||||
var size = objGroup.map.tileWidth * 0.5;
|
var size = objGroup.map.tileWidth * 0.5;
|
||||||
pos.x -= size * 0.5;
|
pos.x -= size * 0.5;
|
||||||
pos.y -= size * 0.5;
|
pos.y -= size * 0.5;
|
||||||
|
if (!obj.shape.parent)
|
||||||
|
container.addChild(obj.shape);
|
||||||
|
es.DrawUtils.drawPixel(obj.shape, pos, objGroup.color, size);
|
||||||
break;
|
break;
|
||||||
case es.TmxObjectType.tile:
|
case es.TmxObjectType.tile:
|
||||||
var tileset = objGroup.map.getTilesetForTileGid(obj.tile.gid);
|
var tileset = objGroup.map.getTilesetForTileGid(obj.tile.gid);
|
||||||
var sourceRect = tileset.tileRegions[obj.tile.gid];
|
var sourceRect = tileset.tileRegions[obj.tile.gid];
|
||||||
pos.y -= obj.tile.tilesetTile.image.height;
|
pos.y -= obj.tile.tilesetTile.image.height;
|
||||||
|
if (!obj.tile.tilesetTile.image.bitmap)
|
||||||
|
container.addChild(obj.tile.tilesetTile.image.bitmap);
|
||||||
|
obj.tile.tilesetTile.image.bitmap.x = pos.x;
|
||||||
|
obj.tile.tilesetTile.image.bitmap.y = pos.y;
|
||||||
|
obj.tile.tilesetTile.image.bitmap.filters = [];
|
||||||
|
obj.tile.tilesetTile.image.bitmap.rotation = 0;
|
||||||
|
obj.tile.tilesetTile.image.bitmap.scaleX = scale.x;
|
||||||
|
obj.tile.tilesetTile.image.bitmap.scaleY = scale.y;
|
||||||
break;
|
break;
|
||||||
case es.TmxObjectType.ellipse:
|
case es.TmxObjectType.ellipse:
|
||||||
pos = new es.Vector2(obj.x + obj.width * 0.5, obj.y + obj.height * 0.5).multiply(scale);
|
pos = new es.Vector2(obj.x + obj.width * 0.5, obj.y + obj.height * 0.5).multiply(scale);
|
||||||
|
if (!obj.shape.parent)
|
||||||
|
container.addChild(obj.shape);
|
||||||
|
es.DrawUtils.drawCircle(obj.shape, pos, obj.width * 0.5, objGroup.color);
|
||||||
break;
|
break;
|
||||||
case es.TmxObjectType.polygon:
|
case es.TmxObjectType.polygon:
|
||||||
case es.TmxObjectType.polyline:
|
case es.TmxObjectType.polyline:
|
||||||
var points = [];
|
var points = [];
|
||||||
for (var i = 0; i < obj.points.length; i++)
|
for (var i = 0; i < obj.points.length; i++)
|
||||||
points[i] = es.Vector2.multiply(obj.points[i], scale);
|
points[i] = es.Vector2.multiply(obj.points[i], scale);
|
||||||
|
es.DrawUtils.drawPoints(obj.shape, pos, points, objGroup.color, obj.objectType == es.TmxObjectType.polygon);
|
||||||
break;
|
break;
|
||||||
case es.TmxObjectType.text:
|
case es.TmxObjectType.text:
|
||||||
|
if (!obj.textField.parent)
|
||||||
|
container.addChild(obj.textField);
|
||||||
|
es.DrawUtils.drawString(obj.textField, obj.text.value, pos, obj.text.color, es.MathHelper.toRadians(obj.rotation), es.Vector2.zero, 1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
if (es.Core.debugRenderEndabled) {
|
||||||
|
if (!obj.textField.parent)
|
||||||
|
container.addChild(obj.textField);
|
||||||
|
es.DrawUtils.drawString(obj.textField, obj.name + "(" + obj.type + ")", es.Vector2.subtract(pos, new es.Vector2(0, 15)), 0xffffff, 0, es.Vector2.zero, 1);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
TiledRendering.renderGroup = function (group, position, scale, layerDepth) {
|
TiledRendering.renderGroup = function (group, container, position, scale, layerDepth) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
if (!group.visible)
|
if (!group.visible)
|
||||||
return;
|
return;
|
||||||
group.layers.forEach(function (layer) {
|
group.layers.forEach(function (layer) {
|
||||||
if (layer instanceof es.TmxGroup) {
|
if (layer instanceof es.TmxGroup) {
|
||||||
_this.renderGroup(layer, position, scale, layerDepth);
|
_this.renderGroup(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
if (layer instanceof es.TmxObjectGroup) {
|
if (layer instanceof es.TmxObjectGroup) {
|
||||||
_this.renderObjectGroup(layer, position, scale, layerDepth);
|
_this.renderObjectGroup(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
if (layer instanceof es.TmxLayer) {
|
if (layer instanceof es.TmxLayer) {
|
||||||
_this.renderLayer(layer, position, scale, layerDepth);
|
_this.renderLayer(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
if (layer instanceof es.TmxImageLayer) {
|
if (layer instanceof es.TmxImageLayer) {
|
||||||
_this.renderImageLayer(layer, position, scale, layerDepth);
|
_this.renderImageLayer(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
TiledRendering.renderTile = function (tile, position, scale, tileWidth, tileHeight, color, layerDepth) {
|
TiledRendering.renderTile = function (tile, container, position, scale, tileWidth, tileHeight, color, layerDepth) {
|
||||||
var gid = tile.gid;
|
var gid = tile.gid;
|
||||||
var tilesetTile = tile.tilesetTile;
|
var tilesetTile = tile.tilesetTile;
|
||||||
if (tilesetTile && tilesetTile.animationFrames.length > 0)
|
if (tilesetTile && tilesetTile.animationFrames.length > 0)
|
||||||
@@ -7935,8 +8378,24 @@ var es;
|
|||||||
ty += (tileHeight - sourceRect.height * scale.y);
|
ty += (tileHeight - sourceRect.height * scale.y);
|
||||||
var pos = new es.Vector2(tx, ty).add(position);
|
var pos = new es.Vector2(tx, ty).add(position);
|
||||||
if (tile.tileset.image) {
|
if (tile.tileset.image) {
|
||||||
|
if (!tile.tilesetTile.image.bitmap.parent)
|
||||||
|
container.addChild(tile.tilesetTile.image.bitmap);
|
||||||
|
tile.tilesetTile.image.bitmap.x = pos.x;
|
||||||
|
tile.tilesetTile.image.bitmap.y = pos.y;
|
||||||
|
tile.tilesetTile.image.bitmap.scaleX = scale.x;
|
||||||
|
tile.tilesetTile.image.bitmap.scaleY = scale.y;
|
||||||
|
tile.tilesetTile.image.bitmap.rotation = rotation;
|
||||||
|
tile.tilesetTile.image.bitmap.filters = [color];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (!tilesetTile.image.bitmap)
|
||||||
|
container.addChild(tilesetTile.image.bitmap);
|
||||||
|
tilesetTile.image.bitmap.x = pos.x;
|
||||||
|
tilesetTile.image.bitmap.y = pos.y;
|
||||||
|
tilesetTile.image.bitmap.scaleX = scale.x;
|
||||||
|
tilesetTile.image.bitmap.scaleY = scale.y;
|
||||||
|
tilesetTile.image.bitmap.rotation = rotation;
|
||||||
|
tilesetTile.image.bitmap.filters = [color];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return TiledRendering;
|
return TiledRendering;
|
||||||
@@ -8020,6 +8479,41 @@ var es;
|
|||||||
}());
|
}());
|
||||||
es.TmxAnimationFrame = TmxAnimationFrame;
|
es.TmxAnimationFrame = TmxAnimationFrame;
|
||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
|
var es;
|
||||||
|
(function (es) {
|
||||||
|
var TmxUtils = (function () {
|
||||||
|
function TmxUtils() {
|
||||||
|
}
|
||||||
|
TmxUtils.decode = function (data, encoding, compression) {
|
||||||
|
compression = compression || "none";
|
||||||
|
encoding = encoding || "none";
|
||||||
|
var text = data.children[0].text;
|
||||||
|
switch (encoding) {
|
||||||
|
case "base64":
|
||||||
|
var decoded = es.Base64Utils.decodeBase64AsArray(text, 4);
|
||||||
|
return (compression === "none") ? decoded : es.Base64Utils.decompress(text, decoded, compression);
|
||||||
|
case "csv":
|
||||||
|
return es.Base64Utils.decodeCSV(text);
|
||||||
|
case "none":
|
||||||
|
var datas = [];
|
||||||
|
for (var i = 0; i < data.children.length; i++) {
|
||||||
|
datas[i] = +data.children[i].attributes.gid;
|
||||||
|
}
|
||||||
|
return datas;
|
||||||
|
default:
|
||||||
|
throw new Error("未定义的编码:" + encoding);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
TmxUtils.color16ToUnit = function ($color) {
|
||||||
|
if (!$color)
|
||||||
|
return 0x000000;
|
||||||
|
var colorStr = "0x" + $color.slice(1);
|
||||||
|
return parseInt(colorStr, 16);
|
||||||
|
};
|
||||||
|
return TmxUtils;
|
||||||
|
}());
|
||||||
|
es.TmxUtils = TmxUtils;
|
||||||
|
})(es || (es = {}));
|
||||||
var ArrayUtils = (function () {
|
var ArrayUtils = (function () {
|
||||||
function ArrayUtils() {
|
function ArrayUtils() {
|
||||||
}
|
}
|
||||||
@@ -8184,106 +8678,52 @@ var ArrayUtils = (function () {
|
|||||||
};
|
};
|
||||||
return ArrayUtils;
|
return ArrayUtils;
|
||||||
}());
|
}());
|
||||||
|
var es;
|
||||||
|
(function (es) {
|
||||||
var Base64Utils = (function () {
|
var Base64Utils = (function () {
|
||||||
function Base64Utils() {
|
function Base64Utils() {
|
||||||
}
|
}
|
||||||
Base64Utils.decode = function (input, isNotStr) {
|
Object.defineProperty(Base64Utils, "nativeBase64", {
|
||||||
if (isNotStr === void 0) { isNotStr = true; }
|
get: function () {
|
||||||
var output = "";
|
return (typeof (window.atob) === "function");
|
||||||
var chr1, chr2, chr3;
|
},
|
||||||
var enc1, enc2, enc3, enc4;
|
enumerable: true,
|
||||||
var i = 0;
|
configurable: true
|
||||||
input = this.getConfKey(input);
|
});
|
||||||
|
Base64Utils.decode = function (input) {
|
||||||
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
||||||
|
if (this.nativeBase64) {
|
||||||
|
return window.atob(input);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var output = [], chr1, chr2, chr3, enc1, enc2, enc3, enc4, i = 0;
|
||||||
while (i < input.length) {
|
while (i < input.length) {
|
||||||
enc1 = this._keyAll.indexOf(input.charAt(i++));
|
enc1 = this._keyStr.indexOf(input.charAt(i++));
|
||||||
enc2 = this._keyAll.indexOf(input.charAt(i++));
|
enc2 = this._keyStr.indexOf(input.charAt(i++));
|
||||||
enc3 = this._keyAll.indexOf(input.charAt(i++));
|
enc3 = this._keyStr.indexOf(input.charAt(i++));
|
||||||
enc4 = this._keyAll.indexOf(input.charAt(i++));
|
enc4 = this._keyStr.indexOf(input.charAt(i++));
|
||||||
chr1 = (enc1 << 2) | (enc2 >> 4);
|
chr1 = (enc1 << 2) | (enc2 >> 4);
|
||||||
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
||||||
chr3 = ((enc3 & 3) << 6) | enc4;
|
chr3 = ((enc3 & 3) << 6) | enc4;
|
||||||
output = output + String.fromCharCode(chr1);
|
output.push(String.fromCharCode(chr1));
|
||||||
if (enc3 != 64) {
|
if (enc3 !== 64) {
|
||||||
if (chr2 == 0) {
|
output.push(String.fromCharCode(chr2));
|
||||||
if (isNotStr)
|
|
||||||
output = output + String.fromCharCode(chr2);
|
|
||||||
}
|
}
|
||||||
else {
|
if (enc4 !== 64) {
|
||||||
output = output + String.fromCharCode(chr2);
|
output.push(String.fromCharCode(chr3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (enc4 != 64) {
|
output = output.join("");
|
||||||
if (chr3 == 0) {
|
|
||||||
if (isNotStr)
|
|
||||||
output = output + String.fromCharCode(chr3);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
output = output + String.fromCharCode(chr3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
output = this._utf8_decode(output);
|
|
||||||
return output;
|
return output;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
Base64Utils._utf8_encode = function (string) {
|
|
||||||
string = string.replace(/\r\n/g, "\n");
|
|
||||||
var utftext = "";
|
|
||||||
for (var n = 0; n < string.length; n++) {
|
|
||||||
var c = string.charCodeAt(n);
|
|
||||||
if (c < 128) {
|
|
||||||
utftext += String.fromCharCode(c);
|
|
||||||
}
|
|
||||||
else if ((c > 127) && (c < 2048)) {
|
|
||||||
utftext += String.fromCharCode((c >> 6) | 192);
|
|
||||||
utftext += String.fromCharCode((c & 63) | 128);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
utftext += String.fromCharCode((c >> 12) | 224);
|
|
||||||
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
|
||||||
utftext += String.fromCharCode((c & 63) | 128);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return utftext;
|
|
||||||
};
|
|
||||||
Base64Utils._utf8_decode = function (utftext) {
|
|
||||||
var string = "";
|
|
||||||
var i = 0;
|
|
||||||
var c = 0;
|
|
||||||
var c1 = 0;
|
|
||||||
var c2 = 0;
|
|
||||||
var c3 = 0;
|
|
||||||
while (i < utftext.length) {
|
|
||||||
c = utftext.charCodeAt(i);
|
|
||||||
if (c < 128) {
|
|
||||||
string += String.fromCharCode(c);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
else if ((c > 191) && (c < 224)) {
|
|
||||||
c2 = utftext.charCodeAt(i + 1);
|
|
||||||
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
|
|
||||||
i += 2;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
c2 = utftext.charCodeAt(i + 1);
|
|
||||||
c3 = utftext.charCodeAt(i + 2);
|
|
||||||
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
|
|
||||||
i += 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return string;
|
|
||||||
};
|
|
||||||
Base64Utils.getConfKey = function (key) {
|
|
||||||
return key.slice(1, key.length);
|
|
||||||
};
|
|
||||||
Base64Utils._keyNum = "0123456789+/";
|
|
||||||
Base64Utils._keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
||||||
Base64Utils._keyAll = Base64Utils._keyNum + Base64Utils._keyStr;
|
|
||||||
Base64Utils.encode = function (input) {
|
Base64Utils.encode = function (input) {
|
||||||
var output = "";
|
input = input.replace(/\r\n/g, "\n");
|
||||||
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
|
if (this.nativeBase64) {
|
||||||
var i = 0;
|
window.btoa(input);
|
||||||
input = this._utf8_encode(input);
|
}
|
||||||
|
else {
|
||||||
|
var output = [], chr1, chr2, chr3, enc1, enc2, enc3, enc4, i = 0;
|
||||||
while (i < input.length) {
|
while (i < input.length) {
|
||||||
chr1 = input.charCodeAt(i++);
|
chr1 = input.charCodeAt(i++);
|
||||||
chr2 = input.charCodeAt(i++);
|
chr2 = input.charCodeAt(i++);
|
||||||
@@ -8298,14 +8738,43 @@ var Base64Utils = (function () {
|
|||||||
else if (isNaN(chr3)) {
|
else if (isNaN(chr3)) {
|
||||||
enc4 = 64;
|
enc4 = 64;
|
||||||
}
|
}
|
||||||
output = output +
|
output.push(this._keyStr.charAt(enc1));
|
||||||
this._keyAll.charAt(enc1) + this._keyAll.charAt(enc2) +
|
output.push(this._keyStr.charAt(enc2));
|
||||||
this._keyAll.charAt(enc3) + this._keyAll.charAt(enc4);
|
output.push(this._keyStr.charAt(enc3));
|
||||||
|
output.push(this._keyStr.charAt(enc4));
|
||||||
|
}
|
||||||
|
output = output.join("");
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
return this._keyStr.charAt(Math.floor((Math.random() * this._keyStr.length))) + output;
|
|
||||||
};
|
};
|
||||||
|
Base64Utils.decodeBase64AsArray = function (input, bytes) {
|
||||||
|
bytes = bytes || 1;
|
||||||
|
var dec = Base64Utils.decode(input), i, j, len;
|
||||||
|
var ar = new Uint32Array(dec.length / bytes);
|
||||||
|
for (i = 0, len = dec.length / bytes; i < len; i++) {
|
||||||
|
ar[i] = 0;
|
||||||
|
for (j = bytes - 1; j >= 0; --j) {
|
||||||
|
ar[i] += dec.charCodeAt((i * bytes) + j) << (j << 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
Base64Utils.decompress = function (data, decoded, compression) {
|
||||||
|
throw new Error("GZIP/ZLIB compressed TMX Tile Map not supported!");
|
||||||
|
};
|
||||||
|
Base64Utils.decodeCSV = function (input) {
|
||||||
|
var entries = input.replace("\n", "").trim().split(",");
|
||||||
|
var result = [];
|
||||||
|
for (var i = 0; i < entries.length; i++) {
|
||||||
|
result.push(+entries[i]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
Base64Utils._keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||||
return Base64Utils;
|
return Base64Utils;
|
||||||
}());
|
}());
|
||||||
|
es.Base64Utils = Base64Utils;
|
||||||
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
(function (es) {
|
(function (es) {
|
||||||
var Color = (function () {
|
var Color = (function () {
|
||||||
@@ -8433,6 +8902,23 @@ var es;
|
|||||||
if (thickness === void 0) { thickness = 1; }
|
if (thickness === void 0) { thickness = 1; }
|
||||||
this.drawLineAngle(shape, start, es.MathHelper.angleBetweenVectors(start, end), es.Vector2.distance(start, end), color, thickness);
|
this.drawLineAngle(shape, start, es.MathHelper.angleBetweenVectors(start, end), es.Vector2.distance(start, end), color, thickness);
|
||||||
};
|
};
|
||||||
|
DrawUtils.drawCircle = function (shape, position, radius, color) {
|
||||||
|
shape.graphics.beginFill(color);
|
||||||
|
shape.graphics.drawCircle(position.x, position.y, radius);
|
||||||
|
shape.graphics.endFill();
|
||||||
|
};
|
||||||
|
DrawUtils.drawPoints = function (shape, position, points, color, closePoly, thickness) {
|
||||||
|
if (closePoly === void 0) { closePoly = true; }
|
||||||
|
if (thickness === void 0) { thickness = 1; }
|
||||||
|
if (points.length < 2)
|
||||||
|
return;
|
||||||
|
for (var i = 1; i < points.length; i++)
|
||||||
|
this.drawLine(shape, es.Vector2.add(position, points[i - 1]), es.Vector2.add(position, points[i]), color, thickness);
|
||||||
|
if (closePoly)
|
||||||
|
this.drawLine(shape, es.Vector2.add(position, points[points.length - 1]), es.Vector2.add(position, points[0]), color, thickness);
|
||||||
|
};
|
||||||
|
DrawUtils.drawString = function (textField, text, position, color, rotation, origin, scale) {
|
||||||
|
};
|
||||||
DrawUtils.drawLineAngle = function (shape, start, radians, length, color, thickness) {
|
DrawUtils.drawLineAngle = function (shape, start, radians, length, color, thickness) {
|
||||||
if (thickness === void 0) { thickness = 1; }
|
if (thickness === void 0) { thickness = 1; }
|
||||||
shape.graphics.beginFill(color);
|
shape.graphics.beginFill(color);
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -6,9 +6,11 @@ module es {
|
|||||||
* 如果空,所有层将被渲染
|
* 如果空,所有层将被渲染
|
||||||
*/
|
*/
|
||||||
public layerIndicesToRender: number[];
|
public layerIndicesToRender: number[];
|
||||||
|
|
||||||
public get width() {
|
public get width() {
|
||||||
return this.tiledMap.width * this.tiledMap.tileWidth;
|
return this.tiledMap.width * this.tiledMap.tileWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get height() {
|
public get height() {
|
||||||
return this.tiledMap.height * this.tiledMap.tileHeight;
|
return this.tiledMap.height * this.tiledMap.tileHeight;
|
||||||
}
|
}
|
||||||
@@ -21,9 +23,10 @@ module es {
|
|||||||
super();
|
super();
|
||||||
this.tiledMap = tiledMap;
|
this.tiledMap = tiledMap;
|
||||||
this._shouldCreateColliders = shouldCreateColliders;
|
this._shouldCreateColliders = shouldCreateColliders;
|
||||||
|
this.displayObject = new egret.DisplayObjectContainer();
|
||||||
|
|
||||||
if (collisionLayerName) {
|
if (collisionLayerName) {
|
||||||
this.collisionLayer = tiledMap.tileLayers.get(collisionLayerName);
|
this.collisionLayer = tiledMap.tileLayers[collisionLayerName];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +54,7 @@ module es {
|
|||||||
let layerType = this.tiledMap.getLayer(layerName);
|
let layerType = this.tiledMap.getLayer(layerName);
|
||||||
for (let layer in this.tiledMap.layers) {
|
for (let layer in this.tiledMap.layers) {
|
||||||
if (this.tiledMap.layers.hasOwnProperty(layer) &&
|
if (this.tiledMap.layers.hasOwnProperty(layer) &&
|
||||||
this.tiledMap.layers.get(layer) == layerType){
|
this.tiledMap.layers[layer] == layerType) {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,12 +94,12 @@ module es {
|
|||||||
|
|
||||||
public render(camera: es.Camera) {
|
public render(camera: es.Camera) {
|
||||||
if (!this.layerIndicesToRender) {
|
if (!this.layerIndicesToRender) {
|
||||||
TiledRendering.renderMap(this.tiledMap, Vector2.add(this.entity.transform.position, this._localOffset),
|
TiledRendering.renderMap(this.tiledMap, this.displayObject as egret.DisplayObjectContainer, Vector2.add(this.entity.transform.position, this._localOffset),
|
||||||
this.transform.scale, this.renderLayer);
|
this.transform.scale, this.renderLayer);
|
||||||
} else {
|
} else {
|
||||||
for (let i = 0; i < this.tiledMap.layers.size; i ++){
|
for (let i = 0; i < this.tiledMap.layers.length; i++) {
|
||||||
if (this.tiledMap.layers.get(i.toString()).visible && this.layerIndicesToRender.contains(i))
|
if (this.tiledMap.layers[i].visible && this.layerIndicesToRender.contains(i))
|
||||||
TiledRendering.renderLayer(this.tiledMap.layers.get(i.toString()), Vector2.add(this.entity.transform.position, this._localOffset),
|
TiledRendering.renderLayer(this.tiledMap.layers[i] as TmxLayer, this.displayObject as egret.DisplayObjectContainer, Vector2.add(this.entity.transform.position, this._localOffset),
|
||||||
this.transform.scale, this.renderLayer);
|
this.transform.scale, this.renderLayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ module es {
|
|||||||
* 核心发射器。只发出核心级别的事件
|
* 核心发射器。只发出核心级别的事件
|
||||||
*/
|
*/
|
||||||
public static emitter: Emitter<CoreEvents>;
|
public static emitter: Emitter<CoreEvents>;
|
||||||
|
/**
|
||||||
|
* 是否启用调试渲染
|
||||||
|
*/
|
||||||
|
public static debugRenderEndabled = false;
|
||||||
/**
|
/**
|
||||||
* 全局访问图形设备
|
* 全局访问图形设备
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ module es {
|
|||||||
public properties: Map<string, string>;
|
public properties: Map<string, string>;
|
||||||
public visible: boolean;
|
public visible: boolean;
|
||||||
public name: string;
|
public name: string;
|
||||||
public layers: TmxList<any>;
|
public layers: ITmxLayer[];
|
||||||
public tileLayers: TmxList<TmxLayer>;
|
public tileLayers: TmxLayer[];
|
||||||
public objectGroups: TmxList<TmxObjectGroup>;
|
public objectGroups: TmxObjectGroup[];
|
||||||
public imageLayers: TmxList<TmxImageLayer>;
|
public imageLayers: TmxImageLayer[];
|
||||||
public groups: TmxList<TmxGroup>;
|
public groups: TmxGroup[];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+10
-10
@@ -26,12 +26,12 @@ module es {
|
|||||||
* 包含所有的ITmxLayers,不管它们的具体类型是什么。
|
* 包含所有的ITmxLayers,不管它们的具体类型是什么。
|
||||||
* 注意,TmxGroup中的层将不在此列表中。TmxGroup管理自己的层列表。
|
* 注意,TmxGroup中的层将不在此列表中。TmxGroup管理自己的层列表。
|
||||||
*/
|
*/
|
||||||
public layers: TmxList<any>;
|
public layers: ITmxLayer[];
|
||||||
public tilesets: TmxList<TmxTileset>;
|
public tilesets: TmxTileset[];
|
||||||
public tileLayers: TmxList<TmxLayer>;
|
public tileLayers: TmxLayer[];
|
||||||
public objectGroups: TmxList<TmxObjectGroup>;
|
public objectGroups: TmxLayer[];
|
||||||
public imageLayers: TmxList<TmxImageLayer>;
|
public imageLayers: TmxImageLayer[];
|
||||||
public groups: TmxList<TmxGroup>;
|
public groups: TmxGroup[];
|
||||||
public properties: Map<string, string>;
|
public properties: Map<string, string>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -59,9 +59,9 @@ module es {
|
|||||||
if (gid == 0)
|
if (gid == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
for (let i = this.tilesets.size - 1; i >= 0; i --){
|
for (let i = this.tilesets.length - 1; i >= 0; i --){
|
||||||
if (this.tilesets.get(i.toString()).firstGid <= gid)
|
if (this.tilesets[i].firstGid <= gid)
|
||||||
return this.tilesets.get(i.toString());
|
return this.tilesets[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
console.error(`tile gid${gid}未在任何tileset中找到`);
|
console.error(`tile gid${gid}未在任何tileset中找到`);
|
||||||
@@ -96,7 +96,7 @@ module es {
|
|||||||
* @param name
|
* @param name
|
||||||
*/
|
*/
|
||||||
public getLayer(name: string): ITmxLayer {
|
public getLayer(name: string): ITmxLayer {
|
||||||
return this.layers.get(name);
|
return this.layers[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,13 +8,15 @@ module es {
|
|||||||
public offsetY: number;
|
public offsetY: number;
|
||||||
public color: number;
|
public color: number;
|
||||||
public drawOrder: DrawOrderType;
|
public drawOrder: DrawOrderType;
|
||||||
public objects: TmxList<TmxObject>;
|
public objects: TmxObject[];
|
||||||
public properties: Map<string, string>;
|
public properties: Map<string, string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TmxObject implements ITmxElement {
|
export class TmxObject implements ITmxElement {
|
||||||
public id: number;
|
public id: number;
|
||||||
public name: string;
|
public name: string;
|
||||||
|
public shape: egret.Shape;
|
||||||
|
public textField: egret.TextField;
|
||||||
public objectType: TmxObjectType;
|
public objectType: TmxObjectType;
|
||||||
public type: string;
|
public type: string;
|
||||||
public x: number;
|
public x: number;
|
||||||
@@ -27,6 +29,11 @@ module es {
|
|||||||
public text: TmxText;
|
public text: TmxText;
|
||||||
public points: Vector2[];
|
public points: Vector2[];
|
||||||
public properties: Map<string, string>;
|
public properties: Map<string, string>;
|
||||||
|
|
||||||
|
constructor(){
|
||||||
|
this.shape = new egret.Shape();
|
||||||
|
this.textField = new egret.TextField();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TmxText {
|
export class TmxText {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
module es {
|
module es {
|
||||||
export class TmxDocument {
|
export class TmxDocument {
|
||||||
public TmxDirectory: string;
|
public tmxDirectory: string;
|
||||||
constructor(){
|
constructor(){
|
||||||
this.TmxDirectory = "";
|
this.tmxDirectory = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -10,37 +10,40 @@ module es {
|
|||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TmxList<T extends ITmxElement> extends Map<string, T>{
|
// export class TmxList<T extends ITmxElement> extends Map<string, T>{
|
||||||
public _nameCount: Map<string, number> = new Map<string, number>();
|
// public _nameCount: Map<string, number> = new Map<string, number>();
|
||||||
|
//
|
||||||
public add(t: T){
|
// public add(t: T){
|
||||||
let tName = t.name;
|
// let tName = t.name;
|
||||||
|
//
|
||||||
// 通过附加数字重命名重复的条目
|
// // 通过附加数字重命名重复的条目
|
||||||
if (this.has(tName))
|
// if (this.has(tName))
|
||||||
this._nameCount.set(tName, this._nameCount.get(tName) + 1);
|
// this._nameCount.set(tName, this._nameCount.get(tName) + 1);
|
||||||
else
|
// else
|
||||||
this._nameCount.set(tName, 0);
|
// this._nameCount.set(tName, 0);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
protected getKeyForItem(item: T): string {
|
// protected getKeyForItem(item: T): string {
|
||||||
let name = item.name;
|
// let name = item.name;
|
||||||
let count = this._nameCount.get(name);
|
// let count = this._nameCount.get(name);
|
||||||
|
//
|
||||||
let dupes = 0;
|
// let dupes = 0;
|
||||||
|
//
|
||||||
// 对于重复的键,附加一个计数器。对于病理情况,插入下划线以确保唯一性
|
// // 对于重复的键,附加一个计数器。对于病理情况,插入下划线以确保唯一性
|
||||||
while (this.has(name)){
|
// while (this.has(name)){
|
||||||
name = name + Enumerable.repeat("_", dupes).toString() + count.toString();
|
// name = name + Enumerable.repeat("_", dupes).toString() + count.toString();
|
||||||
dupes ++;
|
// dupes ++;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return name;
|
// return name;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
export class TmxImage {
|
export class TmxImage {
|
||||||
public texture: egret.Texture;
|
public bitmap: egret.Bitmap;
|
||||||
|
public get texture(): egret.Texture{
|
||||||
|
return this.bitmap.texture;
|
||||||
|
}
|
||||||
public source: string;
|
public source: string;
|
||||||
public format: string;
|
public format: string;
|
||||||
public data: any;
|
public data: any;
|
||||||
@@ -49,9 +52,9 @@ module es {
|
|||||||
public height: number;
|
public height: number;
|
||||||
|
|
||||||
public dispose(){
|
public dispose(){
|
||||||
if (this.texture){
|
if (this.bitmap){
|
||||||
this.texture.dispose();
|
this.texture.dispose();
|
||||||
this.texture = null;
|
this.bitmap = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,406 @@
|
|||||||
|
module es {
|
||||||
|
import Bitmap = egret.Bitmap;
|
||||||
|
|
||||||
|
export class TiledMapLoader {
|
||||||
|
public static loadTmxMap(map: TmxMap, filePath: string){
|
||||||
|
let xMap = RES.getRes(filePath);
|
||||||
|
return this.loadTmxMapData(map, xMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async loadTmxMapData(map: TmxMap, xMap: any){
|
||||||
|
map.version = xMap["version"];
|
||||||
|
map.tiledVersion = xMap["tiledversion"];
|
||||||
|
map.width = xMap["width"];
|
||||||
|
map.height = xMap["height"];
|
||||||
|
map.tileWidth = xMap["tilewidth"];
|
||||||
|
map.tileHeight = xMap["tileheight"];
|
||||||
|
map.hexSideLength = xMap["hexsidelength"];
|
||||||
|
|
||||||
|
map.orientation = this.parseOrientationType(xMap["orientation"]);
|
||||||
|
map.staggerAxis = this.parseStaggerAxisType(xMap["staggeraxis"]);
|
||||||
|
map.staggerIndex = this.parseStaggerIndexType(xMap["staggerindex"]);
|
||||||
|
map.renderOrder = this.parseRenderOrderType(xMap["renderorder"]);
|
||||||
|
|
||||||
|
map.nextObjectID = xMap["nextobjectid"];
|
||||||
|
map.backgroundColor = TmxUtils.color16ToUnit(xMap["color"]);
|
||||||
|
|
||||||
|
map.properties = this.parsePropertyDict(xMap["properties"]);
|
||||||
|
|
||||||
|
// 我们保持记录的最大瓷砖大小的情况下,图像tileset随机大小
|
||||||
|
map.maxTileWidth = map.tileWidth;
|
||||||
|
map.maxTileHeight = map.tileHeight;
|
||||||
|
|
||||||
|
map.tilesets = [];
|
||||||
|
for (let e of xMap["tilesets"]){
|
||||||
|
let tileset = await this.parseTmxTileset(map, e);
|
||||||
|
map.tilesets.push(tileset);
|
||||||
|
|
||||||
|
this.updateMaxTileSizes(tileset);
|
||||||
|
}
|
||||||
|
|
||||||
|
map.layers = [];
|
||||||
|
map.tileLayers = [];
|
||||||
|
map.objectGroups = [];
|
||||||
|
map.imageLayers = [];
|
||||||
|
map.groups = [];
|
||||||
|
|
||||||
|
this.parseLayers(map, xMap, map, map.width, map.height, map.tmxDirectory);
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析xEle中的所有层,将它们放入容器中
|
||||||
|
* @param container
|
||||||
|
* @param xEle
|
||||||
|
* @param map
|
||||||
|
* @param width
|
||||||
|
* @param height
|
||||||
|
* @param tmxDirectory
|
||||||
|
*/
|
||||||
|
public static parseLayers(container: any, xEle: any, map: TmxMap, width: number, height: number, tmxDirectory: string){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static updateMaxTileSizes(tileset: TmxTileset){
|
||||||
|
// 必须迭代字典,因为tile.gid可以是任意顺序的的任何数字
|
||||||
|
tileset.tiles.forEach(tile => {
|
||||||
|
if (tile.image){
|
||||||
|
if (tile.image.width > tileset.map.maxTileWidth)
|
||||||
|
tileset.map.maxTileWidth = tile.image.width;
|
||||||
|
if (tile.image.height > tileset.map.maxTileHeight)
|
||||||
|
tileset.map.maxTileHeight = tile.image.height;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tileset.tileRegions.forEach(region => {
|
||||||
|
let width = region.width;
|
||||||
|
let height = region.height;
|
||||||
|
if (width > tileset.map.maxTileWidth) tileset.map.maxTileWidth = width;
|
||||||
|
if (width > tileset.map.maxTileHeight) tileset.map.maxTileHeight = height;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static parseOrientationType(type: string){
|
||||||
|
if (type == "unknown")
|
||||||
|
return OrientationType.unknown;
|
||||||
|
if (type == "orthogonal")
|
||||||
|
return OrientationType.orthogonal;
|
||||||
|
if (type == "isometric")
|
||||||
|
return OrientationType.isometric;
|
||||||
|
if (type == "staggered")
|
||||||
|
return OrientationType.staggered;
|
||||||
|
if (type == "hexagonal")
|
||||||
|
return OrientationType.hexagonal;
|
||||||
|
|
||||||
|
return OrientationType.unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static parseStaggerAxisType(type: string){
|
||||||
|
if (type == "y")
|
||||||
|
return StaggerAxisType.y;
|
||||||
|
return StaggerAxisType.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static parseStaggerIndexType(type: string){
|
||||||
|
if (type == "even")
|
||||||
|
return StaggerIndexType.even;
|
||||||
|
return StaggerIndexType.odd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static parseRenderOrderType(type: string){
|
||||||
|
if (type == "right-up")
|
||||||
|
return RenderOrderType.rightUp;
|
||||||
|
if (type == "left-down")
|
||||||
|
return RenderOrderType.leftDown;
|
||||||
|
if (type == "left-up")
|
||||||
|
return RenderOrderType.leftUp;
|
||||||
|
return RenderOrderType.rightDown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static parsePropertyDict(prop) {
|
||||||
|
if (!prop)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
let dict = new Map<string, string>();
|
||||||
|
for (let p of prop["property"]){
|
||||||
|
let pname = p["name"];
|
||||||
|
let valueAttr = p["value"];
|
||||||
|
let pval = valueAttr ? valueAttr : p;
|
||||||
|
|
||||||
|
dict.set(pname, pval);
|
||||||
|
}
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async parseTmxTileset(map: TmxMap, xTileset: any){
|
||||||
|
// firstgid总是在TMX中,而不是在TSX中
|
||||||
|
let xFirstGid = xTileset["firstgid"];
|
||||||
|
let firstGid = xFirstGid;
|
||||||
|
let source = xTileset["image"];
|
||||||
|
|
||||||
|
// 如果是嵌入式TmxTileset,即不是外部的,source将为null
|
||||||
|
if (!source){
|
||||||
|
source = "resource/assets/" + source;
|
||||||
|
// 其他所有内容都在TSX文件中
|
||||||
|
let xDocTileset = await RES.getResByUrl(source, null, this, RES.ResourceItem.TYPE_IMAGE);
|
||||||
|
let tileset = this.loadTmxTileset(new TmxTileset(), map, xDocTileset["tileset"], firstGid);
|
||||||
|
|
||||||
|
return tileset;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.loadTmxTileset(new TmxTileset(), map, xTileset, firstGid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async loadTmxTileset(tileset: TmxTileset, map: TmxMap, xTileset: any,
|
||||||
|
firstGid: number){
|
||||||
|
tileset.map = map;
|
||||||
|
tileset.firstGid = firstGid;
|
||||||
|
|
||||||
|
tileset.name = xTileset["name"];
|
||||||
|
tileset.tileWidth = xTileset["tilewidth"];
|
||||||
|
tileset.tileHeight = xTileset["tileheight"];
|
||||||
|
tileset.spacing = xTileset["spacing"] != undefined ? xTileset["spacing"] : 0;
|
||||||
|
tileset.margin = xTileset["margin"] != undefined ? xTileset["margin"] : 0;
|
||||||
|
tileset.columns = xTileset["columns"];
|
||||||
|
tileset.tileCount = xTileset["tilecount"];
|
||||||
|
tileset.tileOffset = this.parseTmxTileOffset(xTileset["tileoffset"]);
|
||||||
|
|
||||||
|
let xImage = xTileset["image"];
|
||||||
|
if (xImage)
|
||||||
|
tileset.image = await this.loadTmxImage(new TmxImage(), xTileset);
|
||||||
|
|
||||||
|
let xTerrainType = xTileset["terraintypes"];
|
||||||
|
if (xTerrainType){
|
||||||
|
tileset.terrains = [];
|
||||||
|
for (let e of xTerrainType["terrains"])
|
||||||
|
tileset.terrains.push(this.parseTmxTerrain(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
tileset.tiles = new Map<number, TmxTilesetTile>();
|
||||||
|
for (let xTile of xTileset["tiles"]){
|
||||||
|
let tile = await this.loadTmxTilesetTile(new TmxTilesetTile(), tileset, xTile, tileset.terrains);
|
||||||
|
tileset.tiles[tile.id] = tile;
|
||||||
|
}
|
||||||
|
|
||||||
|
tileset.properties = this.parsePropertyDict(xTileset["properties"]);
|
||||||
|
|
||||||
|
// 缓存我们的源矩形为每个瓷砖,所以我们不必每次我们渲染计算他们。
|
||||||
|
// 如果我们有一个image,这是一个普通的tileset,否则它是一个image tileset
|
||||||
|
tileset.tileRegions = new Map<number, Rectangle>();
|
||||||
|
if (tileset.image){
|
||||||
|
let id = firstGid;
|
||||||
|
for (let y = tileset.margin; y < tileset.image.height - tileset.margin; y += tileset.tileHeight + tileset.spacing){
|
||||||
|
let column = 0;
|
||||||
|
for (let x = tileset.margin; x < tileset.image.width - tileset.margin; x += tileset.tileWidth + tileset.spacing){
|
||||||
|
tileset.tileRegions.set(id++, new Rectangle(x, y, tileset.tileWidth, tileset.tileHeight));
|
||||||
|
|
||||||
|
if (++column >= tileset.columns)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
tileset.tiles.forEach(tile => {
|
||||||
|
tileset.tileRegions.set(firstGid + tile.id, new Rectangle(0, 0, tile.image.width, tile.image.height));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return tileset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async loadTmxTilesetTile(tile: TmxTilesetTile, tileset: TmxTileset, xTile: any, terrains: TmxTerrain[]){
|
||||||
|
tile.tileset = tileset;
|
||||||
|
tile.id = xTile["id"];
|
||||||
|
|
||||||
|
tile.terrainEdges = xTile["terrain"];
|
||||||
|
tile.probability = xTile["probability"] != undefined ? xTile["probability"] : 1;
|
||||||
|
tile.type = xTile["type"];
|
||||||
|
let xImage = xTile["image"];
|
||||||
|
if (xImage){
|
||||||
|
tile.image = await this.loadTmxImage(new TmxImage(), xImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
tile.objectGroups = [];
|
||||||
|
if (xTile["objectgroup"])
|
||||||
|
for (let e of xTile["objectgroup"])
|
||||||
|
tile.objectGroups.push(this.loadTmxObjectGroup(new TmxObjectGroup(), tileset.map, e));
|
||||||
|
|
||||||
|
tile.animationFrames = [];
|
||||||
|
if (xTile["animation"]){
|
||||||
|
for (let e of xTile["animation"]["frame"])
|
||||||
|
tile.animationFrames.push(this.loadTmxAnimationFrame(new TmxAnimationFrame(), e));
|
||||||
|
}
|
||||||
|
|
||||||
|
tile.properties = this.parsePropertyDict(xTile["properties"]);
|
||||||
|
if (tile.properties)
|
||||||
|
tile.processProperties();
|
||||||
|
return tile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static loadTmxAnimationFrame(frame: TmxAnimationFrame, xFrame: any){
|
||||||
|
frame.gid = xFrame["tileid"];
|
||||||
|
frame.duration = xFrame["duration"] / 1000;
|
||||||
|
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static loadTmxObjectGroup(group: TmxObjectGroup, map: TmxMap, xObjectGroup: any) {
|
||||||
|
group.map = map;
|
||||||
|
group.name = xObjectGroup["name"] != undefined ? xObjectGroup["name"] : "";
|
||||||
|
group.color = TmxUtils.color16ToUnit(xObjectGroup["color"]);
|
||||||
|
group.opacity = xObjectGroup["opacity"] != undefined ? xObjectGroup["opacity"] : 1;
|
||||||
|
group.visible = xObjectGroup["visible"] != undefined ? xObjectGroup["visible"] : true;
|
||||||
|
group.offsetX = xObjectGroup["offsetx"] != undefined ? xObjectGroup["offsetx"] : 0;
|
||||||
|
group.offsetY = xObjectGroup["offsety"] != undefined ? xObjectGroup["offsety"] : 0;
|
||||||
|
|
||||||
|
let drawOrderDict = new Map<string, DrawOrderType>();
|
||||||
|
drawOrderDict.set("unknown", DrawOrderType.unkownOrder);
|
||||||
|
drawOrderDict.set("topdown", DrawOrderType.IndexOrder);
|
||||||
|
drawOrderDict.set("index", DrawOrderType.TopDown);
|
||||||
|
|
||||||
|
let drawOrderValue = xObjectGroup["draworder"];
|
||||||
|
if (drawOrderValue)
|
||||||
|
group.drawOrder = drawOrderDict[drawOrderValue];
|
||||||
|
|
||||||
|
group.objects = [];
|
||||||
|
for (let e of xObjectGroup["object"])
|
||||||
|
group.objects.push(this.loadTmxObject(new TmxObject(), map, e));
|
||||||
|
group.properties = this.parsePropertyDict(xObjectGroup["properties"]);
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static loadTmxObject(obj: TmxObject, map: TmxMap, xObject: any){
|
||||||
|
obj.id = xObject["id"] != undefined ? xObject["id"] : 0;
|
||||||
|
obj.name = xObject["name"] != undefined ? xObject["name"] : "";
|
||||||
|
obj.x = xObject["x"];
|
||||||
|
obj.y = xObject["y"];
|
||||||
|
obj.width = xObject["width"] != undefined ? xObject["width"] : 0;
|
||||||
|
obj.height = xObject["height"] != undefined ? xObject["height"] : 0;
|
||||||
|
obj.type = xObject["type"] != undefined ? xObject["type"] : "";
|
||||||
|
obj.visible = xObject["visible"] != undefined ? xObject["visible"] : true;
|
||||||
|
obj.rotation = xObject["rotation"] != undefined ? xObject["rotation"] : 0;
|
||||||
|
|
||||||
|
// 评估对象类型并分配适当的内容
|
||||||
|
let xGid = xObject["gid"];
|
||||||
|
let xEllipse = xObject["ellipse"];
|
||||||
|
let xPolygon = xObject["polygon"];
|
||||||
|
let xPolyline = xObject["polyline"];
|
||||||
|
let xText = xObject["text"];
|
||||||
|
let xPoint = xObject["point"];
|
||||||
|
|
||||||
|
if (xGid){
|
||||||
|
obj.tile = new TmxLayerTile(map, xGid, Math.round(obj.x), Math.round(obj.y));
|
||||||
|
obj.objectType = TmxObjectType.tile;
|
||||||
|
}else if(xEllipse){
|
||||||
|
obj.objectType = TmxObjectType.ellipse;
|
||||||
|
} else if(xPolygon){
|
||||||
|
obj.points = this.parsePoints(xPolygon);
|
||||||
|
obj.objectType = TmxObjectType.polygon;
|
||||||
|
}else if(xPolyline){
|
||||||
|
obj.points = this.parsePoints(xPolyline);
|
||||||
|
obj.objectType = TmxObjectType.polyline;
|
||||||
|
}else if(xText){
|
||||||
|
obj.text = this.loadTmxText(new TmxText(), xText);
|
||||||
|
obj.objectType = TmxObjectType.text;
|
||||||
|
}else if(xPoint){
|
||||||
|
obj.objectType = TmxObjectType.point;
|
||||||
|
}else{
|
||||||
|
obj.objectType = TmxObjectType.basic;
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.properties = this.parsePropertyDict(xObject["properties"]);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static loadTmxText(text: TmxText, xText: any){
|
||||||
|
text.fontFamily = xText["fontfamily"] != undefined ? xText["fontfamily"] : "sans-serif";
|
||||||
|
text.pixelSize = xText["pixelsize"] != undefined ? xText["pixelsize"] : 16;
|
||||||
|
text.wrap = xText["wrap"] != undefined ? xText["wrap"] : false;
|
||||||
|
text.color = TmxUtils.color16ToUnit(xText["color"]);
|
||||||
|
text.bold = xText["bold"] ? xText["bold"] : false;
|
||||||
|
text.italic = xText["italic"] ? xText["italic"] : false;
|
||||||
|
text.underline = xText["underline"] ? xText["underline"] : false;
|
||||||
|
text.strikeout = xText["strikeout"] ? xText["strikeout"] : false;
|
||||||
|
text.kerning = xText["kerning"] ? xText["kerning"] : true;
|
||||||
|
text.alignment = this.loadTmxAlignment(new TmxAlignment(), xText);
|
||||||
|
text.value = xText;
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static loadTmxAlignment(alignment: TmxAlignment, xText: any){
|
||||||
|
function firstLetterToUpperCase(str: string) {
|
||||||
|
if (!str || str == "")
|
||||||
|
return str;
|
||||||
|
return str[0].toString().toUpperCase() + str.substr(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let xHorizontal = xText["halign"] != undefined ? xText["halign"] : "left";
|
||||||
|
alignment.horizontal = TmxHorizontalAlignment[firstLetterToUpperCase(xHorizontal)];
|
||||||
|
|
||||||
|
let xVertical = xText["valign"] != undefined ? xText["valign"] : "top";
|
||||||
|
alignment.vertical = TmxVerticalAlignment[firstLetterToUpperCase((xVertical))];
|
||||||
|
|
||||||
|
return alignment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static parsePoints(xPoints: any){
|
||||||
|
let pointString: string = xPoints["points"];
|
||||||
|
let pointStringPair = pointString.split(' ');
|
||||||
|
let points = [];
|
||||||
|
|
||||||
|
let index = 0;
|
||||||
|
for (let s of pointStringPair)
|
||||||
|
points[index ++] = this.parsePoint(s);
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static parsePoint(s: string){
|
||||||
|
let pt = s.split(',');
|
||||||
|
let x = Number(pt[0]);
|
||||||
|
let y = Number(pt[1]);
|
||||||
|
return new Vector2(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static parseTmxTerrain(xTerrain: any){
|
||||||
|
let terrain = new TmxTerrain();
|
||||||
|
terrain.name = xTerrain["name"];
|
||||||
|
terrain.tile = xTerrain["tile"];
|
||||||
|
terrain.properties = this.parsePropertyDict(xTerrain["properties"]);
|
||||||
|
|
||||||
|
return terrain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static parseTmxTileOffset(xTileOffset: any){
|
||||||
|
let tmxTileOffset = new TmxTileOffset();
|
||||||
|
if (!xTileOffset){
|
||||||
|
tmxTileOffset.x = 0;
|
||||||
|
tmxTileOffset.y = 0;
|
||||||
|
return tmxTileOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
tmxTileOffset.x = xTileOffset["x"];
|
||||||
|
tmxTileOffset.y = xTileOffset["y"];
|
||||||
|
return tmxTileOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async loadTmxImage(image: TmxImage, xImage: any){
|
||||||
|
let xSource = xImage["image"];
|
||||||
|
if (xSource) {
|
||||||
|
image.source = "resource/assets/" + xSource;
|
||||||
|
image.bitmap = new Bitmap(await RES.getResByUrl(image.source, null, this, RES.ResourceItem.TYPE_IMAGE));
|
||||||
|
}else {
|
||||||
|
image.format = xImage["format"];
|
||||||
|
let xData = xImage["data"];
|
||||||
|
image.data = TmxUtils.decode(xData, xData["encoding"], xData["compression"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
image.trans = TmxUtils.color16ToUnit(xImage["trans"]);
|
||||||
|
image.width = xImage["width"] != undefined ? xImage["width"] : 0;
|
||||||
|
image.height = xImage["height"] != undefined ? xImage["height"] : 0;
|
||||||
|
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,119 +1,154 @@
|
|||||||
module es {
|
module es {
|
||||||
export class TiledRendering {
|
export class TiledRendering {
|
||||||
public static renderMap(map: TmxMap, position: Vector2, scale: Vector2, layerDepth: number) {
|
public static renderMap(map: TmxMap, container: egret.DisplayObjectContainer, position: Vector2, scale: Vector2, layerDepth: number) {
|
||||||
map.layers.forEach(layer => {
|
map.layers.forEach(layer => {
|
||||||
if (layer instanceof TmxLayer && layer.visible) {
|
if (layer instanceof TmxLayer && layer.visible) {
|
||||||
this.renderLayer(layer, position, scale, layerDepth);
|
this.renderLayer(layer, container, position, scale, layerDepth);
|
||||||
} else if (layer instanceof TmxImageLayer && layer.visible) {
|
} else if (layer instanceof TmxImageLayer && layer.visible) {
|
||||||
this.renderImageLayer(layer, position, scale, layerDepth);
|
this.renderImageLayer(layer, container, position, scale, layerDepth);
|
||||||
} else if (layer instanceof TmxGroup && layer.visible) {
|
} else if (layer instanceof TmxGroup && layer.visible) {
|
||||||
this.renderGroup(layer, position, scale, layerDepth);
|
this.renderGroup(layer, container, position, scale, layerDepth);
|
||||||
} else if (layer instanceof TmxObjectGroup && layer.visible) {
|
} else if (layer instanceof TmxObjectGroup && layer.visible) {
|
||||||
this.renderObjectGroup(layer, position, scale, layerDepth);
|
this.renderObjectGroup(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static renderLayer(layer: TmxLayer, position: Vector2, scale: Vector2, layerDepth: number) {
|
public static renderLayer(layer: TmxLayer, container: egret.DisplayObjectContainer, position: Vector2, scale: Vector2, layerDepth: number) {
|
||||||
if (!layer.visible)
|
if (!layer.visible)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
let tileWidth = layer.map.tileWidth * scale.x;
|
let tileWidth = layer.map.tileWidth * scale.x;
|
||||||
let tileHeight = layer.map.tileHeight * scale.y;
|
let tileHeight = layer.map.tileHeight * scale.y;
|
||||||
|
|
||||||
let color = new Color(0, 0, 0, layer.opacity * 255);
|
let color = DrawUtils.getColorMatrix(0x000000);
|
||||||
for (let i = 0; i < layer.tiles.length; i++) {
|
for (let i = 0; i < layer.tiles.length; i++) {
|
||||||
let tile = layer.tiles[i];
|
let tile = layer.tiles[i];
|
||||||
if (!tile)
|
if (!tile)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
this.renderTile(tile, position, scale, tileWidth, tileHeight, color, layerDepth);
|
this.renderTile(tile, container, position, scale, tileWidth, tileHeight, color, layerDepth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static renderImageLayer(layer: TmxImageLayer, position: Vector2, scale: Vector2, layerDepth: number) {
|
public static renderImageLayer(layer: TmxImageLayer, container: egret.DisplayObjectContainer, position: Vector2, scale: Vector2, layerDepth: number) {
|
||||||
if (!layer.visible)
|
if (!layer.visible)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
let color = new Color(0, 0, 0, layer.opacity * 255);
|
let color = DrawUtils.getColorMatrix(0x000000);
|
||||||
let pos = Vector2.add(position, new Vector2(layer.offsetX, layer.offsetY).multiply(scale));
|
let pos = Vector2.add(position, new Vector2(layer.offsetX, layer.offsetY).multiply(scale));
|
||||||
// TODO: draw
|
if (!layer.image.bitmap.parent)
|
||||||
|
container.addChild(layer.image.bitmap);
|
||||||
|
layer.image.bitmap.x = pos.x;
|
||||||
|
layer.image.bitmap.y = pos.y;
|
||||||
|
layer.image.bitmap.scaleX = scale.x;
|
||||||
|
layer.image.bitmap.scaleY = scale.y;
|
||||||
|
layer.image.bitmap.filters = [color];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static renderObjectGroup(objGroup: TmxObjectGroup, position: Vector2, scale: Vector2, layerDepth: number) {
|
public static renderObjectGroup(objGroup: TmxObjectGroup, container: egret.DisplayObjectContainer, position: Vector2, scale: Vector2, layerDepth: number) {
|
||||||
if (!objGroup.visible)
|
if (!objGroup.visible)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (let object in objGroup.objects) {
|
for (let object in objGroup.objects) {
|
||||||
let obj = objGroup.objects.get(object);
|
let obj = objGroup.objects[object];
|
||||||
if (!obj.visible)
|
if (!obj.visible)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// TODO: debug draw
|
// 如果我们不调试渲染,我们只渲染平铺块和文本类型
|
||||||
|
if (!Core.debugRenderEndabled){
|
||||||
|
if (obj.objectType != TmxObjectType.tile && obj.objectType != TmxObjectType.text)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
let pos = Vector2.add(position, new Vector2(obj.x, obj.y).multiply(scale));
|
let pos = Vector2.add(position, new Vector2(obj.x, obj.y).multiply(scale));
|
||||||
switch (obj.objectType) {
|
switch (obj.objectType) {
|
||||||
case TmxObjectType.basic:
|
case TmxObjectType.basic:
|
||||||
// TODO: draw
|
if (!obj.shape.parent)
|
||||||
|
container.addChild(obj.shape);
|
||||||
|
|
||||||
|
let rect = new Rectangle(pos.x, pos.y, obj.width * scale.x, obj.height * scale.y);
|
||||||
|
DrawUtils.drawHollowRect(obj.shape, rect, objGroup.color);
|
||||||
break;
|
break;
|
||||||
case TmxObjectType.point:
|
case TmxObjectType.point:
|
||||||
let size = objGroup.map.tileWidth * 0.5;
|
let size = objGroup.map.tileWidth * 0.5;
|
||||||
pos.x -= size * 0.5;
|
pos.x -= size * 0.5;
|
||||||
pos.y -= size * 0.5;
|
pos.y -= size * 0.5;
|
||||||
// TODO: draw
|
if (!obj.shape.parent)
|
||||||
|
container.addChild(obj.shape);
|
||||||
|
|
||||||
|
DrawUtils.drawPixel(obj.shape, pos, objGroup.color, size);
|
||||||
break;
|
break;
|
||||||
case TmxObjectType.tile:
|
case TmxObjectType.tile:
|
||||||
let tileset = objGroup.map.getTilesetForTileGid(obj.tile.gid);
|
let tileset = objGroup.map.getTilesetForTileGid(obj.tile.gid);
|
||||||
let sourceRect = tileset.tileRegions[obj.tile.gid];
|
let sourceRect = tileset.tileRegions[obj.tile.gid];
|
||||||
pos.y -= obj.tile.tilesetTile.image.height;
|
pos.y -= obj.tile.tilesetTile.image.height;
|
||||||
// TODO: draw
|
|
||||||
|
if (!obj.tile.tilesetTile.image.bitmap)
|
||||||
|
container.addChild(obj.tile.tilesetTile.image.bitmap);
|
||||||
|
obj.tile.tilesetTile.image.bitmap.x = pos.x;
|
||||||
|
obj.tile.tilesetTile.image.bitmap.y = pos.y;
|
||||||
|
obj.tile.tilesetTile.image.bitmap.filters = [];
|
||||||
|
obj.tile.tilesetTile.image.bitmap.rotation = 0;
|
||||||
|
obj.tile.tilesetTile.image.bitmap.scaleX = scale.x;
|
||||||
|
obj.tile.tilesetTile.image.bitmap.scaleY = scale.y;
|
||||||
break;
|
break;
|
||||||
case TmxObjectType.ellipse:
|
case TmxObjectType.ellipse:
|
||||||
pos = new Vector2(obj.x + obj.width * 0.5, obj.y + obj.height * 0.5).multiply(scale);
|
pos = new Vector2(obj.x + obj.width * 0.5, obj.y + obj.height * 0.5).multiply(scale);
|
||||||
// TODO: draw
|
if (!obj.shape.parent)
|
||||||
|
container.addChild(obj.shape);
|
||||||
|
DrawUtils.drawCircle(obj.shape, pos, obj.width * 0.5, objGroup.color);
|
||||||
break;
|
break;
|
||||||
case TmxObjectType.polygon:
|
case TmxObjectType.polygon:
|
||||||
case TmxObjectType.polyline:
|
case TmxObjectType.polyline:
|
||||||
let points = [];
|
let points = [];
|
||||||
for (let i = 0; i < obj.points.length; i++)
|
for (let i = 0; i < obj.points.length; i++)
|
||||||
points[i] = Vector2.multiply(obj.points[i], scale);
|
points[i] = Vector2.multiply(obj.points[i], scale);
|
||||||
// TODO: draw
|
DrawUtils.drawPoints(obj.shape, pos, points, objGroup.color, obj.objectType == TmxObjectType.polygon);
|
||||||
break;
|
break;
|
||||||
case TmxObjectType.text:
|
case TmxObjectType.text:
|
||||||
// TODO: draw
|
if (!obj.textField.parent)
|
||||||
|
container.addChild(obj.textField);
|
||||||
|
DrawUtils.drawString(obj.textField, obj.text.value, pos, obj.text.color, MathHelper.toRadians(obj.rotation),
|
||||||
|
Vector2.zero, 1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// TODO: debug draw
|
if (Core.debugRenderEndabled){
|
||||||
|
if (!obj.textField.parent)
|
||||||
|
container.addChild(obj.textField);
|
||||||
|
DrawUtils.drawString(obj.textField, `${obj.name}(${obj.type})`, Vector2.subtract(pos, new Vector2(0, 15)), 0xffffff, 0, Vector2.zero, 1);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static renderGroup(group: TmxGroup, position: Vector2, scale: Vector2, layerDepth: number) {
|
public static renderGroup(group: TmxGroup, container: egret.DisplayObjectContainer, position: Vector2, scale: Vector2, layerDepth: number) {
|
||||||
if (!group.visible)
|
if (!group.visible)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
group.layers.forEach(layer => {
|
group.layers.forEach(layer => {
|
||||||
if (layer instanceof TmxGroup) {
|
if (layer instanceof TmxGroup) {
|
||||||
this.renderGroup(layer, position, scale, layerDepth);
|
this.renderGroup(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (layer instanceof TmxObjectGroup) {
|
if (layer instanceof TmxObjectGroup) {
|
||||||
this.renderObjectGroup(layer, position, scale,layerDepth);
|
this.renderObjectGroup(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (layer instanceof TmxLayer) {
|
if (layer instanceof TmxLayer) {
|
||||||
this.renderLayer(layer, position, scale, layerDepth);
|
this.renderLayer(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (layer instanceof TmxImageLayer) {
|
if (layer instanceof TmxImageLayer) {
|
||||||
this.renderImageLayer(layer, position, scale, layerDepth);
|
this.renderImageLayer(layer, container, position, scale, layerDepth);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static renderTile(tile: TmxLayerTile, position: Vector2, scale: Vector2, tileWidth: number, tileHeight: number, color: Color, layerDepth: number) {
|
public static renderTile(tile: TmxLayerTile, container: egret.DisplayObjectContainer, position: Vector2, scale: Vector2, tileWidth: number, tileHeight: number, color: egret.ColorMatrixFilter, layerDepth: number) {
|
||||||
let gid = tile.gid;
|
let gid = tile.gid;
|
||||||
|
|
||||||
// 动画tiles(以及来自图像tile的tiles)将位于Tileset本身内,位于单独的TmxTilesetTile对象中,不要与我们在此循环中处理的TmxLayerTiles混淆
|
// 动画tiles(以及来自图像tile的tiles)将位于Tileset本身内,位于单独的TmxTilesetTile对象中,不要与我们在此循环中处理的TmxLayerTiles混淆
|
||||||
@@ -153,9 +188,23 @@ module es {
|
|||||||
|
|
||||||
let pos = new Vector2(tx, ty).add(position);
|
let pos = new Vector2(tx, ty).add(position);
|
||||||
if (tile.tileset.image) {
|
if (tile.tileset.image) {
|
||||||
// TODO: draw
|
if (!tile.tilesetTile.image.bitmap.parent)
|
||||||
|
container.addChild(tile.tilesetTile.image.bitmap);
|
||||||
|
tile.tilesetTile.image.bitmap.x = pos.x;
|
||||||
|
tile.tilesetTile.image.bitmap.y = pos.y;
|
||||||
|
tile.tilesetTile.image.bitmap.scaleX = scale.x;
|
||||||
|
tile.tilesetTile.image.bitmap.scaleY = scale.y;
|
||||||
|
tile.tilesetTile.image.bitmap.rotation = rotation;
|
||||||
|
tile.tilesetTile.image.bitmap.filters = [color];
|
||||||
} else {
|
} else {
|
||||||
// TODO: draw
|
if (!tilesetTile.image.bitmap)
|
||||||
|
container.addChild(tilesetTile.image.bitmap);
|
||||||
|
tilesetTile.image.bitmap.x = pos.x;
|
||||||
|
tilesetTile.image.bitmap.y = pos.y;
|
||||||
|
tilesetTile.image.bitmap.scaleX = scale.x;
|
||||||
|
tilesetTile.image.bitmap.scaleY = scale.y;
|
||||||
|
tilesetTile.image.bitmap.rotation = rotation;
|
||||||
|
tilesetTile.image.bitmap.filters = [color];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ module es {
|
|||||||
public tileOffset: TmxTileOffset;
|
public tileOffset: TmxTileOffset;
|
||||||
public properties: Map<string, string>;
|
public properties: Map<string, string>;
|
||||||
public image: TmxImage;
|
public image: TmxImage;
|
||||||
public terrains: TmxList<TmxTerrain>;
|
public terrains: TmxTerrain[];
|
||||||
/**
|
/**
|
||||||
* 为每个块缓存源矩形
|
* 为每个块缓存源矩形
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ module es {
|
|||||||
public type: string;
|
public type: string;
|
||||||
public properties: Map<string, string>;
|
public properties: Map<string, string>;
|
||||||
public image: TmxImage;
|
public image: TmxImage;
|
||||||
public objectGroups: TmxList<TmxObjectGroup>;
|
public objectGroups: TmxObjectGroup[];
|
||||||
public animationFrames: TmxAnimationFrame[];
|
public animationFrames: TmxAnimationFrame[];
|
||||||
|
|
||||||
// TODO: 为什么动画瓷砖需要添加firstGid
|
// TODO: 为什么动画瓷砖需要添加firstGid
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
module es {
|
||||||
|
export class TmxUtils {
|
||||||
|
/**
|
||||||
|
* 解码
|
||||||
|
* @param data 数据
|
||||||
|
* @param encoding 编码方式 目前暂时只支持XML、base64(无压缩)、csv解析
|
||||||
|
* @param compression 压缩方式
|
||||||
|
* @returns 返回解析后的数据列表
|
||||||
|
*
|
||||||
|
* @version Egret 3.0.3
|
||||||
|
*/
|
||||||
|
static decode(data: any, encoding: any, compression: string): Array<number> {
|
||||||
|
compression = compression || "none";
|
||||||
|
encoding = encoding || "none";
|
||||||
|
var text:string=data.children[0].text;
|
||||||
|
switch (encoding) {
|
||||||
|
case "base64":
|
||||||
|
var decoded = Base64Utils.decodeBase64AsArray(text, 4);
|
||||||
|
return (compression === "none") ? decoded : Base64Utils.decompress(text, decoded, compression);
|
||||||
|
|
||||||
|
case "csv":
|
||||||
|
return Base64Utils.decodeCSV(text);
|
||||||
|
|
||||||
|
case "none":
|
||||||
|
var datas: Array<number> = [];
|
||||||
|
for (var i: number = 0; i < data.children.length; i++) {
|
||||||
|
datas[i] = +data.children[i].attributes.gid;
|
||||||
|
}
|
||||||
|
return datas;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new Error("未定义的编码:" + encoding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将带"#"号的颜色字符串转换为16进制的颜色,例如:可将"#ff0000"转换为"0xff0000"
|
||||||
|
* @param $color 要转换的颜色字符串
|
||||||
|
* @returns 返回16进制的颜色值
|
||||||
|
* @version Egret 3.0.3
|
||||||
|
*/
|
||||||
|
static color16ToUnit($color:string): number {
|
||||||
|
if (!$color)
|
||||||
|
return 0x000000;
|
||||||
|
var colorStr: string = "0x" + $color.slice(1);
|
||||||
|
return parseInt(colorStr, 16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+104
-94
@@ -1,124 +1,134 @@
|
|||||||
class Base64Utils {
|
module es{
|
||||||
private static _keyNum = "0123456789+/";
|
export class Base64Utils {
|
||||||
private static _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
private static _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||||
private static _keyAll = Base64Utils._keyNum + Base64Utils._keyStr;
|
|
||||||
/**
|
/**
|
||||||
* 加密
|
* 判断是否原生支持Base64位解析
|
||||||
|
*/
|
||||||
|
static get nativeBase64() {
|
||||||
|
return (typeof (window.atob) === "function");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解码
|
||||||
* @param input
|
* @param input
|
||||||
*/
|
*/
|
||||||
public static encode = function (input) {
|
static decode(input:string): string {
|
||||||
let output = "";
|
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
||||||
let chr1, chr2, chr3, enc1, enc2, enc3, enc4;
|
|
||||||
let i = 0;
|
if (this.nativeBase64) {
|
||||||
input = this._utf8_encode(input);
|
return window.atob(input);
|
||||||
|
} else {
|
||||||
|
var output: any = [], chr1: number, chr2: number, chr3: number, enc1: number, enc2: number, enc3: number, enc4: number, i: number = 0;
|
||||||
|
|
||||||
|
while (i < input.length) {
|
||||||
|
enc1 = this._keyStr.indexOf(input.charAt(i++));
|
||||||
|
enc2 = this._keyStr.indexOf(input.charAt(i++));
|
||||||
|
enc3 = this._keyStr.indexOf(input.charAt(i++));
|
||||||
|
enc4 = this._keyStr.indexOf(input.charAt(i++));
|
||||||
|
|
||||||
|
chr1 = (enc1 << 2) | (enc2 >> 4);
|
||||||
|
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
||||||
|
chr3 = ((enc3 & 3) << 6) | enc4;
|
||||||
|
|
||||||
|
output.push(String.fromCharCode(chr1));
|
||||||
|
|
||||||
|
if (enc3 !== 64) {
|
||||||
|
output.push(String.fromCharCode(chr2));
|
||||||
|
}
|
||||||
|
if (enc4 !== 64) {
|
||||||
|
output.push(String.fromCharCode(chr3));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output = output.join("");
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编码
|
||||||
|
* @param input
|
||||||
|
*/
|
||||||
|
static encode(input:string): string {
|
||||||
|
input = input.replace(/\r\n/g, "\n");
|
||||||
|
if (this.nativeBase64) {
|
||||||
|
window.btoa(input);
|
||||||
|
} else {
|
||||||
|
var output: any = [], chr1: number, chr2: number, chr3: number, enc1: number, enc2: number, enc3: number, enc4: number, i: number = 0;
|
||||||
while (i < input.length) {
|
while (i < input.length) {
|
||||||
chr1 = input.charCodeAt(i++);
|
chr1 = input.charCodeAt(i++);
|
||||||
chr2 = input.charCodeAt(i++);
|
chr2 = input.charCodeAt(i++);
|
||||||
chr3 = input.charCodeAt(i++);
|
chr3 = input.charCodeAt(i++);
|
||||||
|
|
||||||
enc1 = chr1 >> 2;
|
enc1 = chr1 >> 2;
|
||||||
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
|
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
|
||||||
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
|
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
|
||||||
enc4 = chr3 & 63;
|
enc4 = chr3 & 63;
|
||||||
|
|
||||||
if (isNaN(chr2)) {
|
if (isNaN(chr2)) {
|
||||||
enc3 = enc4 = 64;
|
enc3 = enc4 = 64;
|
||||||
} else if (isNaN(chr3)) {
|
} else if (isNaN(chr3)) {
|
||||||
enc4 = 64;
|
enc4 = 64;
|
||||||
}
|
}
|
||||||
output = output +
|
|
||||||
this._keyAll.charAt(enc1) + this._keyAll.charAt(enc2) +
|
|
||||||
this._keyAll.charAt(enc3) + this._keyAll.charAt(enc4);
|
|
||||||
}
|
|
||||||
return this._keyStr.charAt(Math.floor((Math.random() * this._keyStr.length))) + output;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
output.push(this._keyStr.charAt(enc1));
|
||||||
* 解码
|
output.push(this._keyStr.charAt(enc2));
|
||||||
* @param input
|
output.push(this._keyStr.charAt(enc3));
|
||||||
* @param isNotStr
|
output.push(this._keyStr.charAt(enc4));
|
||||||
*/
|
|
||||||
public static decode(input, isNotStr: boolean = true) {
|
|
||||||
let output = "";
|
|
||||||
let chr1, chr2, chr3;
|
|
||||||
let enc1, enc2, enc3, enc4;
|
|
||||||
let i = 0;
|
|
||||||
input = this.getConfKey(input);
|
|
||||||
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
|
||||||
while (i < input.length) {
|
|
||||||
enc1 = this._keyAll.indexOf(input.charAt(i++));
|
|
||||||
enc2 = this._keyAll.indexOf(input.charAt(i++));
|
|
||||||
enc3 = this._keyAll.indexOf(input.charAt(i++));
|
|
||||||
enc4 = this._keyAll.indexOf(input.charAt(i++));
|
|
||||||
chr1 = (enc1 << 2) | (enc2 >> 4);
|
|
||||||
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
|
||||||
chr3 = ((enc3 & 3) << 6) | enc4;
|
|
||||||
output = output + String.fromCharCode(chr1);
|
|
||||||
if (enc3 != 64) {
|
|
||||||
if (chr2 == 0) {
|
|
||||||
if (isNotStr) output = output + String.fromCharCode(chr2);
|
|
||||||
} else {
|
|
||||||
output = output + String.fromCharCode(chr2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enc4 != 64) {
|
output = output.join("");
|
||||||
if (chr3 == 0) {
|
|
||||||
if (isNotStr) output = output + String.fromCharCode(chr3);
|
|
||||||
} else {
|
|
||||||
output = output + String.fromCharCode(chr3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
output = this._utf8_decode(output);
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static _utf8_encode(string) {
|
|
||||||
string = string.replace(/\r\n/g, "\n");
|
|
||||||
let utftext = "";
|
|
||||||
for (let n = 0; n < string.length; n++) {
|
|
||||||
let c = string.charCodeAt(n);
|
|
||||||
if (c < 128) {
|
|
||||||
utftext += String.fromCharCode(c);
|
|
||||||
} else if ((c > 127) && (c < 2048)) {
|
|
||||||
utftext += String.fromCharCode((c >> 6) | 192);
|
|
||||||
utftext += String.fromCharCode((c & 63) | 128);
|
|
||||||
} else {
|
|
||||||
utftext += String.fromCharCode((c >> 12) | 224);
|
|
||||||
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
|
||||||
utftext += String.fromCharCode((c & 63) | 128);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析Base64格式数据
|
||||||
|
* @param input
|
||||||
|
* @param bytes
|
||||||
|
*/
|
||||||
|
static decodeBase64AsArray(input: string, bytes: number): Uint32Array {
|
||||||
|
bytes = bytes || 1;
|
||||||
|
|
||||||
|
var dec = Base64Utils.decode(input), i, j, len;
|
||||||
|
var ar: Uint32Array = new Uint32Array(dec.length / bytes);
|
||||||
|
|
||||||
|
for (i = 0, len = dec.length / bytes; i < len; i++) {
|
||||||
|
ar[i] = 0;
|
||||||
|
for (j = bytes - 1; j >= 0; --j) {
|
||||||
|
ar[i] += dec.charCodeAt((i * bytes) + j) << (j << 3);
|
||||||
}
|
}
|
||||||
return utftext;
|
}
|
||||||
|
return ar;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static _utf8_decode(utftext) {
|
/**
|
||||||
let string = "";
|
* 暂时不支持
|
||||||
let i = 0;
|
* @param data
|
||||||
let c = 0;
|
* @param decoded
|
||||||
let c1 = 0;
|
* @param compression
|
||||||
let c2 = 0;
|
* @private
|
||||||
let c3 = 0;
|
*/
|
||||||
while (i < utftext.length) {
|
static decompress(data: string, decoded: any, compression: string): any {
|
||||||
c = utftext.charCodeAt(i);
|
throw new Error("GZIP/ZLIB compressed TMX Tile Map not supported!");
|
||||||
if (c < 128) {
|
|
||||||
string += String.fromCharCode(c);
|
|
||||||
i++;
|
|
||||||
} else if ((c > 191) && (c < 224)) {
|
|
||||||
c2 = utftext.charCodeAt(i + 1);
|
|
||||||
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
|
|
||||||
i += 2;
|
|
||||||
} else {
|
|
||||||
c2 = utftext.charCodeAt(i + 1);
|
|
||||||
c3 = utftext.charCodeAt(i + 2);
|
|
||||||
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
|
|
||||||
i += 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static getConfKey(key): string {
|
/**
|
||||||
return key.slice(1, key.length);
|
* 解析csv数据
|
||||||
|
* @param input
|
||||||
|
*/
|
||||||
|
static decodeCSV(input: string): Array<number> {
|
||||||
|
var entries: Array<any> = input.replace("\n", "").trim().split(",");
|
||||||
|
|
||||||
|
var result:Array<number> = [];
|
||||||
|
for (var i:number = 0; i < entries.length; i++) {
|
||||||
|
result.push(+entries[i]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,29 @@ module es {
|
|||||||
this.drawLineAngle(shape, start, MathHelper.angleBetweenVectors(start, end), Vector2.distance(start, end), color, thickness);
|
this.drawLineAngle(shape, start, MathHelper.angleBetweenVectors(start, end), Vector2.distance(start, end), color, thickness);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static drawCircle(shape: egret.Shape, position: Vector2, radius: number, color: number){
|
||||||
|
shape.graphics.beginFill(color);
|
||||||
|
shape.graphics.drawCircle(position.x, position.y, radius);
|
||||||
|
shape.graphics.endFill();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static drawPoints(shape: egret.Shape, position: Vector2, points: Vector2[], color: number,
|
||||||
|
closePoly: boolean = true, thickness: number = 1){
|
||||||
|
if (points.length < 2)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (let i = 1; i < points.length; i ++)
|
||||||
|
this.drawLine(shape, Vector2.add(position, points[i - 1]), Vector2.add(position, points[i]), color, thickness);
|
||||||
|
|
||||||
|
if (closePoly)
|
||||||
|
this.drawLine(shape, Vector2.add(position, points[points.length - 1]), Vector2.add(position, points[0]), color, thickness);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static drawString(textField: egret.TextField, text: string, position: Vector2, color: number, rotation: number,
|
||||||
|
origin: Vector2, scale: number){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static drawLineAngle(shape: egret.Shape, start: Vector2, radians: number, length: number, color: number, thickness = 1) {
|
public static drawLineAngle(shape: egret.Shape, start: Vector2, radians: number, length: number, color: number, thickness = 1) {
|
||||||
shape.graphics.beginFill(color);
|
shape.graphics.beginFill(color);
|
||||||
shape.graphics.drawRect(start.x, start.y, 1, 1);
|
shape.graphics.drawRect(start.x, start.y, 1, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user