Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Commit

Permalink
fix: doors layer on stairs
Browse files Browse the repository at this point in the history
  • Loading branch information
leia-uwu committed Feb 21, 2024
1 parent 61e82e3 commit 5d9be4b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
3 changes: 2 additions & 1 deletion server/src/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ export class GameMap {
const def = MapObjectDefs[type] as StructureDef;

const structure = new Structure(this.game, type, pos, layer, ori);
this.game.grid.addObject(structure);

layer = 0;
for (const layerDef of def.layers) {
const building = this.genBuilding(
Expand All @@ -508,7 +510,6 @@ export class GameMap {
structure.layerObjIds.push(building.id);
}

this.game.grid.addObject(structure);
this.objectCount[type]++;
return structure;
}
Expand Down
29 changes: 28 additions & 1 deletion server/src/objects/obstacle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type ObstacleDef } from "../../../shared/defs/mapObjectsTyping";
import { type Game } from "../game";
import { NetConstants } from "../net/net";
import { type ObjectsFullData, type ObjectsPartialData } from "../net/objectSerialization";
import { type Collider } from "../../../shared/utils/coldet";
import { coldet, type Collider } from "../../../shared/utils/coldet";
import { collider } from "../../../shared/utils/collider";
import { mapHelpers } from "../../../shared/utils/mapHelpers";
import { math } from "../../../shared/utils/math";
Expand Down Expand Up @@ -86,6 +86,8 @@ export class Obstacle extends BaseGameObject implements FullObstacle, PartialObs

layer: number;

originalLayer: number;

destructible: boolean;

rot: number;
Expand All @@ -100,6 +102,7 @@ export class Obstacle extends BaseGameObject implements FullObstacle, PartialObs
this.ori = ori;
this.scale = scale;
this.layer = layer;
this.originalLayer = layer;
this.parentBuildingId = parentBuildingId;
this.isPuzzlePiece = !!puzzlePiece;
this.puzzlePiece = puzzlePiece;
Expand Down Expand Up @@ -177,6 +180,7 @@ export class Obstacle extends BaseGameObject implements FullObstacle, PartialObs
break;
}
}
this.checkLayer();
}

if (def.button) {
Expand All @@ -193,6 +197,28 @@ export class Obstacle extends BaseGameObject implements FullObstacle, PartialObs
}
}

checkLayer(): void {
let newLayer = this.originalLayer;
const def = MapObjectDefs[this.type] as ObstacleDef;
const coll = collider.createCircle(this.pos, def.door!.interactionRad + 1)

Check failure on line 203 in server/src/objects/obstacle.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing semicolon
const objs = this.game.grid.intersectCollider(coll);
for (const obj of objs) {
if (obj.__type === ObjectType.Structure) {
for (const stair of obj.stairs) {
if (coldet.test(coll, stair.downAabb)) {
newLayer = 3;
} else if (coldet.test(coll, stair.upAabb)) {
newLayer = 2;
}
}
}
}
if (newLayer !== this.layer) {
this.layer = newLayer;
this.setDirty();
}
}

damage(amount: number, sourceType: string, _damageType: number): void {
const def = MapObjectDefs[this.type] as ObstacleDef;
if (this.health === 0 || !this.destructible) return;
Expand Down Expand Up @@ -337,6 +363,7 @@ export class Obstacle extends BaseGameObject implements FullObstacle, PartialObs

this.bounds = collider.transform(def.collision, v2.create(0, 0), this.rot, 1);
this.game.grid.updateObject(this);
this.checkLayer();
this.setDirty();
}
}

0 comments on commit 5d9be4b

Please sign in to comment.