Refactor frontend
This commit is contained in:
parent
a4bab29d84
commit
561a66c196
8 changed files with 9 additions and 17 deletions
|
|
@ -47,7 +47,7 @@
|
||||||
"resolve-url-loader": "^3.1.1",
|
"resolve-url-loader": "^3.1.1",
|
||||||
"sass": "^1.27.0",
|
"sass": "^1.27.0",
|
||||||
"sass-loader": "^8.0.2",
|
"sass-loader": "^8.0.2",
|
||||||
"sdf-2d": "^0.7.1",
|
"sdf-2d": "^0.7.2",
|
||||||
"shared": "file:../shared",
|
"shared": "file:../shared",
|
||||||
"socket.io-client": "^2.3.1",
|
"socket.io-client": "^2.3.1",
|
||||||
"socket.io-msgpack-parser": "^2.0.0",
|
"socket.io-msgpack-parser": "^2.0.0",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import { Renderer } from 'sdf-2d';
|
|
||||||
import {
|
import {
|
||||||
Command,
|
Command,
|
||||||
CommandExecutors,
|
CommandExecutors,
|
||||||
|
|
@ -20,28 +19,20 @@ import { CharacterView } from './types/character-view';
|
||||||
export class GameObjectContainer extends CommandReceiver {
|
export class GameObjectContainer extends CommandReceiver {
|
||||||
protected objects: Map<Id, GameObject> = new Map();
|
protected objects: Map<Id, GameObject> = new Map();
|
||||||
public player!: CharacterView;
|
public player!: CharacterView;
|
||||||
public camera!: Camera;
|
public camera: Camera = new Camera(this.game);
|
||||||
|
|
||||||
protected commandExecutors: CommandExecutors = {
|
protected commandExecutors: CommandExecutors = {
|
||||||
[CreatePlayerCommand.type]: (c: CreatePlayerCommand) => {
|
[CreatePlayerCommand.type]: (c: CreatePlayerCommand) => {
|
||||||
if (this.camera) {
|
|
||||||
this.deleteObject(this.camera.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.player = c.character as CharacterView;
|
this.player = c.character as CharacterView;
|
||||||
this.player.isMainCharacter = true;
|
this.player.isMainCharacter = true;
|
||||||
|
|
||||||
this.camera = new Camera(this.game);
|
|
||||||
|
|
||||||
this.addObject(this.player);
|
this.addObject(this.player);
|
||||||
this.addObject(this.camera);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
[CreateObjectsCommand.type]: (c: CreateObjectsCommand) =>
|
[CreateObjectsCommand.type]: (c: CreateObjectsCommand) =>
|
||||||
c.objects.forEach((o) => this.addObject(o as GameObject)),
|
c.objects.forEach((o) => this.addObject(o as GameObject)),
|
||||||
|
|
||||||
[StepCommand.type]: (c: StepCommand) => {
|
[StepCommand.type]: (c: StepCommand) => {
|
||||||
this.objects.forEach((o) => o.handleCommand(c));
|
this.defaultCommandExecutor(c);
|
||||||
|
|
||||||
if (this.player) {
|
if (this.player) {
|
||||||
this.camera.center = this.player.position;
|
this.camera.center = this.player.position;
|
||||||
|
|
@ -68,6 +59,7 @@ export class GameObjectContainer extends CommandReceiver {
|
||||||
|
|
||||||
protected defaultCommandExecutor(c: Command) {
|
protected defaultCommandExecutor(c: Command) {
|
||||||
this.objects.forEach((o) => o.handleCommand(c));
|
this.objects.forEach((o) => o.handleCommand(c));
|
||||||
|
this.camera.handleCommand(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
private addObject(object: GameObject) {
|
private addObject(object: GameObject) {
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,19 @@ import { vec2 } from 'gl-matrix';
|
||||||
import {
|
import {
|
||||||
calculateViewArea,
|
calculateViewArea,
|
||||||
CommandExecutors,
|
CommandExecutors,
|
||||||
GameObject,
|
CommandReceiver,
|
||||||
mixRgb,
|
mixRgb,
|
||||||
settings,
|
settings,
|
||||||
} from 'shared';
|
} from 'shared';
|
||||||
import { RenderCommand } from '../../commands/types/render';
|
import { RenderCommand } from '../../commands/types/render';
|
||||||
import { Game } from '../../game';
|
import { Game } from '../../game';
|
||||||
|
|
||||||
export class Camera extends GameObject {
|
export class Camera extends CommandReceiver {
|
||||||
public center: vec2 = vec2.create();
|
public center: vec2 = vec2.create();
|
||||||
private aspectRatio?: number;
|
private aspectRatio?: number;
|
||||||
|
|
||||||
constructor(private game: Game) {
|
constructor(private game: Game) {
|
||||||
super(null);
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected commandExecutors: CommandExecutors = {
|
protected commandExecutors: CommandExecutors = {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import {
|
||||||
import { BeforeDestroyCommand } from '../../commands/types/before-destroy';
|
import { BeforeDestroyCommand } from '../../commands/types/before-destroy';
|
||||||
import { RenderCommand } from '../../commands/types/render';
|
import { RenderCommand } from '../../commands/types/render';
|
||||||
import { StepCommand } from '../../commands/types/step';
|
import { StepCommand } from '../../commands/types/step';
|
||||||
import { CircleExtrapolator } from '../../helper/circle-extrapolator';
|
import { CircleExtrapolator } from '../../helper/extrapolators/circle-extrapolator';
|
||||||
import { BlobShape } from '../../shapes/blob-shape';
|
import { BlobShape } from '../../shapes/blob-shape';
|
||||||
import { SoundHandler, Sounds } from '../../sound-handler';
|
import { SoundHandler, Sounds } from '../../sound-handler';
|
||||||
import { VibrationHandler } from '../../vibration-handler';
|
import { VibrationHandler } from '../../vibration-handler';
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import {
|
||||||
} from 'shared';
|
} from 'shared';
|
||||||
import { RenderCommand } from '../../commands/types/render';
|
import { RenderCommand } from '../../commands/types/render';
|
||||||
import { StepCommand } from '../../commands/types/step';
|
import { StepCommand } from '../../commands/types/step';
|
||||||
import { Vec2Extrapolator } from '../../helper/vec2-extrapolator';
|
import { Vec2Extrapolator } from '../../helper/extrapolators/vec2-extrapolator';
|
||||||
|
|
||||||
export class ProjectileView extends ProjectileBase {
|
export class ProjectileView extends ProjectileBase {
|
||||||
private light: CircleLight;
|
private light: CircleLight;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue