Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Server Import Paths for Common Code #361

Closed
wants to merge 6 commits into from
Closed
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
40 changes: 40 additions & 0 deletions common/src/definitions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Ammos } from "./ammos";
import { Armors, ArmorType, type ArmorDefinition } from "./armors";
import { Backpacks } from "./backpacks";
import { Badges, type BadgeDefinition } from "./badges";
import { Buildings } from "./buildings";
import { Bullets } from "./bullets";
import { Decals } from "./decals";
import { Emotes, type EmoteDefinition } from "./emotes";
import { Explosions } from "./explosions";
import { Guns, type GunDefinition } from "./guns";
import { HealingItems } from "./healingItems";
import { Loots, type LootDefinition, type WeaponDefinition } from "./loots";
import { PlayerPing } from "./mapPings";
import { Melees, type MeleeDefinition } from "./melees";
import { DEFAULT_SCOPE, ScopeDefinition, Scopes } from "./scopes";
import { SkinDefinition, Skins } from "./skins";
import { SyncedParticleDefinition } from "./syncedParticles";
import { Throwables, ThrowableDefinition } from "./throwables";

export {
Ammos,
Armors, ArmorType, ArmorDefinition,
Backpacks,
Badges, BadgeDefinition,
Buildings,
Bullets,
Decals,
Emotes, EmoteDefinition,
Explosions,
Guns, GunDefinition,
HealingItems,
Loots, LootDefinition, WeaponDefinition,
PlayerPing,
Melees, MeleeDefinition,
DEFAULT_SCOPE, Scopes, ScopeDefinition,
SkinDefinition,
SyncedParticleDefinition,
Throwables, ThrowableDefinition,
Skins
}

Check failure on line 40 in common/src/definitions/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing semicolon
33 changes: 33 additions & 0 deletions common/src/packets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { type DisconnectData, DisconnectPacket } from "./disconnectPacket";
import { GameOverData, GameOverPacket } from "./gameOverPacket";
import { SimpleInputActions, InputAction, PlayerInputData, PlayerInputPacket, NoMobile } from "./inputPacket";
import { JoinedPacketData, JoinedPacket } from "./joinedPacket";
import { JoinPacketData, JoinPacket } from "./joinPacket";
import { KillFeedPacketData, KillFeedPacket, ForEventType } from "./killFeedPacket";
import { MapPacketData, MapPacket } from "./mapPacket";
import { PacketTemplate, Packet, InputPacket, OutputPacket } from "./packet";
import { PacketStream } from "./packetStream";
import { PickupPacketData, PickupPacket } from "./pickupPacket";
import { PingPacket } from "./pingPacket";
import { ReportPacketData, ReportPacket } from "./reportPacket";
import { SpectatePacketData, SpectatePacket } from "./spectatePacket";
import { PlayerData, UpdatePacket, UpdatePacketDataCommon, UpdatePacketDataIn } from "./updatePacket";


Check failure on line 16 in common/src/packets/index.ts

View workflow job for this annotation

GitHub Actions / Lint

More than 1 blank line not allowed
export {
DisconnectData, DisconnectPacket,
GameOverData, GameOverPacket,
SimpleInputActions, InputAction, PlayerInputData, PlayerInputPacket,
JoinedPacketData, JoinedPacket,
JoinPacketData, JoinPacket,
KillFeedPacketData, KillFeedPacket, ForEventType,
MapPacketData, MapPacket,
PacketTemplate, Packet, InputPacket, OutputPacket, NoMobile,
PacketStream,
PickupPacketData, PickupPacket,
PingPacket,
ReportPacketData, ReportPacket,
SpectatePacketData, SpectatePacket,
UpdatePacket, UpdatePacketDataIn, UpdatePacketDataCommon, PlayerData,

Check failure on line 31 in common/src/packets/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected trailing comma

Check failure on line 32 in common/src/packets/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
}

