claude
This commit is contained in:
parent
47603c058e
commit
c074bc2645
11 changed files with 178 additions and 148 deletions
|
|
@ -10,9 +10,9 @@ export abstract class CommandReceiver {
|
|||
protected defaultCommandExecutor(_: Command) {}
|
||||
|
||||
public handleCommand(command: Command) {
|
||||
const commandType = command.type;
|
||||
const commandType = command.constructor.name;
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(this.commandExecutors, commandType)) {
|
||||
if (commandType in this.commandExecutors) {
|
||||
this.commandExecutors[commandType]!(command);
|
||||
} else {
|
||||
this.defaultCommandExecutor(command);
|
||||
|
|
|
|||
|
|
@ -1,9 +1 @@
|
|||
export abstract class Command {
|
||||
public static get type(): string {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public get type(): string {
|
||||
return this.constructor.name;
|
||||
}
|
||||
}
|
||||
export abstract class Command {}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { Command } from '../../command';
|
|||
|
||||
@serializable
|
||||
export class ClientHeartbeatCommand extends Command {
|
||||
public constructor(public readonly clientTimeMs: number = 0) {
|
||||
public constructor(public readonly clientTimeMs: number) {
|
||||
super();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { Command } from '../../command';
|
|||
|
||||
@serializable
|
||||
export class LeapActionCommand extends Command {
|
||||
public constructor(public readonly clientTimeMs: number = 0) {
|
||||
public constructor(public readonly clientTimeMs: number) {
|
||||
super();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { Command } from '../../command';
|
|||
export class MoveActionCommand extends Command {
|
||||
public constructor(
|
||||
public readonly direction: vec2,
|
||||
public readonly clientTimeMs: number = 0,
|
||||
public readonly clientTimeMs: number,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import { Command } from '../../command';
|
|||
export class PrimaryActionCommand extends Command {
|
||||
public constructor(
|
||||
public readonly position: vec2,
|
||||
public readonly charge: number = 0,
|
||||
public readonly clientTimeMs: number = 0,
|
||||
public readonly charge: number,
|
||||
public readonly clientTimeMs: number,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
import { clamp01 } from './clamp';
|
||||
import { settings } from '../settings';
|
||||
|
||||
export const holdDurationToCharge = (heldSeconds: number): number =>
|
||||
clamp01(heldSeconds / settings.chargeShotFullHoldSeconds);
|
||||
|
||||
export const chargeHeldSince = (heldSinceMs: number): number =>
|
||||
holdDurationToCharge((performance.now() - heldSinceMs) / 1000);
|
||||
clamp01((performance.now() - heldSinceMs) / 1000 / settings.chargeShotFullHoldSeconds);
|
||||
|
||||
export const strengthToCharge = (strength: number): number =>
|
||||
clamp01(
|
||||
|
|
|
|||
|
|
@ -92,9 +92,7 @@ export abstract class GameObject {
|
|||
}
|
||||
|
||||
public resetRemoteCalls() {
|
||||
if (this.remoteCalls.length > 0) {
|
||||
this.remoteCalls = [];
|
||||
}
|
||||
this.remoteCalls = [];
|
||||
}
|
||||
|
||||
protected remoteCall(name: string & keyof this, ...args: Array<any>) {
|
||||
|
|
|
|||
|
|
@ -27,11 +27,16 @@ export class PlanetBase extends GameObject implements GroundSurface {
|
|||
public readonly isKeystone: boolean = false,
|
||||
) {
|
||||
super(id);
|
||||
this.center = vertices.reduce((sum, v) => vec2.add(sum, sum, v), vec2.create());
|
||||
this.center = vec2.create();
|
||||
for (const vertex of vertices) {
|
||||
vec2.add(this.center, this.center, vertex);
|
||||
}
|
||||
vec2.scale(this.center, this.center, 1 / vertices.length);
|
||||
this.radius =
|
||||
vertices.reduce((sum, v) => sum + vec2.distance(this.center, v), 0) /
|
||||
vertices.length;
|
||||
let totalRadius = 0;
|
||||
for (const vertex of vertices) {
|
||||
totalRadius += vec2.distance(this.center, vertex);
|
||||
}
|
||||
this.radius = totalRadius / vertices.length;
|
||||
}
|
||||
|
||||
public get team(): CharacterTeam {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { vec2 } from 'gl-matrix';
|
|||
import { Sdf } from './sdf';
|
||||
|
||||
export const evaluateSdf = (target: vec2, objects: Array<Sdf>): number => {
|
||||
let minimum = 1000000;
|
||||
let minimum = Infinity;
|
||||
for (let i = 0; i < objects.length; i++) {
|
||||
const object = objects[i];
|
||||
if (object.canCollide) {
|
||||
|
|
|
|||
|
|
@ -62,7 +62,6 @@ export const settings = {
|
|||
chargeShotSpeedMin: 2500,
|
||||
chargeShotSpeedMax: 3400,
|
||||
backgroundGradient: [rgb255(90, 38, 43), rgb255(43, 39, 73)],
|
||||
blueColor,
|
||||
bluePlanetColor: blueColorDim,
|
||||
npcNames: [
|
||||
'Adam',
|
||||
|
|
@ -114,7 +113,6 @@ export const settings = {
|
|||
'Will',
|
||||
'Wyatt',
|
||||
],
|
||||
redColor,
|
||||
redPlanetColor: redColorDim,
|
||||
colorIndices: {
|
||||
[CharacterTeam.blue]: 0,
|
||||
|
|
|
|||
Loading…
Reference in a new issue