Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

jobs:
build:
name: build-main-pipeline
runs-on: ubuntu-latest

steps:
Expand Down
21 changes: 19 additions & 2 deletions packages/frontend/src/game/hooks/useRespawn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,32 @@ import React from "react";
import { useFrame } from "@react-three/fiber";
import { dispatch, GamePlayerState, getPlayerId } from "../utils/geckos/geckos";
import { PlayerActions, WeaponActions } from "@fps/lib";
import type { Camera, Vector3 } from "three";
import type { Capsule } from "three-stdlib";

interface RespawnProps {
camera: Camera;
capsule: React.MutableRefObject<Capsule>;
playerStateRef: React.MutableRefObject<GamePlayerState>;
playerVelocity: React.MutableRefObject<Vector3>;
wasAliveRef: React.MutableRefObject<boolean>;
}

export const useRespawn = (props: RespawnProps) => {
const { playerStateRef } = props;
const { camera, capsule, playerStateRef, playerVelocity, wasAliveRef } = props;

useFrame(() => {
const isAlive = playerStateRef.current.isAlive;
if (!wasAliveRef.current && isAlive) {
const pos = playerStateRef.current.position;
capsule.current.start.set(pos.x, pos.y, pos.z);
capsule.current.end.set(pos.x, pos.y, pos.z);
camera.position.set(pos.x, pos.y, pos.z);
camera.quaternion.copy(playerStateRef.current.direction);
playerVelocity.current.set(0, 0, 0);
}
wasAliveRef.current = isAlive;

const [gamepad] = navigator.getGamepads();
if (gamepad == null) return;

Expand All @@ -21,7 +38,7 @@ export const useRespawn = (props: RespawnProps) => {
}),
);

// TODO: Update initial spawn to select gun via select class https://app.clickup.com/t/86b5r3rjy
// TODO: Update initial spawn to select gun via select a class https://app.clickup.com/t/86b5r3rjy
if (playerStateRef.current.currentWeapon === null) {
dispatch(
WeaponActions.assignToPlayer({ playerId: getPlayerId(), weapon: "Saiga" }),
Expand Down
22 changes: 6 additions & 16 deletions packages/frontend/src/game/player/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useControls } from "./hooks/useControls";
import { useCameraMotion } from "../hooks/useCameraMotion";
import { useCanPlayerRise } from "./hooks/useCanPlayerRise";
import { useDeleteWeapons } from "./hooks/useDeleteWeapons";
import { useFrame, useThree } from "@react-three/fiber";
import { useThree } from "@react-three/fiber";
import { useHitDetection } from "../hooks/useHitDetection";
import { useRegen } from "./hooks/useRegen";
import { useReload } from "./hooks/useReload";
Expand Down Expand Up @@ -39,24 +39,10 @@ export const Player: React.FC<PlayerProps> = (props) => {
const { camera } = useThree(); // Single camera is shared between hooks
const playerOnFloor = React.useRef(false);
const playerVelocity = React.useRef(new Vector3());
const playerDirection = React.useRef(new Vector3()); // TODO: Remove this and jsut use GamePlayerState https://app.clickup.com/t/86b5v1h2p
const playerDirection = React.useRef(new Vector3()); // TODO: Remove this and just use GamePlayerState https://app.clickup.com/t/86b5v1h2p
const capsule = React.useRef(new Capsule(new Vector3(0, 10, 0), new Vector3(0, 11, 0), 0.5));
const wasAliveRef = React.useRef(playerStateRef.current.isAlive);

// TODO: Move to own hook (or maybe just useRespawn?) https://app.clickup.com/t/86b5v1hxh
useFrame(() => {
const isAlive = playerStateRef.current.isAlive;
if (!wasAliveRef.current && isAlive) {
const pos = playerStateRef.current.position;
capsule.current.start.set(pos.x, pos.y, pos.z);
capsule.current.end.set(pos.x, pos.y, pos.z);
camera.position.set(pos.x, pos.y, pos.z);
camera.quaternion.copy(playerStateRef.current.direction);
playerVelocity.current.set(0, 0, 0);
}
wasAliveRef.current = isAlive;
});

// Handles hit detection
useHitDetection({
gameStateRef,
Expand All @@ -67,7 +53,11 @@ export const Player: React.FC<PlayerProps> = (props) => {

// Handles respawning logic
useRespawn({
camera,
capsule,
playerStateRef,
playerVelocity,
wasAliveRef,
});

// Handles Cannot stand / crouch here messages
Expand Down