Skip to content

Commit

Permalink
GameMap: Use highest z-value when merging actors
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanGrieb committed Nov 16, 2023
1 parent 5524d4d commit 7e6554e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
3 changes: 2 additions & 1 deletion client/src/Unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class Unit extends ActorGroup {
super({
x: options.tile.getCenterPosition()[0] - 28 / 2,
y: options.tile.getCenterPosition()[1] - 28 / 2,
z: 1,
z: 2,
width: 28,
height: 28,
});
Expand All @@ -128,6 +128,7 @@ export class Unit extends ActorGroup {
spriteRegion: SpriteRegion[options.name.toUpperCase()],
x: options.tile.getCenterPosition()[0] - 28 / 2,
y: options.tile.getCenterPosition()[1] - 28 / 2,
z: 2,
width: 28,
height: 28,
});
Expand Down
13 changes: 9 additions & 4 deletions client/src/city/City.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,16 @@ export class City extends ActorGroup {
shadowColor: "black",
lineWidth: 1,
z: 4,
onClick: () => {
Game.getCurrentSceneAs<InGameScene>().toggleCityUI(this);
},
});

if (
this.player == Game.getCurrentSceneAs<InGameScene>().getClientPlayer()
) {
this.nameLabel.setOnClick(() => {
Game.getCurrentSceneAs<InGameScene>().toggleCityUI(this);
});
}

this.nameLabel.conformSize().then(() => {
this.nameLabel.setPosition(
this.tile.getX() -
Expand All @@ -89,7 +94,7 @@ export class City extends ActorGroup {
SpriteRegion[this.player.getCivilizationData()["icon_name"]],
x: this.nameLabel.getX() - 14,
y: this.nameLabel.getY(),
z: 14,
z: 4,
width: 12,
height: 12,
});
Expand Down
2 changes: 2 additions & 0 deletions client/src/map/GameMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,8 @@ export class GameMap {
});
updatedMapChunk.setPosition(chunk.getX(), chunk.getY());

console.log(updatedMapChunk.getZIndex());

Game.getCurrentScene().addActor(updatedMapChunk);
Game.getCurrentScene().removeActor(chunk);

Expand Down
5 changes: 5 additions & 0 deletions client/src/scene/Actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ export class Actor implements SceneObject {
let greatestYHeight = 0; // The height of the actor w/ the greatest y.
let greatestX = 0;
let greatestY = 0;
let greatestZ = 0;

options.actors.forEach((actor: Actor) => {
if (actor.getX() > greatestX) {
Expand All @@ -290,6 +291,9 @@ export class Actor implements SceneObject {
greatestY = actor.getY();
greatestYHeight = actor.getHeight();
}
if (actor.getZIndex() > greatestZ) {
greatestZ = actor.getZIndex();
}
});
canvas.width = options.canvasWidth || greatestX + greatestXWidth + 1000;
canvas.height = options.canvasHeight || greatestY + greatestYHeight + 1000;
Expand All @@ -307,6 +311,7 @@ export class Actor implements SceneObject {
image: image,
x: options.actors[0].getX(),
y: options.actors[0].getY(),
z: greatestZ,
width: canvas.width,
height: canvas.height,
});
Expand Down
14 changes: 12 additions & 2 deletions client/src/scene/type/InGameScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Scene } from "../Scene";

export class InGameScene extends Scene {
private players: AbstractPlayer[];
private clientPlayer: ClientPlayer;
private tileInformationLabel: Label;
private statusBar: StatusBar;
private cityDisplayInfo: CityDisplayInfo;
Expand Down Expand Up @@ -43,7 +44,8 @@ export class InGameScene extends Scene {
const playerJSON = data["players"][i];
const civData = playerJSON["civData"];
if (playerJSON["name"] === data["requestingName"]) {
this.players.push(new ClientPlayer(playerJSON["name"], civData));
this.clientPlayer = new ClientPlayer(playerJSON["name"], civData);
this.players.push(this.clientPlayer);
} else {
this.players.push(new ExternalPlayer(playerJSON["name"], civData));
}
Expand Down Expand Up @@ -75,7 +77,7 @@ export class InGameScene extends Scene {
text: "Next Turn",
x: Game.getWidth() / 2 - 150 / 2,
y: Game.getHeight() - 44,
z: 5,
z: 6,
width: 150,
height: 42,
fontColor: "white",
Expand Down Expand Up @@ -166,7 +168,15 @@ export class InGameScene extends Scene {
return this.players;
}

public getClientPlayer() {
return this.clientPlayer;
}

private openCityUI(city: City) {
if (city.getPlayer() != this.clientPlayer) {
return;
}

this.cityDisplayInfo = new CityDisplayInfo(city);
this.addActor(this.cityDisplayInfo);

Expand Down
8 changes: 7 additions & 1 deletion client/src/ui/Label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,15 @@ export class Label extends Actor {
this.lineWidth = options.lineWidth ?? 0;
this.shadowColor = options.shadowColor ?? this.color;
this.shadowBlur = options.shadowBlur ?? 0;
this.onClickCallback = options.onClick;
this.maxWidth = options.maxWidth;

if (options.onClick) {
this.setOnClick(options.onClick);
}
}

public setOnClick(onClickCallback: Function) {
this.onClickCallback = onClickCallback;
if (this.onClickCallback) {
this.on("clicked", () => {
this.onClickCallback();
Expand Down

0 comments on commit 7e6554e

Please sign in to comment.