Skip to content

Commit

Permalink
fix(dungeon): dungeon maps will correctly track the players viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Mar 6, 2023
1 parent 2757ec0 commit b9d9080
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 42 deletions.
66 changes: 33 additions & 33 deletions content/data/dungeons/1-undead.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,44 @@ givesPointAtCombatLevel: 20
floors:
- name: Crypt Entrance
layout:
- [ ., ., ., ., ., ., ., ., ., ., ., .,] #this is a square https://youtu.be/rreFXFnlKO4?t=238
- [ ., 1, c1, 1, 1, 1, 1, t1, 1, t3, c1, .,]
- [ ., 1, ., 1, ., 1, ., 1, ., 1, ., .,]
- [ ., 1, ., 1, ., 1, ., 1, ., 1, 1, .,]
- [ ., 1, 1, 1, 1, t1, 1, 1, 1, 1, ., .,]
- [ e, t1, ., 1, ., 1, ., 1, ., 1, 1, .,]
- [ ., 1, ., 1, ., 1, ., 1, ., 1, x, .,]
- [ ., 1, 1, 1, 1, 1, 1, t3, 1, 1, ., .,]
- [ ., 1, ., 1, ., 1, ., 1, ., t3, c1, .,]
- [ ., 1, ., 1, ., 1, ., 1, ., 1, ., .,]
- [ ., 1, 1, t1, c1, t1, 1, 1, 1, 1, 1, .,]
- [ ., ., ., ., ., ., ., ., ., ., ., .,]
- [ ., ., ., ., ., ., ., ., ., ., ., .] #this is a square https://youtu.be/rreFXFnlKO4?t=238
- [ ., 1, c1, 1, 1, 1, 1, t1, 1, t3, c1, .]
- [ ., 1, ., 1, ., 1, ., 1, ., 1, ., .]
- [ ., 1, ., 1, ., 1, ., 1, ., 1, 1, .]
- [ ., 1, t1, 1, 1, t1, 1, 1, 1, 1, ., .]
- [ ., e, ., 1, ., 1, ., 1, ., 1, 1, .]
- [ ., 1, ., 1, ., 1, ., 1, ., 1, x, .]
- [ ., 1, 1, 1, 1, 1, 1, t3, 1, 1, ., .]
- [ ., 1, ., 1, ., 1, ., 1, ., t3, c1, .]
- [ ., 1, ., 1, ., 1, ., 1, ., 1, ., .]
- [ ., 1, 1, t1, c1, t1, 1, 1, 1, 1, 1, .]
- [ ., ., ., ., ., ., ., ., ., ., ., .]



- name: Who Put This Maze Here
layout: #21/21
- [ ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., .,]
- [ ., c2, 1, 1, t1, 1, ., 1, 1, 1, 1, 1, 1, 1, ., c2, 1, 1, 1, t1, .,]
- [ ., ., ., ., ., 1, ., 1, ., ., ., ., ., 1, ., ., ., 1, ., 1, .,]
- [ ., 1, 1, 1, 1, 1, ., 1, ., t2, 1, 1, 1, t3, 1, 1, 1, 1, ., 1, .,]
- [ ., 1, ., ., ., ., ., 1, ., 1, ., ., ., ., ., ., ., ., ., 1, .,]
- [ ., 1, ., 1, 1, 1, 1, t5, ., c3, ., c4, 1, 1, t8, 1, ., 1, 1, 1, .,]
- [ ., 1, ., t3, ., ., ., ., ., ., ., ., ., ., ., 1, ., 1, ., ., .,]
- [ ., t3, ., 1, 1, 1, 1, 1, ., 1, 1, 1, 1, 1, t4, 1, ., 1, ., c3, .,]
- [ ., 1, ., ., ., ., ., 1, ., 1, ., ., ., ., ., ., ., 1, ., 1, .,]
- [ ., 1, 1, 1, 1, t3, ., 1, ., 1, ., 1, t7, 1, 1, 1, ., 1, 1, 1, .,]
- [ ., 1, ., ., ., 1, ., 1, ., f, b, f, ., ., ., 1, ., ., ., 1, .,]
- [ ., 1, 1, 1, ., 1, ., 1, t6, 1, ., 1, 1, t4, ., 1, 1, 1, 1, t1, .,]
- [ ., 1, ., t2, ., 1, ., ., ., ., ., ., ., 1, ., ., ., ., ., 1, .,] #may open up or re-close this wall #would have implications though
- [ ., 1, ., 1, ., 1, t5, c3, ., 1, t5, 1, ., 1, ., 1, 1, 1, 1, 1, .,]
- [ ., ., ., 1, ., 1, ., ., ., 1, ., 1, ., 1, ., 1, ., ., ., ., .,]
- [ ., 1, 1, 1, ., 1, ., 1, 1, 1, ., 1, 1, 1, ., 1, 1, t3, 1, 1, .,]
- [ ., 1, ., ., ., 1, ., 1, ., ., ., ., ., ., ., ., ., 1, ., 1, .,]
- [ ., 1, ., c2, 1, 1, ., 1, t2, 1, 1, 1, ., 1, 1, 1, ., c2, ., 1, .,]
- [ ., 1, ., ., ., ., ., ., ., ., ., 1, ., 1, ., 1, ., ., ., 1, .,]
- [ ., e, 1, 1, 1, 1, t1, 1, 1, 1, 1, 1, 1, 1, ., 1, 1, 1, 1, t1, .,]
- [ ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., .,]
- [ ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., .]
- [ ., c2, 1, 1, t1, 1, ., 1, 1, 1, 1, 1, 1, 1, ., c2, 1, 1, 1, t1, .]
- [ ., ., ., ., ., 1, ., 1, ., ., ., ., ., 1, ., ., ., 1, ., 1, .]
- [ ., 1, 1, 1, 1, 1, ., 1, ., t2, 1, 1, 1, t3, 1, 1, 1, 1, ., 1, .]
- [ ., 1, ., ., ., ., ., 1, ., 1, ., ., ., ., ., ., ., ., ., 1, .]
- [ ., 1, ., 1, 1, 1, 1, t5, ., c3, ., c4, 1, 1, t8, 1, ., 1, 1, 1, .]
- [ ., 1, ., t3, ., ., ., ., ., ., ., ., ., ., ., 1, ., 1, ., ., .]
- [ ., t3, ., 1, 1, 1, 1, 1, ., 1, 1, 1, 1, 1, t4, 1, ., 1, ., c3, .]
- [ ., 1, ., ., ., ., ., 1, ., 1, ., ., ., ., ., ., ., 1, ., 1, .]
- [ ., 1, 1, 1, 1, t3, ., 1, ., 1, ., 1, t7, 1, 1, 1, ., 1, 1, 1, .]
- [ ., 1, ., ., ., 1, ., 1, ., f, b, f, ., ., ., 1, ., ., ., 1, .]
- [ ., 1, 1, 1, ., 1, ., 1, t6, 1, ., 1, 1, t4, ., 1, 1, 1, 1, t1, .]
- [ ., 1, ., t2, ., 1, ., ., ., ., ., ., ., 1, ., ., ., ., ., 1, .] #may open up or re-close this wall #would have implications though
- [ ., 1, ., 1, ., 1, t5, c3, ., 1, t5, 1, ., 1, ., 1, 1, 1, 1, 1, .]
- [ ., ., ., 1, ., 1, ., ., ., 1, ., 1, ., 1, ., 1, ., ., ., ., .]
- [ ., 1, 1, 1, ., 1, ., 1, 1, 1, ., 1, 1, 1, ., 1, 1, t3, 1, 1, .]
- [ ., 1, ., ., ., 1, ., 1, ., ., ., ., ., ., ., ., ., 1, ., 1, .]
- [ ., 1, ., c2, 1, 1, ., 1, t2, 1, 1, 1, ., 1, 1, 1, ., c2, ., 1, .]
- [ ., 1, ., ., ., ., ., ., ., ., ., 1, ., 1, ., 1, ., ., ., 1, .]
- [ ., e, 1, 1, 1, 1, t1, 1, 1, 1, 1, 1, 1, 1, ., 1, 1, 1, 1, t1, .]
- [ ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., .]



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
<ion-card-content>
<ion-row>
<ion-col>
<div class="dungeon-container">
<div class="dungeon-row" *ngFor="let row of dungeonView(dungeon.pos, dungeon.dungeon); let y = index; trackBy: trackBy">
<div class="dungeon-container" *ngIf="dungeonDisplay.length > 0">
<div class="dungeon-row" *ngFor="let row of dungeonDisplay; let y = index; trackBy: trackBy">
<div class="dungeon-col" *ngFor="let col of row; let x = index; trackBy: trackBy">
<app-game-icon [icon]="pageData.currentPlayer?.icon ?? 'me'" *ngIf="col === 'me'"></app-game-icon>
<app-game-icon [icon]="getIconForTile(dungeon.dungeon, col)" *ngIf="col !== 'me'" [color]="getColorForTile(dungeon.dungeon, col)"></app-game-icon>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Select, Store } from '@ngxs/store';
import { Observable } from 'rxjs';
import { clamp, cloneDeep } from 'lodash';
import { Observable, Subscription } from 'rxjs';
import { DungeonNode, DungeonTile, IDungeon, IGameDungeonState, IGameEncounterCharacter } from '../../../../../../interfaces';
import { CombatState } from '../../../../../../stores';
import {
Expand All @@ -26,6 +27,9 @@ export class DungeonDisplayComponent implements OnInit, OnDestroy {
@Select(CombatState.currentPlayer) currentPlayer$!: Observable<IGameEncounterCharacter>;
@Select(CombatState.currentDungeon) currentDungeon$!: Observable<IGameDungeonState>;

private dungeonSub!: Subscription;
public dungeonDisplay: DungeonNode[][] = [];

constructor(private store: Store, private contentService: ContentService) { }

private arrowKeys = (event: KeyboardEvent) => {
Expand All @@ -39,10 +43,21 @@ export class DungeonDisplayComponent implements OnInit, OnDestroy {

ngOnInit() {
document.addEventListener('keydown', this.arrowKeys);

this.dungeonSub = this.currentDungeon$.subscribe(dungeon => {
if(!dungeon) {
this.dungeonDisplay = [];
return;
}

this.dungeonDisplay = this.dungeonView(dungeon.pos, dungeon.dungeon);
});
}

ngOnDestroy() {
document.removeEventListener('keydown', this.arrowKeys);

this.dungeonSub?.unsubscribe();
}

trackBy(index: number) {
Expand Down Expand Up @@ -104,16 +119,20 @@ export class DungeonDisplayComponent implements OnInit, OnDestroy {
}

dungeonView(curPos: { x: number; y: number; z: number }, dungeon: IDungeon): DungeonNode[][] {
const offsetTop = Math.min(4, Math.max(0, curPos.y - 4));
const offsetLeft = Math.min(4, Math.max(0, curPos.x - 4));
const dungeonClone = cloneDeep(dungeon);

dungeonClone.floors[curPos.z].layout[curPos.y][curPos.x] = 'me';

const view = dungeon.floors[curPos.z].layout.slice(offsetTop, offsetTop + 9);
const offsetTop = clamp(curPos.y - 4, 0, dungeonClone.floors[curPos.z].layout.length);
const offsetLeft = clamp(curPos.x - 4, 0, dungeonClone.floors[curPos.z].layout[curPos.y].length);

const startOffsetTop = Math.min(offsetTop, dungeonClone.floors[curPos.z].layout.length - 9);
const view = dungeonClone.floors[curPos.z].layout.slice(startOffsetTop, startOffsetTop + 9);
for(let i = 0; i < view.length; i++) {
view[i] = view[i].slice(offsetLeft, offsetLeft + 9);
const startOffsetLeft = Math.min(offsetLeft, view[i].length - 9);
view[i] = view[i].slice(startOffsetLeft, startOffsetLeft + 9);
}

view[curPos.y - offsetTop][curPos.x - offsetLeft] = 'me';

return view;
}

Expand Down

0 comments on commit b9d9080

Please sign in to comment.