Skip to content

Commit

Permalink
Clean up some todos
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Dec 19, 2023
1 parent 21221f6 commit 23726e1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 58 deletions.
4 changes: 2 additions & 2 deletions example/example-city.tmx
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@
</object>
<object id="33" x="210" y="99.8182"/>
<object id="37" x="200" y="89.9091" width="20.1818" height="19.9091"/>
<object id="38" x="186.545" y="99.8182"/>
<object id="39" x="154.727" y="90.3636" width="19.2727" height="19.4545"/>
<object id="38" x="186.545" y="99.8182" rotation="45"/>
<object id="39" x="154.727" y="90.3636" width="19.2727" height="19.4545" rotation="47"/>
</objectgroup>
</map>
15 changes: 2 additions & 13 deletions src/parser/tiled-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,23 +206,12 @@ const TiledImageLayer = z.object({


// FIXME recursive Group Layer definition
// const TiledGroupLayerBase = z.object({
// name: z.string(),
// id: z.number(),
// });
// type TiledGroupLayer = z.infer<typeof TiledTileLayerBase> & {
// layers: TiledLayer[]
// }
const TiledLayer = z.union([
TiledImageLayer,
TiledTileLayer,
TiledObjectLayer,
// TiledGroupLayerBase
TiledObjectLayer
]);

// const TiledGroupLayer = TiledGroupLayerBase.extend({
// layers: z.lazy(() => z.array(TiledLayer))
// });

const TiledObjectGroup = z.object({
draworder: z.string(),
Expand Down Expand Up @@ -882,7 +871,7 @@ export class TiledParser {
switch (node.tagName) {
case 'group': {
// recurse through groups!
// TODO currently we support groups by flattening them :/
// currently we support groups by flattening them, no group types
for (let child of node.children) {
parseHelper(child);
}
Expand Down
32 changes: 3 additions & 29 deletions src/resource/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export class ObjectLayer implements Layer {
const tint = this.tiledObjectLayer.tintcolor ? Color.fromHex(this.tiledObjectLayer.tintcolor) : Color.White;
const offset = vec(this.tiledObjectLayer.offsetx ?? 0, this.tiledObjectLayer.offsety ?? 0);
// TODO object alignment specified in tileset! https://doc.mapeditor.org/en/stable/manual/objects/#insert-tile


// TODO factory instantiation!

const objects = parseObjects(this.tiledObjectLayer);
Expand All @@ -76,11 +78,7 @@ export class ObjectLayer implements Layer {
x: (object.x ?? 0) + offset.x,
y: (object.y ?? 0) + offset.y,
anchor: Vector.Zero,
rotation: toRadians(object.tiledObject.rotation ?? 0), // convert to radians
// ...(this._hasWidthHeight(object) ? {
// width: object.tiledObject.width,
// height: object.tiledObject.height,
// } : {})
rotation: toRadians(object.tiledObject.rotation ?? 0),
});
const graphics = newActor.get(GraphicsComponent);
if (graphics) {
Expand Down Expand Up @@ -166,9 +164,6 @@ export class ObjectLayer implements Layer {
console.log(object);
}

// TODO tile animations
// TODO Tile colliders

this.objects.push(object);
this.actors.push(newActor);
// TODO do we need this?
Expand Down Expand Up @@ -313,7 +308,6 @@ export class TileLayer implements Layer {
const tile = this.tilemap.tiles[i];
tile.addGraphic(sprite);

// TODO DO Tile colliders need to have offset included because
// the whole tilemap uses a giant composite collider relative to the Tilemap
// not individual tiles
const colliders = tileset.getCollidersForGid(gid);
Expand All @@ -332,25 +326,5 @@ export class TileLayer implements Layer {
}
}
}

// I know this looks goofy, but the entity and the layer "it belongs" to are the same here
// tileMapLayer.z = this._calculateZIndex(layer, layer);
// for (let i = 0; i < rawLayer.data.length; i++) {
// let gid = <number>rawLayer.data[i];
// if (gid !== 0) {
// const sprite = this.getSpriteForGid(gid);
// tileMapLayer.tiles[i].addGraphic(sprite);
// const colliders = this.getCollidersForGid(gid);
// for (let collider of colliders) {
// tileMapLayer.tiles[i].addCollider(collider);
// }
// const animation = this.getAnimationForGid(gid);
// if (animation) {
// tileMapLayer.tiles[i].clearGraphics();
// tileMapLayer.tiles[i].addGraphic(animation);
// }
// }
// }
}

}
6 changes: 1 addition & 5 deletions src/resource/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export class Text extends PluginObject {
return BaseAlign.Bottom;
}
case 'center': {
// TODO is this right?
return BaseAlign.Middle;
}
case 'top': {
Expand All @@ -82,7 +81,6 @@ export class Text extends PluginObject {
return TextAlign.Right
}
case 'justify': {
// TODO is this right?
return TextAlign.Start
}
default: {
Expand All @@ -107,9 +105,7 @@ export class Polygon extends PluginObject {
public readonly points: Vector[] = []
constructor(tiledObject: TiledObject, points: {x: number, y: number}[]) {
super({tiledObject});
// TODO why did we need to cook the offset before?
// Maybe it was for tiles with colliders to work properly
this.points = points.map(p => vec(p.x, p.y));//.add(vec(this.x, this.y)));
this.points = points.map(p => vec(p.x, p.y).add(vec(this.x, this.y)));
}
}
export class Polyline extends PluginObject {
Expand Down
14 changes: 10 additions & 4 deletions src/resource/tiled-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@ import { pathRelativeToBase } from "./path-util";
import { PluginObject } from "./objects";

export interface TiledResourceOptions {

/**
* Plugin will operate in headless mode and skip all graphics related
* excalibur items.
*/
headless: boolean;

/**
* Default true. If false, only tilemap will be parsed and displayed, it's up to you to wire up any excalibur behavior.
* Automatically wires excalibur to the following
* * Wire up current scene camera
* * Make Actors/Tiles with colliders on Tiled tiles & Tild objects
* * Support solid layers
*/
useExcaliburWiring?: boolean, // TODO implement
useExcaliburWiring?: boolean; // TODO implement
/**
* Plugin detects the map type based on extension, if you know better you can force an override.
*/
mapFormatOverride?: 'TMX' | 'TMJ',
mapFormatOverride?: 'TMX' | 'TMJ';
/**
* The pathMap helps work around odd things bundlers do with static files.
*
Expand Down Expand Up @@ -287,7 +294,6 @@ export class TiledResource implements Loadable<any> {
}
}

// TODO external tileset collection of images
if (isTiledTilesetCollectionOfImages(tileset)) {
const friendlyTileset = new Tileset({
name: tileset.name,
Expand Down Expand Up @@ -327,7 +333,7 @@ export class TiledResource implements Loadable<any> {
}

addToScene(scene: Scene) {
// TODO pick a position?
// TODO pick a position to insert into the scene?
for (const layer of this.layers) {
if (layer instanceof TileLayer) {
scene.add(layer.tilemap);
Expand Down
6 changes: 1 addition & 5 deletions src/resource/tileset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export interface TileOptions {
* Friendly plugin representation of tiled Tile
*/
export class Tile implements Properties {
// TODO class
id: number;
tileset: Tileset;
tiledTile: TiledTile;
Expand Down Expand Up @@ -63,7 +62,6 @@ export class Tileset implements Properties {
// TODO fill mode
// TODO orientation
// TODO grid width/height
// TODO tileset class
name: string;
class?: string;
firstGid = -1;
Expand Down Expand Up @@ -91,7 +89,6 @@ export class Tileset implements Properties {
this.spritesheet = spritesheet;
this.firstGid = tiledTileset.firstgid;
this.tileCount = tiledTileset.tilecount;
// TODO produce tiles
for (const tile of tiledTileset.tiles) {
this.tiles.push(new Tile({
id: tile.id,
Expand Down Expand Up @@ -160,7 +157,6 @@ export class Tileset implements Properties {
}
return sprite;
}
// TODO should we throw here?
throw new Error(`Tileset: [${this.name}] Could not find sprite for gid: [${gid}] normalized gid: [${normalizedGid}]`);
}

Expand All @@ -186,7 +182,7 @@ export class Tileset implements Properties {
for (let object of tile.objects) {
if (object instanceof Polygon) {
// This is the offset into the first point (local space)
let points = object.points.map(p => p.add(vec(object.x, object.y)).scale(scale));
let points = object.points.map(p => p.scale(scale));
points = this._applyFlipsToPoints(points, gid);
const poly = Shape.Polygon(points);
result.push(poly);
Expand Down

0 comments on commit 23726e1

Please sign in to comment.