Check failure on line 33 in common/src/packets/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing semicolon
45 changes: 45 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
"private": true,
"main": "index.js",
"scripts": {
"build": "tsc",
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
"start": "node dist/server/src/server.js",
"moderation": "node dist/server/src/moderation.js",
"validateDefinitions": "node dist/server/src/validateDefinitions.js",
"dev": "node -r ts-node/register --watch --watch-path=./src --watch-path=../common src/server.ts",
"dev:test": "tsc && node --enable-source-maps dist/server/src/stressTest.js"
"dev:test": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json && node --enable-source-maps dist/server/src/stressTest.js"
},
"keywords": [],
"license": "GPL-3.0",
"devDependencies": {
"@types/node": "^20.12.12",
"@types/sanitize-html": "^2.11.0",
"@types/ws": "^8.5.10",
"tsc-alias": "^1.8.10",
"typescript": "^5.4.5"
},
"dependencies": {
Expand Down
5 changes: 3 additions & 2 deletions server/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TeamSize } from "../../common/src/constants";
import { type Vector } from "../../common/src/utils/vector";
import { TeamSize } from "@common/constants";
import { type Vector } from "@common/utils/vector";

import { type Maps } from "./data/maps";
import { type Game } from "./game";
import { type GamePlugin } from "./pluginManager";
Expand Down Expand Up @@ -38,7 +39,7 @@

censorUsernames: true,

maxTeamSize: TeamSize.Solo,

Check failure on line 42 in server/src/config.ts

View workflow job for this annotation

GitHub Actions / Lint

Unsafe assignment of an error typed value

Check failure on line 42 in server/src/config.ts

View workflow job for this annotation

GitHub Actions / Lint

Unsafe member access .Solo on an `any` value

