This commit is contained in:
David Négrier 2020-07-23 18:47:28 +02:00
parent 2484e4f1df
commit d48d5b0285
5 changed files with 16 additions and 15 deletions

View File

@ -19,7 +19,7 @@ export class MapController {
// Returns a map mapping map name to file name of the map // Returns a map mapping map name to file name of the map
getStartMap() { getStartMap() {
this.App.get("/start-map", (req: Request, res: Response) => { this.App.get("/start-map", (req: Request, res: Response) => {
let url = req.headers.host?.replace('api.', 'maps.') + URL_ROOM_STARTED; const url = req.headers.host?.replace('api.', 'maps.') + URL_ROOM_STARTED;
res.status(OK).send({ res.status(OK).send({
mapUrlStart: url, mapUrlStart: url,
startInstance: "global" startInstance: "global"

View File

@ -252,11 +252,11 @@ export class GameScene extends Phaser.Scene {
}) })
// Scan the object layers for objects to load and load them. // Scan the object layers for objects to load and load them.
let objects = new Map<string, ITiledMapObject[]>(); const objects = new Map<string, ITiledMapObject[]>();
for (let layer of this.mapFile.layers) { for (const layer of this.mapFile.layers) {
if (layer.type === 'objectgroup') { if (layer.type === 'objectgroup') {
for (let object of layer.objects) { for (const object of layer.objects) {
let objectsOfType: ITiledMapObject[]|undefined; let objectsOfType: ITiledMapObject[]|undefined;
if (!objects.has(object.type)) { if (!objects.has(object.type)) {
objectsOfType = new Array<ITiledMapObject>(); objectsOfType = new Array<ITiledMapObject>();
@ -272,16 +272,17 @@ export class GameScene extends Phaser.Scene {
} }
} }
for (let [itemType, objectsOfType] of objects) { for (const [itemType, objectsOfType] of objects) {
// FIXME: we would ideally need for the loader to WAIT for the import to be performed, which means writing our own loader plugin. // FIXME: we would ideally need for the loader to WAIT for the import to be performed, which means writing our own loader plugin.
let itemFactory: ItemFactoryInterface; let itemFactory: ItemFactoryInterface;
switch (itemType) { switch (itemType) {
case 'computer': case 'computer': {
let module = await import('../Items/Computer/computer'); const module = await import('../Items/Computer/computer');
itemFactory = module.default as ItemFactoryInterface; itemFactory = module.default;
break; break;
}
default: default:
throw new Error('Unsupported object type: "'+ itemType +'"'); throw new Error('Unsupported object type: "'+ itemType +'"');
} }
@ -295,9 +296,9 @@ export class GameScene extends Phaser.Scene {
this.createPromise.then(() => { this.createPromise.then(() => {
itemFactory.create(this); itemFactory.create(this);
for (let object of objectsOfType) { for (const object of objectsOfType) {
// TODO: we should pass here a factory to create sprites (maybe?) // TODO: we should pass here a factory to create sprites (maybe?)
let actionableItem = itemFactory.factory(this, object); const actionableItem = itemFactory.factory(this, object);
this.actionableItems.push(actionableItem); this.actionableItems.push(actionableItem);
} }
}); });
@ -675,8 +676,8 @@ export class GameScene extends Phaser.Scene {
let shortestDistance: number = Infinity; let shortestDistance: number = Infinity;
let selectedItem: ActionableItem|null = null; let selectedItem: ActionableItem|null = null;
for (let item of this.actionableItems) { for (const item of this.actionableItems) {
let distance = item.actionableDistance(x, y); const distance = item.actionableDistance(x, y);
if (distance !== null && distance < shortestDistance) { if (distance !== null && distance < shortestDistance) {
shortestDistance = distance; shortestDistance = distance;
selectedItem = item; selectedItem = item;

View File

@ -18,7 +18,7 @@ export class ActionableItem {
* OR null if we are out of range. * OR null if we are out of range.
*/ */
public actionableDistance(x: number, y: number): number|null { public actionableDistance(x: number, y: number): number|null {
let distanceSquared = (x - this.sprite.x)*(x - this.sprite.x) + (y - this.sprite.y)*(y - this.sprite.y); const distanceSquared = (x - this.sprite.x)*(x - this.sprite.x) + (y - this.sprite.y)*(y - this.sprite.y);
if (distanceSquared < this.activationRadiusSquared) { if (distanceSquared < this.activationRadiusSquared) {
return distanceSquared; return distanceSquared;
} else { } else {

View File

@ -15,7 +15,7 @@ export default {
}, },
factory: (scene: GameScene, object: ITiledMapObject): ActionableItem => { factory: (scene: GameScene, object: ITiledMapObject): ActionableItem => {
// Idée: ESSAYER WebPack? https://paultavares.wordpress.com/2018/07/02/webpack-how-to-generate-an-es-module-bundle/ // Idée: ESSAYER WebPack? https://paultavares.wordpress.com/2018/07/02/webpack-how-to-generate-an-es-module-bundle/
let foo = new Sprite(scene, object.x, object.y, 'computer'); const foo = new Sprite(scene, object.x, object.y, 'computer');
scene.add.existing(foo); scene.add.existing(foo);
return new ActionableItem(foo, 32); return new ActionableItem(foo, 32);

View File

@ -27,7 +27,7 @@ const config: GameConfig = {
callbacks: { callbacks: {
postBoot: game => { postBoot: game => {
// FIXME: we should fore WebGL in the config. // FIXME: we should fore WebGL in the config.
let renderer = game.renderer as WebGLRenderer; const renderer = game.renderer as WebGLRenderer;
renderer.addPipeline(OutlinePipeline.KEY, new OutlinePipeline(game)); renderer.addPipeline(OutlinePipeline.KEY, new OutlinePipeline(game));
} }
} }