Skip to content

Commit

Permalink
#206 remove tileSize from char
Browse files Browse the repository at this point in the history
  • Loading branch information
Annoraaq committed Oct 17, 2021
1 parent 0d55ddc commit 3bce776
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 23 deletions.
9 changes: 2 additions & 7 deletions src/GridCharacter/GridCharacter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ describe("GridCharacter", () => {
isBlocking: jest.fn(),
getDepthOfCharLayer: jest.fn().mockReturnValue(DEPTH_OF_CHAR_LAYER),
getTransition: jest.fn(),
getTileWidth: jest.fn().mockReturnValue(TILE_WIDTH),
getTileHeight: jest.fn().mockReturnValue(TILE_HEIGHT),
};
gridSpriteMock = <any>{
getRawSprite: jest.fn(),
Expand All @@ -73,7 +75,6 @@ describe("GridCharacter", () => {
gridCharacter = new GridCharacter("player", {
sprite: gridSpriteMock,
tilemap: gridTilemapMock,
tileSize: new Vector2(TILE_WIDTH, TILE_HEIGHT),
speed: 3,
collides: true,
walkingAnimationMapping: 3,
Expand All @@ -84,7 +85,6 @@ describe("GridCharacter", () => {
gridCharacter = new GridCharacter("player", {
sprite: gridSpriteMock,
tilemap: gridTilemapMock,
tileSize: new Vector2(TILE_WIDTH, TILE_HEIGHT),
speed: 3,
collides: true,
charLayer: "someLayer",
Expand All @@ -98,7 +98,6 @@ describe("GridCharacter", () => {
gridCharacter = new GridCharacter("player", {
sprite: gridSpriteMock,
tilemap: gridTilemapMock,
tileSize: new Vector2(TILE_WIDTH, TILE_HEIGHT),
speed: 3,
collides: true,
});
Expand All @@ -107,7 +106,6 @@ describe("GridCharacter", () => {
gridCharacter = new GridCharacter("player", {
sprite: gridSpriteMock,
tilemap: gridTilemapMock,
tileSize: new Vector2(TILE_WIDTH, TILE_HEIGHT),
speed: 3,
collides: false,
});
Expand Down Expand Up @@ -377,7 +375,6 @@ describe("GridCharacter", () => {
gridCharacter = new GridCharacter("player", {
sprite: gridSpriteMock,
tilemap: gridTilemapMock,
tileSize: new Vector2(TILE_WIDTH, TILE_HEIGHT),
speed: 3,
offsetX: customOffsetX,
offsetY: customOffsetY,
Expand Down Expand Up @@ -754,7 +751,6 @@ describe("GridCharacter", () => {
gridCharacter = new GridCharacter("player", {
sprite: gridSpriteMock,
tilemap: gridTilemapMock,
tileSize: new Vector2(TILE_WIDTH, TILE_HEIGHT),
speed: 3,
collides: false,
walkingAnimationMapping: 3,
Expand Down Expand Up @@ -894,7 +890,6 @@ describe("GridCharacter", () => {
gridCharacter = new GridCharacter("player", {
sprite: gridSpriteMock,
tilemap: gridTilemapMock,
tileSize: new Vector2(TILE_WIDTH, TILE_HEIGHT),
speed: 3,
walkingAnimationMapping: 3,
container: containerMock,
Expand Down
7 changes: 4 additions & 3 deletions src/GridCharacter/GridCharacter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export interface CharConfig {
sprite: GridSprite;
// sprite2: Phaser.GameObjects.Sprite;
tilemap: GridTilemap;
tileSize: Vector2;
speed: number;
collides: boolean;
walkingAnimationMapping?: CharacterIndex | WalkingAnimationMapping;
Expand Down Expand Up @@ -86,8 +85,10 @@ export class GridCharacter {
this.speed = config.speed;
this.collides = config.collides;
this.customOffset = new Vector2(config.offsetX || 0, config.offsetY || 0);
this.tileSize = config.tileSize.clone();

this.tileSize = new Vector2(
this.tilemap.getTileWidth(),
this.tilemap.getTileHeight()
);
this._tilePos.layer = config.charLayer;

this.sprite = config.sprite;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ describe("IsometricGridCharacter", () => {
isBlocking: jest.fn().mockReturnValue(false),
getDepthOfCharLayer: jest.fn().mockReturnValue(DEPTH_OF_CHAR_LAYER),
getTransition: jest.fn(),
getTileWidth: jest.fn().mockReturnValue(TILE_WIDTH),
getTileHeight: jest.fn().mockReturnValue(TILE_HEIGHT),
};
gridSpriteMock = <any>{
getRawSprite: jest.fn(),
Expand All @@ -64,7 +66,6 @@ describe("IsometricGridCharacter", () => {
gridCharacter = new IsometricGridCharacter("player", {
sprite: gridSpriteMock,
tilemap: gridTilemapMock,
tileSize: new Vector2(TILE_WIDTH, TILE_HEIGHT),
speed: 1,
walkingAnimationMapping: 3,
collides: true,
Expand All @@ -77,7 +78,6 @@ describe("IsometricGridCharacter", () => {
gridCharacter = new IsometricGridCharacter("player", {
sprite: gridSpriteMock,
tilemap: gridTilemapMock,
tileSize: new Vector2(TILE_WIDTH, TILE_HEIGHT),
speed: 1,
offsetX: customOffsetX,
offsetY: customOffsetY,
Expand Down
7 changes: 0 additions & 7 deletions src/GridEngine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ describe("GridEngine", () => {
expect(GridCharacter).toHaveBeenCalledWith("player", {
sprite: mockGridSprite,
tilemap: mockGridTileMap,
tileSize: new Vector2(32, 32),
speed: 4,
container: containerMock,
offsetX: undefined,
Expand All @@ -271,7 +270,6 @@ describe("GridEngine", () => {
expect(IsometricGridCharacter).toHaveBeenCalledWith("player", {
sprite: playerSpriteMock,
tilemap: mockGridTileMap,
tileSize: new Vector2(32, 32),
speed: 4,
container: undefined,
offsetX: undefined,
Expand Down Expand Up @@ -311,7 +309,6 @@ describe("GridEngine", () => {
});
expect(GridCharacter).toHaveBeenCalledWith("player", {
sprite: playerSpriteMock,
tileSize: new Vector2(32, 32),
tilemap: mockGridTileMap,
speed: 4,
collides: true,
Expand Down Expand Up @@ -356,7 +353,6 @@ describe("GridEngine", () => {
});
expect(GridCharacter).toHaveBeenCalledWith("player", {
sprite: playerSpriteMock,
tileSize: new Vector2(32, 32),
tilemap: mockGridTileMap,
speed: 4,
walkingAnimationMapping,
Expand Down Expand Up @@ -440,7 +436,6 @@ describe("GridEngine", () => {
});
expect(GridCharacter).toHaveBeenCalledWith("player", {
sprite: playerSpriteMock,
tileSize: new Vector2(32, 32),
tilemap: mockGridTileMap,
speed: 2,
walkingAnimationMapping: 3,
Expand All @@ -464,7 +459,6 @@ describe("GridEngine", () => {
});
expect(GridCharacter).toHaveBeenCalledWith("player", {
sprite: playerSpriteMock,
tileSize: new Vector2(32, 32),
tilemap: mockGridTileMap,
speed: 4,
walkingAnimationMapping: 3,
Expand All @@ -488,7 +482,6 @@ describe("GridEngine", () => {
});
expect(GridCharacter).toHaveBeenCalledWith("player", {
sprite: playerSpriteMock,
tileSize: new Vector2(32, 32),
tilemap: mockGridTileMap,
speed: 2,
walkingAnimationMapping: 3,
Expand Down
4 changes: 0 additions & 4 deletions src/GridEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,6 @@ export class GridEngine {
// sprite2,
speed: charData.speed || 4,
tilemap: this.gridTilemap,
tileSize: new Vector2(
this.gridTilemap.getTileWidth(),
this.gridTilemap.getTileHeight()
),
walkingAnimationMapping: charData.walkingAnimationMapping,
container: charData.container,
offsetX: charData.offsetX,
Expand Down

0 comments on commit 3bce776

Please sign in to comment.