roles: {
"developr": { password: "developr", isDev: true },
Expand Down Expand Up @@ -138,7 +139,7 @@
* specifying a cron pattern and an array of team sizes
* allows for team sizes to change periodically
*/
readonly maxTeamSize: TeamSize | {

Check failure on line 142 in server/src/config.ts

View workflow job for this annotation

GitHub Actions / Lint

'any' overrides all other types in this union type
/**
* The duration between switches. Must be a cron pattern.
*/
Expand Down
2 changes: 1 addition & 1 deletion server/src/data/gasStages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GasState } from "../../../common/src/constants";
import { GasState } from "@common/constants";

export interface GasStage {
readonly state: GasState
Expand All @@ -11,7 +11,7 @@

export const GasStages: GasStage[] = [
{
state: GasState.Inactive,

Check failure on line 14 in server/src/data/gasStages.ts

View workflow job for this annotation

GitHub Actions / Lint

Unsafe assignment of an error typed value

Check failure on line 14 in server/src/data/gasStages.ts

View workflow job for this annotation

GitHub Actions / Lint

Unsafe member access .Inactive on an `any` value
duration: 0,
oldRadius: 0.762,
newRadius: 0.762,
Expand Down
4 changes: 2 additions & 2 deletions server/src/data/lootTables.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type LootDefinition } from "../../../common/src/definitions/loots";
import { type ReferenceTo } from "../../../common/src/utils/objectDefinitions";
import { type LootDefinition } from "@common/definitions/loots";
import { type ReferenceTo } from "@common/utils/objectDefinitions";

export type WeightedItem =
(
Expand Down
18 changes: 10 additions & 8 deletions server/src/data/maps.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { type WebSocket } from "uWebSockets.js";
import { Buildings, type BuildingDefinition } from "../../../common/src/definitions/buildings";
import { Loots } from "../../../common/src/definitions/loots";
import { Obstacles, type ObstacleDefinition } from "../../../common/src/definitions/obstacles";
import { type Variation } from "../../../common/src/typings";
import { Collision } from "../../../common/src/utils/math";
import { ItemType, type ReferenceTo } from "../../../common/src/utils/objectDefinitions";
import { random } from "../../../common/src/utils/random";
import { Vec, type Vector } from "../../../common/src/utils/vector";

import { Buildings, type BuildingDefinition } from "@common/definitions/buildings";
import { Loots } from "@common/definitions/loots";
import { Obstacles, type ObstacleDefinition } from "@common/definitions/obstacles";
import { type Variation } from "@common/typings";
import { Collision } from "@common/utils/math";
import { ItemType, type ReferenceTo } from "@common/utils/objectDefinitions";
import { random } from "@common/utils/random";
import { Vec, type Vector } from "@common/utils/vector";

import { type GunItem } from "../inventory/gunItem";
import { type GameMap } from "../map";
import { Player, type PlayerContainer } from "../objects/player";
Expand Down
13 changes: 7 additions & 6 deletions server/src/defaultPlugins/placeObjectPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { type ObstacleDefinition } from "../../../common/src/definitions/obstacles";
import { Orientation } from "../../../common/src/typings";
import { ColorStyles, styleText } from "../../../common/src/utils/ansiColoring";
import { ExtendedMap } from "../../../common/src/utils/misc";
import { type ReferenceTo } from "../../../common/src/utils/objectDefinitions";
import { Vec } from "../../../common/src/utils/vector";
import { type ObstacleDefinition } from "@common/definitions/obstacles";
import { Orientation } from "@common/typings";
import { ColorStyles, styleText } from "@common/utils/ansiColoring";
import { ExtendedMap } from "@common/utils/misc";
import { type ReferenceTo } from "@common/utils/objectDefinitions";
import { Vec } from "@common/utils/vector";

import { Obstacle } from "../objects/obstacle";
import { Player } from "../objects/player";
import { Events, GamePlugin } from "../pluginManager";
Expand Down
3 changes: 2 additions & 1 deletion server/src/defaultPlugins/teleportPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Vec } from "../../../common/src/utils/vector";
import { Vec } from "@common/utils/vector";

import { Events, GamePlugin } from "../pluginManager";

/**
Expand Down
11 changes: 6 additions & 5 deletions server/src/defaultPlugins/weaponSwapPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { GunDefinition, Guns } from "../../../common/src/definitions/guns";
import { MeleeDefinition, Melees } from "../../../common/src/definitions/melees";
import { ThrowableDefinition, Throwables } from "../../../common/src/definitions/throwables";
import { ItemType } from "../../../common/src/utils/objectDefinitions";
import { pickRandomInArray } from "../../../common/src/utils/random";
import { GunDefinition, Guns } from "@common/definitions/guns";
import { MeleeDefinition, Melees } from "@common/definitions/melees";
import { ThrowableDefinition, Throwables } from "@common/definitions/throwables";
import { ItemType } from "@common/utils/objectDefinitions";
import { pickRandomInArray } from "@common/utils/random";

import { GunItem } from "../inventory/gunItem";
import { Player } from "../objects/player";
import { Events, GamePlugin } from "../pluginManager";
Expand Down
48 changes: 25 additions & 23 deletions server/src/game.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
import { type TemplatedApp, type WebSocket } from "uWebSockets.js";
import { isMainThread, parentPort, workerData } from "worker_threads";
import { GameConstants, KillfeedMessageType, ObjectCategory, TeamSize } from "../../common/src/constants";
import { type ExplosionDefinition } from "../../common/src/definitions/explosions";
import { type LootDefinition } from "../../common/src/definitions/loots";
import { MapPings, type MapPing } from "../../common/src/definitions/mapPings";
import { Obstacles, type ObstacleDefinition } from "../../common/src/definitions/obstacles";
import { SyncedParticles, type SyncedParticleDefinition, type SyncedParticleSpawnerDefinition } from "../../common/src/definitions/syncedParticles";
import { type ThrowableDefinition } from "../../common/src/definitions/throwables";
import { PlayerInputPacket } from "../../common/src/packets/inputPacket";
import { JoinPacket, type JoinPacketData } from "../../common/src/packets/joinPacket";
import { JoinedPacket } from "../../common/src/packets/joinedPacket";
import { KillFeedPacket, type KillFeedPacketData } from "../../common/src/packets/killFeedPacket";
import { type InputPacket, type OutputPacket } from "../../common/src/packets/packet";
import { PacketStream } from "../../common/src/packets/packetStream";
import { PingPacket } from "../../common/src/packets/pingPacket";
import { SpectatePacket } from "../../common/src/packets/spectatePacket";
import { type PingSerialization } from "../../common/src/packets/updatePacket";
import { CircleHitbox, type Hitbox } from "../../common/src/utils/hitbox";
import { EaseFunctions, Geometry, Numeric } from "../../common/src/utils/math";
import { Timeout } from "../../common/src/utils/misc";
import { ItemType, MapObjectSpawnMode, type ReifiableDef } from "../../common/src/utils/objectDefinitions";
import { pickRandomInArray, randomFloat, randomPointInsideCircle, randomRotation } from "../../common/src/utils/random";
import { OBJECT_ID_BITS, SuroiBitStream } from "../../common/src/utils/suroiBitStream";
import { Vec, type Vector } from "../../common/src/utils/vector";

import { GameConstants, KillfeedMessageType, ObjectCategory, TeamSize } from "@common/constants";
import { type ExplosionDefinition } from "@common/definitions/explosions";
import { type LootDefinition } from "@common/definitions/loots";
import { MapPings, type MapPing } from "@common/definitions/mapPings";
import { Obstacles, type ObstacleDefinition } from "@common/definitions/obstacles";
import { SyncedParticles, type SyncedParticleDefinition, type SyncedParticleSpawnerDefinition } from "@common/definitions/syncedParticles";
import { type ThrowableDefinition } from "@common/definitions/throwables";
import { PlayerInputPacket } from "@common/packets/inputPacket";
import { JoinPacket, type JoinPacketData } from "@common/packets/joinPacket";
import { JoinedPacket } from "@common/packets/joinedPacket";
import { KillFeedPacket, type KillFeedPacketData } from "@common/packets/killFeedPacket";
import { type InputPacket, type OutputPacket } from "@common/packets/packet";
import { PacketStream } from "@common/packets/packetStream";
import { PingPacket } from "@common/packets/pingPacket";
import { SpectatePacket } from "@common/packets/spectatePacket";
import { type PingSerialization } from "@common/packets/updatePacket";
import { CircleHitbox, type Hitbox } from "@common/utils/hitbox";
import { EaseFunctions, Geometry, Numeric } from "@common/utils/math";
import { Timeout } from "@common/utils/misc";
import { ItemType, MapObjectSpawnMode, type ReifiableDef } from "@common/utils/objectDefinitions";
import { pickRandomInArray, randomFloat, randomPointInsideCircle, randomRotation } from "@common/utils/random";
import { OBJECT_ID_BITS, SuroiBitStream } from "@common/utils/suroiBitStream";
import { Vec, type Vector } from "@common/utils/vector";

import { Config, SpawnMode } from "./config";
import { Maps } from "./data/maps";
import { WorkerMessages, type GameData, type WorkerInitData, type WorkerMessage } from "./gameManager";
Expand Down
4 changes: 3 additions & 1 deletion server/src/gameManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import path from "node:path";
import { Worker } from "node:worker_threads";
import { type GetGameResponse } from "../../common/src/typings";

import { type GetGameResponse } from "@common/typings";

import { Config } from "./config";
import { maxTeamSize } from "./server";
import { Logger } from "./utils/misc";
Expand Down
13 changes: 7 additions & 6 deletions server/src/gas.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { GasState } from "../../common/src/constants";
import { CircleHitbox } from "../../common/src/utils/hitbox";
import { Geometry, Numeric } from "../../common/src/utils/math";
import { MapObjectSpawnMode } from "../../common/src/utils/objectDefinitions";
import { randomBoolean, randomPointInsideCircle } from "../../common/src/utils/random";
import { Vec, type Vector } from "../../common/src/utils/vector";
import { GasState } from "@common/constants";
import { CircleHitbox } from "@common/utils/hitbox";
import { Geometry, Numeric } from "@common/utils/math";
import { MapObjectSpawnMode } from "@common/utils/objectDefinitions";
import { randomBoolean, randomPointInsideCircle } from "@common/utils/random";
import { Vec, type Vector } from "@common/utils/vector";

import { Config, GasMode } from "./config";
import { GasStages } from "./data/gasStages";
import { type Game } from "./game";
Expand Down
Loading
Loading