Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Feb 26, 2025
1 parent fc086eb commit ff2e3d5
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/consts.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const HEALTH_CHANGE_TENSION_TIMER = 75;
export const HEALTH_CHANGE_TENSION_TIMER_MS = 750;
8 changes: 4 additions & 4 deletions src/entities/playable/playable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { applyGenericBoxStyle, DefaultTextStyle } from "../../mixins/styles";
import { Viewport } from "pixi-viewport";
import { handleDamageInRadius } from "../../utils/damage";
import { RecordedEntityState } from "../../state/model";
import { HEALTH_CHANGE_TENSION_TIMER } from "../../consts";
import { HEALTH_CHANGE_TENSION_TIMER_MS } from "../../consts";
import { first, skip, Subscription } from "rxjs";
import Logger from "../../log";
import { TiledSpriteAnimated } from "../../utils/tiledspriteanimated";
Expand Down Expand Up @@ -97,7 +97,7 @@ export abstract class PlayableEntity<
this.healthSub = this.wormIdent.health$.pipe(skip(1)).subscribe((h) => {
this.healthTarget = h;
// TODO: Potentially further delay until the player has stopped moving.
this.healthChangeTensionTimer = HEALTH_CHANGE_TENSION_TIMER;
this.healthChangeTensionTimer = HEALTH_CHANGE_TENSION_TIMER_MS;
});

this.nameText.position.set(0, -5);
Expand Down Expand Up @@ -180,7 +180,7 @@ export abstract class PlayableEntity<

// Only decrease the timer when we have come to a standstill.
if (this.healthChangeTensionTimer && this.canReduceHealthTimer) {
this.healthChangeTensionTimer -= dt;
this.healthChangeTensionTimer -= dMs;
}

// If the timer has run out, set to null to indiciate it has expired.
Expand All @@ -206,7 +206,7 @@ export abstract class PlayableEntity<

// If we are dead, set a new timer to decrease to explode after a small delay.
if (this.visibleHealth === 0) {
this.healthChangeTensionTimer = HEALTH_CHANGE_TENSION_TIMER;
this.healthChangeTensionTimer = HEALTH_CHANGE_TENSION_TIMER_MS;
}
}
}
Expand Down
40 changes: 24 additions & 16 deletions src/entities/playable/worm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ export interface WormRecordedState extends PlayableRecordedState {
facingRight: boolean;
}

const FRICTION_WHEN_ACTIVE = 0.075;
const FRICTION_WHEN_IDLE = 0.125;

/**
* Physical representation of a worm on the map. May be controlled.
*/
Expand All @@ -105,25 +108,25 @@ export class Worm extends PlayableEntity<WormRecordedState> {
Worm.springArrow = assets.textures.spring;
}

private static springArrow: Texture;
private static texture: Texture;
// TODO: Best place for this var?
private arrowSprite: TiledSpriteAnimated;
private currentWeapon: IWeaponDefinition = WeaponBazooka;
private impactVelocity = 0;
private perRoundState: PerRoundState = { ...DEFAULT_PER_ROUND_STATE };
private static idleAnim: Texture;
private static impactDamageMultiplier = 0.75;
private static minImpactForDamage = 12;
protected fireWeaponDuration = 0;
private currentWeapon: IWeaponDefinition = WeaponBazooka;
protected state = new WormState(InnerWormState.Inactive);
private static springArrow: Texture;
private static texture: Texture;
private turnEndedReason: EndTurnReason | undefined;
private impactVelocity = 0;
// TODO: Best place for this var?
private weaponSprite: Sprite;
private weaponTimerSecs = 3;
public fireAngle = 0;
protected targettingGfx: Graphics;
protected facingRight = true;
private perRoundState: PerRoundState = { ...DEFAULT_PER_ROUND_STATE };
private weaponSprite: Sprite;
private arrowSprite: TiledSpriteAnimated;
protected fireWeaponDuration = 0;
protected motionTween?: TweenEngine;
protected state = new WormState(InnerWormState.Inactive);
protected targettingGfx: Graphics;
public fireAngle = 0;

