created PathfindingManager. WIP
This commit is contained in:
parent
82c2d21423
commit
000b2cfe73
9550
front/package-lock.json
generated
Normal file
9550
front/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -48,6 +48,7 @@
|
|||||||
"axios": "^0.21.2",
|
"axios": "^0.21.2",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"deep-copy-ts": "^0.5.0",
|
"deep-copy-ts": "^0.5.0",
|
||||||
|
"easystarjs": "^0.4.4",
|
||||||
"generic-type-guard": "^3.2.0",
|
"generic-type-guard": "^3.2.0",
|
||||||
"google-protobuf": "^3.13.0",
|
"google-protobuf": "^3.13.0",
|
||||||
"phaser": "^3.54.0",
|
"phaser": "^3.54.0",
|
||||||
|
@ -1,10 +1,4 @@
|
|||||||
import type {
|
import type { ITiledMap, ITiledMapLayer, ITiledMapObject, ITiledMapProperty } from "../Map/ITiledMap";
|
||||||
ITiledMap,
|
|
||||||
ITiledMapLayer,
|
|
||||||
ITiledMapObject,
|
|
||||||
ITiledMapObjectLayer,
|
|
||||||
ITiledMapProperty,
|
|
||||||
} from "../Map/ITiledMap";
|
|
||||||
import { flattenGroupLayersMap } from "../Map/LayersFlattener";
|
import { flattenGroupLayersMap } from "../Map/LayersFlattener";
|
||||||
import TilemapLayer = Phaser.Tilemaps.TilemapLayer;
|
import TilemapLayer = Phaser.Tilemaps.TilemapLayer;
|
||||||
import { DEPTH_OVERLAY_INDEX } from "./DepthIndexes";
|
import { DEPTH_OVERLAY_INDEX } from "./DepthIndexes";
|
||||||
@ -120,6 +114,22 @@ export class GameMap {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getCollisionsGrid(): number[][] {
|
||||||
|
const collisionsLayer = this.findPhaserLayer("collisions");
|
||||||
|
if (!collisionsLayer) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const grid: number[][] = [];
|
||||||
|
for (let y = 0; y < collisionsLayer.height; y += 1) {
|
||||||
|
const row: number[] = [];
|
||||||
|
for (let x = 0; x < collisionsLayer.width; x += 1) {
|
||||||
|
row.push(collisionsLayer.getTileAt(x, y) ? 1 : 0);
|
||||||
|
}
|
||||||
|
grid.push(row);
|
||||||
|
}
|
||||||
|
return grid;
|
||||||
|
}
|
||||||
|
|
||||||
private getLayersByKey(key: number): Array<ITiledMapLayer> {
|
private getLayersByKey(key: number): Array<ITiledMapLayer> {
|
||||||
return this.flatLayers.filter((flatLayer) => flatLayer.type === "tilelayer" && flatLayer.data[key] !== 0);
|
return this.flatLayers.filter((flatLayer) => flatLayer.type === "tilelayer" && flatLayer.data[key] !== 0);
|
||||||
}
|
}
|
||||||
|
@ -48,9 +48,9 @@ import { PropertyUtils } from "../Map/PropertyUtils";
|
|||||||
import { GameMapPropertiesListener } from "./GameMapPropertiesListener";
|
import { GameMapPropertiesListener } from "./GameMapPropertiesListener";
|
||||||
import { analyticsClient } from "../../Administration/AnalyticsClient";
|
import { analyticsClient } from "../../Administration/AnalyticsClient";
|
||||||
import { GameMapProperties } from "./GameMapProperties";
|
import { GameMapProperties } from "./GameMapProperties";
|
||||||
|
import { PathfindingManager } from "../../Utils/PathfindingManager";
|
||||||
import type {
|
import type {
|
||||||
GroupCreatedUpdatedMessageInterface,
|
GroupCreatedUpdatedMessageInterface,
|
||||||
MessageUserJoined,
|
|
||||||
MessageUserMovedInterface,
|
MessageUserMovedInterface,
|
||||||
MessageUserPositionInterface,
|
MessageUserPositionInterface,
|
||||||
OnConnectInterface,
|
OnConnectInterface,
|
||||||
@ -66,7 +66,6 @@ import type { ITiledMap, ITiledMapLayer, ITiledMapProperty, ITiledMapObject, ITi
|
|||||||
import type { AddPlayerInterface } from "./AddPlayerInterface";
|
import type { AddPlayerInterface } from "./AddPlayerInterface";
|
||||||
import { CameraManager, CameraManagerEvent, CameraManagerEventCameraUpdateData } from "./CameraManager";
|
import { CameraManager, CameraManagerEvent, CameraManagerEventCameraUpdateData } from "./CameraManager";
|
||||||
import type { HasPlayerMovedEvent } from "../../Api/Events/HasPlayerMovedEvent";
|
import type { HasPlayerMovedEvent } from "../../Api/Events/HasPlayerMovedEvent";
|
||||||
import type { Character } from "../Entity/Character";
|
|
||||||
|
|
||||||
import { peerStore } from "../../Stores/PeerStore";
|
import { peerStore } from "../../Stores/PeerStore";
|
||||||
import { biggestAvailableAreaStore } from "../../Stores/BiggestAvailableAreaStore";
|
import { biggestAvailableAreaStore } from "../../Stores/BiggestAvailableAreaStore";
|
||||||
@ -89,8 +88,7 @@ import SpriteSheetFile = Phaser.Loader.FileTypes.SpriteSheetFile;
|
|||||||
import { deepCopy } from "deep-copy-ts";
|
import { deepCopy } from "deep-copy-ts";
|
||||||
import FILE_LOAD_ERROR = Phaser.Loader.Events.FILE_LOAD_ERROR;
|
import FILE_LOAD_ERROR = Phaser.Loader.Events.FILE_LOAD_ERROR;
|
||||||
import { MapStore } from "../../Stores/Utils/MapStore";
|
import { MapStore } from "../../Stores/Utils/MapStore";
|
||||||
import { followUsersColorStore, followUsersStore } from "../../Stores/FollowStore";
|
import { followUsersColorStore } from "../../Stores/FollowStore";
|
||||||
import { getColorRgbFromHue } from "../../WebRtc/ColorGenerator";
|
|
||||||
import Camera = Phaser.Cameras.Scene2D.Camera;
|
import Camera = Phaser.Cameras.Scene2D.Camera;
|
||||||
|
|
||||||
export interface GameSceneInitInterface {
|
export interface GameSceneInitInterface {
|
||||||
@ -203,6 +201,7 @@ export class GameScene extends DirtyScene {
|
|||||||
private mapTransitioning: boolean = false; //used to prevent transitions happening at the same time.
|
private mapTransitioning: boolean = false; //used to prevent transitions happening at the same time.
|
||||||
private emoteManager!: EmoteManager;
|
private emoteManager!: EmoteManager;
|
||||||
private cameraManager!: CameraManager;
|
private cameraManager!: CameraManager;
|
||||||
|
private pathfindingManager!: PathfindingManager;
|
||||||
private preloading: boolean = true;
|
private preloading: boolean = true;
|
||||||
private startPositionCalculator!: StartPositionCalculator;
|
private startPositionCalculator!: StartPositionCalculator;
|
||||||
private sharedVariablesManager!: SharedVariablesManager;
|
private sharedVariablesManager!: SharedVariablesManager;
|
||||||
@ -568,6 +567,9 @@ export class GameScene extends DirtyScene {
|
|||||||
{ x: this.Map.widthInPixels, y: this.Map.heightInPixels },
|
{ x: this.Map.widthInPixels, y: this.Map.heightInPixels },
|
||||||
waScaleManager
|
waScaleManager
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.pathfindingManager = new PathfindingManager(this, this.gameMap.getCollisionsGrid());
|
||||||
|
this.pathfindingManager.findPath({ x: 1, y: 3 }, { x: 29, y: 3 });
|
||||||
biggestAvailableAreaStore.recompute();
|
biggestAvailableAreaStore.recompute();
|
||||||
this.cameraManager.startFollowPlayer(this.CurrentPlayer);
|
this.cameraManager.startFollowPlayer(this.CurrentPlayer);
|
||||||
|
|
||||||
|
43
front/src/Utils/PathfindingManager.ts
Normal file
43
front/src/Utils/PathfindingManager.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import * as EasyStar from "easystarjs";
|
||||||
|
|
||||||
|
export class PathfindingManager {
|
||||||
|
private scene: Phaser.Scene;
|
||||||
|
|
||||||
|
private easyStar;
|
||||||
|
|
||||||
|
constructor(scene: Phaser.Scene, collisionsGrid: number[][]) {
|
||||||
|
this.scene = scene;
|
||||||
|
|
||||||
|
this.easyStar = new EasyStar.js();
|
||||||
|
|
||||||
|
this.setGrid(collisionsGrid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public findPath(start: { x: number; y: number }, end: { x: number; y: number }): void {
|
||||||
|
console.log("TRY TO FIND PATH");
|
||||||
|
this.easyStar.findPath(start.x, start.y, end.x, end.y, (path) => {
|
||||||
|
if (path === null) {
|
||||||
|
console.warn("Path was not found.");
|
||||||
|
} else {
|
||||||
|
console.log("path was found");
|
||||||
|
console.log(path);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.easyStar.calculate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private setGrid(grid: number[][]): void {
|
||||||
|
console.log(grid);
|
||||||
|
this.easyStar.setGrid(grid);
|
||||||
|
this.easyStar.setAcceptableTiles([0]); // zeroes are walkable
|
||||||
|
this.logGridToTheConsole(grid);
|
||||||
|
}
|
||||||
|
|
||||||
|
private logGridToTheConsole(grid: number[][]): void {
|
||||||
|
let rowNumber = 0;
|
||||||
|
for (const row of grid) {
|
||||||
|
console.log(`${rowNumber}:\t${row}`);
|
||||||
|
rowNumber += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1990,6 +1990,13 @@ dot-case@^3.0.4:
|
|||||||
no-case "^3.0.4"
|
no-case "^3.0.4"
|
||||||
tslib "^2.0.3"
|
tslib "^2.0.3"
|
||||||
|
|
||||||
|
easystarjs@^0.4.4:
|
||||||
|
version "0.4.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/easystarjs/-/easystarjs-0.4.4.tgz#8cec6d20d0d8660715da0301d1da440370a8f40a"
|
||||||
|
integrity sha512-ZSt0TkB8xuIXRIrKsM3jkmk1/cZUtyvf0DqOXf6wuKq9slx9UA5kkLtiaWhtmOQFJFKdabbvXwk6RO0znghArQ==
|
||||||
|
dependencies:
|
||||||
|
heap "0.2.6"
|
||||||
|
|
||||||
ee-first@1.1.1:
|
ee-first@1.1.1:
|
||||||
version "1.1.1"
|
version "1.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
|
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
|
||||||
@ -2925,6 +2932,11 @@ he@^1.2.0:
|
|||||||
resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
|
resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
|
||||||
integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==
|
integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==
|
||||||
|
|
||||||
|
heap@0.2.6:
|
||||||
|
version "0.2.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/heap/-/heap-0.2.6.tgz#087e1f10b046932fc8594dd9e6d378afc9d1e5ac"
|
||||||
|
integrity sha1-CH4fELBGky/IWU3Z5tN4r8nR5aw=
|
||||||
|
|
||||||
hmac-drbg@^1.0.1:
|
hmac-drbg@^1.0.1:
|
||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"
|
resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"
|
||||||
|
Loading…
Reference in New Issue
Block a user