get itemPlacementPosition() {
const trans = this.body.translation();
Expand Down Expand Up @@ -214,7 +217,7 @@ export class Worm extends PlayableEntity<WormRecordedState> {
.setActiveEvents(ActiveEvents.COLLISION_EVENTS)
.setCollisionGroups(Worm.collisionBitmask)
.setSolverGroups(Worm.collisionBitmask)
.setFriction(0.025)
.setFriction(FRICTION_WHEN_IDLE)
.setRestitution(0.65),
RigidBodyDesc.dynamic()
.setTranslation(position.worldX, position.worldY)
Expand Down Expand Up @@ -285,6 +288,7 @@ export class Worm extends PlayableEntity<WormRecordedState> {
teamGroupToColorSet(this.wormIdent.team.group).fg,
true,
);
this.collider.setFriction(FRICTION_WHEN_ACTIVE);
this.state.transition(InnerWormState.Idle);
this.cameraLockPriority = CameraLockPriority.SuggestedLockLocal;
this.perRoundState = { ...DEFAULT_PER_ROUND_STATE };
Expand Down Expand Up @@ -321,7 +325,7 @@ export class Worm extends PlayableEntity<WormRecordedState> {
3000,
);
}

this.collider.setFriction(FRICTION_WHEN_IDLE);
this.state.transition(InnerWormState.Inactive);
Controller.removeListener("inputBegin", this.onInputBegin);
Controller.removeListener("inputEnd", this.onInputEnd);
Expand Down Expand Up @@ -533,7 +537,7 @@ export class Worm extends PlayableEntity<WormRecordedState> {
radius: MetersValue,
opts: OnDamageOpts,
): void {
logger.info("onDamage");
this.collider.setFriction(FRICTION_WHEN_ACTIVE);
super.onDamage(point, radius, opts);
if (this.state.isPlaying) {
this.state.transition(InnerWormState.Inactive);
Expand Down Expand Up @@ -684,7 +688,7 @@ export class Worm extends PlayableEntity<WormRecordedState> {
}
(this.sprite as TiledSpriteAnimated).update(dMs);
this.wireframe.setDebugText(
`worm_state: ${this.state.stateName}, velocity: ${this.body.linvel().y} ${this.impactVelocity}, aim: ${this.fireAngle}`,
`worm_state: ${this.state.stateName}, velocity: ${this.body.linvel().y} ${this.impactVelocity}, aim: ${this.fireAngle}, friction: ${this.collider.friction()}`,
);
this.weaponSprite.visible = this.state.showWeapon;
this.arrowSprite.visible = this.state.canMove && !this.hasPerformedAction;
Expand All @@ -694,6 +698,10 @@ export class Worm extends PlayableEntity<WormRecordedState> {
this.arrowSprite.x = this.sprite.x;
this.arrowSprite.y = this.healthTextBox.y - 25;
}
if (!this.state.active && !this.body.isMoving()) {
this.collider.setFriction(FRICTION_WHEN_IDLE);
}

if (!this.state.shouldUpdate) {
// Do nothing.
return;
Expand Down
27 changes: 14 additions & 13 deletions src/logic/gamestate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
BehaviorSubject,
combineLatest,
distinctUntilChanged,
filter,
map,
merge,
skip,
Expand Down Expand Up @@ -178,19 +179,18 @@ export class GameState {
this.remainingRoundTimeSeconds$,
this.roundState$,
this.world.entitiesMoving$,
]).subscribe(([seconds, roundState, moving]) => {
if (seconds) {
return;
}
console.log({ seconds, roundState, moving });
if (roundState === RoundState.Preround) {
logger.info("Moving round to playing");
this.playerMoved();
} else if (roundState === RoundState.Playing) {
console.log("Moving round to finished");
this.roundState.next(RoundState.Finished);
}
});
])
.pipe(filter(([seconds]) => seconds === 0))
.subscribe(([seconds, roundState, moving]) => {
logger.info("State accumulator", seconds, roundState, moving);
if (roundState === RoundState.Preround) {
logger.info("Moving round to playing");
this.playerMoved();
} else if (roundState === RoundState.Playing) {
logger.info("Moving round to finished");
this.roundState.next(RoundState.Finished);
}
});
}

public pauseTimer() {
Expand Down Expand Up @@ -228,6 +228,7 @@ export class GameState {
}

public markAsFinished() {
logger.info("Mark as finished");
this.roundState.next(RoundState.Finished);
}

Expand Down
12 changes: 7 additions & 5 deletions src/net/netGameState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,12 @@ export class NetGameState extends GameState {
return;
}

if (roundState === RoundState.Preround) {
this.playerMoved();
} else {
this.roundState.next(RoundState.Finished);
}
// if (roundState === RoundState.Preround) {
// console.log("Setting moved");
// this.playerMoved();
// } else {
// console.log("Setting finished")
// this.roundState.next(RoundState.Finished);
// }
}
}
6 changes: 3 additions & 3 deletions src/overlays/gameStateOverlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { teamGroupToColorSet } from "../logic/teams";
import { GameWorld } from "../world";
import { Toaster } from "./toaster";
import { WindDial } from "./windDial";
import { HEALTH_CHANGE_TENSION_TIMER } from "../consts";
import { HEALTH_CHANGE_TENSION_TIMER_MS } from "../consts";
import Logger from "../log";
import { combineLatest, delay, first, map, Observable } from "rxjs";
import { combineLatest, debounceTime, first, map, Observable } from "rxjs";
import { RoundTimer } from "./roundTimer";

const logger = new Logger("GameStateOverlay");
Expand Down Expand Up @@ -94,7 +94,7 @@ export class GameStateOverlay {
this.gfx.position.set(width / 2, (height / 10) * 8.75);
});
this.gameWorld.entitiesMoving$
.pipe(delay(HEALTH_CHANGE_TENSION_TIMER))
.pipe(debounceTime(HEALTH_CHANGE_TENSION_TIMER_MS))
.subscribe((f) => {
this.shouldChangeTeamHealth = f;
});
Expand Down
6 changes: 4 additions & 2 deletions src/overlays/roundTimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ export class RoundTimer {
align: "center",
},
});
const { width, height } = text;
this.container = new Container();
this.container.addChild(this.gfx);
this.container.addChild(text);

this.roundTimeRemaining.subscribe((timeSeconds) => {
text.text = timeSeconds === 0 ? "--" : timeSeconds;
text.text =
timeSeconds === 0 ? "--" : timeSeconds.toString().padStart(2, "0");
});

this.currentTeamColors.subscribe((color) => {
this.gfx.clear();
// Round timer
applyGenericBoxStyle(this.gfx, color?.fg)
.roundRect(-8, 8, text.width + 16, text.height, 4)
.roundRect(-8, 8, width + 16, height, 4)
.stroke()
.fill();
});
Expand Down
7 changes: 6 additions & 1 deletion src/scenarios/netGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,12 @@ export default async function runScenario(game: Game) {
) {
world.setBroadcasting(false);
}
log.info("Round state sub fired for", roundState, worm, entsMoving);
log.info(
"GameState Round state sub fired for",
roundState,
worm,
entsMoving,
);
if (
worm === undefined &&
roundState === RoundState.Finished &&
Expand Down

0 comments on commit ff2e3d5

Please sign in to comment.